Merge "Perform a permission check on the title when changing the page language"
[lhc/web/wiklou.git] / maintenance / deleteDefaultMessages.php
index 35a7ca7..ba8662a 100644 (file)
@@ -35,13 +35,14 @@ class DeleteDefaultMessages extends Maintenance {
                parent::__construct();
                $this->addDescription( 'Deletes all pages in the MediaWiki namespace' .
                        ' which were last edited by "MediaWiki default"' );
+               $this->addOption( 'dry-run', 'Perform a dry run, delete nothing' );
        }
 
        public function execute() {
                global $wgUser;
 
                $this->output( "Checking existence of old default messages..." );
-               $dbr = $this->getDB( DB_SLAVE );
+               $dbr = $this->getDB( DB_REPLICA );
                $res = $dbr->select( [ 'page', 'revision' ],
                        [ 'page_namespace', 'page_title' ],
                        [
@@ -52,14 +53,23 @@ class DeleteDefaultMessages extends Maintenance {
                );
 
                if ( $dbr->numRows( $res ) == 0 ) {
-                       # No more messages left
+                       // No more messages left
                        $this->output( "done.\n" );
+                       return;
+               }
 
+               $dryrun = $this->hasOption( 'dry-run' );
+               if ( $dryrun ) {
+                       foreach ( $res as $row ) {
+                               $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+                               $this->output( "\n* [[$title]]" );
+                       }
+                       $this->output( "\n\nRun again without --dry-run to delete these pages.\n" );
                        return;
                }
 
-               # Deletions will be made by $user temporarly added to the bot group
-               # in order to hide it in RecentChanges.
+               // Deletions will be made by $user temporarly added to the bot group
+               // in order to hide it in RecentChanges.
                $user = User::newFromName( 'MediaWiki default' );
                if ( !$user ) {
                        $this->error( "Invalid username", true );
@@ -67,7 +77,7 @@ class DeleteDefaultMessages extends Maintenance {
                $user->addGroup( 'bot' );
                $wgUser = $user;
 
-               # Handle deletion
+               // Handle deletion
                $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
                $dbw = $this->getDB( DB_MASTER );