r107386 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107385‎ | r107386 | r107387 >
Date:15:29, 27 December 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Integrate $wgDeleteRevisionsLimit in Title::getUserPermissionsErrors() (only if doing expensive checks)
* Moved WikiPage::estimateRevisionCount() and WikiPage::isBigDeletion() to Title and marked those WikiPage methods as deprecated (only call in extensions removed in r107385)
* Show an error message when deleting a page to move another one in Special:MovePage and the deletion fails due to permissions errors (previously the form would simply show again)
* Cache the result of Title::estimateRevisionCount() since it's called two times when showing the deletion form and the user doesn't have 'bigdelete' right (one for the permissions check and the other when showing the number of revisions)
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiDelete.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMovepage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1289,18 +1289,6 @@
12901290 return;
12911291 }
12921292
1293 - # Hack for big sites
1294 - $bigHistory = $this->mPage->isBigDeletion();
1295 - if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
1296 - global $wgDeleteRevisionsLimit;
1297 -
1298 - $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1299 - $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1300 - array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1301 -
1302 - return;
1303 - }
1304 -
13051293 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
13061294 $deleteReason = $wgRequest->getText( 'wpReason' );
13071295
@@ -1338,7 +1326,7 @@
13391327
13401328 // If the page has a history, insert a warning
13411329 if ( $hasHistory ) {
1342 - $revisions = $this->mPage->estimateRevisionCount();
 1330+ $revisions = $this->mTitle->estimateRevisionCount();
13431331 // @todo FIXME: i18n issue/patchwork message
13441332 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
13451333 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
Index: trunk/phase3/includes/api/ApiDelete.php
@@ -112,11 +112,6 @@
113113 * @return Title::getUserPermissionsErrors()-like array
114114 */
115115 public static function delete( Page $page, User $user, $token, &$reason = null ) {
116 - if ( $page->isBigDeletion() && !$user->isAllowed( 'bigdelete' ) ) {
117 - global $wgDeleteRevisionsLimit;
118 - return array( array( 'delete-toobig', $wgDeleteRevisionsLimit ) );
119 - }
120 -
121116 $title = $page->getTitle();
122117 $errors = self::getPermissionsError( $title, $user, $token );
123118 if ( count( $errors ) ) {
Index: trunk/phase3/includes/Title.php
@@ -64,6 +64,7 @@
6565 var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand
6666 var $mLatestID = false; // /< ID of most recent revision
6767 var $mCounter = -1; // /< Number of times this page has been viewed (-1 means "not loaded")
 68+ private $mEstimateRevisions; // /< Estimated number of revisions; null of not loaded
6869 var $mRestrictions = array(); // /< Array of groups allowed to edit this article
6970 var $mOldRestrictions = false;
7071 var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images?
@@ -1843,6 +1844,8 @@
18441845 * @return Array list of errors
18451846 */
18461847 private function checkActionPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
 1848+ global $wgDeleteRevisionsLimit, $wgLang;
 1849+
18471850 if ( $action == 'protect' ) {
18481851 if ( count( $this->getUserPermissionsErrorsInternal( 'edit', $user, $doExpensiveQueries, true ) ) ) {
18491852 // If they can't edit, they shouldn't protect.
@@ -1875,6 +1878,12 @@
18761879 } elseif ( !$this->isMovable() ) {
18771880 $errors[] = array( 'immobile-target-page' );
18781881 }
 1882+ } elseif ( $action == 'delete' ) {
 1883+ if ( $doExpensiveQueries && $wgDeleteRevisionsLimit
 1884+ && !$this->userCan( 'bigdelete', $user ) && $this->isBigDeletion() )
 1885+ {
 1886+ $errors[] = array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) );
 1887+ }
18791888 }
18801889 return $errors;
18811890 }
@@ -2887,6 +2896,7 @@
28882897 $this->mLength = -1;
28892898 $this->mLatestID = false;
28902899 $this->mCounter = -1;
 2900+ $this->mEstimateRevisions = null;
28912901 }
28922902
28932903 /**
@@ -4001,6 +4011,41 @@
40024012 }
40034013
40044014 /**
 4015+ * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit
 4016+ *
 4017+ * @return bool
 4018+ */
 4019+ public function isBigDeletion() {
 4020+ global $wgDeleteRevisionsLimit;
 4021+
 4022+ if ( !$wgDeleteRevisionsLimit ) {
 4023+ return false;
 4024+ }
 4025+
 4026+ $revCount = $this->estimateRevisionCount();
 4027+ return $revCount > $wgDeleteRevisionsLimit;
 4028+ }
 4029+
 4030+ /**
 4031+ * Get the approximate revision count of this page.
 4032+ *
 4033+ * @return int
 4034+ */
 4035+ public function estimateRevisionCount() {
 4036+ if ( !$this->exists() ) {
 4037+ return 0;
 4038+ }
 4039+
 4040+ if ( $this->mEstimateRevisions === null ) {
 4041+ $dbr = wfGetDB( DB_SLAVE );
 4042+ $this->mEstimateRevisions = $dbr->estimateRowCount( 'revision', '*',
 4043+ array( 'rev_page' => $this->getArticleId() ), __METHOD__ );
 4044+ }
 4045+
 4046+ return $this->mEstimateRevisions;
 4047+ }
 4048+
 4049+ /**
40054050 * Get the number of revisions between the given revision.
40064051 * Used for diffs and other things that really need it.
40074052 *
Index: trunk/phase3/includes/WikiPage.php
@@ -1560,27 +1560,25 @@
15611561 }
15621562
15631563 /**
1564 - * @return bool whether or not the page surpasses $wgDeleteRevisionsLimit revisions
 1564+ * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit
 1565+ *
 1566+ * @deprecated in 1.19; use Title::isBigDeletion() instead.
 1567+ * @return bool
15651568 */
15661569 public function isBigDeletion() {
1567 - global $wgDeleteRevisionsLimit;
1568 -
1569 - if ( $wgDeleteRevisionsLimit ) {
1570 - $revCount = $this->estimateRevisionCount();
1571 -
1572 - return $revCount > $wgDeleteRevisionsLimit;
1573 - }
1574 -
1575 - return false;
 1570+ wfDeprecated( __METHOD__, '1.19' );
 1571+ return $this->mTitle->isBigDeletion();
15761572 }
15771573
15781574 /**
1579 - * @return int approximate revision count
 1575+ * Get the approximate revision count of this page.
 1576+ *
 1577+ * @deprecated in 1.19; use Title::estimateRevisionCount() instead.
 1578+ * @return int
15801579 */
15811580 public function estimateRevisionCount() {
1582 - $dbr = wfGetDB( DB_SLAVE );
1583 - return $dbr->estimateRowCount( 'revision', '*',
1584 - array( 'rev_page' => $this->getId() ), __METHOD__ );
 1581+ wfDeprecated( __METHOD__, '1.19' );
 1582+ return $this->mTitle->estimateRevisionCount();
15851583 }
15861584
15871585 /**
Index: trunk/phase3/includes/specials/SpecialMovepage.php
@@ -360,13 +360,11 @@
361361 $nt = $this->newTitle;
362362
363363 # Delete to make way if requested
364 - if ( !count( $nt->getUserPermissionsErrors( 'delete', $user ) ) && $this->deleteAndMove ) {
365 - $page = WikiPage::factory( $nt );
366 -
367 - # Disallow deletions of big articles
368 - $bigHistory = $page->isBigDeletion();
369 - if( $bigHistory && count( $nt->getUserPermissionsErrors( 'bigdelete', $user ) ) ) {
370 - $this->showForm( array( 'delete-toobig', $this->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
 364+ if ( $this->deleteAndMove ) {
 365+ $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
 366+ if ( count( $permErrors ) ) {
 367+ # Only show the first error
 368+ $this->showForm( $permErrors[0] );
371369 return;
372370 }
373371
@@ -381,6 +379,7 @@
382380 }
383381
384382 $error = ''; // passed by ref
 383+ $page = WikiPage::factory( $nt );
385384 if ( !$page->doDeleteArticle( $reason, false, 0, true, $error, $user ) ) {
386385 $this->showForm( array( 'cannotdelete', wfEscapeWikiText( $nt->getPrefixedText() ) ) );
387386 return;

Follow-up revisions

RevisionCommit summaryAuthorDate
r107424Per Reedy, fix for r107386: fix usage of undefined variableialex21:16, 27 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107385Use $flags & EDIT_NEW to check for a new page instead of the number of revisionsialex15:20, 27 December 2011

Comments

#Comment by Raymond (talk | contribs)   20:51, 27 December 2011

PHP Notice: Undefined variable: bigHistory in /www/w/includes/Article.php on line 1340

#Comment by IAlex (talk | contribs)   21:17, 27 December 2011

Fixed in r107424 (and sorry to have mentioned the wrong person in the commit summary).

Status & tagging log