MediaWiki
REL1_22
|
00001 <?php 00025 require_once __DIR__ . '/Maintenance.php'; 00026 00033 class DeleteDefaultMessages extends Maintenance { 00034 public function __construct() { 00035 parent::__construct(); 00036 $this->mDescription = "Deletes all pages in the MediaWiki namespace" . 00037 " which were last edited by \"MediaWiki default\""; 00038 } 00039 00040 public function execute() { 00041 global $wgUser; 00042 00043 $this->output( "Checking existence of old default messages..." ); 00044 $dbr = wfGetDB( DB_SLAVE ); 00045 $res = $dbr->select( array( 'page', 'revision' ), 00046 array( 'page_namespace', 'page_title' ), 00047 array( 00048 'page_namespace' => NS_MEDIAWIKI, 00049 'page_latest=rev_id', 00050 'rev_user_text' => 'MediaWiki default', 00051 ) 00052 ); 00053 00054 if ( $dbr->numRows( $res ) == 0 ) { 00055 # No more messages left 00056 $this->output( "done.\n" ); 00057 return; 00058 } 00059 00060 # Deletions will be made by $user temporarly added to the bot group 00061 # in order to hide it in RecentChanges. 00062 $user = User::newFromName( 'MediaWiki default' ); 00063 if ( !$user ) { 00064 $this->error( "Invalid username", true ); 00065 } 00066 $user->addGroup( 'bot' ); 00067 $wgUser = $user; 00068 00069 # Handle deletion 00070 $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' ); 00071 $dbw = wfGetDB( DB_MASTER ); 00072 00073 foreach ( $res as $row ) { 00074 wfWaitForSlaves(); 00075 $dbw->ping(); 00076 $title = Title::makeTitle( $row->page_namespace, $row->page_title ); 00077 $page = WikiPage::factory( $title ); 00078 $dbw->begin( __METHOD__ ); 00079 $error = ''; // Passed by ref 00080 $page->doDeleteArticle( 'No longer required', false, 0, false, $error, $user ); 00081 $dbw->commit( __METHOD__ ); 00082 } 00083 00084 $this->output( "done!\n", 'msg' ); 00085 } 00086 } 00087 00088 $maintClass = "DeleteDefaultMessages"; 00089 require_once RUN_MAINTENANCE_IF_MAIN;