Revert r52336 "Merge maintenance-work branch:"
[lhc/web/wiklou.git] / maintenance / deleteBatch.php
index 6e44d63..5aeea78 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Deletes a batch of pages
  * Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] [listfile]
  * @file
  * @ingroup Maintenance
  */
-require_once( "Maintenance.php" );
-
-class DeleteBatch extends Maintenance {
-       
-       public function __construct() {
-               parent::__construct();
-               $this->mDescription = "Deletes a batch of pages";
-               $this->addParam( 'u', "User to perform deletion", false, true );
-               $this->addParam( 'r', "Reason to delete page", false, true );
-               $this->addParam( 'i', "Interval to sleep between deletions" );
-               $this->addArgs( array( 'listfile' ) );
+
+$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 == '' ) {
+               continue;
        }
-       
-       public function execute() {
-               global $wgUser;
-
-               # Change to current working directory
-               $oldCwd = getcwd();
-               chdir( $oldCwd );
-       
-               # Options processing
-               $user = $this->getOption( 'u', 'Delete page script' );
-               $reason = $this->getOption( 'r', '' );
-               $interval = $this->getOption( 'i', 0 );
-               if( $this->hasArg() ) {
-                       $file = fopen( $this->getArg(), 'r' );
-               } else {
-                       $file = $this->getStdin();
-               }
+       $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;
+       }
+
 
-               # Setup
-               if( !$file ) {
-                       $this->error( "Unable to read file, exiting\n", true );
+       print $page->getPrefixedText();
+       $dbw->begin();
+       if( $page->getNamespace() == NS_FILE ) {
+               $art = new ImagePage( $page );
+               $img = wfFindFile( $art->mTitle );
+               if( !$img || !$img->delete( $reason ) ) {
+                       print "FAILED to delete image file... ";
                }
-               $wgUser = User::newFromName( $user );
-               $dbw = wfGetDB( DB_MASTER );
-
-               # Handle each entry
-               for ( $linenum = 1; !feof( $file ); $linenum++ ) {
-                       $line = trim( fgets( $file ) );
-                       if ( $line == '' ) {
-                               continue;
-                       }
-                       $page = Title::newFromText( $line );
-                       if ( is_null( $page ) ) {
-                               $this->output( "Invalid title '$line' on line $linenum\n" );
-                               continue;
-                       }
-                       if( !$page->exists() ) {
-                               $this->output( "Skipping nonexistent page '$line'\n" );
-                               continue;
-                       }
-       
-       
-                       $this->output( $page->getPrefixedText() );
-                       $dbw->begin();
-                       if( $page->getNamespace() == NS_FILE ) {
-                               $art = new ImagePage( $page );
-                               $img = wfFindFile( $art->mTitle );
-                               if( !$img || !$img->delete( $reason ) ) {
-                                       $this->output( "FAILED to delete image file... " );
-                               }
-                       } else {
-                               $art = new Article( $page );
-                       }
-                       $success = $art->doDeleteArticle( $reason );
-                       $dbw->immediateCommit();
-                       if ( $success ) {
-                               $this->output( "\n" );
-                       } else {
-                               $this->output( " FAILED to delete article\n" );
-                       }
-       
-                       if ( $interval ) {
-                               sleep( $interval );
-                       }
-                       wfWaitForSlaves( 5 );
-}
+       } else {
+               $art = new Article( $page );
+       }
+       $success = $art->doDeleteArticle( $reason );
+       $dbw->immediateCommit();
+       if ( $success ) {
+               print "\n";
+       } else {
+               print " FAILED to delete image page\n";
+       }
+
+       if ( $interval ) {
+               sleep( $interval );
        }
+       wfWaitForSlaves( 5 );
 }
 
-$maintClass = "DeleteBatch";
-require_once( DO_MAINTENANCE );
+
+