Skip to content

Commit 820446e

Browse files
committed
maintenance: Add --dry-run option to deleteDefaultMessages.php
For back-compat, keep the default as-is, because it is also used as a post-update script by the installer. But for convenience and safe manual use, do add a dry-run option. (Ideally this would be a --delete option and dry-run by default.) Change-Id: I3ca70f15f50b66f9d19fa705cef9a4aae2dd4e5c
1 parent d7bc765 commit 820446e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

maintenance/deleteDefaultMessages.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct() {
3535
parent::__construct();
3636
$this->addDescription( 'Deletes all pages in the MediaWiki namespace' .
3737
' which were last edited by "MediaWiki default"' );
38+
$this->addOption( 'dry-run', 'Perform a dry run, delete nothing' );
3839
}
3940

4041
public function execute() {
@@ -52,22 +53,31 @@ public function execute() {
5253
);
5354

5455
if ( $dbr->numRows( $res ) == 0 ) {
55-
# No more messages left
56+
// No more messages left
5657
$this->output( "done.\n" );
58+
return;
59+
}
5760

61+
$dryrun = $this->hasOption( 'dry-run' );
62+
if ( $dryrun ) {
63+
foreach ( $res as $row ) {
64+
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
65+
$this->output( "\n* [[$title]]" );
66+
}
67+
$this->output( "\n\nRun again without --dry-run to delete these pages.\n" );
5868
return;
5969
}
6070

61-
# Deletions will be made by $user temporarly added to the bot group
62-
# in order to hide it in RecentChanges.
71+
// Deletions will be made by $user temporarly added to the bot group
72+
// in order to hide it in RecentChanges.
6373
$user = User::newFromName( 'MediaWiki default' );
6474
if ( !$user ) {
6575
$this->error( "Invalid username", true );
6676
}
6777
$user->addGroup( 'bot' );
6878
$wgUser = $user;
6979

70-
# Handle deletion
80+
// Handle deletion
7181
$this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
7282
$dbw = $this->getDB( DB_MASTER );
7383

0 commit comments

Comments
 (0)