34require_once __DIR__ .
'/Maintenance.php';
44 parent::__construct();
45 $this->
addDescription(
'Edit an article from the command line, text is from stdin' );
46 $this->
addOption(
'user',
'Username',
false,
true,
'u' );
47 $this->
addOption(
'summary',
'Edit summary',
false,
true,
's' );
48 $this->
addOption(
'remove',
'Remove a slot (requires --slot).',
false,
false );
49 $this->
addOption(
'minor',
'Minor edit',
false,
false,
'm' );
50 $this->
addOption(
'bot',
'Bot edit',
false,
false,
'b' );
51 $this->
addOption(
'autosummary',
'Enable autosummary',
false,
false,
'a' );
52 $this->
addOption(
'no-rc',
'Do not show the change in recent changes',
false,
false,
'r' );
53 $this->
addOption(
'nocreate',
'Don\'t create new pages',
false,
false );
54 $this->
addOption(
'createonly',
'Only create new pages',
false,
false );
55 $this->
addOption(
'slot',
'Slot role name',
false,
true );
58 'Parse title input as a message, e.g. "{{int:mainpage}}" or "News_{{CURRENTYEAR}}',
61 $this->
addArg(
'title',
'Title of article to edit' );
66 $userName = $this->
getOption(
'user',
false );
67 $summary = $this->
getOption(
'summary',
'' );
71 $autoSummary = $this->
hasOption(
'autosummary' );
73 $slot = $this->
getOption(
'slot', SlotRecord::MAIN );
75 if ( $userName ===
false ) {
76 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
78 $user = User::newFromName( $userName );
83 if ( $user->isAnon() ) {
84 $user->addToDatabase();
86 StubGlobalUser::setUser( $user );
88 $titleInput = $this->
getArg( 0 );
90 if ( $this->
hasOption(
'parse-title' ) ) {
91 $titleInput = (
new RawMessage(
'$1' ) )->params( $titleInput )->text();
94 $title = Title::newFromText( $titleInput );
99 if ( $this->
hasOption(
'nocreate' ) && !$title->exists() ) {
101 } elseif ( $this->
hasOption(
'createonly' ) && $title->exists() ) {
108 if ( $slot === SlotRecord::MAIN ) {
109 $this->
fatalError(
"Cannot remove main slot! Use --slot to specify." );
115 $text = $this->
getStdin( Maintenance::STDIN_ALL );
116 $content = ContentHandler::makeContent( $text, $title );
120 $this->
output(
"Saving..." );
121 $updater = $page->newPageUpdater( $user );
128 if ( $content ===
false ) {
129 $updater->removeSlot( $slot );
131 $updater->setContent( $slot, $content );
134 $updater->saveRevision( CommentStoreComment::newUnsavedComment( $summary ), $flags );
135 $status = $updater->getStatus();
137 if ( $status->isOK() ) {
138 $this->
output(
"done\n" );
140 $this->
output(
"failed\n" );
142 if ( !$status->isGood() ) {
143 $this->
error( $status );
145 return $status->isOK();
151require_once RUN_MAINTENANCE_IF_MAIN;
const EDIT_FORCE_BOT
Mark the edit a "bot" edit regardless of user rights.
const EDIT_MINOR
Mark this edit minor, if the user is allowed to do so.
const EDIT_AUTOSUMMARY
Fill in blank summaries with generated text where possible.
Maintenance script to make a page edit.
__construct()
Default constructor.
execute()
Do the actual work.All child classes will need to implement thisbool|null|void True for success,...
Base class for content handling.
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.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.