Improve clarity of diff-multi message
authorJackmcbarn <jackmcbarn@gmail.com>
Wed, 8 Jan 2014 20:29:42 +0000 (15:29 -0500)
committerJackmcbarn <jackmcbarn@gmail.com>
Thu, 9 Jan 2014 15:10:35 +0000 (10:10 -0500)
When one user has made all of the intermediate revisions in a diff,
make it clear whether or not this is the same user that made the
latest revision.

Bug: 59833
Change-Id: I7db9a02ae8bc7a8e092fcdc257b5e17595de02b4

includes/Title.php
includes/diff/DifferenceEngine.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 096a04d..a41602f 100644 (file)
@@ -4376,9 +4376,11 @@ class Title {
        }
 
        /**
-        * Get the number of authors between the given revisions or revision IDs.
+        * Get the authors between the given revisions or revision IDs.
         * Used for diffs and other things that really need it.
         *
+        * @since 1.23
+        *
         * @param int|Revision $old Old revision or rev ID (first before range by default)
         * @param int|Revision $new New revision or rev ID (first after range by default)
         * @param int $limit Maximum number of authors
@@ -4387,9 +4389,9 @@ class Title {
         *     'include_new' Include $new in the range; $old is excluded.
         *     'include_both' Include both $old and $new in the range.
         *     Unknown option values are ignored.
-        * @return int Number of revision authors in the range; zero if not both revisions exist
+        * @return array|null Names of revision authors in the range; null if not both revisions exist
         */
-       public function countAuthorsBetween( $old, $new, $limit, $options = array() ) {
+       public function getAuthorsBetween( $old, $new, $limit, $options = array() ) {
                if ( !( $old instanceof Revision ) ) {
                        $old = Revision::newFromTitle( $this, (int)$old );
                }
@@ -4400,8 +4402,9 @@ class Title {
                // Add $old->getPage() != $new->getPage() || $old->getPage() != $this->getArticleID()
                // in the sanity check below?
                if ( !$old || !$new ) {
-                       return 0; // nothing to compare
+                       return null; // nothing to compare
                }
+               $authors = array();
                $old_cmp = '>';
                $new_cmp = '<';
                $options = (array)$options;
@@ -4417,12 +4420,19 @@ class Title {
                }
                // No DB query needed if $old and $new are the same or successive revisions:
                if ( $old->getId() === $new->getId() ) {
-                       return ( $old_cmp === '>' && $new_cmp === '<' ) ? 0 : 1;
+                       return ( $old_cmp === '>' && $new_cmp === '<' ) ? array() : array( $old->getRawUserText() );
                } elseif ( $old->getId() === $new->getParentId() ) {
-                       if ( $old_cmp === '>' || $new_cmp === '<' ) {
-                               return ( $old_cmp === '>' && $new_cmp === '<' ) ? 0 : 1;
+                       if ( $old_cmp === '>=' && $new_cmp === '<=' ) {
+                               $authors[] = $old->getRawUserText();
+                               if ( $old->getRawUserText() != $new->getRawUserText() ) {
+                                       $authors[] = $new->getRawUserText();
+                               }
+                       } elseif ( $old_cmp === '>=' ) {
+                               $authors[] = $old->getRawUserText();
+                       } elseif ( $new_cmp === '<=' ) {
+                               $authors[] = $new->getRawUserText();
                        }
-                       return ( $old->getRawUserText() === $new->getRawUserText() ) ? 1 : 2;
+                       return $authors;
                }
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'revision', 'DISTINCT rev_user_text',
@@ -4433,7 +4443,29 @@ class Title {
                        ), __METHOD__,
                        array( 'LIMIT' => $limit + 1 ) // add one so caller knows it was truncated
                );
-               return (int)$dbr->numRows( $res );
+               foreach ( $res as $row ) {
+                       $authors[] = $row->rev_user_text;
+               }
+               return $authors;
+       }
+
+       /**
+        * Get the number of authors between the given revisions or revision IDs.
+        * Used for diffs and other things that really need it.
+        *
+        * @param int|Revision $old Old revision or rev ID (first before range by default)
+        * @param int|Revision $new New revision or rev ID (first after range by default)
+        * @param int $limit Maximum number of authors
+        * @param string|array $options (Optional): Single option, or an array of options:
+        *     'include_old' Include $old in the range; $new is excluded.
+        *     'include_new' Include $new in the range; $old is excluded.
+        *     'include_both' Include both $old and $new in the range.
+        *     Unknown option values are ignored.
+        * @return int Number of revision authors in the range; zero if not both revisions exist
+        */
+       public function countAuthorsBetween( $old, $new, $limit, $options = array() ) {
+               $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
+               return $authors ? count( $authors ) : 0;
        }
 
        /**
index b7601e9..f4551e6 100644 (file)
@@ -963,7 +963,11 @@ class DifferenceEngine extends ContextSource {
                $nEdits = $this->mNewPage->countRevisionsBetween( $oldRev, $newRev );
                if ( $nEdits > 0 ) {
                        $limit = 100; // use diff-multi-manyusers if too many users
-                       $numUsers = $this->mNewPage->countAuthorsBetween( $oldRev, $newRev, $limit );
+                       $users = $this->mNewPage->getAuthorsBetween( $oldRev, $newRev, $limit );
+                       $numUsers = count( $users );
+                       if( $numUsers == 1 && $users[0] == $newRev->getRawUserText() ) {
+                               $numUsers = 0; // special case to say "by the same user" instead of "by one other user"
+                       }
 
                        return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
                }
@@ -979,11 +983,13 @@ class DifferenceEngine extends ContextSource {
         * @return string
         */
        public static function intermediateEditsMsg( $numEdits, $numUsers, $limit ) {
-               if ( $numUsers > $limit ) {
+               if ( $numUsers === 0 ) {
+                       $msg = 'diff-multi-sameuser';
+               } elseif ( $numUsers > $limit ) {
                        $msg = 'diff-multi-manyusers';
                        $numUsers = $limit;
                } else {
-                       $msg = 'diff-multi';
+                       $msg = 'diff-multi-otherusers';
                }
 
                return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
index 2a10a78..9b888ca 100644 (file)
@@ -1798,7 +1798,8 @@ Note that using the navigation links will reset this column.',
 'showhideselectedversions'    => 'Change visibility of selected revisions',
 'editundo'                    => 'undo',
 'diff-empty'                  => '(No difference)',
-'diff-multi'                  => '({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} by {{PLURAL:$2|one user|$2 users}} not shown)',
+'diff-multi-sameuser'         => '({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} by the same user not shown)',
+'diff-multi-otherusers'       => '({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} by {{PLURAL:$2|one other user|$2 users}} not shown)',
 'diff-multi-manyusers'        => '({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} by more than $2 {{PLURAL:$2|user|users}} not shown)',
 'difference-missing-revision' => '{{PLURAL:$2|One revision|$2 revisions}} of this difference ($1) {{PLURAL:$2|was|were}} not found.
 
index 327c183..6497275 100644 (file)
@@ -2758,12 +2758,20 @@ See also:
 This message has sometimes a tooltip {{msg-mw|tooltip-undo}}
 {{Identical|Undo}}',
 'diff-empty' => 'This message appears instead of a "diff" when comparing two revisions that are identical.',
-'diff-multi' => "This message appears in the revision history of a page when comparing two versions which aren't consecutive.
+'diff-multi-sameuser' => "This message appears in the revision history of a page when comparing two versions which aren't consecutive, and the intermediate revisions were all created by the same user as the new revision.
 
 Parameters:
 * $1 - the number of revisions
-* $2 - the number of distinct users who made those revisions
 See also:
+* {{msg-mw|Diff-multi-otherusers}}
+* {{msg-mw|Diff-multi-manyusers}}",
+'diff-multi-otherusers' => "This message appears in the revision history of a page when comparing two versions which aren't consecutive, and at least one of the intermediate revisions was created by a user other than the user who created the new revision.
+
+Parameters:
+* $1 - the number of revisions
+* $2 - the number of distinct other users who made those revisions
+See also:
+* {{msg-mw|Diff-multi-sameuser}}
 * {{msg-mw|Diff-multi-manyusers}}",
 'diff-multi-manyusers' => "This message appears in the revision history of a page when comparing two versions which aren't consecutive, and the intermediate revisions have been edited by more than 100 users.
 
@@ -2771,7 +2779,8 @@ Parameters:
 * $1 - the number of revisions, will always be 101 or more
 * $2 - the number of users that were found, which was limited at 100
 See also:
-* {{msg-mw|Diff-multi}}",
+* {{msg-mw|Diff-multi-sameuser}}
+* {{msg-mw|Diff-multi-otherusers}}",
 'difference-missing-revision' => 'Text displayed when the requested revision does not exist using a diff link.
 
 Example: [{{canonicalurl:Project:News|diff=426850&oldid=99999999}} Diff with invalid revision#]
index aa8f5ed..c7365e8 100644 (file)
@@ -941,7 +941,8 @@ $wgMessageStructure = array(
                'showhideselectedversions',
                'editundo',
                'diff-empty',
-               'diff-multi',
+               'diff-multi-sameuser',
+               'diff-multi-otherusers',
                'diff-multi-manyusers',
                'difference-missing-revision',
        ),