Merge "merge msg script now detects extensions main files"
[lhc/web/wiklou.git] / maintenance / edit.php
1 <?php
2 /**
3 * Make a page 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 /**
26 * Maintenance script to make a page edit.
27 *
28 * @ingroup Maintenance
29 */
30 class EditCLI extends Maintenance {
31 public function __construct() {
32 parent::__construct();
33 $this->mDescription = "Edit an article from the command line, text is from stdin";
34 $this->addOption( 'user', 'Username', false, true, 'u' );
35 $this->addOption( 'summary', 'Edit summary', false, true, 's' );
36 $this->addOption( 'minor', 'Minor edit', false, false, 'm' );
37 $this->addOption( 'bot', 'Bot edit', false, false, 'b' );
38 $this->addOption( 'autosummary', 'Enable autosummary', false, false, 'a' );
39 $this->addOption( 'no-rc', 'Do not show the change in recent changes', false, false, 'r' );
40 $this->addArg( 'title', 'Title of article to edit' );
41 }
42
43 public function execute() {
44 global $wgUser, $wgTitle;
45
46 $userName = $this->getOption( 'user', 'Maintenance script' );
47 $summary = $this->getOption( 'summary', '' );
48 $minor = $this->hasOption( 'minor' );
49 $bot = $this->hasOption( 'bot' );
50 $autoSummary = $this->hasOption( 'autosummary' );
51 $noRC = $this->hasOption( 'no-rc' );
52
53 $wgUser = User::newFromName( $userName );
54 if ( !$wgUser ) {
55 $this->error( "Invalid username", true );
56 }
57 if ( $wgUser->isAnon() ) {
58 $wgUser->addToDatabase();
59 }
60
61 $wgTitle = Title::newFromText( $this->getArg() );
62 if ( !$wgTitle ) {
63 $this->error( "Invalid title", true );
64 }
65
66 $page = WikiPage::factory( $wgTitle );
67
68 # Read the text
69 $text = $this->getStdin( Maintenance::STDIN_ALL );
70
71 # Do the edit
72 $this->output( "Saving... " );
73 $status = $page->doEdit( $text, $summary,
74 ( $minor ? EDIT_MINOR : 0 ) |
75 ( $bot ? EDIT_FORCE_BOT : 0 ) |
76 ( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
77 ( $noRC ? EDIT_SUPPRESS_RC : 0 ) );
78 if ( $status->isOK() ) {
79 $this->output( "done\n" );
80 $exit = 0;
81 } else {
82 $this->output( "failed\n" );
83 $exit = 1;
84 }
85 if ( !$status->isGood() ) {
86 $this->output( $status->getWikiText() . "\n" );
87 }
88 exit( $exit );
89 }
90 }
91
92 $maintClass = "EditCLI";
93 require_once( RUN_MAINTENANCE_IF_MAIN );
94