MediaWiki  REL1_19
edit.php
Go to the documentation of this file.
00001 <?php
00023 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
00024 
00025 class EditCLI extends Maintenance {
00026         public function __construct() {
00027                 parent::__construct();
00028                 $this->mDescription = "Edit an article from the command line, text is from stdin";
00029                 $this->addOption( 'user', 'Username', false, true, 'u' );
00030                 $this->addOption( 'summary', 'Edit summary', false, true, 's' );
00031                 $this->addOption( 'minor', 'Minor edit', false, false, 'm' );
00032                 $this->addOption( 'bot', 'Bot edit', false, false, 'b' );
00033                 $this->addOption( 'autosummary', 'Enable autosummary', false, false, 'a' );
00034                 $this->addOption( 'no-rc', 'Do not show the change in recent changes', false, false, 'r' );
00035                 $this->addArg( 'title', 'Title of article to edit' );
00036         }
00037 
00038         public function execute() {
00039                 global $wgUser, $wgTitle;
00040 
00041                 $userName = $this->getOption( 'user', 'Maintenance script' );
00042                 $summary = $this->getOption( 'summary', '' );
00043                 $minor = $this->hasOption( 'minor' );
00044                 $bot = $this->hasOption( 'bot' );
00045                 $autoSummary = $this->hasOption( 'autosummary' );
00046                 $noRC = $this->hasOption( 'no-rc' );
00047 
00048                 $wgUser = User::newFromName( $userName );
00049                 if ( !$wgUser ) {
00050                         $this->error( "Invalid username", true );
00051                 }
00052                 if ( $wgUser->isAnon() ) {
00053                         $wgUser->addToDatabase();
00054                 }
00055 
00056                 $wgTitle = Title::newFromText( $this->getArg() );
00057                 if ( !$wgTitle ) {
00058                         $this->error( "Invalid title", true );
00059                 }
00060 
00061                 $page = WikiPage::factory( $wgTitle );
00062 
00063                 # Read the text
00064                 $text = $this->getStdin( Maintenance::STDIN_ALL );
00065 
00066                 # Do the edit
00067                 $this->output( "Saving... " );
00068                 $status = $page->doEdit( $text, $summary,
00069                         ( $minor ? EDIT_MINOR : 0 ) |
00070                         ( $bot ? EDIT_FORCE_BOT : 0 ) |
00071                         ( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
00072                         ( $noRC ? EDIT_SUPPRESS_RC : 0 ) );
00073                 if ( $status->isOK() ) {
00074                         $this->output( "done\n" );
00075                         $exit = 0;
00076                 } else {
00077                         $this->output( "failed\n" );
00078                         $exit = 1;
00079                 }
00080                 if ( !$status->isGood() ) {
00081                         $this->output( $status->getWikiText() . "\n" );
00082                 }
00083                 exit( $exit );
00084         }
00085 }
00086 
00087 $maintClass = "EditCLI";
00088 require_once( RUN_MAINTENANCE_IF_MAIN );
00089