X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FdeleteDefaultMessages.php;h=326073f1a28ed33f2a510871b6e988773548d380;hb=d90508d3c2f646895c60406d242cb65d33c9306d;hp=69f4f893fc41acbee33328e442a13d8c7ce2a4ed;hpb=e968a1f431ad058dcb14adb2757bde5664b99a79;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/deleteDefaultMessages.php b/maintenance/deleteDefaultMessages.php index 69f4f893fc..326073f1a2 100644 --- a/maintenance/deleteDefaultMessages.php +++ b/maintenance/deleteDefaultMessages.php @@ -35,6 +35,7 @@ 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() { @@ -42,32 +43,47 @@ class DeleteDefaultMessages extends Maintenance { $this->output( "Checking existence of old default messages..." ); $dbr = $this->getDB( DB_REPLICA ); - $res = $dbr->select( [ 'page', 'revision' ], + + $actorQuery = ActorMigration::newMigration() + ->getWhere( $dbr, 'rev_user', User::newFromName( 'MediaWiki default' ) ); + $res = $dbr->select( + [ 'page', 'revision' ] + $actorQuery['tables'], [ 'page_namespace', 'page_title' ], [ 'page_namespace' => NS_MEDIAWIKI, - 'page_latest=rev_id', - 'rev_user_text' => 'MediaWiki default', - ] + $actorQuery['conds'], + ], + __METHOD__, + [], + [ 'revision' => [ 'JOIN', 'page_latest=rev_id' ] ] + $actorQuery['joins'] ); 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 ); + $this->fatalError( "Invalid username" ); } $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 ); @@ -85,5 +101,5 @@ class DeleteDefaultMessages extends Maintenance { } } -$maintClass = "DeleteDefaultMessages"; +$maintClass = DeleteDefaultMessages::class; require_once RUN_MAINTENANCE_IF_MAIN;