userLookup = $userLookup; if ( !$this->userLookup ) { $this->userLookup = function ( User $user ) { return $user->getId(); }; } } /** * Returns a list of registered users linked in an edit summary * * @param string $summary * @return User[] Array of username => User object */ public function parse( $summary ) { // Remove section autocomments. Replace with characters that can't be in titles, // to prevent fun stuff like "[[foo /* section */ bar]]". $summary = preg_replace( '#/\*.*?\*/#', ' [] ', $summary ); $users = []; $regex = '/\[\[([' . Title::legalChars() . ']++)(?:\|.*?)?\]\]/'; if ( preg_match_all( $regex, $summary, $matches ) ) { foreach ( $matches[1] as $match ) { if ( $match[0] === ':' ) { continue; } $title = Title::newFromText( $match ); if ( $title && $title->isLocal() && $title->getNamespace() === NS_USER ) { $user = User::newFromName( $title->getText() ); $lookup = $this->userLookup; if ( $user && $lookup( $user ) > 0 ) { $users[$user->getName()] = $user; } } } } return $users; } }