$this->context->getUser()->spreadAnyEditBlock();
} );
}
-
- $config = $this->context->getConfig();
- if ( $config->get( 'EnableBlockNoticeStats' ) ) {
- $wiki = $config->get( 'DBname' );
- $statsd = MediaWikiServices::getInstance()->getStatsdDataFactory();
- $statsd->increment( 'BlockNotices.' . $wiki . '.WikitextEditor.shown' );
- }
}
$this->displayPermissionsError( $permErrors );
$content = $this->getPreloadedContent( $preload, $params );
}
// For existing pages, get text based on "undo" or section parameters.
- } else {
- if ( $this->section != '' ) {
- // Get section edit text (returns $def_text for invalid sections)
- $orig = $this->getOriginalContent( $user );
- $content = $orig ? $orig->getSection( $this->section ) : null;
+ } elseif ( $this->section != '' ) {
+ // Get section edit text (returns $def_text for invalid sections)
+ $orig = $this->getOriginalContent( $user );
+ $content = $orig ? $orig->getSection( $this->section ) : null;
- if ( !$content ) {
- $content = $def_content;
- }
- } else {
- $undoafter = $request->getInt( 'undoafter' );
- $undo = $request->getInt( 'undo' );
-
- if ( $undo > 0 && $undoafter > 0 ) {
- $undorev = Revision::newFromId( $undo );
- $oldrev = Revision::newFromId( $undoafter );
- $undoMsg = null;
-
- # Sanity check, make sure it's the right page,
- # the revisions exist and they were not deleted.
- # Otherwise, $content will be left as-is.
- if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
- !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
- !$oldrev->isDeleted( Revision::DELETED_TEXT )
+ if ( !$content ) {
+ $content = $def_content;
+ }
+ } else {
+ $undoafter = $request->getInt( 'undoafter' );
+ $undo = $request->getInt( 'undo' );
+
+ if ( $undo > 0 && $undoafter > 0 ) {
+ $undorev = Revision::newFromId( $undo );
+ $oldrev = Revision::newFromId( $undoafter );
+ $undoMsg = null;
+
+ # Sanity check, make sure it's the right page,
+ # the revisions exist and they were not deleted.
+ # Otherwise, $content will be left as-is.
+ if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
+ !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
+ !$oldrev->isDeleted( Revision::DELETED_TEXT )
+ ) {
+ if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev )
+ || !$this->isSupportedContentModel( $oldrev->getContentModel() )
) {
- if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev )
- || !$this->isSupportedContentModel( $oldrev->getContentModel() )
- ) {
- // Hack for undo while EditPage can't handle multi-slot editing
- $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [
- 'action' => 'mcrundo',
- 'undo' => $undo,
- 'undoafter' => $undoafter,
- ] ) );
- return false;
- } else {
- $content = $this->page->getUndoContent( $undorev, $oldrev );
+ // Hack for undo while EditPage can't handle multi-slot editing
+ $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [
+ 'action' => 'mcrundo',
+ 'undo' => $undo,
+ 'undoafter' => $undoafter,
+ ] ) );
+ return false;
+ } else {
+ $content = $this->page->getUndoContent( $undorev, $oldrev );
- if ( $content === false ) {
- # Warn the user that something went wrong
- $undoMsg = 'failure';
- }
+ if ( $content === false ) {
+ # Warn the user that something went wrong
+ $undoMsg = 'failure';
}
+ }
- if ( $undoMsg === null ) {
- $oldContent = $this->page->getContent( Revision::RAW );
- $popts = ParserOptions::newFromUserAndLang(
- $user, MediaWikiServices::getInstance()->getContentLanguage() );
- $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts );
- if ( $newContent->getModel() !== $oldContent->getModel() ) {
- // The undo may change content
- // model if its reverting the top
- // edit. This can result in
- // mismatched content model/format.
- $this->contentModel = $newContent->getModel();
- $this->contentFormat = $oldrev->getContentFormat();
- }
+ if ( $undoMsg === null ) {
+ $oldContent = $this->page->getContent( Revision::RAW );
+ $popts = ParserOptions::newFromUserAndLang(
+ $user, MediaWikiServices::getInstance()->getContentLanguage() );
+ $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts );
+ if ( $newContent->getModel() !== $oldContent->getModel() ) {
+ // The undo may change content
+ // model if its reverting the top
+ // edit. This can result in
+ // mismatched content model/format.
+ $this->contentModel = $newContent->getModel();
+ $this->contentFormat = $oldrev->getContentFormat();
+ }
- if ( $newContent->equals( $oldContent ) ) {
- # Tell the user that the undo results in no change,
- # i.e. the revisions were already undone.
- $undoMsg = 'nochange';
- $content = false;
- } else {
- # Inform the user of our success and set an automatic edit summary
- $undoMsg = 'success';
-
- # If we just undid one rev, use an autosummary
- $firstrev = $oldrev->getNext();
- if ( $firstrev && $firstrev->getId() == $undo ) {
- $userText = $undorev->getUserText();
- if ( $userText === '' ) {
- $undoSummary = $this->context->msg(
- 'undo-summary-username-hidden',
- $undo
- )->inContentLanguage()->text();
- } else {
- $undoSummary = $this->context->msg(
- 'undo-summary',
- $undo,
- $userText
- )->inContentLanguage()->text();
- }
- if ( $this->summary === '' ) {
- $this->summary = $undoSummary;
- } else {
- $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
- ->inContentLanguage()->text() . $this->summary;
- }
- $this->undidRev = $undo;
+ if ( $newContent->equals( $oldContent ) ) {
+ # Tell the user that the undo results in no change,
+ # i.e. the revisions were already undone.
+ $undoMsg = 'nochange';
+ $content = false;
+ } else {
+ # Inform the user of our success and set an automatic edit summary
+ $undoMsg = 'success';
+
+ # If we just undid one rev, use an autosummary
+ $firstrev = $oldrev->getNext();
+ if ( $firstrev && $firstrev->getId() == $undo ) {
+ $userText = $undorev->getUserText();
+ if ( $userText === '' ) {
+ $undoSummary = $this->context->msg(
+ 'undo-summary-username-hidden',
+ $undo
+ )->inContentLanguage()->text();
+ } else {
+ $undoSummary = $this->context->msg(
+ 'undo-summary',
+ $undo,
+ $userText
+ )->inContentLanguage()->text();
}
- $this->formtype = 'diff';
+ if ( $this->summary === '' ) {
+ $this->summary = $undoSummary;
+ } else {
+ $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
+ ->inContentLanguage()->text() . $this->summary;
+ }
+ $this->undidRev = $undo;
}
+ $this->formtype = 'diff';
}
- } else {
- // Failed basic sanity checks.
- // Older revisions may have been removed since the link
- // was created, or we may simply have got bogus input.
- $undoMsg = 'norev';
}
-
- $out = $this->context->getOutput();
- // Messages: undo-success, undo-failure, undo-main-slot-only, undo-norev,
- // undo-nochange.
- $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
- $this->editFormPageTop .= Html::rawElement(
- 'div', [ 'class' => $class ],
- $out->parseAsInterface(
- $this->context->msg( 'undo-' . $undoMsg )->plain()
- )
- );
+ } else {
+ // Failed basic sanity checks.
+ // Older revisions may have been removed since the link
+ // was created, or we may simply have got bogus input.
+ $undoMsg = 'norev';
}
- if ( $content === false ) {
- // Hack for restoring old revisions while EditPage
- // can't handle multi-slot editing.
+ $out = $this->context->getOutput();
+ // Messages: undo-success, undo-failure, undo-main-slot-only, undo-norev,
+ // undo-nochange.
+ $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
+ $this->editFormPageTop .= Html::rawElement(
+ 'div', [ 'class' => $class ],
+ $out->parseAsInterface(
+ $this->context->msg( 'undo-' . $undoMsg )->plain()
+ )
+ );
+ }
- $curRevision = $this->page->getRevision();
- $oldRevision = $this->mArticle->getRevisionFetched();
+ if ( $content === false ) {
+ // Hack for restoring old revisions while EditPage
+ // can't handle multi-slot editing.
- if ( $curRevision
- && $oldRevision
- && $curRevision->getId() !== $oldRevision->getId()
- && ( WikiPage::hasDifferencesOutsideMainSlot( $oldRevision, $curRevision )
- || !$this->isSupportedContentModel( $oldRevision->getContentModel() ) )
- ) {
- $this->context->getOutput()->redirect(
- $this->mTitle->getFullURL(
- [
- 'action' => 'mcrrestore',
- 'restore' => $oldRevision->getId(),
- ]
- )
- );
+ $curRevision = $this->page->getRevision();
+ $oldRevision = $this->mArticle->getRevisionFetched();
- return false;
- }
- }
+ if ( $curRevision
+ && $oldRevision
+ && $curRevision->getId() !== $oldRevision->getId()
+ && ( WikiPage::hasDifferencesOutsideMainSlot( $oldRevision, $curRevision )
+ || !$this->isSupportedContentModel( $oldRevision->getContentModel() ) )
+ ) {
+ $this->context->getOutput()->redirect(
+ $this->mTitle->getFullURL(
+ [
+ 'action' => 'mcrrestore',
+ 'restore' => $oldRevision->getId(),
+ ]
+ )
+ );
- if ( $content === false ) {
- $content = $this->getOriginalContent( $user );
+ return false;
}
}
+
+ if ( $content === false ) {
+ $content = $this->getOriginalContent( $user );
+ }
}
return $content;
* @return string
*/
private function newSectionSummary( &$sectionanchor = null ) {
- global $wgParser;
-
if ( $this->sectiontitle !== '' ) {
$sectionanchor = $this->guessSectionName( $this->sectiontitle );
// If no edit summary was specified, create one automatically from the section
// title and have it link to the new section. Otherwise, respect the summary as
// passed.
if ( $this->summary === '' ) {
- $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
+ $cleanSectionTitle = MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $this->sectiontitle );
return $this->context->msg( 'newsectionsummary' )
->plaintextParams( $cleanSectionTitle )->inContentLanguage()->text();
}
$sectionanchor = $this->guessSectionName( $this->summary );
# This is a new section, so create a link to the new section
# in the revision summary.
- $cleanSummary = $wgParser->stripSectionName( $this->summary );
+ $cleanSummary = MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $this->summary );
return $this->context->msg( 'newsectionsummary' )
->plaintextParams( $cleanSummary )->inContentLanguage()->text();
}
$out->addHTML( $this->editFormTextTop );
- if ( $this->wasDeletedSinceLastEdit() ) {
- if ( $this->formtype !== 'save' ) {
- $out->wrapWikiMsg( "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
- 'deletedwhileediting' );
- }
+ if ( $this->wasDeletedSinceLastEdit() && $this->formtype !== 'save' ) {
+ $out->wrapWikiMsg( "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
+ 'deletedwhileediting' );
}
// @todo add EditForm plugin interface and use it here!
public static function extractSectionTitle( $text ) {
preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches );
if ( !empty( $matches[2] ) ) {
- global $wgParser;
- return $wgParser->stripSectionName( trim( $matches[2] ) );
+ return MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( trim( $matches[2] ) );
} else {
return false;
}
$this->addExplainConflictHeader( $out );
$this->editRevId = $this->page->getLatest();
} else {
- if ( $this->section != '' && $this->section != 'new' ) {
- if ( !$this->summary && !$this->preview && !$this->diff ) {
- $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object
- if ( $sectionTitle !== false ) {
- $this->summary = "/* $sectionTitle */ ";
- }
+ if ( $this->section != '' && $this->section != 'new' && !$this->summary &&
+ !$this->preview && !$this->diff
+ ) {
+ $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object
+ if ( $sectionTitle !== false ) {
+ $this->summary = "/* $sectionTitle */ ";
}
}
'anonpreviewwarning'
);
}
- } else {
- if ( $this->mTitle->isUserConfigPage() ) {
- # Check the skin exists
- if ( $this->isWrongCaseUserConfigPage() ) {
- $out->wrapWikiMsg(
- "<div class='error' id='mw-userinvalidconfigtitle'>\n$1\n</div>",
- [ 'userinvalidconfigtitle', $this->mTitle->getSkinFromConfigSubpage() ]
- );
- }
- if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) {
- $isUserCssConfig = $this->mTitle->isUserCssConfigPage();
- $isUserJsonConfig = $this->mTitle->isUserJsonConfigPage();
- $isUserJsConfig = $this->mTitle->isUserJsConfigPage();
-
- $warning = $isUserCssConfig
- ? 'usercssispublic'
- : ( $isUserJsonConfig ? 'userjsonispublic' : 'userjsispublic' );
-
- $out->wrapWikiMsg( '<div class="mw-userconfigpublic">$1</div>', $warning );
-
- if ( $this->formtype !== 'preview' ) {
- $config = $this->context->getConfig();
- if ( $isUserCssConfig && $config->get( 'AllowUserCss' ) ) {
- $out->wrapWikiMsg(
- "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
- [ 'usercssyoucanpreview' ]
- );
- } elseif ( $isUserJsonConfig /* No comparable 'AllowUserJson' */ ) {
- $out->wrapWikiMsg(
- "<div id='mw-userjsonyoucanpreview'>\n$1\n</div>",
- [ 'userjsonyoucanpreview' ]
- );
- } elseif ( $isUserJsConfig && $config->get( 'AllowUserJs' ) ) {
- $out->wrapWikiMsg(
- "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
- [ 'userjsyoucanpreview' ]
- );
- }
+ } elseif ( $this->mTitle->isUserConfigPage() ) {
+ # Check the skin exists
+ if ( $this->isWrongCaseUserConfigPage() ) {
+ $out->wrapWikiMsg(
+ "<div class='error' id='mw-userinvalidconfigtitle'>\n$1\n</div>",
+ [ 'userinvalidconfigtitle', $this->mTitle->getSkinFromConfigSubpage() ]
+ );
+ }
+ if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) {
+ $isUserCssConfig = $this->mTitle->isUserCssConfigPage();
+ $isUserJsonConfig = $this->mTitle->isUserJsonConfigPage();
+ $isUserJsConfig = $this->mTitle->isUserJsConfigPage();
+
+ $warning = $isUserCssConfig
+ ? 'usercssispublic'
+ : ( $isUserJsonConfig ? 'userjsonispublic' : 'userjsispublic' );
+
+ $out->wrapWikiMsg( '<div class="mw-userconfigpublic">$1</div>', $warning );
+
+ if ( $this->formtype !== 'preview' ) {
+ $config = $this->context->getConfig();
+ if ( $isUserCssConfig && $config->get( 'AllowUserCss' ) ) {
+ $out->wrapWikiMsg(
+ "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
+ [ 'usercssyoucanpreview' ]
+ );
+ } elseif ( $isUserJsonConfig /* No comparable 'AllowUserJson' */ ) {
+ $out->wrapWikiMsg(
+ "<div id='mw-userjsonyoucanpreview'>\n$1\n</div>",
+ [ 'userjsonyoucanpreview' ]
+ );
+ } elseif ( $isUserJsConfig && $config->get( 'AllowUserJs' ) ) {
+ $out->wrapWikiMsg(
+ "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
+ [ 'userjsyoucanpreview' ]
+ );
}
}
}
if ( $this->nosummary ) {
return;
}
- } else {
- if ( !$this->mShowSummaryField ) {
- return;
- }
+ } elseif ( !$this->mShowSummaryField ) {
+ return;
}
$labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse();
return "";
}
- global $wgParser;
-
if ( $isSubjectPreview ) {
$summary = $this->context->msg( 'newsectionsummary' )
- ->rawParams( $wgParser->stripSectionName( $summary ) )
+ ->rawParams( MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $summary ) )
->inContentLanguage()->text();
}
$lang->formatNum( $maxArticleSize )
]
);
- } else {
- if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
- $out->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
- [
- 'longpage-hint',
- $lang->formatSize( strlen( $this->textbox1 ) ),
- strlen( $this->textbox1 )
- ]
- );
- }
+ } elseif ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
+ $out->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
+ [
+ 'longpage-hint',
+ $lang->formatSize( strlen( $this->textbox1 ) ),
+ strlen( $this->textbox1 )
+ ]
+ );
}
}
* @return string
*/
private function guessSectionName( $text ) {
- global $wgParser;
-
// Detect Microsoft browsers
$userAgent = $this->context->getRequest()->getHeader( 'User-Agent' );
+ $parser = MediaWikiServices::getInstance()->getParser();
if ( $userAgent && preg_match( '/MSIE|Edge/', $userAgent ) ) {
// ...and redirect them to legacy encoding, if available
- return $wgParser->guessLegacySectionNameFromWikiText( $text );
+ return $parser->guessLegacySectionNameFromWikiText( $text );
}
// Meanwhile, real browsers get real anchors
- $name = $wgParser->guessSectionNameFromWikiText( $text );
+ $name = $parser->guessSectionNameFromWikiText( $text );
// With one little caveat: per T216029, fragments in HTTP redirects need to be urlencoded,
// otherwise Chrome double-escapes the rest of the URL.
return '#' . urlencode( mb_substr( $name, 1 ) );