Merge "Don't estimate the revision count for page deletions"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 19 Aug 2014 15:03:01 +0000 (15:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 19 Aug 2014 15:03:01 +0000 (15:03 +0000)
includes/Title.php
includes/page/Article.php
languages/i18n/en.json
languages/i18n/qqq.json

index 526bc92..1676a1b 100644 (file)
@@ -158,6 +158,9 @@ class Title {
 
        /** @var TitleValue A corresponding TitleValue object */
        private $mTitleValue = null;
+
+       /** @var bool Would deleting this page be a big deletion? */
+       private $mIsBigDeletion = null;
        // @}
 
        /**
@@ -3271,6 +3274,7 @@ class Title {
                $this->mEstimateRevisions = null;
                $this->mPageLanguage = false;
                $this->mDbPageLanguage = null;
+               $this->mIsBigDeletion = null;
        }
 
        /**
@@ -4377,12 +4381,32 @@ class Title {
                        return false;
                }
 
-               $revCount = $this->estimateRevisionCount();
-               return $revCount > $wgDeleteRevisionsLimit;
+               if ( $this->mIsBigDeletion === null ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+
+                       $innerQuery = $dbr->selectSQLText(
+                               'revision',
+                               '1',
+                               array( 'rev_page' => $this->getArticleID() ),
+                               __METHOD__,
+                               array( 'LIMIT' => $wgDeleteRevisionsLimit + 1 )
+                       );
+
+                       $revCount = $dbr->query(
+                               'SELECT COUNT(*) FROM (' . $innerQuery . ') AS innerQuery',
+                               __METHOD__
+                       );
+                       $revCount = $revCount->fetchRow();
+                       $revCount = $revCount['COUNT(*)'];
+
+                       $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
+               }
+
+               return $this->mIsBigDeletion;
        }
 
        /**
-        * Get the  approximate revision count of this page.
+        * Get the approximate revision count of this page.
         *
         * @return int
         */
index c54c692..da88a69 100644 (file)
@@ -1624,7 +1624,20 @@ class Article implements Page {
 
                // If the page has a history, insert a warning
                if ( $hasHistory ) {
-                       $revisions = $this->mTitle->estimateRevisionCount();
+                       $title = $this->getTitle();
+
+                       // The following can use the real revision count as this is only being shown for users that can delete
+                       // this page.
+                       // This, as a side-effect, also makes sure that the following query isn't being run for pages with a
+                       // larger history, unless the user has the 'bigdelete' right (and is about to delete this page).
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $revisions = $edits = (int)$dbr->selectField(
+                               'revision',
+                               'COUNT(rev_page)',
+                               array( 'rev_page' => $title->getArticleID() ),
+                               __METHOD__
+                       );
+
                        // @todo FIXME: i18n issue/patchwork message
                        $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
                                wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
@@ -1635,7 +1648,7 @@ class Article implements Page {
                                '</strong>'
                        );
 
-                       if ( $this->mTitle->isBigDeletion() ) {
+                       if ( $title->isBigDeletion() ) {
                                global $wgDeleteRevisionsLimit;
                                $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
                                        array(
index a43a742..6b1ed8c 100644 (file)
        "exbeforeblank": "content before blanking was: \"$1\"",
        "delete-confirm": "Delete \"$1\"",
        "delete-legend": "Delete",
-       "historywarning": "<strong>Warning:</strong> The page you are about to delete has a history with approximately $1 {{PLURAL:$1|revision|revisions}}:",
+       "historywarning": "<strong>Warning:</strong> The page you are about to delete has a history with $1 {{PLURAL:$1|revision|revisions}}:",
        "confirmdeletetext": "You are about to delete a page along with all of its history.\nPlease confirm that you intend to do this, that you understand the consequences, and that you are doing this in accordance with [[{{MediaWiki:Policy-url}}|the policy]].",
        "actioncomplete": "Action complete",
        "actionfailed": "Action failed",
index 74e2954..c7abc08 100644 (file)
        "exbeforeblank": "Automated deletion reason when deleting a page for admins providing that the page was blanked before deletion.\n\nParameters:\n* $1 - content before blanking",
        "delete-confirm": "Used as page title. Parameters:\n* $1 - the page title\n{{Identical|Delete}}",
        "delete-legend": "{{Identical|Delete}}",
-       "historywarning": "Warning when about to delete a page that has history.\n\nFollowed by a link which points to the history page.\n\nParameters:\n* $1 - the <b>approximate</b> number of revisions that the page has, the message should not claim to give an exact count",
+       "historywarning": "Warning when about to delete a page that has history.\n\nFollowed by a link which points to the history page.\n\nParameters:\n* $1 - the number of revisions that the page has",
        "confirmdeletetext": "Introduction shown when deleting a page.\n\nRefers to {{msg-mw|Policy-url}}.",
        "actioncomplete": "Used in several situations, for example when a page has been deleted.\n\nSee also:\n* {{msg-mw|Actionfailed|page title}}",
        "actionfailed": "Used as page title when the submit operation failed, in [[Special:RevisionDelete]].\n\nSee also:\n* {{msg-mw|Actioncomplete|page title}}",