Update categoriespagetext message
[lhc/web/wiklou.git] / maintenance / edit.php
index 75ec12b..60ed252 100644 (file)
@@ -31,7 +31,7 @@ require_once __DIR__ . '/Maintenance.php';
 class EditCLI extends Maintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Edit an article from the command line, text is from stdin";
+               $this->addDescription( 'Edit an article from the command line, text is from stdin' );
                $this->addOption( 'user', 'Username', false, true, 'u' );
                $this->addOption( 'summary', 'Edit summary', false, true, 's' );
                $this->addOption( 'minor', 'Minor edit', false, false, 'm' );
@@ -46,16 +46,20 @@ class EditCLI extends Maintenance {
        public function execute() {
                global $wgUser;
 
-               $userName = $this->getOption( 'user', 'Maintenance script' );
+               $userName = $this->getOption( 'user', false );
                $summary = $this->getOption( 'summary', '' );
                $minor = $this->hasOption( 'minor' );
                $bot = $this->hasOption( 'bot' );
                $autoSummary = $this->hasOption( 'autosummary' );
                $noRC = $this->hasOption( 'no-rc' );
 
-               $wgUser = User::newFromName( $userName );
+               if ( $userName === false ) {
+                       $wgUser = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
+               } else {
+                       $wgUser = User::newFromName( $userName );
+               }
                if ( !$wgUser ) {
-                       $this->error( "Invalid username", true );
+                       $this->fatalError( "Invalid username" );
                }
                if ( $wgUser->isAnon() ) {
                        $wgUser->addToDatabase();
@@ -63,13 +67,13 @@ class EditCLI extends Maintenance {
 
                $title = Title::newFromText( $this->getArg() );
                if ( !$title ) {
-                       $this->error( "Invalid title", true );
+                       $this->fatalError( "Invalid title" );
                }
 
                if ( $this->hasOption( 'nocreate' ) && !$title->exists() ) {
-                       $this->error( "Page does not exist", true );
+                       $this->fatalError( "Page does not exist" );
                } elseif ( $this->hasOption( 'createonly' ) && $title->exists() ) {
-                       $this->error( "Page already exists", true );
+                       $this->fatalError( "Page already exists" );
                }
 
                $page = WikiPage::factory( $title );
@@ -93,11 +97,11 @@ class EditCLI extends Maintenance {
                        $exit = 1;
                }
                if ( !$status->isGood() ) {
-                       $this->output( $status->getWikiText() . "\n" );
+                       $this->output( $status->getWikiText( false, false, 'en' ) . "\n" );
                }
                exit( $exit );
        }
 }
 
-$maintClass = "EditCLI";
+$maintClass = EditCLI::class;
 require_once RUN_MAINTENANCE_IF_MAIN;