Merge "Remove unused private var and fix phpdoc"
[lhc/web/wiklou.git] / maintenance / edit.php
index 6e69651..75ec12b 100644 (file)
@@ -38,6 +38,8 @@ class EditCLI extends Maintenance {
                $this->addOption( 'bot', 'Bot edit', false, false, 'b' );
                $this->addOption( 'autosummary', 'Enable autosummary', false, false, 'a' );
                $this->addOption( 'no-rc', 'Do not show the change in recent changes', false, false, 'r' );
+               $this->addOption( 'nocreate', 'Don\'t create new pages', false, false );
+               $this->addOption( 'createonly', 'Only create new pages', false, false );
                $this->addArg( 'title', 'Title of article to edit' );
        }
 
@@ -52,8 +54,6 @@ class EditCLI extends Maintenance {
                $noRC = $this->hasOption( 'no-rc' );
 
                $wgUser = User::newFromName( $userName );
-               $context = RequestContext::getMain();
-               $context->setUser( $wgUser );
                if ( !$wgUser ) {
                        $this->error( "Invalid username", true );
                }
@@ -65,7 +65,12 @@ class EditCLI extends Maintenance {
                if ( !$title ) {
                        $this->error( "Invalid title", true );
                }
-               $context->setTitle( $title );
+
+               if ( $this->hasOption( 'nocreate' ) && !$title->exists() ) {
+                       $this->error( "Page does not exist", true );
+               } elseif ( $this->hasOption( 'createonly' ) && $title->exists() ) {
+                       $this->error( "Page already exists", true );
+               }
 
                $page = WikiPage::factory( $title );