64 $userName = $this->getOption(
'user',
false );
65 $summary = $this->getOption(
'summary',
'' );
66 $remove = $this->hasOption(
'remove' );
67 $minor = $this->hasOption(
'minor' );
68 $bot = $this->hasOption(
'bot' );
69 $autoSummary = $this->hasOption(
'autosummary' );
70 $noRC = $this->hasOption(
'no-rc' );
71 $slot = $this->getOption(
'slot', SlotRecord::MAIN );
73 if ( $userName ===
false ) {
74 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
76 $user = User::newFromName( $userName );
79 $this->fatalError(
"Invalid username" );
81 if ( $user->isAnon() ) {
82 $user->addToDatabase();
84 StubGlobalUser::setUser( $user );
86 $titleInput = $this->getArg( 0 );
88 if ( $this->hasOption(
'parse-title' ) ) {
89 $titleInput = (
new RawMessage(
'$1' ) )->params( $titleInput )->text();
92 $title = Title::newFromText( $titleInput );
94 $this->fatalError(
"Invalid title" );
97 if ( $this->hasOption(
'nocreate' ) && !$title->exists() ) {
98 $this->fatalError(
"Page does not exist" );
99 } elseif ( $this->hasOption(
'createonly' ) && $title->exists() ) {
100 $this->fatalError(
"Page already exists" );
103 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
106 if ( $slot === SlotRecord::MAIN ) {
107 $this->fatalError(
"Cannot remove main slot! Use --slot to specify." );
113 $text = $this->getStdin( Maintenance::STDIN_ALL );
114 $content = ContentHandler::makeContent( $text, $title );
118 $this->output(
"Saving..." );
119 $updater = $page->newPageUpdater( $user );
126 if ( $content ===
false ) {
127 $updater->removeSlot( $slot );
129 $updater->setContent( $slot, $content );
132 $updater->saveRevision( CommentStoreComment::newUnsavedComment( $summary ), $flags );
133 $status = $updater->getStatus();
135 if ( $status->isOK() ) {
136 $this->output(
"done\n" );
138 $this->output(
"failed\n" );
140 if ( !$status->isGood() ) {
141 $this->error( $status );
143 return $status->isOK();