From a0c354bc51927202314c0e96beacd5fa53f80cfd Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 27 Dec 2011 15:56:35 +0000 Subject: [PATCH] * Use WikiPage instead of Article (or ImagePage) to call doDeleteArticle() * Rename some variable for consistency * Check for valid user before opening the file containing pages to delete, there's no point doing the latter if the former fails * Don't ouput "FAILED to delete associated file" if the file is from a foreign repository --- maintenance/deleteBatch.php | 39 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/maintenance/deleteBatch.php b/maintenance/deleteBatch.php index 2b0026d777..812b28dc16 100644 --- a/maintenance/deleteBatch.php +++ b/maintenance/deleteBatch.php @@ -49,9 +49,16 @@ class DeleteBatch extends Maintenance { chdir( $oldCwd ); # Options processing - $user = $this->getOption( 'u', 'Delete page script' ); + $username = $this->getOption( 'u', 'Delete page script' ); $reason = $this->getOption( 'r', '' ); $interval = $this->getOption( 'i', 0 ); + + $user = User::newFromName( $username ); + if ( !$user ) { + $this->error( "Invalid username", true ); + } + $wgUser = $user; + if ( $this->hasArg() ) { $file = fopen( $this->getArg(), 'r' ); } else { @@ -62,10 +69,7 @@ class DeleteBatch extends Maintenance { if ( !$file ) { $this->error( "Unable to read file, exiting", true ); } - $wgUser = User::newFromName( $user ); - if ( !$wgUser ) { - $this->error( "Invalid username", true ); - } + $dbw = wfGetDB( DB_MASTER ); # Handle each entry @@ -74,30 +78,27 @@ class DeleteBatch extends Maintenance { if ( $line == '' ) { continue; } - $page = Title::newFromText( $line ); - if ( is_null( $page ) ) { + $title = Title::newFromText( $line ); + if ( is_null( $title ) ) { $this->output( "Invalid title '$line' on line $linenum\n" ); continue; } - if ( !$page->exists() ) { + if ( !$title->exists() ) { $this->output( "Skipping nonexistent page '$line'\n" ); continue; } - $this->output( $page->getPrefixedText() ); + $this->output( $title->getPrefixedText() ); $dbw->begin(); - if ( $page->getNamespace() == NS_FILE ) { - $art = new ImagePage( $page ); - $img = wfFindFile( $art->mTitle ); - if ( !$img - || !$img->isLocal() - || !$img->delete( $reason ) ) { - $this->output( " FAILED to delete image file... " ); + if ( $title->getNamespace() == NS_FILE ) { + $img = wfFindFile( $title ); + if ( $img && $img->isLocal() && !$img->delete( $reason ) ) { + $this->output( " FAILED to delete associated file... " ); } - } else { - $art = new Article( $page ); } - $success = $art->doDeleteArticle( $reason ); + $page = WikiPage::factory( $title ); + $error = ''; + $success = $page->doDeleteArticle( $reason, false, 0, true, $error, $user ); $dbw->commit(); if ( $success ) { $this->output( " Deleted!\n" ); -- 2.20.1