2006-12-16 06:15:04 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2012-07-10 16:50:19 +00:00
|
|
|
* Make a page edit.
|
2009-08-02 19:35:17 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-07-17 05:40:40 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2006-12-16 06:15:04 +00:00
|
|
|
|
2022-12-28 21:50:03 +00:00
|
|
|
use MediaWiki\CommentStore\CommentStoreComment;
|
2022-12-12 02:10:13 +00:00
|
|
|
use MediaWiki\Language\RawMessage;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2022-10-25 16:58:49 +00:00
|
|
|
use MediaWiki\StubObject\StubGlobalUser;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2018-09-24 21:10:08 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2006-12-16 06:15:04 +00:00
|
|
|
|
2012-07-10 16:50:19 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to make a page edit.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class EditCLI extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Edit an article from the command line, text is from stdin' );
|
2011-04-06 18:37:09 +00:00
|
|
|
$this->addOption( 'user', 'Username', false, true, 'u' );
|
|
|
|
|
$this->addOption( 'summary', 'Edit summary', false, true, 's' );
|
2018-09-14 09:20:12 +00:00
|
|
|
$this->addOption( 'remove', 'Remove a slot (requires --slot).', false, false );
|
2011-04-06 18:37:09 +00:00
|
|
|
$this->addOption( 'minor', 'Minor edit', false, false, 'm' );
|
|
|
|
|
$this->addOption( 'bot', 'Bot edit', false, false, 'b' );
|
|
|
|
|
$this->addOption( 'autosummary', 'Enable autosummary', false, false, 'a' );
|
|
|
|
|
$this->addOption( 'no-rc', 'Do not show the change in recent changes', false, false, 'r' );
|
2013-12-10 22:13:53 +00:00
|
|
|
$this->addOption( 'nocreate', 'Don\'t create new pages', false, false );
|
|
|
|
|
$this->addOption( 'createonly', 'Only create new pages', false, false );
|
2018-09-14 09:20:12 +00:00
|
|
|
$this->addOption( 'slot', 'Slot role name', false, true );
|
2021-11-17 15:30:16 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'parse-title',
|
|
|
|
|
'Parse title input as a message, e.g. "{{int:mainpage}}" or "News_{{CURRENTYEAR}}',
|
|
|
|
|
false, false, 'p'
|
|
|
|
|
);
|
2009-08-18 23:06:24 +00:00
|
|
|
$this->addArg( 'title', 'Title of article to edit' );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2006-12-16 06:15:04 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2015-09-04 16:17:42 +00:00
|
|
|
$userName = $this->getOption( 'user', false );
|
2011-04-06 18:37:09 +00:00
|
|
|
$summary = $this->getOption( 'summary', '' );
|
2018-09-14 09:20:12 +00:00
|
|
|
$remove = $this->hasOption( 'remove' );
|
2011-04-06 18:37:09 +00:00
|
|
|
$minor = $this->hasOption( 'minor' );
|
|
|
|
|
$bot = $this->hasOption( 'bot' );
|
|
|
|
|
$autoSummary = $this->hasOption( 'autosummary' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$noRC = $this->hasOption( 'no-rc' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$slot = $this->getOption( 'slot', SlotRecord::MAIN );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2015-09-04 16:17:42 +00:00
|
|
|
if ( $userName === false ) {
|
2021-05-03 21:34:26 +00:00
|
|
|
$user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [ 'steal' => true ] );
|
2015-09-04 16:17:42 +00:00
|
|
|
} else {
|
2020-06-05 01:37:01 +00:00
|
|
|
$user = User::newFromName( $userName );
|
2015-09-04 16:17:42 +00:00
|
|
|
}
|
2020-06-05 01:37:01 +00:00
|
|
|
if ( !$user ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Invalid username" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2020-06-05 01:37:01 +00:00
|
|
|
if ( $user->isAnon() ) {
|
|
|
|
|
$user->addToDatabase();
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2021-09-04 19:19:47 +00:00
|
|
|
StubGlobalUser::setUser( $user );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2021-11-17 15:30:16 +00:00
|
|
|
$titleInput = $this->getArg( 0 );
|
|
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'parse-title' ) ) {
|
|
|
|
|
$titleInput = ( new RawMessage( '$1' ) )->params( $titleInput )->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = Title::newFromText( $titleInput );
|
2013-11-17 02:03:11 +00:00
|
|
|
if ( !$title ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Invalid title" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2013-12-10 22:13:53 +00:00
|
|
|
if ( $this->hasOption( 'nocreate' ) && !$title->exists() ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Page does not exist" );
|
2013-12-10 22:13:53 +00:00
|
|
|
} elseif ( $this->hasOption( 'createonly' ) && $title->exists() ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Page already exists" );
|
2013-12-10 22:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2018-09-14 09:20:12 +00:00
|
|
|
if ( $remove ) {
|
2018-09-24 21:10:08 +00:00
|
|
|
if ( $slot === SlotRecord::MAIN ) {
|
2018-09-14 09:20:12 +00:00
|
|
|
$this->fatalError( "Cannot remove main slot! Use --slot to specify." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$content = false;
|
|
|
|
|
} else {
|
|
|
|
|
# Read the text
|
|
|
|
|
$text = $this->getStdin( Maintenance::STDIN_ALL );
|
|
|
|
|
$content = ContentHandler::makeContent( $text, $title );
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Do the edit
|
2021-07-21 16:34:05 +00:00
|
|
|
$this->output( "Saving..." );
|
2020-06-05 01:37:01 +00:00
|
|
|
$updater = $page->newPageUpdater( $user );
|
2018-09-14 09:20:12 +00:00
|
|
|
|
|
|
|
|
$flags = ( $minor ? EDIT_MINOR : 0 ) |
|
2010-05-22 16:50:39 +00:00
|
|
|
( $bot ? EDIT_FORCE_BOT : 0 ) |
|
2009-08-02 19:35:17 +00:00
|
|
|
( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
|
2018-09-14 09:20:12 +00:00
|
|
|
( $noRC ? EDIT_SUPPRESS_RC : 0 );
|
|
|
|
|
|
|
|
|
|
if ( $content === false ) {
|
|
|
|
|
$updater->removeSlot( $slot );
|
|
|
|
|
} else {
|
|
|
|
|
$updater->setContent( $slot, $content );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$updater->saveRevision( CommentStoreComment::newUnsavedComment( $summary ), $flags );
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( $status->isOK() ) {
|
|
|
|
|
$this->output( "done\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "failed\n" );
|
|
|
|
|
}
|
|
|
|
|
if ( !$status->isGood() ) {
|
Maintenance: Print errors from StatusValue objects in a consistent way
Allow Maintenance::error() and Maintenance::fatalError() to take
StatusValue objects. They now print each error message from the
status on a separate line, in English, ignoring on-wiki message
overrides, as wikitext but after parser function expansion.
Thoughts on the previously commonly used methods:
- $status->getMessage( false, false, 'en' )->text()
Almost the same as the new output, but it allows on-wiki message
overrides, and if there is more than one error, it prefixes each
line with a '*' (like a wikitext list).
- $status->getMessage( false, false, 'en' )->plain()
- $status->getWikiText( false, false, 'en' )
As above, but these forms do not expand parser functions
such as {{GENDER:}}.
- print_r( $status->getErrorsArray(), true )
- print_r( $status->getErrors(), true )
These forms output the message keys instead of the message text,
which is not very human-readable.
The error messages are now always printed using error() rather
than output(), which means they go to STDERR rather than STDOUT
and they're printed even with the --quiet flag.
Change-Id: I5b8e7c7ed2a896a1029f58857a478d3f1b4b0589
2024-06-06 23:50:00 +00:00
|
|
|
$this->error( $status );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2021-08-30 18:54:47 +00:00
|
|
|
return $status->isOK();
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2006-12-16 06:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = EditCLI::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|