20require_once __DIR__ .
'/Maintenance.php';
30 parent::__construct();
31 $this->
addDescription(
'Edit an article from the command line, text is from stdin' );
32 $this->
addOption(
'user',
'Username',
false,
true,
'u' );
33 $this->
addOption(
'summary',
'Edit summary',
false,
true,
's' );
34 $this->
addOption(
'remove',
'Remove a slot (requires --slot).',
false,
false );
35 $this->
addOption(
'minor',
'Minor edit',
false,
false,
'm' );
36 $this->
addOption(
'bot',
'Bot edit',
false,
false,
'b' );
37 $this->
addOption(
'autosummary',
'Enable autosummary',
false,
false,
'a' );
38 $this->
addOption(
'no-rc',
'Do not show the change in recent changes',
false,
false,
'r' );
39 $this->
addOption(
'nocreate',
'Don\'t create new pages',
false,
false );
40 $this->
addOption(
'createonly',
'Only create new pages',
false,
false );
41 $this->
addOption(
'slot',
'Slot role name',
false,
true );
44 'Parse title input as a message, e.g. "{{int:mainpage}}" or "News_{{CURRENTYEAR}}',
47 $this->
addArg(
'title',
'Title of article to edit' );
52 $userName = $this->
getOption(
'user',
false );
53 $summary = $this->
getOption(
'summary',
'' );
57 $autoSummary = $this->
hasOption(
'autosummary' );
59 $slot = $this->
getOption(
'slot', SlotRecord::MAIN );
61 if ( $userName ===
false ) {
62 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
64 $user = User::newFromName( $userName );
69 if ( $user->isAnon() ) {
70 $user->addToDatabase();
72 StubGlobalUser::setUser( $user );
74 $titleInput = $this->
getArg( 0 );
76 if ( $this->
hasOption(
'parse-title' ) ) {
77 $titleInput = (
new RawMessage(
'$1' ) )->params( $titleInput )->text();
80 $title = Title::newFromText( $titleInput );
85 if ( $this->
hasOption(
'nocreate' ) && !$title->exists() ) {
87 } elseif ( $this->
hasOption(
'createonly' ) && $title->exists() ) {
94 if ( $slot === SlotRecord::MAIN ) {
95 $this->
fatalError(
"Cannot remove main slot! Use --slot to specify." );
101 $text = $this->
getStdin( Maintenance::STDIN_ALL );
102 $content = ContentHandler::makeContent( $text, $title );
106 $this->
output(
"Saving..." );
107 $updater = $page->newPageUpdater( $user );
114 if ( $content ===
false ) {
115 $updater->removeSlot( $slot );
117 $updater->setContent( $slot, $content );
120 $updater->saveRevision( CommentStoreComment::newUnsavedComment( $summary ), $flags );
121 $status = $updater->getStatus();
123 if ( $status->isOK() ) {
124 $this->
output(
"done\n" );
126 $this->
output(
"failed\n" );
128 if ( !$status->isGood() ) {
129 $this->
error( $status );
131 return $status->isOK();
137require_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.