X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FEditPage.php;h=bd58c81292c6d0e1f7c9ab4e7906d9361f69369b;hp=9d2d4021bd08f7da7d54e7bdae84f0f5130b38c1;hb=a154a28c7a4442a7d08689036dc54688b0867a64;hpb=6d09f88785bf4b7fe821634d3438106b6f335a94 diff --git a/includes/EditPage.php b/includes/EditPage.php index 9d2d4021bd..bd58c81292 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -40,6 +40,11 @@ use Wikimedia\ScopedCallback; * headaches, which may be fatal. */ class EditPage { + /** + * Used for Unicode support checks + */ + const UNICODE_CHECK = 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ'; + /** * Status: Article successfully updated */ @@ -177,6 +182,11 @@ class EditPage { */ const AS_CANNOT_USE_CUSTOM_MODEL = 241; + /** + * Status: edit rejected because browser doesn't support Unicode. + */ + const AS_UNICODE_NOT_SUPPORTED = 242; + /** * HTML id and name for the beginning of the edit form. */ @@ -203,12 +213,18 @@ class EditPage { */ const POST_EDIT_COOKIE_DURATION = 1200; - /** @var Article */ + /** + * @deprecated for public usage since 1.30 use EditPage::getArticle() + * @var Article + */ public $mArticle; /** @var WikiPage */ private $page; - /** @var Title */ + /** + * @deprecated for public usage since 1.30 use EditPage::getTitle() + * @var Title + */ public $mTitle; /** @var null|Title */ @@ -220,16 +236,28 @@ class EditPage { /** @var bool */ public $isConflict = false; - /** @var bool */ + /** + * @deprecated since 1.30 use Title::isCssJsSubpage() + * @var bool + */ public $isCssJsSubpage = false; - /** @var bool */ + /** + * @deprecated since 1.30 use Title::isCssSubpage() + * @var bool + */ public $isCssSubpage = false; - /** @var bool */ + /** + * @deprecated since 1.30 use Title::isJsSubpage() + * @var bool + */ public $isJsSubpage = false; - /** @var bool */ + /** + * @deprecated since 1.30 + * @var bool + */ public $isWrongCaseCssJsPage = false; /** @var bool New page or new section */ @@ -413,6 +441,11 @@ class EditPage { */ private $isOldRev = false; + /** + * @var string|null What the user submitted in the 'wpUnicodeCheck' field + */ + private $unicodeCheck; + /** * @param Article $article */ @@ -469,6 +502,10 @@ class EditPage { */ public function getContextTitle() { if ( is_null( $this->mContextTitle ) ) { + wfDebugLog( + 'GlobalTitleFail', + __METHOD__ . ' called by ' . wfGetAllCallers( 5 ) . ' with no title set.' + ); global $wgTitle; return $wgTitle; } else { @@ -511,6 +548,7 @@ class EditPage { * @deprecated since 1.29, call edit directly */ public function submit() { + wfDeprecated( __METHOD__, '1.29' ); $this->edit(); } @@ -526,7 +564,6 @@ class EditPage { * the newly-edited page. */ public function edit() { - global $wgOut, $wgRequest, $wgUser; // Allow extensions to modify/prevent this form or submission if ( !Hooks::run( 'AlternateEdit', [ $this ] ) ) { return; @@ -534,13 +571,14 @@ class EditPage { wfDebug( __METHOD__ . ": enter\n" ); + $request = $this->context->getRequest(); // If they used redlink=1 and the page exists, redirect to the main article - if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) { - $wgOut->redirect( $this->mTitle->getFullURL() ); + if ( $request->getBool( 'redlink' ) && $this->mTitle->exists() ) { + $this->context->getOutput()->redirect( $this->mTitle->getFullURL() ); return; } - $this->importFormData( $wgRequest ); + $this->importFormData( $request ); $this->firsttime = false; if ( wfReadOnly() && $this->save ) { @@ -569,9 +607,8 @@ class EditPage { wfDebug( __METHOD__ . ": User can't edit\n" ); // Auto-block user's IP if the account was "hard" blocked if ( !wfReadOnly() ) { - $user = $wgUser; - DeferredUpdates::addCallableUpdate( function () use ( $user ) { - $user->spreadAnyEditBlock(); + DeferredUpdates::addCallableUpdate( function () { + $this->context->getUser()->spreadAnyEditBlock(); } ); } $this->displayPermissionsError( $permErrors ); @@ -608,10 +645,11 @@ class EditPage { $this->isConflict = false; // css / js subpages of user pages get a special treatment + // The following member variables are deprecated since 1.30, + // the functions should be used instead. $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage(); $this->isCssSubpage = $this->mTitle->isCssSubpage(); $this->isJsSubpage = $this->mTitle->isJsSubpage(); - // @todo FIXME: Silly assignment. $this->isWrongCaseCssJsPage = $this->isWrongCaseCssJsPage(); # Show applicable editing introductions @@ -656,15 +694,14 @@ class EditPage { * @return array */ protected function getEditPermissionErrors( $rigor = 'secure' ) { - global $wgUser; - - $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser, $rigor ); + $user = $this->context->getUser(); + $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $user, $rigor ); # Can this title be created? if ( !$this->mTitle->exists() ) { $permErrors = array_merge( $permErrors, wfArrayDiff2( - $this->mTitle->getUserPermissionsErrors( 'create', $wgUser, $rigor ), + $this->mTitle->getUserPermissionsErrors( 'create', $user, $rigor ), $permErrors ) ); @@ -701,13 +738,12 @@ class EditPage { * @throws PermissionsError */ protected function displayPermissionsError( array $permErrors ) { - global $wgRequest, $wgOut; - - if ( $wgRequest->getBool( 'redlink' ) ) { + $out = $this->context->getOutput(); + if ( $this->context->getRequest()->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. - $wgOut->redirect( $this->mTitle->getFullURL() ); + $out->redirect( $this->mTitle->getFullURL() ); return; } @@ -722,7 +758,7 @@ class EditPage { $this->displayViewSourcePage( $content, - $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) + $out->formatPermissionsErrorMessage( $permErrors, 'edit' ) ); } @@ -732,29 +768,28 @@ class EditPage { * @param string $errorMessage additional wikitext error message to display */ protected function displayViewSourcePage( Content $content, $errorMessage = '' ) { - global $wgOut; - - Hooks::run( 'EditPage::showReadOnlyForm:initial', [ $this, &$wgOut ] ); + $out = $this->context->getOutput(); + Hooks::run( 'EditPage::showReadOnlyForm:initial', [ $this, &$out ] ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $wgOut->setPageTitle( $this->context->msg( + $out->setRobotPolicy( 'noindex,nofollow' ); + $out->setPageTitle( $this->context->msg( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) ); - $wgOut->addBacklinkSubtitle( $this->getContextTitle() ); - $wgOut->addHTML( $this->editFormPageTop ); - $wgOut->addHTML( $this->editFormTextTop ); + $out->addBacklinkSubtitle( $this->getContextTitle() ); + $out->addHTML( $this->editFormPageTop ); + $out->addHTML( $this->editFormTextTop ); if ( $errorMessage !== '' ) { - $wgOut->addWikiText( $errorMessage ); - $wgOut->addHTML( "
\n" ); + $out->addWikiText( $errorMessage ); + $out->addHTML( "
\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; - $wgOut->addWikiMsg( 'viewyourtext' ); + $out->addWikiMsg( 'viewyourtext' ); } else { try { $text = $this->toEditText( $content ); @@ -763,20 +798,20 @@ class EditPage { # (e.g. for an old revision with a different model) $text = $content->serialize(); } - $wgOut->addWikiMsg( 'viewsourcetext' ); + $out->addWikiMsg( 'viewsourcetext' ); } - $wgOut->addHTML( $this->editFormTextBeforeContent ); + $out->addHTML( $this->editFormTextBeforeContent ); $this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] ); - $wgOut->addHTML( $this->editFormTextAfterContent ); + $out->addHTML( $this->editFormTextAfterContent ); - $wgOut->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) ); + $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) ); - $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' ); + $out->addModules( 'mediawiki.action.edit.collapsibleFooter' ); - $wgOut->addHTML( $this->editFormTextBottom ); + $out->addHTML( $this->editFormTextBottom ); if ( $this->mTitle->exists() ) { - $wgOut->returnToMain( null, $this->mTitle ); + $out->returnToMain( null, $this->mTitle ); } } @@ -786,18 +821,19 @@ class EditPage { * @return bool */ protected function previewOnOpen() { - global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces; - if ( $wgRequest->getVal( 'preview' ) == 'yes' ) { + global $wgPreviewOnOpenNamespaces; + $request = $this->context->getRequest(); + if ( $request->getVal( 'preview' ) == 'yes' ) { // Explicit override from request return true; - } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) { + } elseif ( $request->getVal( 'preview' ) == 'no' ) { // Explicit override from request return false; } elseif ( $this->section == 'new' ) { // Nothing *to* preview for new sections return false; - } elseif ( ( $wgRequest->getVal( 'preload' ) !== null || $this->mTitle->exists() ) - && $wgUser->getOption( 'previewonfirst' ) + } elseif ( ( $request->getVal( 'preload' ) !== null || $this->mTitle->exists() ) + && $this->context->getUser()->getOption( 'previewonfirst' ) ) { // Standard preference behavior return true; @@ -850,8 +886,6 @@ class EditPage { * @throws ErrorPageError */ public function importFormData( &$request ) { - global $wgContLang, $wgUser; - # Section edit can come from either the form or a link $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) ); @@ -865,7 +899,7 @@ class EditPage { # These fields need to be checked for encoding. # Also remove trailing whitespace, but don't remove _initial_ # whitespace from the text boxes. This may be significant formatting. - $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' ); + $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) ); if ( !$request->getCheck( 'wpTextbox2' ) ) { // Skip this if wpTextbox2 has input, it indicates that we came // from a conflict page with raw page text, not a custom form @@ -876,8 +910,9 @@ class EditPage { } } - # Truncate for whole multibyte characters - $this->summary = $wgContLang->truncate( $request->getText( 'wpSummary' ), 255 ); + $this->unicodeCheck = $request->getText( 'wpUnicodeCheck' ); + + $this->summary = $request->getText( 'wpSummary' ); # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for @@ -889,7 +924,7 @@ class EditPage { # currently doing double duty as both edit summary and section title. Right now this # is just to allow API edits to work around this limitation, but this should be # incorporated into the actual edit form when EditPage is rewritten (Bugs 18654, 26312). - $this->sectiontitle = $wgContLang->truncate( $request->getText( 'wpSectionTitle' ), 255 ); + $this->sectiontitle = $request->getText( 'wpSectionTitle' ); $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle ); $this->edittime = $request->getVal( 'wpEdittime' ); @@ -961,14 +996,15 @@ class EditPage { $this->minoredit = $request->getCheck( 'wpMinoredit' ); $this->watchthis = $request->getCheck( 'wpWatchthis' ); + $user = $this->context->getUser(); # Don't force edit summaries when a user is editing their own user or talk page if ( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK ) - && $this->mTitle->getText() == $wgUser->getName() + && $this->mTitle->getText() == $user->getName() ) { $this->allowBlankSummary = true; } else { $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' ) - || !$wgUser->getOption( 'forceeditsummary' ); + || !$user->getOption( 'forceeditsummary' ); } $this->autoSumm = $request->getText( 'wpAutoSummary' ); @@ -1084,7 +1120,6 @@ class EditPage { * @return bool If the requested section is valid */ public function initialiseForm() { - global $wgUser; $this->edittime = $this->page->getTimestamp(); $this->editRevId = $this->page->getLatest(); @@ -1094,19 +1129,20 @@ class EditPage { } $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 ( $wgUser->getOption( 'watchdefault' ) ) { + if ( $user->getOption( 'watchdefault' ) ) { # Watch all edits $this->watchthis = true; - } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) { + } elseif ( $user->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) { # Watch creations $this->watchthis = true; - } elseif ( $wgUser->isWatched( $this->mTitle ) ) { + } elseif ( $user->isWatched( $this->mTitle ) ) { # Already watched $this->watchthis = true; } - if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew ) { + if ( $user->getOption( 'minordefault' ) && !$this->isNew ) { $this->minoredit = true; } if ( $this->textbox1 === false ) { @@ -1123,10 +1159,12 @@ class EditPage { * @since 1.21 */ protected function getContentObject( $def_content = null ) { - global $wgOut, $wgRequest, $wgUser, $wgContLang; + global $wgContLang; $content = false; + $user = $this->context->getUser(); + $request = $this->context->getRequest(); // For message page not locally set, use the i18n message. // For other non-existent articles, use preload text if any. if ( !$this->mTitle->exists() || $this->section == 'new' ) { @@ -1138,10 +1176,10 @@ class EditPage { } if ( $content === false ) { # If requested, preload some text. - $preload = $wgRequest->getVal( 'preload', + $preload = $request->getVal( 'preload', // Custom preload text for new sections $this->section === 'new' ? 'MediaWiki:addsection-preload' : '' ); - $params = $wgRequest->getArray( 'preloadparams', [] ); + $params = $request->getArray( 'preloadparams', [] ); $content = $this->getPreloadedContent( $preload, $params ); } @@ -1149,15 +1187,15 @@ class EditPage { } else { if ( $this->section != '' ) { // Get section edit text (returns $def_text for invalid sections) - $orig = $this->getOriginalContent( $wgUser ); + $orig = $this->getOriginalContent( $user ); $content = $orig ? $orig->getSection( $this->section ) : null; if ( !$content ) { $content = $def_content; } } else { - $undoafter = $wgRequest->getInt( 'undoafter' ); - $undo = $wgRequest->getInt( 'undo' ); + $undoafter = $request->getInt( 'undoafter' ); + $undo = $request->getInt( 'undo' ); if ( $undo > 0 && $undoafter > 0 ) { $undorev = Revision::newFromId( $undo ); @@ -1177,8 +1215,8 @@ class EditPage { $undoMsg = 'failure'; } else { $oldContent = $this->page->getContent( Revision::RAW ); - $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); - $newContent = $content->preSaveTransform( $this->mTitle, $wgUser, $popts ); + $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang ); + $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts ); if ( $newContent->getModel() !== $oldContent->getModel() ) { // The undo may change content // model if its reverting the top @@ -1231,14 +1269,15 @@ class EditPage { $undoMsg = 'norev'; } + $out = $this->context->getOutput(); // Messages: undo-success, undo-failure, undo-norev, undo-nochange $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}"; - $this->editFormPageTop .= $wgOut->parse( "
" . + $this->editFormPageTop .= $out->parse( "
" . $this->context->msg( 'undo-' . $undoMsg )->plain() . '
', true, /* interface */true ); } if ( $content === false ) { - $content = $this->getOriginalContent( $wgUser ); + $content = $this->getOriginalContent( $user ); } } } @@ -1364,8 +1403,6 @@ class EditPage { * @since 1.21 */ protected function getPreloadedContent( $preload, $params = [] ) { - global $wgUser; - if ( !empty( $this->mPreloadContent ) ) { return $this->mPreloadContent; } @@ -1376,9 +1413,10 @@ class EditPage { return $handler->makeEmptyContent(); } + $user = $this->context->getUser(); $title = Title::newFromText( $preload ); # Check for existence to avoid getting MediaWiki:Noarticletext - if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) { + if ( $title === null || !$title->exists() || !$title->userCan( 'read', $user ) ) { // TODO: somehow show a warning to the user! return $handler->makeEmptyContent(); } @@ -1387,14 +1425,14 @@ class EditPage { if ( $page->isRedirect() ) { $title = $page->getRedirectTarget(); # Same as before - if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) { + if ( $title === null || !$title->exists() || !$title->userCan( 'read', $user ) ) { // TODO: somehow show a warning to the user! return $handler->makeEmptyContent(); } $page = WikiPage::factory( $title ); } - $parserOptions = ParserOptions::newFromUser( $wgUser ); + $parserOptions = ParserOptions::newFromUser( $user ); $content = $page->getContent( Revision::RAW ); if ( !$content ) { @@ -1428,10 +1466,10 @@ class EditPage { * @private */ public function tokenOk( &$request ) { - global $wgUser; $token = $request->getVal( 'wpEditToken' ); - $this->mTokenOk = $wgUser->matchEditToken( $token ); - $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token ); + $user = $this->context->getUser(); + $this->mTokenOk = $user->matchEditToken( $token ); + $this->mTokenOkExceptSuffix = $user->matchEditTokenNoSuffix( $token ); return $this->mTokenOk; } @@ -1460,7 +1498,7 @@ class EditPage { $val = 'restored'; } - $response = RequestContext::getMain()->getRequest()->response(); + $response = $this->context->getRequest()->response(); $response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION ); } @@ -1471,10 +1509,8 @@ class EditPage { * @return Status The resulting status object. */ public function attemptSave( &$resultDetails = false ) { - global $wgUser; - # Allow bots to exempt some edits from bot flagging - $bot = $wgUser->isAllowed( 'bot' ) && $this->bot; + $bot = $this->context->getUser()->isAllowed( 'bot' ) && $this->bot; $status = $this->internalAttemptSave( $resultDetails, $bot ); Hooks::run( 'EditPage::attemptSave:after', [ $this, $status, $resultDetails ] ); @@ -1486,9 +1522,7 @@ class EditPage { * Log when a page was successfully saved after the edit conflict view */ private function incrementResolvedConflicts() { - global $wgRequest; - - if ( $wgRequest->getText( 'mode' ) !== 'conflict' ) { + if ( $this->context->getRequest()->getText( 'mode' ) !== 'conflict' ) { return; } @@ -1506,8 +1540,6 @@ class EditPage { * @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 @@ -1523,9 +1555,11 @@ class EditPage { } } + $out = $this->context->getOutput(); + // "wpExtraQueryRedirect" is a hidden input to modify // after save URL and is not used by actual edit form - $request = RequestContext::getMain()->getRequest(); + $request = $this->context->getRequest(); $extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' ); switch ( $status->value ) { @@ -1546,7 +1580,8 @@ class EditPage { case self::AS_CANNOT_USE_CUSTOM_MODEL: case self::AS_PARSE_ERROR: - $wgOut->addWikiText( '
' . "\n" . $status->getWikiText() . '
' ); + case self::AS_UNICODE_NOT_SUPPORTED: + $out->addWikiText( '
' . "\n" . $status->getWikiText() . '
' ); return true; case self::AS_SUCCESS_NEW_ARTICLE: @@ -1559,7 +1594,7 @@ class EditPage { } } $anchor = isset( $resultDetails['sectionanchor'] ) ? $resultDetails['sectionanchor'] : ''; - $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $anchor ); + $out->redirect( $this->mTitle->getFullURL( $query ) . $anchor ); return false; case self::AS_SUCCESS_UPDATE: @@ -1587,7 +1622,7 @@ class EditPage { } } - $wgOut->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor ); + $out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor ); return false; case self::AS_SPAM_ERROR: @@ -1595,7 +1630,7 @@ class EditPage { return false; case self::AS_BLOCKED_PAGE_FOR_USER: - throw new UserBlockedError( $wgUser->getBlock() ); + throw new UserBlockedError( $this->context->getUser()->getBlock() ); case self::AS_IMAGE_REDIRECT_ANON: case self::AS_IMAGE_REDIRECT_LOGGED: @@ -1734,10 +1769,11 @@ class EditPage { * time. */ public function internalAttemptSave( &$result, $bot = false ) { - global $wgUser, $wgRequest, $wgMaxArticleSize; + global $wgMaxArticleSize; global $wgContentHandlerUseDB; $status = Status::newGood(); + $user = $this->context->getUser(); if ( !Hooks::run( 'EditPage::attemptSave', [ $this ] ) ) { wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" ); @@ -1746,11 +1782,18 @@ class EditPage { return $status; } - $spam = $wgRequest->getText( 'wpAntispam' ); + if ( $this->unicodeCheck !== self::UNICODE_CHECK ) { + $status->fatal( 'unicode-support-fail' ); + $status->value = self::AS_UNICODE_NOT_SUPPORTED; + return $status; + } + + $request = $this->context->getRequest(); + $spam = $request->getText( 'wpAntispam' ); if ( $spam !== '' ) { wfDebugLog( 'SimpleAntiSpam', - $wgUser->getName() . + $user->getName() . ' editing "' . $this->mTitle->getPrefixedText() . '" submitted bogus field "' . @@ -1779,9 +1822,9 @@ class EditPage { # Check image redirect if ( $this->mTitle->getNamespace() == NS_FILE && $textbox_content->isRedirect() && - !$wgUser->isAllowed( 'upload' ) + !$user->isAllowed( 'upload' ) ) { - $code = $wgUser->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED; + $code = $user->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED; $status->setResult( false, $code ); return $status; @@ -1806,7 +1849,7 @@ class EditPage { } if ( $match !== false ) { $result['spam'] = $match; - $ip = $wgRequest->getIP(); + $ip = $request->getIP(); $pdbk = $this->mTitle->getPrefixedDBkey(); $match = str_replace( "\n", '', $match ); wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" ); @@ -1829,10 +1872,10 @@ class EditPage { return $status; } - if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) { + if ( $user->isBlockedFrom( $this->mTitle, false ) ) { // Auto-block user's IP if the account was "hard" blocked if ( !wfReadOnly() ) { - $wgUser->spreadAnyEditBlock(); + $user->spreadAnyEditBlock(); } # Check block state against master, thus 'false'. $status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER ); @@ -1847,8 +1890,8 @@ class EditPage { return $status; } - if ( !$wgUser->isAllowed( 'edit' ) ) { - if ( $wgUser->isAnon() ) { + if ( !$user->isAllowed( 'edit' ) ) { + if ( $user->isAnon() ) { $status->setResult( false, self::AS_READ_ONLY_PAGE_ANON ); return $status; } else { @@ -1864,15 +1907,15 @@ class EditPage { $status->fatal( 'editpage-cannot-use-custom-model' ); $status->value = self::AS_CANNOT_USE_CUSTOM_MODEL; return $status; - } elseif ( !$wgUser->isAllowed( 'editcontentmodel' ) ) { + } elseif ( !$user->isAllowed( 'editcontentmodel' ) ) { $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL ); return $status; } // Make sure the user can edit the page under the new content model too $titleWithNewContentModel = clone $this->mTitle; $titleWithNewContentModel->setContentModel( $this->contentModel ); - if ( !$titleWithNewContentModel->userCan( 'editcontentmodel', $wgUser ) - || !$titleWithNewContentModel->userCan( 'edit', $wgUser ) + if ( !$titleWithNewContentModel->userCan( 'editcontentmodel', $user ) + || !$titleWithNewContentModel->userCan( 'edit', $user ) ) { $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL ); return $status; @@ -1884,7 +1927,7 @@ class EditPage { if ( $this->changeTags ) { $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange( - $this->changeTags, $wgUser ); + $this->changeTags, $user ); if ( !$changeTagsStatus->isOK() ) { $changeTagsStatus->value = self::AS_CHANGE_TAG_ERROR; return $changeTagsStatus; @@ -1896,8 +1939,8 @@ class EditPage { $status->value = self::AS_READ_ONLY_PAGE; return $status; } - if ( $wgUser->pingLimiter() || $wgUser->pingLimiter( 'linkpurge', 0 ) - || ( $changingContentModel && $wgUser->pingLimiter( 'editcontentmodel' ) ) + if ( $user->pingLimiter() || $user->pingLimiter( 'linkpurge', 0 ) + || ( $changingContentModel && $user->pingLimiter( 'editcontentmodel' ) ) ) { $status->fatal( 'actionthrottledtext' ); $status->value = self::AS_RATE_LIMITED; @@ -1918,7 +1961,7 @@ class EditPage { if ( $new ) { // Late check for create permission, just in case *PARANOIA* - if ( !$this->mTitle->userCan( 'create', $wgUser ) ) { + if ( !$this->mTitle->userCan( 'create', $user ) ) { $status->fatal( 'nocreatetext' ); $status->value = self::AS_NO_CREATE_PERMISSION; wfDebug( __METHOD__ . ": no create permission\n" ); @@ -1942,7 +1985,7 @@ class EditPage { return $status; } - if ( !$this->runPostMergeFilters( $textbox_content, $status, $wgUser ) ) { + if ( !$this->runPostMergeFilters( $textbox_content, $status, $user ) ) { return $status; } @@ -1978,7 +2021,7 @@ class EditPage { ) { $this->isConflict = true; if ( $this->section == 'new' ) { - if ( $this->page->getUserText() == $wgUser->getName() && + if ( $this->page->getUserText() == $user->getName() && $this->page->getComment() == $this->newSectionSummary() ) { // Probably a duplicate submission of a new comment. @@ -1994,7 +2037,7 @@ class EditPage { } elseif ( $this->section == '' && Revision::userWasLastToEdit( DB_MASTER, $this->mTitle->getArticleID(), - $wgUser->getId(), $this->edittime + $user->getId(), $this->edittime ) ) { # Suppress edit conflict with self, except for section edits where merging is required. @@ -2064,7 +2107,7 @@ class EditPage { return $status; } - if ( !$this->runPostMergeFilters( $content, $status, $wgUser ) ) { + if ( !$this->runPostMergeFilters( $content, $status, $user ) ) { return $status; } @@ -2085,7 +2128,7 @@ class EditPage { return $status; } } elseif ( !$this->allowBlankSummary - && !$content->equals( $this->getOriginalContent( $wgUser ) ) + && !$content->equals( $this->getOriginalContent( $user ) ) && !$content->isRedirect() && md5( $this->summary ) == $this->autoSumm ) { @@ -2155,7 +2198,7 @@ class EditPage { $this->summary, $flags, false, - $wgUser, + $user, $content->getDefaultFormat(), $this->changeTags, $this->undidRev @@ -2179,7 +2222,7 @@ class EditPage { $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 - $wgUser->pingLimiter( 'linkpurge' ); + $user->pingLimiter( 'linkpurge' ); } $result['redirect'] = $content->isRedirect(); @@ -2188,7 +2231,7 @@ class EditPage { // If the content model changed, add a log entry if ( $changingContentModel ) { $this->addContentModelChangeLogEntry( - $wgUser, + $user, $new ? false : $oldContentModel, $this->contentModel, $this->summary @@ -2222,13 +2265,11 @@ class EditPage { * Register the change of watch status */ protected function updateWatchlist() { - global $wgUser; - - if ( !$wgUser->isLoggedIn() ) { + $user = $this->context->getUser(); + if ( !$user->isLoggedIn() ) { return; } - $user = $wgUser; $title = $this->mTitle; $watch = $this->watchthis; // Do this in its own transaction to reduce contention... @@ -2342,29 +2383,32 @@ class EditPage { } public function setHeaders() { - global $wgOut, $wgUser, $wgAjaxEditStash; + global $wgAjaxEditStash; + + $out = $this->context->getOutput(); - $wgOut->addModules( 'mediawiki.action.edit' ); - $wgOut->addModuleStyles( 'mediawiki.action.edit.styles' ); + $out->addModules( 'mediawiki.action.edit' ); + $out->addModuleStyles( 'mediawiki.action.edit.styles' ); - if ( $wgUser->getOption( 'showtoolbar' ) ) { + $user = $this->context->getUser(); + if ( $user->getOption( 'showtoolbar' ) ) { // The addition of default buttons is handled by getEditToolbar() which // has its own dependency on this module. The call here ensures the module // is loaded in time (it has position "top") for other modules to register // buttons (e.g. extensions, gadgets, user scripts). - $wgOut->addModules( 'mediawiki.toolbar' ); + $out->addModules( 'mediawiki.toolbar' ); } - if ( $wgUser->getOption( 'uselivepreview' ) ) { - $wgOut->addModules( 'mediawiki.action.edit.preview' ); + if ( $user->getOption( 'uselivepreview' ) ) { + $out->addModules( 'mediawiki.action.edit.preview' ); } - if ( $wgUser->getOption( 'useeditwarning' ) ) { - $wgOut->addModules( 'mediawiki.action.edit.editWarning' ); + if ( $user->getOption( 'useeditwarning' ) ) { + $out->addModules( 'mediawiki.action.edit.editWarning' ); } # Enabled article-related sidebar, toplinks, etc. - $wgOut->setArticleRelated( true ); + $out->setArticleRelated( true ); $contextTitle = $this->getContextTitle(); if ( $this->isConflict ) { @@ -2387,10 +2431,10 @@ class EditPage { if ( $displayTitle === false ) { $displayTitle = $contextTitle->getPrefixedText(); } - $wgOut->setPageTitle( $this->context->msg( $msg, $displayTitle ) ); + $out->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( [ + $out->addJsConfigVars( [ 'wgEditMessage' => $msg, 'wgAjaxEditStash' => $wgAjaxEditStash, ] ); @@ -2400,16 +2444,16 @@ class EditPage { * Show all applicable editing introductions */ protected function showIntro() { - global $wgOut, $wgUser; if ( $this->suppressIntro ) { return; } + $out = $this->context->getOutput(); $namespace = $this->mTitle->getNamespace(); if ( $namespace == NS_MEDIAWIKI ) { # Show a warning if editing an interface message - $wgOut->wrapWikiMsg( "
\n$1\n
", 'editinginterface' ); + $out->wrapWikiMsg( "
\n$1\n
", 'editinginterface' ); # If this is a default message (but not css or js), # show a hint that it is translatable on translatewiki.net if ( !$this->mTitle->hasContentModel( CONTENT_MODEL_CSS ) @@ -2417,7 +2461,7 @@ class EditPage { ) { $defaultMessageText = $this->mTitle->getDefaultMessageText(); if ( $defaultMessageText !== false ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", + $out->wrapWikiMsg( "
\n$1\n
", 'translateinterface' ); } } @@ -2429,11 +2473,11 @@ class EditPage { # there must be a description url to show a hint to shared repo if ( $descUrl ) { if ( !$this->mTitle->exists() ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", [ + $out->wrapWikiMsg( "
\n$1\n
", [ 'sharedupload-desc-create', $file->getRepo()->getDisplayName(), $descUrl ] ); } else { - $wgOut->wrapWikiMsg( "
\n$1\n
", [ + $out->wrapWikiMsg( "
\n$1\n
", [ 'sharedupload-desc-edit', $file->getRepo()->getDisplayName(), $descUrl ] ); } @@ -2449,12 +2493,12 @@ class EditPage { $ip = User::isIP( $username ); $block = Block::newFromTarget( $user, $user ); if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist - $wgOut->wrapWikiMsg( "
\n$1\n
", + $out->wrapWikiMsg( "
\n$1\n
", [ 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ] ); } elseif ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) { # Show log extract if the user is currently blocked LogEventsList::showLogExtract( - $wgOut, + $out, 'block', MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(), '', @@ -2474,8 +2518,8 @@ class EditPage { $helpLink = wfExpandUrl( Skin::makeInternalOrExternalUrl( $this->context->msg( 'helppage' )->inContentLanguage()->text() ) ); - if ( $wgUser->isLoggedIn() ) { - $wgOut->wrapWikiMsg( + if ( $this->context->getUser()->isLoggedIn() ) { + $out->wrapWikiMsg( // Suppress the external link icon, consider the help url an internal one "
\n$1\n
", [ @@ -2484,7 +2528,7 @@ class EditPage { ] ); } else { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( // Suppress the external link icon, consider the help url an internal one "
\n$1\n
", [ @@ -2498,7 +2542,7 @@ class EditPage { if ( !$this->mTitle->exists() ) { $dbr = wfGetDB( DB_REPLICA ); - LogEventsList::showLogExtract( $wgOut, [ 'delete', 'move' ], $this->mTitle, + LogEventsList::showLogExtract( $out, [ 'delete', 'move' ], $this->mTitle, '', [ 'lim' => 10, @@ -2519,9 +2563,8 @@ class EditPage { if ( $this->editintro ) { $title = Title::newFromText( $this->editintro ); if ( $title instanceof Title && $title->exists() && $title->userCan( 'read' ) ) { - global $wgOut; // Added using template syntax, to take 's into account. - $wgOut->addWikiTextTitleTidy( + $this->context->getOutput()->addWikiTextTitleTidy( '
{{:' . $title->getFullText() . '}}
', $this->mTitle ); @@ -2593,7 +2636,7 @@ class EditPage { } /** - * Send the edit form and related headers to $wgOut + * Send the edit form and related headers to OutputPage * @param callable|null $formCallback That takes an OutputPage parameter; will be called * during form output near the top, for captchas and the like. * @@ -2601,8 +2644,6 @@ class EditPage { * use the EditPage::showEditForm:fields hook instead. */ public function showEditForm( $formCallback = null ) { - global $wgOut, $wgUser; - # need to parse the preview early so that we know which templates are used, # otherwise users with "show preview after edit box" will get a blank list # we parse this near the beginning so that setHeaders can do the title @@ -2612,9 +2653,11 @@ class EditPage { $previewOutput = $this->getPreviewText(); } + $out = $this->context->getOutput(); + // Avoid PHP 7.1 warning of passing $this by reference $editPage = $this; - Hooks::run( 'EditPage::showEditForm:initial', [ &$editPage, &$wgOut ] ); + Hooks::run( 'EditPage::showEditForm:initial', [ &$editPage, &$out ] ); $this->setHeaders(); @@ -2627,19 +2670,20 @@ class EditPage { // We use $this->section to much before this and getVal('wgSection') directly in other places // at this point we can't reset $this->section to '' to fallback to non-section editing. // Someone is welcome to try refactoring though - $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' ); + $out->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' ); return; } $this->showHeader(); - $wgOut->addHTML( $this->editFormPageTop ); + $out->addHTML( $this->editFormPageTop ); - if ( $wgUser->getOption( 'previewontop' ) ) { + $user = $this->context->getUser(); + if ( $user->getOption( 'previewontop' ) ) { $this->displayPreviewArea( $previewOutput, true ); } - $wgOut->addHTML( $this->editFormTextTop ); + $out->addHTML( $this->editFormTextTop ); $showToolbar = true; if ( $this->wasDeletedSinceLastEdit() ) { @@ -2648,14 +2692,14 @@ class EditPage { // Add an confirmation checkbox and explanation. $showToolbar = false; } else { - $wgOut->wrapWikiMsg( "
\n$1\n
", + $out->wrapWikiMsg( "
\n$1\n
", 'deletedwhileediting' ); } } // @todo add EditForm plugin interface and use it here! // search for textarea1 and textarea2, and allow EditForm to override all uses. - $wgOut->addHTML( Html::openElement( + $out->addHTML( Html::openElement( 'form', [ 'class' => 'mw-editform', @@ -2669,11 +2713,14 @@ class EditPage { if ( is_callable( $formCallback ) ) { wfWarn( 'The $formCallback parameter to ' . __METHOD__ . 'is deprecated' ); - call_user_func_array( $formCallback, [ &$wgOut ] ); + call_user_func_array( $formCallback, [ &$out ] ); } + // Add a check for Unicode support + $out->addHTML( Html::hidden( 'wpUnicodeCheck', self::UNICODE_CHECK ) ); + // Add an empty field to trip up spambots - $wgOut->addHTML( + $out->addHTML( Xml::openElement( 'div', [ 'id' => 'antispam-container', 'style' => 'display: none;' ] ) . Html::rawElement( 'label', @@ -2694,7 +2741,7 @@ class EditPage { // Avoid PHP 7.1 warning of passing $this by reference $editPage = $this; - Hooks::run( 'EditPage::showEditForm:fields', [ &$editPage, &$wgOut ] ); + Hooks::run( 'EditPage::showEditForm:fields', [ &$editPage, &$out ] ); // Put these up at the top to ensure they aren't lost on early form submission $this->showFormBeforeText(); @@ -2708,7 +2755,7 @@ class EditPage { $key = $comment === '' ? 'confirmrecreate-noreason' : 'confirmrecreate'; - $wgOut->addHTML( + $out->addHTML( '
' . $this->context->msg( $key, $username, "$comment" )->parse() . Xml::checkLabel( $this->context->msg( 'recreate' )->text(), 'wpRecreate', 'wpRecreate', false, @@ -2720,7 +2767,7 @@ class EditPage { # When the summary is hidden, also hide them on preview/show changes if ( $this->nosummary ) { - $wgOut->addHTML( Html::hidden( 'nosummary', true ) ); + $out->addHTML( Html::hidden( 'nosummary', true ) ); } # If a blank edit summary was previously provided, and the appropriate @@ -2731,15 +2778,15 @@ class EditPage { # For a bit more sophisticated detection of blank summaries, hash the # automatic one and pass that in the hidden field wpAutoSummary. if ( $this->missingSummary || ( $this->section == 'new' && $this->nosummary ) ) { - $wgOut->addHTML( Html::hidden( 'wpIgnoreBlankSummary', true ) ); + $out->addHTML( Html::hidden( 'wpIgnoreBlankSummary', true ) ); } if ( $this->undidRev ) { - $wgOut->addHTML( Html::hidden( 'wpUndidRevision', $this->undidRev ) ); + $out->addHTML( Html::hidden( 'wpUndidRevision', $this->undidRev ) ); } if ( $this->selfRedirect ) { - $wgOut->addHTML( Html::hidden( 'wpIgnoreSelfRedirect', true ) ); + $out->addHTML( Html::hidden( 'wpIgnoreSelfRedirect', true ) ); } if ( $this->hasPresetSummary ) { @@ -2750,29 +2797,29 @@ class EditPage { } $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary ); - $wgOut->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) ); + $out->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) ); - $wgOut->addHTML( Html::hidden( 'oldid', $this->oldid ) ); - $wgOut->addHTML( Html::hidden( 'parentRevId', $this->getParentRevId() ) ); + $out->addHTML( Html::hidden( 'oldid', $this->oldid ) ); + $out->addHTML( Html::hidden( 'parentRevId', $this->getParentRevId() ) ); - $wgOut->addHTML( Html::hidden( 'format', $this->contentFormat ) ); - $wgOut->addHTML( Html::hidden( 'model', $this->contentModel ) ); + $out->addHTML( Html::hidden( 'format', $this->contentFormat ) ); + $out->addHTML( Html::hidden( 'model', $this->contentModel ) ); - $wgOut->enableOOUI(); + $out->enableOOUI(); if ( $this->section == 'new' ) { $this->showSummaryInput( true, $this->summary ); - $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary ) ); + $out->addHTML( $this->getSummaryPreview( true, $this->summary ) ); } - $wgOut->addHTML( $this->editFormTextBeforeContent ); + $out->addHTML( $this->editFormTextBeforeContent ); - if ( !$this->isCssJsSubpage && $showToolbar && $wgUser->getOption( 'showtoolbar' ) ) { - $wgOut->addHTML( self::getEditToolbar( $this->mTitle ) ); + if ( !$this->mTitle->isCssJsSubpage() && $showToolbar && $user->getOption( 'showtoolbar' ) ) { + $out->addHTML( self::getEditToolbar( $this->mTitle ) ); } if ( $this->blankArticle ) { - $wgOut->addHTML( Html::hidden( 'wpIgnoreBlankArticle', true ) ); + $out->addHTML( Html::hidden( 'wpIgnoreBlankArticle', true ) ); } if ( $this->isConflict ) { @@ -2790,7 +2837,7 @@ class EditPage { $this->showContentForm(); } - $wgOut->addHTML( $this->editFormTextAfterContent ); + $out->addHTML( $this->editFormTextAfterContent ); $this->showStandardInputs(); @@ -2800,17 +2847,17 @@ class EditPage { $this->showEditTools(); - $wgOut->addHTML( $this->editFormTextAfterTools . "\n" ); + $out->addHTML( $this->editFormTextAfterTools . "\n" ); - $wgOut->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) ); + $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) ); - $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ], + $out->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ], Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) ); - $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ], + $out->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ], self::getPreviewLimitReport( $this->mParserOutput ) ) ); - $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' ); + $out->addModules( 'mediawiki.action.edit.collapsibleFooter' ); if ( $this->isConflict ) { try { @@ -2823,7 +2870,7 @@ class EditPage { $this->contentFormat, $ex->getMessage() ); - $wgOut->addWikiText( '
' . $msg->text() . '
' ); + $out->addWikiText( '
' . $msg->text() . '
' ); } } @@ -2837,14 +2884,14 @@ class EditPage { } else { $mode = 'text'; } - $wgOut->addHTML( Html::hidden( 'mode', $mode, [ 'id' => 'mw-edit-mode' ] ) ); + $out->addHTML( Html::hidden( 'mode', $mode, [ 'id' => 'mw-edit-mode' ] ) ); // Marker for detecting truncated form data. This must be the last // parameter sent in order to be of use, so do not move me. - $wgOut->addHTML( Html::hidden( 'wpUltimateParam', true ) ); - $wgOut->addHTML( $this->editFormTextBottom . "\n\n" ); + $out->addHTML( Html::hidden( 'wpUltimateParam', true ) ); + $out->addHTML( $this->editFormTextBottom . "\n\n" ); - if ( !$wgUser->getOption( 'previewontop' ) ) { + if ( !$user->getOption( 'previewontop' ) ) { $this->displayPreviewArea( $previewOutput, false ); } } @@ -2891,11 +2938,12 @@ class EditPage { } protected function showHeader() { - global $wgOut, $wgUser; global $wgAllowUserCss, $wgAllowUserJs; + $out = $this->context->getOutput(); + $user = $this->context->getUser(); if ( $this->isConflict ) { - $this->addExplainConflictHeader( $wgOut ); + $this->addExplainConflictHeader( $out ); $this->editRevId = $this->page->getLatest(); } else { if ( $this->section != '' && $this->section != 'new' ) { @@ -2907,46 +2955,42 @@ class EditPage { } } - $buttonLabel = $this->context->msg( $this->getSaveButtonLabel() )->text(); + $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text(); if ( $this->missingComment ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", 'missingcommenttext' ); + $out->wrapWikiMsg( "
\n$1\n
", 'missingcommenttext' ); } if ( $this->missingSummary && $this->section != 'new' ) { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( "
\n$1\n
", [ 'missingsummary', $buttonLabel ] ); } if ( $this->missingSummary && $this->section == 'new' ) { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( "
\n$1\n
", [ 'missingcommentheader', $buttonLabel ] ); } if ( $this->blankArticle ) { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( "
\n$1\n
", [ 'blankarticle', $buttonLabel ] ); } if ( $this->selfRedirect ) { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( "
\n$1\n
", [ 'selfredirect', $buttonLabel ] ); } if ( $this->hookError !== '' ) { - $wgOut->addWikiText( $this->hookError ); - } - - if ( !$this->checkUnicodeCompliantBrowser() ) { - $wgOut->addWikiMsg( 'nonunicodebrowser' ); + $out->addWikiText( $this->hookError ); } if ( $this->section != 'new' ) { @@ -2954,13 +2998,13 @@ class EditPage { if ( $revision ) { // Let sysop know that this will make private content public if saved - if ( !$revision->userCan( Revision::DELETED_TEXT, $wgUser ) ) { - $wgOut->wrapWikiMsg( + if ( !$revision->userCan( Revision::DELETED_TEXT, $user ) ) { + $out->wrapWikiMsg( "\n", 'rev-deleted-text-permission' ); } elseif ( $revision->isDeleted( Revision::DELETED_TEXT ) ) { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( "\n", 'rev-deleted-text-view' ); @@ -2968,26 +3012,26 @@ class EditPage { if ( !$revision->isCurrent() ) { $this->mArticle->setOldSubtitle( $revision->getId() ); - $wgOut->addWikiMsg( 'editingold' ); + $out->addWikiMsg( 'editingold' ); $this->isOldRev = true; } } elseif ( $this->mTitle->exists() ) { // Something went wrong - $wgOut->wrapWikiMsg( "
\n$1\n
\n", + $out->wrapWikiMsg( "
\n$1\n
\n", [ 'missing-revision', $this->oldid ] ); } } } if ( wfReadOnly() ) { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( "
\n$1\n
", [ 'readonlywarning', wfReadOnlyReason() ] ); - } elseif ( $wgUser->isAnon() ) { + } elseif ( $user->isAnon() ) { if ( $this->formtype != 'preview' ) { - $wgOut->wrapWikiMsg( + $out->wrapWikiMsg( "
\n$1\n
", [ 'anoneditwarning', // Log-in link @@ -3001,33 +3045,34 @@ class EditPage { ] ); } else { - $wgOut->wrapWikiMsg( "
\n$1
", + $out->wrapWikiMsg( "
\n$1
", 'anonpreviewwarning' ); } } else { - if ( $this->isCssJsSubpage ) { + if ( $this->mTitle->isCssJsSubpage() ) { # Check the skin exists - if ( $this->isWrongCaseCssJsPage ) { - $wgOut->wrapWikiMsg( + if ( $this->isWrongCaseCssJsPage() ) { + $out->wrapWikiMsg( "
\n$1\n
", [ 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ] ); } - if ( $this->getTitle()->isSubpageOf( $wgUser->getUserPage() ) ) { - $wgOut->wrapWikiMsg( '
$1
', - $this->isCssSubpage ? 'usercssispublic' : 'userjsispublic' + if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) { + $isCssSubpage = $this->mTitle->isCssSubpage(); + $out->wrapWikiMsg( '
$1
', + $isCssSubpage ? 'usercssispublic' : 'userjsispublic' ); if ( $this->formtype !== 'preview' ) { - if ( $this->isCssSubpage && $wgAllowUserCss ) { - $wgOut->wrapWikiMsg( + if ( $isCssSubpage && $wgAllowUserCss ) { + $out->wrapWikiMsg( "
\n$1\n
", [ 'usercssyoucanpreview' ] ); } - if ( $this->isJsSubpage && $wgAllowUserJs ) { - $wgOut->wrapWikiMsg( + if ( $this->mTitle->isJsSubpage() && $wgAllowUserJs ) { + $out->wrapWikiMsg( "
\n$1\n
", [ 'userjsyoucanpreview' ] ); @@ -3163,8 +3208,6 @@ class EditPage { * @param string $summary The text of the summary to display */ protected function showSummaryInput( $isSubjectPreview, $summary = "" ) { - global $wgOut; - # Add a class if 'missingsummary' is triggered to allow styling of the summary line $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary'; if ( $isSubjectPreview ) { @@ -3178,7 +3221,7 @@ class EditPage { } $labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse(); - $wgOut->addHTML( $this->getSummaryInputWidget( + $this->context->getOutput()->addHTML( $this->getSummaryInputWidget( $summary, $labelText, [ 'class' => $summaryClass ] @@ -3215,21 +3258,15 @@ class EditPage { } protected function showFormBeforeText() { - global $wgOut; - - $wgOut->addHTML( Html::hidden( 'wpSection', htmlspecialchars( $this->section ) ) ); - $wgOut->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) ); - $wgOut->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) ); - $wgOut->addHTML( Html::hidden( 'editRevId', $this->editRevId ) ); - $wgOut->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) ); - - if ( !$this->checkUnicodeCompliantBrowser() ) { - $wgOut->addHTML( Html::hidden( 'safemode', '1' ) ); - } + $out = $this->context->getOutput(); + $out->addHTML( Html::hidden( 'wpSection', htmlspecialchars( $this->section ) ) ); + $out->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) ); + $out->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) ); + $out->addHTML( Html::hidden( 'editRevId', $this->editRevId ) ); + $out->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) ); } protected function showFormAfterText() { - global $wgOut, $wgUser; /** * To make it harder for someone to slip a user a page * which submits an edit form to the wiki without their @@ -3242,7 +3279,11 @@ class EditPage { * include the constant suffix to prevent editing from * broken text-mangling proxies. */ - $wgOut->addHTML( "\n" . Html::hidden( "wpEditToken", $wgUser->getEditToken() ) . "\n" ); + $this->context->getOutput()->addHTML( + "\n" . + Html::hidden( "wpEditToken", $this->context->getUser()->getEditToken() ) . + "\n" + ); } /** @@ -3316,18 +3357,14 @@ class EditPage { } protected function showTextbox( $text, $name, $customAttribs = [] ) { - global $wgOut, $wgUser; + $wikitext = $this->addNewLineAtEnd( $text ); - $wikitext = $this->safeUnicodeOutput( $text ); - $wikitext = $this->addNewLineAtEnd( $wikitext ); + $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $this->context->getUser() ); - $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $wgUser ); - - $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) ); + $this->context->getOutput()->addHTML( Html::textarea( $name, $wikitext, $attribs ) ); } protected function displayPreviewArea( $previewOutput, $isOnTop = false ) { - global $wgOut; $classes = []; if ( $isOnTop ) { $classes[] = 'ontop'; @@ -3339,7 +3376,8 @@ class EditPage { $attribs['style'] = 'display: none;'; } - $wgOut->addHTML( Xml::openElement( 'div', $attribs ) ); + $out = $this->context->getOutput(); + $out->addHTML( Xml::openElement( 'div', $attribs ) ); if ( $this->formtype == 'preview' ) { $this->showPreview( $previewOutput ); @@ -3348,10 +3386,10 @@ class EditPage { $pageViewLang = $this->mTitle->getPageViewLanguage(); $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(), 'class' => 'mw-content-' . $pageViewLang->getDir() ]; - $wgOut->addHTML( Html::rawElement( 'div', $attribs ) ); + $out->addHTML( Html::rawElement( 'div', $attribs ) ); } - $wgOut->addHTML( '
' ); + $out->addHTML( '
' ); if ( $this->formtype == 'diff' ) { try { @@ -3363,26 +3401,26 @@ class EditPage { $this->contentFormat, $ex->getMessage() ); - $wgOut->addWikiText( '
' . $msg->text() . '
' ); + $out->addWikiText( '
' . $msg->text() . '
' ); } } } /** - * Append preview output to $wgOut. + * Append preview output to OutputPage. * Includes category rendering if this is a category page. * * @param string $text The HTML to be output for the preview. */ protected function showPreview( $text ) { - global $wgOut; if ( $this->mArticle instanceof CategoryPage ) { $this->mArticle->openShowCategory(); } # This hook seems slightly odd here, but makes things more # consistent for extensions. - Hooks::run( 'OutputPageBeforeHTML', [ &$wgOut, &$text ] ); - $wgOut->addHTML( $text ); + $out = $this->context->getOutput(); + Hooks::run( 'OutputPageBeforeHTML', [ &$out, &$text ] ); + $out->addHTML( $text ); if ( $this->mArticle instanceof CategoryPage ) { $this->mArticle->closeShowCategory(); } @@ -3396,7 +3434,7 @@ class EditPage { * save and then make a comparison. */ public function showDiff() { - global $wgUser, $wgContLang, $wgOut; + global $wgContLang; $oldtitlemsg = 'currentrev'; # if message does not exist, show diff against the preloaded default @@ -3426,8 +3464,9 @@ class EditPage { if ( $newContent ) { Hooks::run( 'EditPageGetDiffContent', [ $this, &$newContent ] ); - $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); - $newContent = $newContent->preSaveTransform( $this->mTitle, $wgUser, $popts ); + $user = $this->context->getUser(); + $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang ); + $newContent = $newContent->preSaveTransform( $this->mTitle, $user, $popts ); } if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) { @@ -3451,7 +3490,7 @@ class EditPage { $difftext = ''; } - $wgOut->addHTML( '
' . $difftext . '
' ); + $this->context->getOutput()->addHTML( '
' . $difftext . '
' ); } /** @@ -3460,8 +3499,7 @@ class EditPage { protected function showHeaderCopyrightWarning() { $msg = 'editpage-head-copy-warn'; if ( !$this->context->msg( $msg )->isDisabled() ) { - global $wgOut; - $wgOut->wrapWikiMsg( "
\n$1\n
", + $this->context->getOutput()->wrapWikiMsg( "
\n$1\n
", 'editpage-head-copy-warn' ); } } @@ -3478,10 +3516,10 @@ class EditPage { $msg = 'editpage-tos-summary'; Hooks::run( 'EditPageTosSummary', [ $this->mTitle, &$msg ] ); if ( !$this->context->msg( $msg )->isDisabled() ) { - global $wgOut; - $wgOut->addHTML( '
' ); - $wgOut->addWikiMsg( $msg ); - $wgOut->addHTML( '
' ); + $out = $this->context->getOutput(); + $out->addHTML( '
' ); + $out->addWikiMsg( $msg ); + $out->addHTML( '
' ); } } @@ -3490,8 +3528,7 @@ class EditPage { * characters not present on most keyboards for copying/pasting. */ protected function showEditTools() { - global $wgOut; - $wgOut->addHTML( '
' . + $this->context->getOutput()->addHTML( '
' . $this->context->msg( 'edittools' )->inContentLanguage()->parse() . '
' ); } @@ -3585,28 +3622,28 @@ class EditPage { } protected function showStandardInputs( &$tabindex = 2 ) { - global $wgOut; - $wgOut->addHTML( "
\n" ); + $out = $this->context->getOutput(); + $out->addHTML( "
\n" ); if ( $this->section != 'new' ) { $this->showSummaryInput( false, $this->summary ); - $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary ) ); + $out->addHTML( $this->getSummaryPreview( false, $this->summary ) ); } - $checkboxes = $this->getCheckboxesOOUI( + $checkboxes = $this->getCheckboxesWidget( $tabindex, [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ] ); $checkboxesHTML = new OOUI\HorizontalLayout( [ 'items' => $checkboxes ] ); - $wgOut->addHTML( "
" . $checkboxesHTML . "
\n" ); + $out->addHTML( "
" . $checkboxesHTML . "
\n" ); // Show copyright warning. - $wgOut->addWikiText( $this->getCopywarn() ); - $wgOut->addHTML( $this->editFormTextAfterWarn ); + $out->addWikiText( $this->getCopywarn() ); + $out->addHTML( $this->editFormTextAfterWarn ); - $wgOut->addHTML( "
\n" ); - $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" ); + $out->addHTML( "
\n" ); + $out->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" ); $cancel = $this->getCancelLink(); if ( $cancel !== '' ) { @@ -3626,13 +3663,13 @@ class EditPage { $this->context->msg( 'word-separator' )->escaped() . $this->context->msg( 'newwindow' )->parse(); - $wgOut->addHTML( " {$cancel}\n" ); - $wgOut->addHTML( " {$edithelp}\n" ); - $wgOut->addHTML( "
\n" ); + $out->addHTML( " {$cancel}\n" ); + $out->addHTML( " {$edithelp}\n" ); + $out->addHTML( "
\n" ); - Hooks::run( 'EditPage::showStandardInputs:options', [ $this, $wgOut, &$tabindex ] ); + Hooks::run( 'EditPage::showStandardInputs:options', [ $this, $out, &$tabindex ] ); - $wgOut->addHTML( "
\n" ); + $out->addHTML( "
\n" ); } /** @@ -3640,14 +3677,13 @@ class EditPage { * If you want to use another entry point to this function, be careful. */ protected function showConflict() { - global $wgOut; - + $out = $this->context->getOutput(); // Avoid PHP 7.1 warning of passing $this by reference $editPage = $this; - if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$wgOut ] ) ) { + if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$out ] ) ) { $this->incrementConflictStats(); - $wgOut->wrapWikiMsg( '

$1

', "yourdiff" ); + $out->wrapWikiMsg( '

$1

', "yourdiff" ); $content1 = $this->toEditContent( $this->textbox1 ); $content2 = $this->toEditContent( $this->textbox2 ); @@ -3660,7 +3696,7 @@ class EditPage { $this->context->msg( 'storedversion' )->text() ); - $wgOut->wrapWikiMsg( '

$1

', "yourtext" ); + $out->wrapWikiMsg( '

$1

', "yourtext" ); $this->showTextbox2(); } } @@ -3790,9 +3826,11 @@ class EditPage { * @return string */ public function getPreviewText() { - global $wgOut, $wgRawHtml, $wgLang; + global $wgRawHtml; global $wgAllowUserCss, $wgAllowUserJs; + $out = $this->context->getOutput(); + if ( $wgRawHtml && !$this->mTokenOk ) { // Could be an offsite preview attempt. This is very unsafe if // HTML is enabled, as it could be an attack. @@ -3801,7 +3839,7 @@ class EditPage { // Do not put big scary notice, if previewing the empty // string, which happens when you initially edit // a category page, due to automatic preview-on-open. - $parsedNote = $wgOut->parse( "
" . + $parsedNote = $out->parse( "
" . $this->context->msg( 'session_fail_preview_html' )->text() . "
", true, /* interface */true ); } @@ -3824,7 +3862,8 @@ class EditPage { # provide a anchor link to the editform $continueEditing = '' . - '[[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . + '[[#' . self::EDITFORM_ID . '|' . + $this->context->getLanguage()->getArrow() . ' ' . $this->context->msg( 'continue-editing' )->text() . ']]'; if ( $this->mTriedSave && !$this->mTokenOk ) { if ( $this->mTokenOkExceptSuffix ) { @@ -3889,7 +3928,7 @@ class EditPage { $parserOutput = $parserResult['parserOutput']; $previewHTML = $parserResult['html']; $this->mParserOutput = $parserOutput; - $wgOut->addParserOutputMetadata( $parserOutput ); + $out->addParserOutputMetadata( $parserOutput ); if ( count( $parserOutput->getWarnings() ) ) { $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() ); @@ -3915,7 +3954,7 @@ class EditPage { $previewhead = "
\n" . '

' . $this->context->msg( 'preview' )->escaped() . "

" . - $wgOut->parse( $note, true, /* interface */true ) . $conflict . "
\n"; + $out->parse( $note, true, /* interface */true ) . $conflict . "
\n"; $pageViewLang = $this->mTitle->getPageViewLanguage(); $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(), @@ -3952,11 +3991,11 @@ class EditPage { * - html: The HTML to be displayed */ protected function doPreviewParse( Content $content ) { - global $wgUser; + $user = $this->context->getUser(); $parserOptions = $this->getPreviewParserOptions(); - $pstContent = $content->preSaveTransform( $this->mTitle, $wgUser, $parserOptions ); + $pstContent = $content->preSaveTransform( $this->mTitle, $user, $parserOptions ); $scopedCallback = $parserOptions->setupFakeRevision( - $this->mTitle, $pstContent, $wgUser ); + $this->mTitle, $pstContent, $user ); $parserOutput = $pstContent->getParserOutput( $this->mTitle, null, $parserOptions ); ScopedCallback::consume( $scopedCallback ); $parserOutput->setEditSectionTokens( false ); // no section edit links @@ -4143,11 +4182,11 @@ class EditPage { * @return array */ public function getCheckboxesDefinition( $checked ) { - global $wgUser; $checkboxes = []; + $user = $this->context->getUser(); // don't show the minor edit checkbox if it's a new page or section - if ( !$this->isNew && $wgUser->isAllowed( 'minoredit' ) ) { + if ( !$this->isNew && $user->isAllowed( 'minoredit' ) ) { $checkboxes['wpMinoredit'] = [ 'id' => 'wpMinoredit', 'label-message' => 'minoredit', @@ -4159,7 +4198,7 @@ class EditPage { ]; } - if ( $wgUser->isLoggedIn() ) { + if ( $user->isLoggedIn() ) { $checkboxes['wpWatchthis'] = [ 'id' => 'wpWatchthis', 'label-message' => 'watchthis', @@ -4181,13 +4220,12 @@ class EditPage { * Returns an array of html code of the following checkboxes old style: * minor and watch * + * @deprecated since 1.30 Use getCheckboxesWidget() or getCheckboxesDefinition() instead * @param int &$tabindex Current tabindex * @param array $checked See getCheckboxesDefinition() * @return array */ public function getCheckboxes( &$tabindex, $checked ) { - global $wgUseMediaWikiUIEverywhere; - $checkboxes = []; $checkboxesDef = $this->getCheckboxesDefinition( $checked ); @@ -4222,10 +4260,6 @@ class EditPage { ' ' . Xml::tags( 'label', $labelAttribs, $label ); - if ( $wgUseMediaWikiUIEverywhere ) { - $checkboxHtml = Html::rawElement( 'div', [ 'class' => 'mw-ui-checkbox' ], $checkboxHtml ); - } - $checkboxes[ $legacyName ] = $checkboxHtml; } @@ -4236,21 +4270,34 @@ class EditPage { } /** - * Returns an array of html code of the following checkboxes: - * minor and watch + * Returns an array of checkboxes for the edit form, including 'minor' and 'watch' checkboxes and + * any other added by extensions. * + * @deprecated since 1.30 Use getCheckboxesWidget() or getCheckboxesDefinition() instead * @param int &$tabindex Current tabindex * @param array $checked Array of checkbox => bool, where bool indicates the checked * status of the checkbox * - * @return array + * @return array Associative array of string keys to OOUI\FieldLayout instances */ public function getCheckboxesOOUI( &$tabindex, $checked ) { + return $this->getCheckboxesWidget( $tabindex, $checked ); + } + + /** + * Returns an array of checkboxes for the edit form, including 'minor' and 'watch' checkboxes and + * any other added by extensions. + * + * @param int &$tabindex Current tabindex + * @param array $checked Array of checkbox => bool, where bool indicates the checked + * status of the checkbox + * + * @return array Associative array of string keys to OOUI\FieldLayout instances + */ + public function getCheckboxesWidget( &$tabindex, $checked ) { $checkboxes = []; $checkboxesDef = $this->getCheckboxesDefinition( $checked ); - $origTabindex = $tabindex; - foreach ( $checkboxesDef as $name => $options ) { $legacyName = isset( $options['legacy-name'] ) ? $options['legacy-name'] : $name; @@ -4286,7 +4333,19 @@ class EditPage { // Backwards-compatibility hack to run the EditPageBeforeEditChecks hook. It's important, // people have used it for the weirdest things completely unrelated to checkboxes... // And if we're gonna run it, might as well allow its legacy checkboxes to be shown. - $legacyCheckboxes = $this->getCheckboxes( $origTabindex, $checked ); + $legacyCheckboxes = []; + if ( !$this->isNew ) { + $legacyCheckboxes['minor'] = ''; + } + $legacyCheckboxes['watch'] = ''; + // Copy new-style checkboxes into an old-style structure + foreach ( $checkboxes as $name => $oouiLayout ) { + $legacyCheckboxes[$name] = (string)$oouiLayout; + } + // Avoid PHP 7.1 warning of passing $this by reference + $ep = $this; + Hooks::run( 'EditPageBeforeEditChecks', [ &$ep, &$legacyCheckboxes, &$tabindex ], '1.29' ); + // Copy back any additional old-style checkboxes into the new-style structure foreach ( $legacyCheckboxes as $name => $html ) { if ( $html && !isset( $checkboxes[$name] ) ) { $checkboxes[$name] = new OOUI\Widget( [ 'content' => new OOUI\HtmlSnippet( $html ) ] ); @@ -4301,9 +4360,9 @@ class EditPage { * * @return string */ - private function getSaveButtonLabel() { + protected function getSubmitButtonLabel() { $labelAsPublish = - $this->mArticle->getContext()->getConfig()->get( 'EditSubmitButtonLabelPublish' ); + $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' ); // Can't use $this->isNew as that's also true if we're adding a new section to an extant page $newPage = !$this->mTitle->exists(); @@ -4328,7 +4387,7 @@ class EditPage { public function getEditButtons( &$tabindex ) { $buttons = []; - $buttonLabel = $this->context->msg( $this->getSaveButtonLabel() )->text(); + $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text(); $attribs = [ 'name' => 'wpSave', @@ -4397,18 +4456,17 @@ class EditPage { * they have attempted to edit a nonexistent section. */ public function noSuchSectionPage() { - global $wgOut; - - $wgOut->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) ); + $out = $this->context->getOutput(); + $out->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) ); $res = $this->context->msg( 'nosuchsectiontext', $this->section )->parseAsBlock(); // Avoid PHP 7.1 warning of passing $this by reference $editPage = $this; Hooks::run( 'EditPageNoSuchSection', [ &$editPage, &$res ] ); - $wgOut->addHTML( $res ); + $out->addHTML( $res ); - $wgOut->returnToMain( false, $this->mTitle ); + $out->returnToMain( false, $this->mTitle ); } /** @@ -4417,177 +4475,69 @@ class EditPage { * @param string|array|bool $match Text (or array of texts) which triggered one or more filters */ public function spamPageWithContent( $match = false ) { - global $wgOut, $wgLang; $this->textbox2 = $this->textbox1; if ( is_array( $match ) ) { - $match = $wgLang->listToText( $match ); + $match = $this->context->getLanguage()->listToText( $match ); } - $wgOut->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) ); + $out = $this->context->getOutput(); + $out->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) ); - $wgOut->addHTML( '
' ); - $wgOut->addWikiMsg( 'spamprotectiontext' ); + $out->addHTML( '
' ); + $out->addWikiMsg( 'spamprotectiontext' ); if ( $match ) { - $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) ); + $out->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) ); } - $wgOut->addHTML( '
' ); + $out->addHTML( '
' ); - $wgOut->wrapWikiMsg( '

$1

', "yourdiff" ); + $out->wrapWikiMsg( '

$1

', "yourdiff" ); $this->showDiff(); - $wgOut->wrapWikiMsg( '

$1

', "yourtext" ); + $out->wrapWikiMsg( '

$1

', "yourtext" ); $this->showTextbox2(); - $wgOut->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] ); - } - - /** - * Check if the browser is on a blacklist of user-agents known to - * mangle UTF-8 data on form submission. Returns true if Unicode - * should make it through, false if it's known to be a problem. - * @return bool - */ - private function checkUnicodeCompliantBrowser() { - global $wgBrowserBlackList, $wgRequest; - - $currentbrowser = $wgRequest->getHeader( 'User-Agent' ); - if ( $currentbrowser === false ) { - // No User-Agent header sent? Trust it by default... - return true; - } - - foreach ( $wgBrowserBlackList as $browser ) { - if ( preg_match( $browser, $currentbrowser ) ) { - return false; - } - } - return true; + $out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] ); } /** * Filter an input field through a Unicode de-armoring process if it * came from an old browser with known broken Unicode editing issues. * + * @deprecated since 1.30, does nothing + * * @param WebRequest $request * @param string $field * @return string */ protected function safeUnicodeInput( $request, $field ) { - $text = rtrim( $request->getText( $field ) ); - return $request->getBool( 'safemode' ) - ? $this->unmakeSafe( $text ) - : $text; + return rtrim( $request->getText( $field ) ); } /** * Filter an output field through a Unicode armoring process if it is * going to an old browser with known broken Unicode editing issues. * + * @deprecated since 1.30, does nothing + * * @param string $text * @return string */ protected function safeUnicodeOutput( $text ) { - return $this->checkUnicodeCompliantBrowser() - ? $text - : $this->makeSafe( $text ); - } - - /** - * A number of web browsers are known to corrupt non-ASCII characters - * in a UTF-8 text editing environment. To protect against this, - * detected browsers will be served an armored version of the text, - * with non-ASCII chars converted to numeric HTML character references. - * - * Preexisting such character references will have a 0 added to them - * to ensure that round-trips do not alter the original data. - * - * @param string $invalue - * @return string - */ - private function makeSafe( $invalue ) { - // Armor existing references for reversibility. - $invalue = strtr( $invalue, [ "&#x" => "�" ] ); - - $bytesleft = 0; - $result = ""; - $working = 0; - $valueLength = strlen( $invalue ); - for ( $i = 0; $i < $valueLength; $i++ ) { - $bytevalue = ord( $invalue[$i] ); - if ( $bytevalue <= 0x7F ) { // 0xxx xxxx - $result .= chr( $bytevalue ); - $bytesleft = 0; - } elseif ( $bytevalue <= 0xBF ) { // 10xx xxxx - $working = $working << 6; - $working += ( $bytevalue & 0x3F ); - $bytesleft--; - if ( $bytesleft <= 0 ) { - $result .= "&#x" . strtoupper( dechex( $working ) ) . ";"; - } - } elseif ( $bytevalue <= 0xDF ) { // 110x xxxx - $working = $bytevalue & 0x1F; - $bytesleft = 1; - } elseif ( $bytevalue <= 0xEF ) { // 1110 xxxx - $working = $bytevalue & 0x0F; - $bytesleft = 2; - } else { // 1111 0xxx - $working = $bytevalue & 0x07; - $bytesleft = 3; - } - } - return $result; - } - - /** - * Reverse the previously applied transliteration of non-ASCII characters - * back to UTF-8. Used to protect data from corruption by broken web browsers - * as listed in $wgBrowserBlackList. - * - * @param string $invalue - * @return string - */ - private function unmakeSafe( $invalue ) { - $result = ""; - $valueLength = strlen( $invalue ); - for ( $i = 0; $i < $valueLength; $i++ ) { - if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i + 3] != '0' ) ) { - $i += 3; - $hexstring = ""; - do { - $hexstring .= $invalue[$i]; - $i++; - } while ( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) ); - - // Do some sanity checks. These aren't needed for reversibility, - // but should help keep the breakage down if the editor - // breaks one of the entities whilst editing. - if ( ( substr( $invalue, $i, 1 ) == ";" ) && ( strlen( $hexstring ) <= 6 ) ) { - $codepoint = hexdec( $hexstring ); - $result .= UtfNormal\Utils::codepointToUtf8( $codepoint ); - } else { - $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 ); - } - } else { - $result .= substr( $invalue, $i, 1 ); - } - } - // reverse the transform that we made for reversibility reasons. - return strtr( $result, [ "�" => "&#x" ] ); + return $text; } /** * @since 1.29 */ protected function addEditNotices() { - global $wgOut; - + $out = $this->context->getOutput(); $editNotices = $this->mTitle->getEditNotices( $this->oldid ); if ( count( $editNotices ) ) { - $wgOut->addHTML( implode( "\n", $editNotices ) ); + $out->addHTML( implode( "\n", $editNotices ) ); } else { $msg = $this->context->msg( 'editnotice-notext' ); if ( !$msg->isDisabled() ) { - $wgOut->addHTML( + $out->addHTML( '
' . $msg->parseAsBlock() . '
' @@ -4600,10 +4550,8 @@ class EditPage { * @since 1.29 */ protected function addTalkPageText() { - global $wgOut; - if ( $this->mTitle->isTalkPage() ) { - $wgOut->addWikiMsg( 'talkpagetext' ); + $this->context->getOutput()->addWikiMsg( 'talkpagetext' ); } } @@ -4611,26 +4559,28 @@ class EditPage { * @since 1.29 */ protected function addLongPageWarningHeader() { - global $wgMaxArticleSize, $wgOut, $wgLang; + global $wgMaxArticleSize; if ( $this->contentLength === false ) { $this->contentLength = strlen( $this->textbox1 ); } + $out = $this->context->getOutput(); + $lang = $this->context->getLanguage(); if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", + $out->wrapWikiMsg( "
\n$1\n
", [ 'longpageerror', - $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ), - $wgLang->formatNum( $wgMaxArticleSize ) + $lang->formatNum( round( $this->contentLength / 1024, 3 ) ), + $lang->formatNum( $wgMaxArticleSize ) ] ); } else { if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", + $out->wrapWikiMsg( "
\n$1\n
", [ 'longpage-hint', - $wgLang->formatSize( strlen( $this->textbox1 ) ), + $lang->formatSize( strlen( $this->textbox1 ) ), strlen( $this->textbox1 ) ] ); @@ -4642,8 +4592,7 @@ class EditPage { * @since 1.29 */ protected function addPageProtectionWarningHeaders() { - global $wgOut; - + $out = $this->context->getOutput(); if ( $this->mTitle->isProtected( 'edit' ) && MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ] ) { @@ -4654,7 +4603,7 @@ class EditPage { # Then it must be protected based on static groups (regular) $noticeMsg = 'protectedpagewarning'; } - LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '', + LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '', [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] ); } if ( $this->mTitle->isCascadeProtected() ) { @@ -4670,10 +4619,10 @@ class EditPage { } } $notice .= '
'; - $wgOut->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] ); + $out->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] ); } if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) { - LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '', + LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '', [ 'lim' => 1, 'showIfEmpty' => false, 'msgKey' => [ 'titleprotectedwarning' ], @@ -4688,7 +4637,7 @@ class EditPage { protected function addExplainConflictHeader( OutputPage $out ) { $out->wrapWikiMsg( "
\n$1\n
", - [ 'explainconflict', $this->context->msg( $this->getSaveButtonLabel() )->text() ] + [ 'explainconflict', $this->context->msg( $this->getSubmitButtonLabel() )->text() ] ); }