Mattflaschen has uploaded a new change for review. https://gerrit.wikimedia.org/r/217984
Change subject: Separate logic for extracting usernames from picking the right one ...................................................................... Separate logic for extracting usernames from picking the right one Pull out the logic that extracts usernames from links. This allows it to be reused by the LQT->Flow import code. Bug: T101979 Change-Id: Ib16a09cf1f388f56944cd1bb564384535728156e --- M includes/DiscussionParser.php 1 file changed, 43 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/84/217984/1 diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php index 0e3f168..e9b9980 100644 --- a/includes/DiscussionParser.php +++ b/includes/DiscussionParser.php @@ -578,32 +578,28 @@ } /** - * From a line in a wiki page, determine which user, if any, - * has signed it. + * From a line in the signature, extract all the users linked to * - * @param $line string The line. - * @param Title $title - * @return bool|array false for none, Array for success. - * - First element is the position of the signature. - * - Second element is the normalised user name. + * @param string $line Line of text potentially including linked user, user talk, + * and contribution pages + * @return array Array of users; empty array for none detected */ - static public function getUserFromLine( $line, Title $title = null ) { - global $wgParser; - - // match all title-like excerpts in this line - if ( !preg_match_all( '/\[\[([^\[]+)\]\]/', $line, $matches ) ) { - return false; - } - + static public function extractUsersFromLine( $line ) { /* * Signatures can look like anything (as defined by i18n messages * "signature" & "signature-anon"). * A signature can, e.g., be both a link to user & user-talk page. - * I'll be looping backwards through all founds links, figure out what - * matches to a user, regenerate the signature based on that user, and - * see if it matches! + * */ - $matches = array_reverse( $matches[1] ); + // match all title-like excerpts in this line + if ( !preg_match_all( '/\[\[([^\[]+)\]\]/', $line, $matches ) ) { + return array(); + } + + $matches = $matches[1]; + + $usernames = array(); + foreach ( $matches as $match ) { /* * Create an object out of the link title. @@ -618,15 +614,41 @@ // figure out if we the link is related to a user if ( $title && ( $title->getNamespace() === NS_USER || $title->getNamespace() === NS_USER_TALK ) ) { - $username = $title->getText(); + $usernames[] = $title->getText(); } elseif ( $title && $title->isSpecial( 'Contributions' ) ) { $parts = explode( '/', $title->getText(), 2 ); - $username = end( $parts ); + $usernames[] = end( $parts ); } else { // move on to next matched title-like excerpt continue; } + } + return $usernames; + } + + /** + * From a line in a wiki page, determine which user, if any, + * has signed it. + * + * @param string $line The line. + * @param Title $title + * @return bool|array false for none, Array for success. + * - First element is the position of the signature. + * - Second element is the normalised user name. + */ + static public function getUserFromLine( $line, Title $title = null ) { + global $wgParser; + + /* + * First we call extractUsersFromLine to get all the potential usernames + * from the line. Then, we loop backwards through them, figure out which + * match to a user, regenera the signature based on that user, and + * see if it matches! + */ + $usernames = self::extractUsersFromLine( $line ); + $usernames = array_reverse( $usernames ); + foreach ( $usernames as $username ) { // generate (dateless) signature from the user we think we've // discovered the signature from // don't validate the username - anon (IP) is fine! -- To view, visit https://gerrit.wikimedia.org/r/217984 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib16a09cf1f388f56944cd1bb564384535728156e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits