Some improvements to Special:MergeHistory
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 10 Jun 2014 21:27:49 +0000 (14:27 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 10 Jun 2014 21:40:21 +0000 (21:40 +0000)
* Added a 5000 revision limit.
* Also fixed the radio-button selection to reflect the URL
  params so the "unmerge" log link works as expected.
* Added some TODO comments.

bug: 66155
Change-Id: Ib70e9d58ae2de723b965e52c679c4e786016420e

includes/specials/SpecialMergeHistory.php
languages/i18n/en.json
languages/i18n/qqq.json

index 097f1b6..a27cf4c 100644 (file)
@@ -283,7 +283,7 @@ class SpecialMergeHistory extends SpecialPage {
                $last = $this->message['last'];
 
                $ts = wfTimestamp( TS_MW, $row->rev_timestamp );
-               $checkBox = Xml::radio( 'mergepoint', $ts, false );
+               $checkBox = Xml::radio( 'mergepoint', $ts, ( $this->mTimestamp === $ts ) );
 
                $user = $this->getUser();
 
@@ -325,6 +325,18 @@ class SpecialMergeHistory extends SpecialPage {
                                ->rawParams( $checkBox, $last, $pageLink, $userLink, $stxt, $comment )->escaped() );
        }
 
+       /**
+        * Actually attempt the history move
+        *
+        * @todo: if all versions of page A are moved to B and then a user
+        * tries to do a reverse-merge via the "unmerge" log link, then page
+        * A will still be a redirect (as it was after the original merge),
+        * though it will have the old revisions back from before (as expected).
+        * The user may have to "undo" the redirect manually to finish the "unmerge".
+        * Maybe this should delete redirects at the target page of merges?
+        *
+        * @return boolean Success
+        */
        function merge() {
                # Get the titles directly from the IDs, in case the target page params
                # were spoofed. The queries are done based on the IDs, so it's best to
@@ -368,7 +380,7 @@ class SpecialMergeHistory extends SpecialPage {
 
                        return false;
                }
-               # Update the revisions
+               # Get the timestamp pivot condition
                if ( $this->mTimestamp ) {
                        $timewhere = "rev_timestamp <= {$this->mTimestamp}";
                        $timestampLimit = wfTimestamp( TS_MW, $this->mTimestamp );
@@ -376,6 +388,18 @@ class SpecialMergeHistory extends SpecialPage {
                        $timewhere = "rev_timestamp <= {$maxtimestamp}";
                        $timestampLimit = wfTimestamp( TS_MW, $lasttimestamp );
                }
+               # Check that there are not too many revisions to move
+               $limit = 5000; // avoid too much slave lag
+               $count = $dbw->select( 'revision', '1',
+                       array( 'rev_page' => $this->mTargetID, $timewhere ),
+                       __METHOD__,
+                       array( 'LIMIT' => $limit + 1 )
+               )->numRows();
+               if ( $count > $limit ) {
+                       $this->getOutput()->addWikiMsg( 'mergehistory-fail-toobig' );
+
+                       return false;
+               }
                # Do the moving...
                $dbw->update(
                        'revision',
@@ -452,6 +476,7 @@ class SpecialMergeHistory extends SpecialPage {
                        array( $destTitle->getPrefixedText(), $timestampLimit ), $this->getUser()
                );
 
+               # @TODO: message should use redirect=no
                $this->getOutput()->addWikiMsg( 'mergehistory-success',
                        $targetTitle->getPrefixedText(), $destTitle->getPrefixedText(), $count );
 
index df4a05f..6f56d0a 100644 (file)
        "mergehistory-empty": "No revisions can be merged.",
        "mergehistory-success": "$3 {{PLURAL:$3|revision|revisions}} of [[:$1]] successfully merged into [[:$2]].",
        "mergehistory-fail": "Unable to perform history merge, please recheck the page and time parameters.",
+       "mergehistory-fail-toobig" : "Unable to perform history merge as more than the limit of $1 {{PLURAL:$1|revision|revisions}} would be moved.",
        "mergehistory-no-source": "Source page $1 does not exist.",
        "mergehistory-no-destination": "Destination page $1 does not exist.",
        "mergehistory-invalid-source": "Source page must be a valid title.",
index 2dd4d63..424c807 100644 (file)
        "mergehistory-empty": "Used in [[Special:MergeHistory]].",
        "mergehistory-success": "Used in [[Special:MergeHistory]].\n* $1 - target page title\n* $2 - destination page title\n* $3 - number of revisions which succeeded to merge",
        "mergehistory-fail": "Used as error message in [[Special:MergeHistory]].",
+       "mergehistory-fail-toobig": "Used as error message in [[Special:MergeHistory]].\n* $1 - maximum allowed number of revisions that can be moved",
        "mergehistory-no-source": "Used as error message in [[Special:MergeHistory]].\n* $1 - source page title\nSee also:\n* {{msg-mw|mergehistory-invalid-source}}\n* {{msg-mw|mergehistory-invalid-destination}}\n* {{msg-mw|mergehistory-no-destination}}\n* {{msg-mw|mergehistory-same-destination}}",
        "mergehistory-no-destination": "Used as error message in [[Special:MergeHistory]].\n* $1 - destination page title\nSee also:\n* {{msg-mw|mergehistory-invalid-source}}\n* {{msg-mw|mergehistory-no-source}}\n* {{msg-mw|mergehistory-invalid-destination}}\n* {{msg-mw|mergehistory-same-destination}}",
        "mergehistory-invalid-source": "Used as error message in [[Special:MergeHistory]].\n\nSee also:\n* {{msg-mw|mergehistory-no-source}}\n* {{msg-mw|mergehistory-invalid-destination}}\n* {{msg-mw|mergehistory-no-destination}}\n* {{msg-mw|mergehistory-same-destination}}",