Change "Special:近易" to "Special:監修" in zh-classical
[lhc/web/wiklou.git] / maintenance / deleteBatch.php
index 93507b3..c3cbdeb 100644 (file)
@@ -39,7 +39,7 @@ class DeleteBatch extends Maintenance {
 
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Deletes a batch of pages";
+               $this->addDescription( 'Deletes a batch of pages' );
                $this->addOption( 'u', "User to perform deletion", false, true );
                $this->addOption( 'r', "Reason to delete page", false, true );
                $this->addOption( 'i', "Interval to sleep between deletions" );
@@ -55,13 +55,17 @@ class DeleteBatch extends Maintenance {
                chdir( $oldCwd );
 
                # Options processing
-               $username = $this->getOption( 'u', 'Delete page script' );
+               $username = $this->getOption( 'u', false );
                $reason = $this->getOption( 'r', '' );
                $interval = $this->getOption( 'i', 0 );
 
-               $user = User::newFromName( $username );
+               if ( $username === false ) {
+                       $user = User::newSystemUser( 'Delete page script', [ 'steal' => true ] );
+               } else {
+                       $user = User::newFromName( $username );
+               }
                if ( !$user ) {
-                       $this->error( "Invalid username", true );
+                       $this->fatalError( "Invalid username" );
                }
                $wgUser = $user;
 
@@ -73,15 +77,14 @@ class DeleteBatch extends Maintenance {
 
                # Setup
                if ( !$file ) {
-                       $this->error( "Unable to read file, exiting", true );
+                       $this->fatalError( "Unable to read file, exiting" );
                }
 
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
 
                # Handle each entry
-               // @codingStandardsIgnoreStart Ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
+               // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
                for ( $linenum = 1; !feof( $file ); $linenum++ ) {
-                       // @codingStandardsIgnoreEnd
                        $line = trim( fgets( $file ) );
                        if ( $line == '' ) {
                                continue;
@@ -97,17 +100,15 @@ class DeleteBatch extends Maintenance {
                        }
 
                        $this->output( $title->getPrefixedText() );
-                       $dbw->begin( __METHOD__ );
                        if ( $title->getNamespace() == NS_FILE ) {
-                               $img = wfFindFile( $title, array( 'ignoreRedirect' => true ) );
+                               $img = wfFindFile( $title, [ 'ignoreRedirect' => true ] );
                                if ( $img && $img->isLocal() && !$img->delete( $reason ) ) {
                                        $this->output( " FAILED to delete associated file... " );
                                }
                        }
                        $page = WikiPage::factory( $title );
                        $error = '';
-                       $success = $page->doDeleteArticle( $reason, false, 0, false, $error, $user );
-                       $dbw->commit( __METHOD__ );
+                       $success = $page->doDeleteArticle( $reason, false, 0, true, $error, $user );
                        if ( $success ) {
                                $this->output( " Deleted!\n" );
                        } else {