Merge "Whitelist the <wbr> element."
[mediawiki.git] / maintenance / edit.php
blob7c24f0fab7a6c8f548a1c21fb6faa3cfab422d46
1 <?php
2 /**
3 * Make a page edit.
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.
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.
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
20 * @file
21 * @ingroup Maintenance
24 require_once __DIR__ . '/Maintenance.php';
26 /**
27 * Maintenance script to make a page edit.
29 * @ingroup Maintenance
31 class EditCLI extends Maintenance {
32 public function __construct() {
33 parent::__construct();
34 $this->mDescription = "Edit an article from the command line, text is from stdin";
35 $this->addOption( 'user', 'Username', false, true, 'u' );
36 $this->addOption( 'summary', 'Edit summary', false, true, 's' );
37 $this->addOption( 'minor', 'Minor edit', false, false, 'm' );
38 $this->addOption( 'bot', 'Bot edit', false, false, 'b' );
39 $this->addOption( 'autosummary', 'Enable autosummary', false, false, 'a' );
40 $this->addOption( 'no-rc', 'Do not show the change in recent changes', false, false, 'r' );
41 $this->addArg( 'title', 'Title of article to edit' );
44 public function execute() {
45 global $wgUser, $wgTitle;
47 $userName = $this->getOption( 'user', 'Maintenance script' );
48 $summary = $this->getOption( 'summary', '' );
49 $minor = $this->hasOption( 'minor' );
50 $bot = $this->hasOption( 'bot' );
51 $autoSummary = $this->hasOption( 'autosummary' );
52 $noRC = $this->hasOption( 'no-rc' );
54 $wgUser = User::newFromName( $userName );
55 $context = RequestContext::getMain();
56 $context->setUser( $wgUser );
57 if ( !$wgUser ) {
58 $this->error( "Invalid username", true );
60 if ( $wgUser->isAnon() ) {
61 $wgUser->addToDatabase();
64 $wgTitle = Title::newFromText( $this->getArg() );
65 if ( !$wgTitle ) {
66 $this->error( "Invalid title", true );
68 $context->setTitle( $wgTitle );
70 $page = WikiPage::factory( $wgTitle );
72 # Read the text
73 $text = $this->getStdin( Maintenance::STDIN_ALL );
74 $content = ContentHandler::makeContent( $text, $wgTitle );
76 # Do the edit
77 $this->output( "Saving... " );
78 $status = $page->doEditContent( $content, $summary,
79 ( $minor ? EDIT_MINOR : 0 ) |
80 ( $bot ? EDIT_FORCE_BOT : 0 ) |
81 ( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
82 ( $noRC ? EDIT_SUPPRESS_RC : 0 ) );
83 if ( $status->isOK() ) {
84 $this->output( "done\n" );
85 $exit = 0;
86 } else {
87 $this->output( "failed\n" );
88 $exit = 1;
90 if ( !$status->isGood() ) {
91 $this->output( $status->getWikiText() . "\n" );
93 exit( $exit );
97 $maintClass = "EditCLI";
98 require_once RUN_MAINTENANCE_IF_MAIN;