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' );
65 $userName = $this->
getOption(
'user',
false );
66 $summary = $this->
getOption(
'summary',
'' );
70 $autoSummary = $this->
hasOption(
'autosummary' );
72 $slot = $this->
getOption(
'slot', SlotRecord::MAIN );
74 if ( $userName ===
false ) {
75 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
77 $user = User::newFromName( $userName );
82 if ( $user->isAnon() ) {
83 $user->addToDatabase();
85 StubGlobalUser::setUser( $user );
87 $titleInput = $this->
getArg( 0 );
89 if ( $this->
hasOption(
'parse-title' ) ) {
90 $titleInput = (
new RawMessage(
'$1' ) )->params( $titleInput )->text();
93 $title = Title::newFromText( $titleInput );
98 if ( $this->
hasOption(
'nocreate' ) && !$title->exists() ) {
100 } elseif ( $this->
hasOption(
'createonly' ) && $title->exists() ) {
107 if ( $slot === SlotRecord::MAIN ) {
108 $this->
fatalError(
"Cannot remove main slot! Use --slot to specify." );
114 $text = $this->
getStdin( Maintenance::STDIN_ALL );
115 $content = ContentHandler::makeContent( $text, $title );
119 $this->
output(
"Saving..." );
120 $updater = $page->newPageUpdater( $user );
127 if ( $content ===
false ) {
128 $updater->removeSlot( $slot );
130 $updater->setContent( $slot, $content );
133 $updater->saveRevision( CommentStoreComment::newUnsavedComment( $summary ), $flags );
134 $status = $updater->getStatus();
136 if ( $status->isOK() ) {
137 $this->
output(
"done\n" );
139 $this->
output(
"failed\n" );
141 if ( !$status->isGood() ) {
142 $this->
error( $status );
144 return $status->isOK();
150require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to make a page edit.
__construct()
Default constructor.
execute()
Do the actual work.
A content handler knows how do deal with a specific type of content on a wiki page.
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.