*/
use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
/**
* The edit page/HTML interface (split from Article)
* the newly-edited page.
*/
function edit() {
+ global $wgOut, $wgRequest, $wgUser;
// Allow extensions to modify/prevent this form or submission
if ( !Hooks::run( 'AlternateEdit', [ $this ] ) ) {
return;
wfDebug( __METHOD__ . ": enter\n" );
- $request = $this->context->getRequest();
- $out = $this->context->getOutput();
// If they used redlink=1 and the page exists, redirect to the main article
- if ( $request->getBool( 'redlink' ) && $this->mTitle->exists() ) {
- $out->redirect( $this->mTitle->getFullURL() );
+ if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) {
+ $wgOut->redirect( $this->mTitle->getFullURL() );
return;
}
- $this->importFormData( $request );
+ $this->importFormData( $wgRequest );
$this->firsttime = false;
if ( wfReadOnly() && $this->save ) {
wfDebug( __METHOD__ . ": User can't edit\n" );
// Auto-block user's IP if the account was "hard" blocked
if ( !wfReadOnly() ) {
- $user = $this->context->getUser();
+ $user = $wgUser;
DeferredUpdates::addCallableUpdate( function () use ( $user ) {
$user->spreadAnyEditBlock();
} );
$revision = $this->mArticle->getRevisionFetched();
// Disallow editing revisions with content models different from the current one
- if ( $revision && $revision->getContentModel() !== $this->contentModel ) {
- $this->displayViewSourcePage(
- $this->getContentObject(),
- wfMessage(
- 'contentmodelediterror',
- $revision->getContentModel(),
- $this->contentModel
- )->plain()
- );
- return;
+ // Undo edits being an exception in order to allow reverting content model changes.
+ if ( $revision
+ && $revision->getContentModel() !== $this->contentModel
+ ) {
+ $prevRev = null;
+ if ( $this->undidRev ) {
+ $undidRevObj = Revision::newFromId( $this->undidRev );
+ $prevRev = $undidRevObj ? $undidRevObj->getPrevious() : null;
+ }
+ if ( !$this->undidRev
+ || !$prevRev
+ || $prevRev->getContentModel() !== $this->contentModel
+ ) {
+ $this->displayViewSourcePage(
+ $this->getContentObject(),
+ $this->context->msg(
+ 'contentmodelediterror',
+ $revision->getContentModel(),
+ $this->contentModel
+ )->plain()
+ );
+ return;
+ }
}
$this->isConflict = false;
* @return array
*/
protected function getEditPermissionErrors( $rigor = 'secure' ) {
- $user = $this->context->getUser();
- $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $user, $rigor );
+ global $wgUser;
+
+ $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser, $rigor );
# Can this title be created?
if ( !$this->mTitle->exists() ) {
$permErrors = array_merge(
$permErrors,
wfArrayDiff2(
- $this->mTitle->getUserPermissionsErrors( 'create', $user, $rigor ),
+ $this->mTitle->getUserPermissionsErrors( 'create', $wgUser, $rigor ),
$permErrors
)
);
* @throws PermissionsError
*/
protected function displayPermissionsError( array $permErrors ) {
- $out = $this->context->getOutput();
- if ( $this->context->getRequest()->getBool( 'redlink' ) ) {
+ global $wgRequest, $wgOut;
+
+ if ( $wgRequest->getBool( 'redlink' ) ) {
// The edit page was reached via a red link.
// Redirect to the article page and let them click the edit tab if
// they really want a permission error.
- $out->redirect( $this->mTitle->getFullURL() );
+ $wgOut->redirect( $this->mTitle->getFullURL() );
return;
}
$this->displayViewSourcePage(
$content,
- $out->formatPermissionsErrorMessage( $permErrors, 'edit' )
+ $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' )
);
}
* @param string $errorMessage additional wikitext error message to display
*/
protected function displayViewSourcePage( Content $content, $errorMessage = '' ) {
- $out = $this->context->getOutput();
- Hooks::run( 'EditPage::showReadOnlyForm:initial', [ $this, &$out ] );
+ global $wgOut;
+
+ Hooks::run( 'EditPage::showReadOnlyForm:initial', [ $this, &$wgOut ] );
- $out->setRobotPolicy( 'noindex,nofollow' );
- $out->setPageTitle( wfMessage(
+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
+ $wgOut->setPageTitle( $this->context->msg(
'viewsource-title',
$this->getContextTitle()->getPrefixedText()
) );
- $out->addBacklinkSubtitle( $this->getContextTitle() );
- $out->addHTML( $this->editFormPageTop );
- $out->addHTML( $this->editFormTextTop );
+ $wgOut->addBacklinkSubtitle( $this->getContextTitle() );
+ $wgOut->addHTML( $this->editFormPageTop );
+ $wgOut->addHTML( $this->editFormTextTop );
if ( $errorMessage !== '' ) {
- $out->addWikiText( $errorMessage );
- $out->addHTML( "<hr />\n" );
+ $wgOut->addWikiText( $errorMessage );
+ $wgOut->addHTML( "<hr />\n" );
}
# If the user made changes, preserve them when showing the markup
# (This happens when a user is blocked during edit, for instance)
if ( !$this->firsttime ) {
$text = $this->textbox1;
- $out->addWikiMsg( 'viewyourtext' );
+ $wgOut->addWikiMsg( 'viewyourtext' );
} else {
try {
$text = $this->toEditText( $content );
# (e.g. for an old revision with a different model)
$text = $content->serialize();
}
- $out->addWikiMsg( 'viewsourcetext' );
+ $wgOut->addWikiMsg( 'viewsourcetext' );
}
- $out->addHTML( $this->editFormTextBeforeContent );
+ $wgOut->addHTML( $this->editFormTextBeforeContent );
$this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] );
- $out->addHTML( $this->editFormTextAfterContent );
+ $wgOut->addHTML( $this->editFormTextAfterContent );
- $out->addHTML( Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
- Linker::formatTemplates( $this->getTemplates() ) ) );
+ $wgOut->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
- $out->addModules( 'mediawiki.action.edit.collapsibleFooter' );
+ $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
- $out->addHTML( $this->editFormTextBottom );
+ $wgOut->addHTML( $this->editFormTextBottom );
if ( $this->mTitle->exists() ) {
- $out->returnToMain( null, $this->mTitle );
+ $wgOut->returnToMain( null, $this->mTitle );
}
}
* @return bool
*/
protected function previewOnOpen() {
- global $wgPreviewOnOpenNamespaces;
- $request = $this->context->getRequest();
- if ( $request->getVal( 'preview' ) == 'yes' ) {
+ global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
+ if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
// Explicit override from request
return true;
- } elseif ( $request->getVal( 'preview' ) == 'no' ) {
+ } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
// Explicit override from request
return false;
} elseif ( $this->section == 'new' ) {
// Nothing *to* preview for new sections
return false;
- } elseif ( ( $request->getVal( 'preload' ) !== null || $this->mTitle->exists() )
- && $this->context->getUser()->getOption( 'previewonfirst' )
+ } elseif ( ( $wgRequest->getVal( 'preload' ) !== null || $this->mTitle->exists() )
+ && $wgUser->getOption( 'previewonfirst' )
) {
// Standard preference behavior
return true;
* @throws ErrorPageError
*/
function importFormData( &$request ) {
- global $wgContLang;
+ global $wgContLang, $wgUser;
# Section edit can come from either the form or a link
$this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
$this->watchthis = $request->getCheck( 'wpWatchthis' );
# Don't force edit summaries when a user is editing their own user or talk page
- $user = $this->context->getUser();
if ( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK )
- && $this->mTitle->getText() == $user->getName()
+ && $this->mTitle->getText() == $wgUser->getName()
) {
$this->allowBlankSummary = true;
} else {
$this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' )
- || !$user->getOption( 'forceeditsummary' );
+ || !$wgUser->getOption( 'forceeditsummary' );
}
$this->autoSumm = $request->getText( 'wpAutoSummary' );
// May be overridden by revision.
$this->contentFormat = $request->getText( 'format', $this->contentFormat );
- if ( !ContentHandler::getForModelID( $this->contentModel )
- ->isSupportedFormat( $this->contentFormat )
- ) {
+ try {
+ $handler = ContentHandler::getForModelID( $this->contentModel );
+ } catch ( MWUnknownContentModelException $e ) {
+ throw new ErrorPageError(
+ 'editpage-invalidcontentmodel-title',
+ 'editpage-invalidcontentmodel-text',
+ [ $this->contentModel ]
+ );
+ }
+
+ if ( !$handler->isSupportedFormat( $this->contentFormat ) ) {
throw new ErrorPageError(
'editpage-notsupportedcontentformat-title',
'editpage-notsupportedcontentformat-text',
* @return bool If the requested section is valid
*/
function initialiseForm() {
+ global $wgUser;
$this->edittime = $this->page->getTimestamp();
$this->editRevId = $this->page->getLatest();
return false;
}
$this->textbox1 = $this->toEditText( $content );
- $user = $this->context->getUser();
// activate checkboxes if user wants them to be always active
# Sort out the "watch" checkbox
- if ( $user->getOption( 'watchdefault' ) ) {
+ if ( $wgUser->getOption( 'watchdefault' ) ) {
# Watch all edits
$this->watchthis = true;
- } elseif ( $user->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
+ } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
# Watch creations
$this->watchthis = true;
- } elseif ( $user->isWatched( $this->mTitle ) ) {
+ } elseif ( $wgUser->isWatched( $this->mTitle ) ) {
# Already watched
$this->watchthis = true;
}
- if ( $user->getOption( 'minordefault' ) && !$this->isNew ) {
+ if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew ) {
$this->minoredit = true;
}
if ( $this->textbox1 === false ) {
* @since 1.21
*/
protected function getContentObject( $def_content = null ) {
- global $wgContLang;
+ global $wgOut, $wgRequest, $wgUser, $wgContLang;
$content = false;
- $request = $this->context->getRequest();
- $user = $this->context->getUser();
// For message page not locally set, use the i18n message.
// For other non-existent articles, use preload text if any.
}
if ( $content === false ) {
# If requested, preload some text.
- $preload = $request->getVal( 'preload',
+ $preload = $wgRequest->getVal( 'preload',
// Custom preload text for new sections
$this->section === 'new' ? 'MediaWiki:addsection-preload' : '' );
- $params = $request->getArray( 'preloadparams', [] );
+ $params = $wgRequest->getArray( 'preloadparams', [] );
$content = $this->getPreloadedContent( $preload, $params );
}
} else {
if ( $this->section != '' ) {
// Get section edit text (returns $def_text for invalid sections)
- $orig = $this->getOriginalContent( $user );
+ $orig = $this->getOriginalContent( $wgUser );
$content = $orig ? $orig->getSection( $this->section ) : null;
if ( !$content ) {
$content = $def_content;
}
} else {
- $undoafter = $request->getInt( 'undoafter' );
- $undo = $request->getInt( 'undo' );
+ $undoafter = $wgRequest->getInt( 'undoafter' );
+ $undo = $wgRequest->getInt( 'undo' );
if ( $undo > 0 && $undoafter > 0 ) {
$undorev = Revision::newFromId( $undo );
$undoMsg = 'failure';
} else {
$oldContent = $this->page->getContent( Revision::RAW );
- $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
- $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts );
+ $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+ $newContent = $content->preSaveTransform( $this->mTitle, $wgUser, $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,
if ( $firstrev && $firstrev->getId() == $undo ) {
$userText = $undorev->getUserText();
if ( $userText === '' ) {
- $undoSummary = wfMessage(
+ $undoSummary = $this->context->msg(
'undo-summary-username-hidden',
$undo
)->inContentLanguage()->text();
} else {
- $undoSummary = wfMessage(
+ $undoSummary = $this->context->msg(
'undo-summary',
$undo,
$userText
if ( $this->summary === '' ) {
$this->summary = $undoSummary;
} else {
- $this->summary = $undoSummary . wfMessage( 'colon-separator' )
+ $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
->inContentLanguage()->text() . $this->summary;
}
$this->undidRev = $undo;
// Messages: undo-success, undo-failure, undo-norev, undo-nochange
$class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
- $this->editFormPageTop .= $this->context->getOutput()->parse(
- "<div class=\"{$class}\">" .
- wfMessage( 'undo-' . $undoMsg )->plain() . '</div>', true, /* interface */true );
+ $this->editFormPageTop .= $wgOut->parse( "<div class=\"{$class}\">" .
+ $this->context->msg( 'undo-' . $undoMsg )->plain() . '</div>', true, /* interface */true );
}
if ( $content === false ) {
- $content = $this->getOriginalContent( $user );
+ $content = $this->getOriginalContent( $wgUser );
}
}
}
$handler = ContentHandler::getForModelID( $this->contentModel );
return $handler->makeEmptyContent();
- } else {
+ } elseif ( !$this->undidRev ) {
// Content models should always be the same since we error
- // out if they are different before this point.
+ // out if they are different before this point (in ->edit()).
+ // The exception being, during an undo, the current revision might
+ // differ from the prior revision.
$logger = LoggerFactory::getInstance( 'editpage' );
if ( $this->contentModel !== $rev->getContentModel() ) {
$logger->warning( "Overriding content model from current edit {prev} to {new}", [
] );
$this->contentFormat = $rev->getContentFormat();
}
-
- return $content;
}
+ return $content;
}
/**
* @private
*/
function tokenOk( &$request ) {
+ global $wgUser;
$token = $request->getVal( 'wpEditToken' );
- $user = $this->context->getUser();
- $this->mTokenOk = $user->matchEditToken( $token );
- $this->mTokenOkExceptSuffix = $user->matchEditTokenNoSuffix( $token );
+ $this->mTokenOk = $wgUser->matchEditToken( $token );
+ $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
return $this->mTokenOk;
}
$val = 'restored';
}
- $response = $this->context->getRequest()->response();
+ $response = RequestContext::getMain()->getRequest()->response();
$response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION, [
'httpOnly' => false,
] );
* @return Status The resulting status object.
*/
public function attemptSave( &$resultDetails = false ) {
+ global $wgUser;
+
# Allow bots to exempt some edits from bot flagging
- $bot = $this->context->getUser()->isAllowed( 'bot' ) && $this->bot;
+ $bot = $wgUser->isAllowed( 'bot' ) && $this->bot;
$status = $this->internalAttemptSave( $resultDetails, $bot );
Hooks::run( 'EditPage::attemptSave:after', [ $this, $status, $resultDetails ] );
* @return bool False, if output is done, true if rest of the form should be displayed
*/
private function handleStatus( Status $status, $resultDetails ) {
+ global $wgUser, $wgOut;
+
/**
* @todo FIXME: once the interface for internalAttemptSave() is made
* nicer, this should use the message in $status
}
}
- $out = $this->context->getOutput();
-
// "wpExtraQueryRedirect" is a hidden input to modify
// after save URL and is not used by actual edit form
- $request = $this->context->getRequest();
+ $request = RequestContext::getMain()->getRequest();
$extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' );
switch ( $status->value ) {
case self::AS_CANNOT_USE_CUSTOM_MODEL:
case self::AS_PARSE_ERROR:
- $out->addWikiText( '<div class="error">' . "\n" . $status->getWikiText() . '</div>' );
+ $wgOut->addWikiText( '<div class="error">' . "\n" . $status->getWikiText() . '</div>' );
return true;
case self::AS_SUCCESS_NEW_ARTICLE:
}
}
$anchor = isset( $resultDetails['sectionanchor'] ) ? $resultDetails['sectionanchor'] : '';
- $out->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
+ $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
return false;
case self::AS_SUCCESS_UPDATE:
}
}
- $out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
+ $wgOut->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
return false;
case self::AS_SPAM_ERROR:
return false;
case self::AS_BLOCKED_PAGE_FOR_USER:
- throw new UserBlockedError( $this->context->getUser()->getBlock() );
+ throw new UserBlockedError( $wgUser->getBlock() );
case self::AS_IMAGE_REDIRECT_ANON:
case self::AS_IMAGE_REDIRECT_LOGGED:
// Run new style post-section-merge edit filter
if ( !Hooks::run( 'EditFilterMergedContent',
- [ $this->context, $content, $status, $this->summary,
+ [ $this->mArticle->getContext(), $content, $status, $this->summary,
$user, $this->minoredit ] )
) {
# Error messages etc. could be handled within the hook...
// passed.
if ( $this->summary === '' ) {
$cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
- return wfMessage( 'newsectionsummary' )
+ return $this->context->msg( 'newsectionsummary' )
->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
}
} elseif ( $this->summary !== '' ) {
# This is a new section, so create a link to the new section
# in the revision summary.
$cleanSummary = $wgParser->stripSectionName( $this->summary );
- return wfMessage( 'newsectionsummary' )
+ return $this->context->msg( 'newsectionsummary' )
->rawParams( $cleanSummary )->inContentLanguage()->text();
}
return $this->summary;
* time.
*/
function internalAttemptSave( &$result, $bot = false ) {
- global $wgParser, $wgMaxArticleSize, $wgContentHandlerUseDB;
+ global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize;
+ global $wgContentHandlerUseDB;
$status = Status::newGood();
- $user = $this->context->getUser();
- $request = $this->context->getRequest();
if ( !Hooks::run( 'EditPage::attemptSave', [ $this ] ) ) {
wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
return $status;
}
- $spam = $request->getText( 'wpAntispam' );
+ $spam = $wgRequest->getText( 'wpAntispam' );
if ( $spam !== '' ) {
wfDebugLog(
'SimpleAntiSpam',
- $user->getName() .
+ $wgUser->getName() .
' editing "' .
$this->mTitle->getPrefixedText() .
'" submitted bogus field "' .
# Check image redirect
if ( $this->mTitle->getNamespace() == NS_FILE &&
$textbox_content->isRedirect() &&
- !$user->isAllowed( 'upload' )
+ !$wgUser->isAllowed( 'upload' )
) {
- $code = $user->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED;
+ $code = $wgUser->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED;
$status->setResult( false, $code );
return $status;
}
if ( $match !== false ) {
$result['spam'] = $match;
- $ip = $request->getIP();
+ $ip = $wgRequest->getIP();
$pdbk = $this->mTitle->getPrefixedDBkey();
$match = str_replace( "\n", '', $match );
wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
return $status;
}
- if ( $user->isBlockedFrom( $this->mTitle, false ) ) {
+ if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
// Auto-block user's IP if the account was "hard" blocked
if ( !wfReadOnly() ) {
- $user->spreadAnyEditBlock();
+ $wgUser->spreadAnyEditBlock();
}
# Check block state against master, thus 'false'.
$status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
return $status;
}
- if ( !$user->isAllowed( 'edit' ) ) {
- if ( $user->isAnon() ) {
+ if ( !$wgUser->isAllowed( 'edit' ) ) {
+ if ( $wgUser->isAnon() ) {
$status->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
return $status;
} else {
$status->fatal( 'editpage-cannot-use-custom-model' );
$status->value = self::AS_CANNOT_USE_CUSTOM_MODEL;
return $status;
- } elseif ( !$user->isAllowed( 'editcontentmodel' ) ) {
+ } elseif ( !$wgUser->isAllowed( 'editcontentmodel' ) ) {
$status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
return $status;
if ( $this->changeTags ) {
$changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
- $this->changeTags, $user );
+ $this->changeTags, $wgUser );
if ( !$changeTagsStatus->isOK() ) {
$changeTagsStatus->value = self::AS_CHANGE_TAG_ERROR;
return $changeTagsStatus;
$status->value = self::AS_READ_ONLY_PAGE;
return $status;
}
- if ( $user->pingLimiter() || $user->pingLimiter( 'linkpurge', 0 ) ) {
+ if ( $wgUser->pingLimiter() || $wgUser->pingLimiter( 'linkpurge', 0 )
+ || ( $changingContentModel && $wgUser->pingLimiter( 'editcontentmodel' ) )
+ ) {
$status->fatal( 'actionthrottledtext' );
$status->value = self::AS_RATE_LIMITED;
return $status;
if ( $new ) {
// Late check for create permission, just in case *PARANOIA*
- if ( !$this->mTitle->userCan( 'create', $user ) ) {
+ if ( !$this->mTitle->userCan( 'create', $wgUser ) ) {
$status->fatal( 'nocreatetext' );
$status->value = self::AS_NO_CREATE_PERMISSION;
wfDebug( __METHOD__ . ": no create permission\n" );
return $status;
}
- if ( !$this->runPostMergeFilters( $textbox_content, $status, $user ) ) {
+ if ( !$this->runPostMergeFilters( $textbox_content, $status, $wgUser ) ) {
return $status;
}
) {
$this->isConflict = true;
if ( $this->section == 'new' ) {
- if ( $this->page->getUserText() == $user->getName() &&
+ if ( $this->page->getUserText() == $wgUser->getName() &&
$this->page->getComment() == $this->newSectionSummary()
) {
// Probably a duplicate submission of a new comment.
} elseif ( $this->section == ''
&& Revision::userWasLastToEdit(
DB_MASTER, $this->mTitle->getArticleID(),
- $user->getId(), $this->edittime
+ $wgUser->getId(), $this->edittime
)
) {
# Suppress edit conflict with self, except for section edits where merging is required.
return $status;
}
- if ( !$this->runPostMergeFilters( $content, $status, $user ) ) {
+ if ( !$this->runPostMergeFilters( $content, $status, $wgUser ) ) {
return $status;
}
return $status;
}
} elseif ( !$this->allowBlankSummary
- && !$content->equals( $this->getOriginalContent( $user ) )
+ && !$content->equals( $this->getOriginalContent( $wgUser ) )
&& !$content->isRedirect()
&& md5( $this->summary ) == $this->autoSumm
) {
$this->summary,
$flags,
false,
- $user,
+ $wgUser,
$content->getDefaultFormat(),
$this->changeTags
);
$result['nullEdit'] = $doEditStatus->hasMessage( 'edit-no-change' );
if ( $result['nullEdit'] ) {
// We don't know if it was a null edit until now, so increment here
- $user->pingLimiter( 'linkpurge' );
+ $wgUser->pingLimiter( 'linkpurge' );
}
$result['redirect'] = $content->isRedirect();
// If the content model changed, add a log entry
if ( $changingContentModel ) {
$this->addContentModelChangeLogEntry(
- $user,
+ $wgUser,
$new ? false : $oldContentModel,
$this->contentModel,
$this->summary
if ( $displayTitle === false ) {
$displayTitle = $contextTitle->getPrefixedText();
}
- $wgOut->setPageTitle( wfMessage( $msg, $displayTitle ) );
+ $wgOut->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
# Transmit the name of the message to JavaScript for live preview
# Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys
$wgOut->addJsConfigVars( [
# Try to add a custom edit intro, or use the standard one if this is not possible.
if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
$helpLink = wfExpandUrl( Skin::makeInternalOrExternalUrl(
- wfMessage( 'helppage' )->inContentLanguage()->text()
+ $this->context->msg( 'helppage' )->inContentLanguage()->text()
) );
if ( $wgUser->isLoggedIn() ) {
$wgOut->wrapWikiMsg(
}
if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
- throw new MWException( 'This content model is not supported: '
- . ContentHandler::getLocalizedName( $content->getModel() ) );
+ throw new MWException( 'This content model is not supported: ' . $content->getModel() );
}
return $content->serialize( $this->contentFormat );
$this->contentModel, $this->contentFormat );
if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
- throw new MWException( 'This content model is not supported: '
- . ContentHandler::getLocalizedName( $content->getModel() ) );
+ throw new MWException( 'This content model is not supported: ' . $content->getModel() );
}
return $content;
. Html::rawElement(
'label',
[ 'for' => 'wpAntispam' ],
- wfMessage( 'simpleantispam-label' )->parse()
+ $this->context->msg( 'simpleantispam-label' )->parse()
)
. Xml::element(
'input',
: 'confirmrecreate';
$wgOut->addHTML(
'<div class="mw-confirm-recreate">' .
- wfMessage( $key, $username, "<nowiki>$comment</nowiki>" )->parse() .
- Xml::checkLabel( wfMessage( 'recreate' )->text(), 'wpRecreate', 'wpRecreate', false,
+ $this->context->msg( $key, $username, "<nowiki>$comment</nowiki>" )->parse() .
+ Xml::checkLabel( $this->context->msg( 'recreate' )->text(), 'wpRecreate', 'wpRecreate', false,
[ 'title' => Linker::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' ]
) .
'</div>'
$wgOut->addHTML( $this->editFormTextAfterTools . "\n" );
- $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
- Linker::formatTemplates( $this->getTemplates(), $this->preview, $this->section != '' ) ) );
+ $wgOut->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
$wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ],
Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) );
$this->showConflict();
} catch ( MWContentSerializationException $ex ) {
// this can't really happen, but be nice if it does.
- $msg = wfMessage(
+ $msg = $this->context->msg(
'content-failed-to-parse',
$this->contentModel,
$this->contentFormat,
}
+ /**
+ * Wrapper around TemplatesOnThisPageFormatter to make
+ * a "templates on this page" list.
+ *
+ * @param Title[] $templates
+ * @return string HTML
+ */
+ protected function makeTemplatesOnThisPageList( array $templates ) {
+ $templateListFormatter = new TemplatesOnThisPageFormatter(
+ $this->context, MediaWikiServices::getInstance()->getLinkRenderer()
+ );
+
+ // preview if preview, else section if section, else false
+ $type = false;
+ if ( $this->preview ) {
+ $type = 'preview';
+ } elseif ( $this->section != '' ) {
+ $type = 'section';
+ }
+
+ return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
+ $templateListFormatter->format( $templates, $type )
+ );
+
+ }
+
/**
* Extract the section title from current section text, if any.
*
if ( count( $editNotices ) ) {
$wgOut->addHTML( implode( "\n", $editNotices ) );
} else {
- $msg = wfMessage( 'editnotice-notext' );
+ $msg = $this->context->msg( 'editnotice-notext' );
if ( !$msg->isDisabled() ) {
$wgOut->addHTML(
'<div class="mw-editnotice-notext">'
]
);
} else {
- if ( !wfMessage( 'longpage-hint' )->isDisabled() ) {
+ if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
$wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
[
'longpage-hint',
* subclasses may reorganize the form.
* Note that you do not need to worry about the label's for=, it will be
* inferred by the id given to the input. You can remove them both by
- * passing array( 'id' => false ) to $userInputAttrs.
+ * passing [ 'id' => false ] to $userInputAttrs.
*
* @param string $summary The value of the summary input
* @param string $labelText The html to place inside the label
* @param array $inputAttrs Array of attrs to use on the input
* @param array $spanLabelAttrs Array of attrs to use on the span inside the label
*
- * @return array An array in the format array( $label, $input )
+ * @return array An array in the format [ $label, $input ]
*/
function getSummaryInput( $summary = "", $labelText = null,
$inputAttrs = null, $spanLabelAttrs = null
return;
}
}
- $labelText = wfMessage( $isSubjectPreview ? 'subject' : 'summary' )->parse();
+ $labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse();
list( $label, $input ) = $this->getSummaryInput(
$summary,
$labelText,
global $wgParser;
if ( $isSubjectPreview ) {
- $summary = wfMessage( 'newsectionsummary' )->rawParams( $wgParser->stripSectionName( $summary ) )
+ $summary = $this->context->msg( 'newsectionsummary' )
+ ->rawParams( $wgParser->stripSectionName( $summary ) )
->inContentLanguage()->text();
}
$message = $isSubjectPreview ? 'subject-preview' : 'summary-preview';
- $summary = wfMessage( $message )->parse()
+ $summary = $this->context->msg( $message )->parse()
. Linker::commentBlock( $summary, $this->mTitle, $isSubjectPreview );
return Xml::tags( 'div', [ 'class' => 'mw-summary-preview' ], $summary );
}
try {
$this->showDiff();
} catch ( MWContentSerializationException $ex ) {
- $msg = wfMessage(
+ $msg = $this->context->msg(
'content-failed-to-parse',
$this->contentModel,
$this->contentFormat,
}
if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) {
- $oldtitle = wfMessage( $oldtitlemsg )->parse();
- $newtitle = wfMessage( 'yourtext' )->parse();
+ $oldtitle = $this->context->msg( $oldtitlemsg )->parse();
+ $newtitle = $this->context->msg( 'yourtext' )->parse();
if ( !$oldContent ) {
$oldContent = $newContent->getContentHandler()->makeEmptyContent();
*/
protected function showHeaderCopyrightWarning() {
$msg = 'editpage-head-copy-warn';
- if ( !wfMessage( $msg )->isDisabled() ) {
+ if ( !$this->context->msg( $msg )->isDisabled() ) {
global $wgOut;
$wgOut->wrapWikiMsg( "<div class='editpage-head-copywarn'>\n$1\n</div>",
'editpage-head-copy-warn' );
protected function showTosSummary() {
$msg = 'editpage-tos-summary';
Hooks::run( 'EditPageTosSummary', [ $this->mTitle, &$msg ] );
- if ( !wfMessage( $msg )->isDisabled() ) {
+ if ( !$this->context->msg( $msg )->isDisabled() ) {
global $wgOut;
$wgOut->addHTML( '<div class="mw-tos-summary">' );
$wgOut->addWikiMsg( $msg );
protected function showEditTools() {
global $wgOut;
$wgOut->addHTML( '<div class="mw-editTools">' .
- wfMessage( 'edittools' )->inContentLanguage()->parse() .
+ $this->context->msg( 'edittools' )->inContentLanguage()->parse() .
'</div>' );
}
Hooks::run( 'EditPageCopyrightWarning', [ $title, &$copywarnMsg ] );
return "<div id=\"editpage-copywarn\">\n" .
- call_user_func_array( 'wfMessage', $copywarnMsg )->$format() . "\n</div>";
+ call_user_func_array( 'wfMessage', $copywarnMsg )->title( $title )->$format() . "\n</div>";
}
/**
if ( $cancel !== '' ) {
$cancel .= Html::element( 'span',
[ 'class' => 'mw-editButtons-pipe-separator' ],
- wfMessage( 'pipe-separator' )->text() );
+ $this->context->msg( 'pipe-separator' )->text() );
}
- $message = wfMessage( 'edithelppage' )->inContentLanguage()->text();
+ $message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text();
$edithelpurl = Skin::makeInternalOrExternalUrl( $message );
$attrs = [
'target' => 'helpwindow',
'href' => $edithelpurl,
];
- $edithelp = Html::linkButton( wfMessage( 'edithelp' )->text(),
+ $edithelp = Html::linkButton( $this->context->msg( 'edithelp' )->text(),
$attrs, [ 'mw-ui-quiet' ] ) .
- wfMessage( 'word-separator' )->escaped() .
- wfMessage( 'newwindow' )->parse();
+ $this->context->msg( 'word-separator' )->escaped() .
+ $this->context->msg( 'newwindow' )->parse();
$wgOut->addHTML( " <span class='cancelLink'>{$cancel}</span>\n" );
$wgOut->addHTML( " <span class='editHelp'>{$edithelp}</span>\n" );
$de = $handler->createDifferenceEngine( $this->mArticle->getContext() );
$de->setContent( $content2, $content1 );
$de->showDiff(
- wfMessage( 'yourtext' )->parse(),
- wfMessage( 'storedversion' )->text()
+ $this->context->msg( 'yourtext' )->parse(),
+ $this->context->msg( 'storedversion' )->text()
);
$wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
return Linker::linkKnown(
$this->getContextTitle(),
- wfMessage( 'cancel' )->parse(),
+ $this->context->msg( 'cancel' )->parse(),
Html::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ),
$cancelParams
);
* @return bool|stdClass
*/
protected function getLastDelete() {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
$data = $dbr->selectRow(
[ 'logging', 'user' ],
[
// Quick paranoid permission checks...
if ( is_object( $data ) ) {
if ( $data->log_deleted & LogPage::DELETED_USER ) {
- $data->user_name = wfMessage( 'rev-deleted-user' )->escaped();
+ $data->user_name = $this->context->msg( 'rev-deleted-user' )->escaped();
}
if ( $data->log_deleted & LogPage::DELETED_COMMENT ) {
- $data->log_comment = wfMessage( 'rev-deleted-comment' )->escaped();
+ $data->log_comment = $this->context->msg( 'rev-deleted-comment' )->escaped();
}
}
// string, which happens when you initially edit
// a category page, due to automatic preview-on-open.
$parsedNote = $wgOut->parse( "<div class='previewnote'>" .
- wfMessage( 'session_fail_preview_html' )->text() . "</div>", true, /* interface */true );
+ $this->context->msg( 'session_fail_preview_html' )->text() . "</div>",
+ true, /* interface */true );
}
$stats->increment( 'edit.failures.session_loss' );
return $parsedNote;
# provide a anchor link to the editform
$continueEditing = '<span class="mw-continue-editing">' .
'[[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' .
- wfMessage( 'continue-editing' )->text() . ']]</span>';
+ $this->context->msg( 'continue-editing' )->text() . ']]</span>';
if ( $this->mTriedSave && !$this->mTokenOk ) {
if ( $this->mTokenOkExceptSuffix ) {
- $note = wfMessage( 'token_suffix_mismatch' )->plain();
+ $note = $this->context->msg( 'token_suffix_mismatch' )->plain();
$stats->increment( 'edit.failures.bad_token' );
} else {
- $note = wfMessage( 'session_fail_preview' )->plain();
+ $note = $this->context->msg( 'session_fail_preview' )->plain();
$stats->increment( 'edit.failures.session_loss' );
}
} elseif ( $this->incompleteForm ) {
- $note = wfMessage( 'edit_form_incomplete' )->plain();
+ $note = $this->context->msg( 'edit_form_incomplete' )->plain();
if ( $this->mTriedSave ) {
$stats->increment( 'edit.failures.incomplete_form' );
}
} else {
- $note = wfMessage( 'previewnote' )->plain() . ' ' . $continueEditing;
+ $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
}
# don't parse non-wikitext pages, show message about preview
# Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
if ( $level && $format ) {
$note = "<div id='mw-{$level}{$format}preview'>" .
- wfMessage( "{$level}{$format}preview" )->text() .
+ $this->context->msg( "{$level}{$format}preview" )->text() .
' ' . $continueEditing . "</div>";
}
}
}
} catch ( MWContentSerializationException $ex ) {
- $m = wfMessage(
+ $m = $this->context->msg(
'content-failed-to-parse',
$this->contentModel,
$this->contentFormat,
if ( $this->isConflict ) {
$conflict = '<h2 id="mw-previewconflict">'
- . wfMessage( 'previewconflict' )->escaped() . "</h2>\n";
+ . $this->context->msg( 'previewconflict' )->escaped() . "</h2>\n";
} else {
$conflict = '<hr />';
}
$previewhead = "<div class='previewnote'>\n" .
- '<h2 id="mw-previewheader">' . wfMessage( 'preview' )->escaped() . "</h2>" .
+ '<h2 id="mw-previewheader">' . $this->context->msg( 'preview' )->escaped() . "</h2>" .
$wgOut->parse( $note, true, /* interface */true ) . $conflict . "</div>\n";
$pageViewLang = $this->mTitle->getPageViewLanguage();
// don't show the minor edit checkbox if it's a new page or section
if ( !$this->isNew ) {
$checkboxes['minor'] = '';
- $minorLabel = wfMessage( 'minoredit' )->parse();
+ $minorLabel = $this->context->msg( 'minoredit' )->parse();
if ( $wgUser->isAllowed( 'minoredit' ) ) {
$attribs = [
'tabindex' => ++$tabindex,
- 'accesskey' => wfMessage( 'accesskey-minoredit' )->text(),
+ 'accesskey' => $this->context->msg( 'accesskey-minoredit' )->text(),
'id' => 'wpMinoredit',
];
$minorEditHtml =
}
}
- $watchLabel = wfMessage( 'watchthis' )->parse();
+ $watchLabel = $this->context->msg( 'watchthis' )->parse();
$checkboxes['watch'] = '';
if ( $wgUser->isLoggedIn() ) {
$attribs = [
'tabindex' => ++$tabindex,
- 'accesskey' => wfMessage( 'accesskey-watch' )->text(),
+ 'accesskey' => $this->context->msg( 'accesskey-watch' )->text(),
'id' => 'wpWatchthis',
];
$watchThisHtml =
public function getEditButtons( &$tabindex ) {
$buttons = [];
- $labelAsPublish = $this->mArticle->getContext()->getConfig()->get( 'EditButtonPublishNotSave' );
+ $labelAsPublish =
+ $this->mArticle->getContext()->getConfig()->get( 'EditSubmitButtonLabelPublish' );
+
+ // Can't use $this->isNew as that's also true if we're adding a new section to an extant page
if ( $labelAsPublish ) {
- $buttonLabelKey = $this->isNew ? 'publishpage' : 'publishchanges';
+ $buttonLabelKey = !$this->mTitle->exists() ? 'publishpage' : 'publishchanges';
} else {
- $buttonLabelKey = $this->isNew ? 'savearticle' : 'savechanges';
+ $buttonLabelKey = !$this->mTitle->exists() ? 'savearticle' : 'savechanges';
}
- $buttonLabel = wfMessage( $buttonLabelKey )->text();
+ $buttonLabel = $this->context->msg( $buttonLabelKey )->text();
$attribs = [
'id' => 'wpSave',
'name' => 'wpSave',
'name' => 'wpPreview',
'tabindex' => $tabindex,
] + Linker::tooltipAndAccesskeyAttribs( 'preview' );
- $buttons['preview'] = Html::submitButton( wfMessage( 'showpreview' )->text(),
+ $buttons['preview'] = Html::submitButton( $this->context->msg( 'showpreview' )->text(),
$attribs );
$buttons['live'] = '';
'name' => 'wpDiff',
'tabindex' => ++$tabindex,
] + Linker::tooltipAndAccesskeyAttribs( 'diff' );
- $buttons['diff'] = Html::submitButton( wfMessage( 'showdiff' )->text(),
+ $buttons['diff'] = Html::submitButton( $this->context->msg( 'showdiff' )->text(),
$attribs );
Hooks::run( 'EditPageBeforeEditButtons', [ &$this, &$buttons, &$tabindex ] );
function noSuchSectionPage() {
global $wgOut;
- $wgOut->prepareErrorPage( wfMessage( 'nosuchsectiontitle' ) );
+ $wgOut->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) );
- $res = wfMessage( 'nosuchsectiontext', $this->section )->parseAsBlock();
+ $res = $this->context->msg( 'nosuchsectiontext', $this->section )->parseAsBlock();
Hooks::run( 'EditPageNoSuchSection', [ &$this, &$res ] );
$wgOut->addHTML( $res );
if ( is_array( $match ) ) {
$match = $wgLang->listToText( $match );
}
- $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );
+ $wgOut->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) );
$wgOut->addHTML( '<div id="spamprotected">' );
$wgOut->addWikiMsg( 'spamprotectiontext' );