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( 'u', 'Username', false, true );
00030 $this->addOption( 's', 'Edit summary', false, true );
00031 $this->addOption( 'm', 'Minor edit' );
00032 $this->addOption( 'b', 'Bot edit' );
00033 $this->addOption( 'a', 'Enable autosummary' );
00034 $this->addOption( 'no-rc', 'Do not show the change in recent changes' );
00035 $this->addArg( 'title', 'Title of article to edit' );
00036 }
00037
00038 public function execute() {
00039 global $wgUser, $wgTitle, $wgArticle;
00040
00041 $userName = $this->getOption( 'u', 'Maintenance script' );
00042 $summary = $this->getOption( 's', '' );
00043 $minor = $this->hasOption( 'm' );
00044 $bot = $this->hasOption( 'b' );
00045 $autoSummary = $this->hasOption( 'a' );
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 $wgArticle = new Article( $wgTitle );
00062
00063 # Read the text
00064 $text = $this->getStdin( Maintenance::STDIN_ALL );
00065
00066 # Do the edit
00067 $this->output( "Saving... " );
00068 $status = $wgArticle->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( DO_MAINTENANCE );
00089