Remove unused global $IP
[lhc/web/wiklou.git] / maintenance / edit.php
1 <?php
2 /**
3 * Make an edit
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @ingroup Maintenance
21 */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class EditCLI extends Maintenance {
26 public function __construct() {
27 parent::__construct();
28 $this->mDescription = "Edit an article from the command line, text is from stdin";
29 $this->addOption( 'u', 'Username', false, true );
30 $this->addOption( 's', 'Edit summary', false, true );
31 $this->addOption( 'm', 'Minor edit' );
32 $this->addOption( 'b', 'Bot edit' );
33 $this->addOption( 'a', 'Enable autosummary' );
34 $this->addOption( 'no-rc', 'Do not show the change in recent changes' );
35 $this->addArg( 'title', 'Title of article to edit' );
36 }
37
38 public function execute() {
39 global $wgUser, $wgArticle;
40
41 $userName = $this->getOption( 'u', 'Maintenance script' );
42 $summary = $this->getOption( 's', '' );
43 $minor = $this->hasOption( 'm' );
44 $bot = $this->hasOption( 'b' );
45 $autoSummary = $this->hasOption( 'a' );
46 $noRC = $this->hasOption( 'no-rc' );
47
48 $wgUser = User::newFromName( $userName );
49 if ( !$wgUser ) {
50 $this->error( "Invalid username", true );
51 }
52 if ( $wgUser->isAnon() ) {
53 $wgUser->addToDatabase();
54 }
55
56 $title = Title::newFromText( $this->getArg() );
57 if ( !$title ) {
58 $this->error( "Invalid title", true );
59 }
60
61 $wgArticle = new Article( $title );
62
63 # Read the text
64 $text = $this->getStdin( Maintenance::STDIN_ALL );
65
66 # Do the edit
67 $this->output( "Saving... " );
68 $status = $wgArticle->doEdit( $text, $summary,
69 ( $minor ? EDIT_MINOR : 0 ) |
70 ( $bot ? EDIT_FORCE_BOT : 0 ) |
71 ( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
72 ( $noRC ? EDIT_SUPPRESS_RC : 0 ) );
73 if ( $status->isOK() ) {
74 $this->output( "done\n" );
75 $exit = 0;
76 } else {
77 $this->output( "failed\n" );
78 $exit = 1;
79 }
80 if ( !$status->isGood() ) {
81 $this->output( $status->getWikiText() . "\n" );
82 }
83 exit( $exit );
84 }
85 }
86
87 $maintClass = "EditCLI";
88 require_once( DO_MAINTENANCE );
89