00001 <?php 00030 require_once( dirname(__FILE__) . '/Maintenance.php' ); 00031 00032 class DeleteBatch extends Maintenance { 00033 00034 public function __construct() { 00035 parent::__construct(); 00036 $this->mDescription = "Deletes a batch of pages"; 00037 $this->addOption( 'u', "User to perform deletion", false, true ); 00038 $this->addOption( 'r', "Reason to delete page", false, true ); 00039 $this->addOption( 'i', "Interval to sleep between deletions" ); 00040 $this->addArg( 'listfile', 'File with titles to delete, separated by newlines', false ); 00041 } 00042 00043 public function execute() { 00044 global $wgUser; 00045 00046 # Change to current working directory 00047 $oldCwd = getcwd(); 00048 chdir( $oldCwd ); 00049 00050 # Options processing 00051 $user = $this->getOption( 'u', 'Delete page script' ); 00052 $reason = $this->getOption( 'r', '' ); 00053 $interval = $this->getOption( 'i', 0 ); 00054 if( $this->hasArg() ) { 00055 $file = fopen( $this->getArg(), 'r' ); 00056 } else { 00057 $file = $this->getStdin(); 00058 } 00059 00060 # Setup 00061 if( !$file ) { 00062 $this->error( "Unable to read file, exiting", true ); 00063 } 00064 $wgUser = User::newFromName( $user ); 00065 $dbw = wfGetDB( DB_MASTER ); 00066 00067 # Handle each entry 00068 for ( $linenum = 1; !feof( $file ); $linenum++ ) { 00069 $line = trim( fgets( $file ) ); 00070 if ( $line == '' ) { 00071 continue; 00072 } 00073 $page = Title::newFromText( $line ); 00074 if ( is_null( $page ) ) { 00075 $this->output( "Invalid title '$line' on line $linenum\n" ); 00076 continue; 00077 } 00078 if( !$page->exists() ) { 00079 $this->output( "Skipping nonexistent page '$line'\n" ); 00080 continue; 00081 } 00082 00083 00084 $this->output( $page->getPrefixedText() ); 00085 $dbw->begin(); 00086 if( $page->getNamespace() == NS_FILE ) { 00087 $art = new ImagePage( $page ); 00088 $img = wfFindFile( $art->mTitle ); 00089 if( !$img || !$img->delete( $reason ) ) { 00090 $this->output( "FAILED to delete image file... " ); 00091 } 00092 } else { 00093 $art = new Article( $page ); 00094 } 00095 $success = $art->doDeleteArticle( $reason ); 00096 $dbw->commit(); 00097 if ( $success ) { 00098 $this->output( "\n" ); 00099 } else { 00100 $this->output( " FAILED to delete article\n" ); 00101 } 00102 00103 if ( $interval ) { 00104 sleep( $interval ); 00105 } 00106 wfWaitForSlaves( 5 ); 00107 } 00108 } 00109 } 00110 00111 $maintClass = "DeleteBatch"; 00112 require_once( DO_MAINTENANCE );