31require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
41 $this->
addDescription(
'Edit an article from the command line, text is from stdin' );
42 $this->
addOption(
'user',
'Username',
false,
true,
'u' );
43 $this->
addOption(
'summary',
'Edit summary',
false,
true,
's' );
44 $this->
addOption(
'remove',
'Remove a slot (requires --slot).',
false,
false );
45 $this->
addOption(
'minor',
'Minor edit',
false,
false,
'm' );
46 $this->
addOption(
'bot',
'Bot edit',
false,
false,
'b' );
47 $this->
addOption(
'autosummary',
'Enable autosummary',
false,
false,
'a' );
48 $this->
addOption(
'no-rc',
'Do not show the change in recent changes',
false,
false,
'r' );
49 $this->
addOption(
'nocreate',
'Don\'t create new pages',
false,
false );
50 $this->
addOption(
'createonly',
'Only create new pages',
false,
false );
51 $this->
addOption(
'slot',
'Slot role name',
false,
true );
54 'Parse title input as a message, e.g. "{{int:mainpage}}" or "News_{{CURRENTYEAR}}',
57 $this->
addArg(
'title',
'Title of article to edit' );
61 $userName = $this->
getOption(
'user',
false );
62 $summary = $this->
getOption(
'summary',
'' );
66 $autoSummary = $this->
hasOption(
'autosummary' );
68 $slot = $this->
getOption(
'slot', SlotRecord::MAIN );
70 if ( $userName ===
false ) {
78 if ( $user->isAnon() ) {
79 $user->addToDatabase();
81 StubGlobalUser::setUser( $user );
83 $titleInput = $this->
getArg( 0 );
85 if ( $this->
hasOption(
'parse-title' ) ) {
86 $titleInput = (
new RawMessage(
'$1' ) )->params( $titleInput )->text();
89 $title = Title::newFromText( $titleInput );
100 $page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle(
$title );
103 if ( $slot === SlotRecord::MAIN ) {
104 $this->
fatalError(
"Cannot remove main slot! Use --slot to specify." );
115 $this->
output(
"Saving..." );
116 $updater = $page->newPageUpdater( $user );
124 $updater->removeSlot( $slot );
126 $updater->setContent( $slot,
$content );
129 $updater->saveRevision( CommentStoreComment::newUnsavedComment( $summary ), $flags );
130 $status = $updater->getStatus();
132 if ( $status->isOK() ) {
133 $this->
output(
"done\n" );
135 $this->
output(
"failed\n" );
137 if ( !$status->isGood() ) {
138 $this->
output( $status->getMessage(
false,
false,
'en' )->text() .
"\n" );
140 return $status->isOK();
145require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to make a page edit.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static newFromName( $name, $validate='valid')
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
const MAINTENANCE_SCRIPT_USER
Username used for various maintenance scripts.