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