r29872 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r29871 | r29872 (on ViewVC) | r29873 >
Date:23:08, 16 January 2008
Author:brion
Status:ok
Tags:
Comment:Quick hack in: $wgDeleteRevisionsLimit and 'bigdelete' permission.
Should keep us from the couple-of-times-yearly "oops someone deleted the sandbox" fun.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Article.php
===================================================================
--- trunk/phase3/includes/Article.php	(revision 29871)
+++ trunk/phase3/includes/Article.php	(revision 29872)
@@ -1942,7 +1942,18 @@
 			$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' ) );
 
 		# Better double-check that it hasn't been deleted yet!
@@ -1976,6 +1987,30 @@
 		
 		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
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 29871)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 29872)
@@ -1099,6 +1099,7 @@
 $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 @@
  */
 $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
 #
 
Views
Toolbox