From 9a98513204b5f17a13836b8fa9678f762c7fa21c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 15 Jun 2006 04:58:03 +0000 Subject: [PATCH] A batch-deletion script based on the batch-move script --- maintenance/deleteBatch.php | 85 +++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 maintenance/deleteBatch.php diff --git a/maintenance/deleteBatch.php b/maintenance/deleteBatch.php new file mode 100644 index 0000000000..697dffd7a4 --- /dev/null +++ b/maintenance/deleteBatch.php @@ -0,0 +1,85 @@ +] [-r ] [-i ] +# where +# is a file where each line has two titles separated by a pipe +# character. The first title is the source, the second is the destination. +# is the username +# is the move reason +# is the number of seconds to sleep for after each move + +$oldCwd = getcwd(); +$optionsWithArgs = array( 'u', 'r', 'i' ); +require_once( 'commandLine.inc' ); + +chdir( $oldCwd ); + +# Options processing + +$filename = 'php://stdin'; +$user = 'Delete page script'; +$reason = ''; +$interval = 0; + +if ( isset( $args[0] ) ) { + $filename = $args[0]; +} +if ( isset( $options['u'] ) ) { + $user = $options['u']; +} +if ( isset( $options['r'] ) ) { + $reason = $options['r']; +} +if ( isset( $options['i'] ) ) { + $interval = $options['i']; +} + +$wgUser = User::newFromName( $user ); + + +# Setup complete, now start + +$file = fopen( $filename, 'r' ); +if ( !$file ) { + print "Unable to read file, exiting\n"; + exit; +} + +$dbw =& wfGetDB( DB_MASTER ); + +for ( $linenum = 1; !feof( $file ); $linenum++ ) { + $line = trim( fgets( $file ) ); + if ( $line === false ) { + break; + } + $page = Title::newFromText( $line ); + if ( is_null( $page ) ) { + print "Invalid title '$line' on line $linenum\n"; + continue; + } + if( !$page->exists() ) { + print "Skipping nonexistent page '$line'\n"; + continue; + } + + + print $page->getPrefixedText(); + $dbw->begin(); + if( $page->getNamespace() == NS_IMAGE ) { + $art = new ImagePage( $page ); + } else { + $art = new Article( $page ); + } + $art->doDelete( $reason ); + $dbw->immediateCommit(); + print "\n"; + + if ( $interval ) { + sleep( $interval ); + } + wfWaitForSlaves( 5 ); +} + + +?> -- 2.20.1