From: Brion Vibber Date: Wed, 16 Jan 2008 23:08:19 +0000 (+0000) Subject: Quick hack in: $wgDeleteRevisionsLimit and 'bigdelete' permission. X-Git-Tag: 1.31.0-rc.0~49951 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=40e0f29922fdd501dcf8cfc6625806627016754d;p=lhc%2Fweb%2Fwiklou.git Quick hack in: $wgDeleteRevisionsLimit and 'bigdelete' permission. Should keep us from the couple-of-times-yearly "oops someone deleted the sandbox" fun. --- diff --git a/includes/Article.php b/includes/Article.php index 1749a8d579..eace63491a 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1942,6 +1942,17 @@ class Article { $wgOut->showPermissionsErrorPage( $permission_errors ); return; } + + # Hack for big sites + if( $this->isBigDeletion() ) { + $permission_errors = $this->mTitle->getUserPermissionsErrors( + 'bigdelete', $wgUser ); + + if( count( $permission_errors ) > 0 ) { + $wgOut->showPermissionsErrorPage( $permission_errors ); + return; + } + } $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) ); @@ -1976,6 +1987,30 @@ class Article { return $this->confirmDelete( '', $reason ); } + + /** + * @return bool whether or not the page surpasses $wgDeleteRevisionsLimit revisions + */ + function isBigDeletion() { + global $wgDeleteRevisionsLimit; + if( $wgDeleteRevisionsLimit ) { + $revCount = $this->estimateRevisionCount(); + return $revCount > $wgDeleteRevisionsLimit; + } + return false; + } + + /** + * @return int approximate revision count + */ + function estimateRevisionCount() { + $dbr = wfGetDB(); + // For an exact count... + //return $dbr->selectField( 'revision', 'COUNT(*)', + // array( 'rev_page' => $this->getId() ), __METHOD__ ); + return $dbr->estimateRowCount( 'revision', '*', + array( 'rev_page' => $this->getId() ), __METHOD__ ); + } /** * Get the last N authors diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e0fff685d2..efea489be3 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1099,6 +1099,7 @@ $wgGroupPermissions['bot' ]['apihighlimits'] = true; $wgGroupPermissions['sysop']['block'] = true; $wgGroupPermissions['sysop']['createaccount'] = true; $wgGroupPermissions['sysop']['delete'] = true; +$wgGroupPermissions['sysop']['bigdelete'] = true; // can be separately configured for pages with > $wgDeleteRevisionsLimit revs $wgGroupPermissions['sysop']['deletedhistory'] = true; // can view deleted history entries, but not see or restore the text $wgGroupPermissions['sysop']['undelete'] = true; $wgGroupPermissions['sysop']['editinterface'] = true; @@ -1247,6 +1248,12 @@ $wgAutopromote = array( */ $wgAddGroups = $wgRemoveGroups = array(); +/** + * Optional to restrict deletion of pages with higher revision counts + * to users with the 'bigdelete' permission. (Default given to sysops.) + */ +$wgDeleteRevisionsLimit = 0; + # Proxy scanner settings #