summaryrefslogtreecommitdiff
path: root/maintenance/deleteBatch.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2006-10-11 18:12:39 +0000
committerPierre Schmitz <pierre@archlinux.de>2006-10-11 18:12:39 +0000
commit183851b06bd6c52f3cae5375f433da720d410447 (patch)
treea477257decbf3360127f6739c2f9d0ec57a03d39 /maintenance/deleteBatch.php
MediaWiki 1.7.1 wiederhergestellt
Diffstat (limited to 'maintenance/deleteBatch.php')
-rw-r--r--maintenance/deleteBatch.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/maintenance/deleteBatch.php b/maintenance/deleteBatch.php
new file mode 100644
index 00000000..697dffd7
--- /dev/null
+++ b/maintenance/deleteBatch.php
@@ -0,0 +1,85 @@
+<?php
+
+# delete a batch of pages
+# Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] <listfile>
+# where
+# <listfile> 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.
+# <user> is the username
+# <reason> is the move reason
+# <interval> 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 );
+}
+
+
+?>