Quick hack in: $wgDeleteRevisionsLimit and 'bigdelete' permission.
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 16 Jan 2008 23:08:19 +0000 (23:08 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 16 Jan 2008 23:08:19 +0000 (23:08 +0000)
Should keep us from the couple-of-times-yearly "oops someone deleted the sandbox" fun.

includes/Article.php
includes/DefaultSettings.php

index 1749a8d..eace634 100644 (file)
@@ -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
index e0fff68..efea489 100644 (file)
@@ -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
 #