00001 <?php 00007 $optionsWithArgs = array( 'u', 's' ); 00008 00009 require_once( 'commandLine.inc' ); 00010 00011 if ( count( $args ) == 0 || isset( $options['help'] ) ) { 00012 print <<<EOT 00013 Edit an article from the command line 00014 00015 Usage: php edit.php [options...] <title> 00016 00017 Options: 00018 -u <user> Username 00019 -s <summary> Edit summary 00020 -m Minor edit 00021 -b Bot (hidden) edit 00022 -a Enable autosummary 00023 --no-rc Do not show the change in recent changes 00024 00025 If the specified user does not exist, it will be created. 00026 The text for the edit will be read from stdin. 00027 00028 EOT; 00029 exit( 1 ); 00030 } 00031 00032 $userName = isset( $options['u'] ) ? $options['u'] : 'Maintenance script'; 00033 $summary = isset( $options['s'] ) ? $options['s'] : ''; 00034 $minor = isset( $options['m'] ); 00035 $bot = isset( $options['b'] ); 00036 $autoSummary = isset( $options['a'] ); 00037 $noRC = isset( $options['no-rc'] ); 00038 00039 $wgUser = User::newFromName( $userName ); 00040 if ( !$wgUser ) { 00041 print "Invalid username\n"; 00042 exit( 1 ); 00043 } 00044 if ( $wgUser->isAnon() ) { 00045 $wgUser->addToDatabase(); 00046 } 00047 00048 $wgTitle = Title::newFromText( $args[0] ); 00049 if ( !$wgTitle ) { 00050 print "Invalid title\n"; 00051 exit( 1 ); 00052 } 00053 00054 $wgArticle = new Article( $wgTitle ); 00055 00056 # Read the text 00057 $text = file_get_contents( 'php://stdin' ); 00058 00059 # Do the edit 00060 print "Saving... "; 00061 $status = $wgArticle->doEdit( $text, $summary, 00062 ( $minor ? EDIT_MINOR : 0 ) | 00063 ( $bot ? EDIT_FORCE_BOT : 0 ) | 00064 ( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) | 00065 ( $noRC ? EDIT_SUPPRESS_RC : 0 ) ); 00066 if ( $status->isOK() ) { 00067 print "done\n"; 00068 $exit = 0; 00069 } else { 00070 print "failed\n"; 00071 $exit = 1; 00072 } 00073 if ( !$status->isGood() ) { 00074 print $status->getWikiText() . "\n"; 00075 } 00076 exit( $exit ); 00077