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