X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FEditPage.php;h=ff224c55983dfc4fcb9f1f44709f2b324781a8df;hb=99f1d55818c1cd2ea05b659e327463f31a23e7a8;hp=8bccb0dec68648741f0001e77560bfafc6ca0e5c;hpb=a71461d6f11de0a7462ac5645ed38da077e9b5a6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 8bccb0dec6..ff224c5598 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\EditPage\TextboxBuilder; +use MediaWiki\EditPage\TextConflictHelper; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; use Wikimedia\ScopedCallback; @@ -40,6 +42,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 +184,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 +215,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 +238,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 +443,23 @@ class EditPage { */ private $isOldRev = false; + /** + * @var string|null What the user submitted in the 'wpUnicodeCheck' field + */ + private $unicodeCheck; + + /** + * Factory function to create an edit conflict helper + * + * @var callable + */ + private $editConflictHelperFactory; + + /** + * @var TextConflictHelper|null + */ + private $editConflictHelper; + /** * @param Article $article */ @@ -426,6 +473,7 @@ class EditPage { $handler = ContentHandler::getForModelID( $this->contentModel ); $this->contentFormat = $handler->getDefaultFormat(); + $this->editConflictHelperFactory = [ $this, 'newTextConflictHelper' ]; } /** @@ -469,6 +517,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 { @@ -482,6 +534,7 @@ class EditPage { * @deprecated since 1.30 */ public function isOouiEnabled() { + wfDeprecated( __METHOD__, '1.30' ); return true; } @@ -527,7 +580,6 @@ class EditPage { * the newly-edited page. */ public function edit() { - global $wgRequest, $wgUser; // Allow extensions to modify/prevent this form or submission if ( !Hooks::run( 'AlternateEdit', [ $this ] ) ) { return; @@ -535,13 +587,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() ) { + 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 ) { @@ -570,9 +623,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 ); @@ -609,10 +661,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 @@ -657,15 +710,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 ) ); @@ -702,10 +754,8 @@ class EditPage { * @throws PermissionsError */ protected function displayPermissionsError( array $permErrors ) { - global $wgRequest; - $out = $this->context->getOutput(); - if ( $wgRequest->getBool( 'redlink' ) ) { + 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. @@ -787,24 +837,32 @@ class EditPage { * @return bool */ protected function previewOnOpen() { - global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces; - if ( $wgRequest->getVal( 'preview' ) == 'yes' ) { + $config = $this->context->getConfig(); + $previewOnOpenNamespaces = $config->get( 'PreviewOnOpenNamespaces' ); + $request = $this->context->getRequest(); + if ( $config->get( 'RawHtml' ) ) { + // If raw HTML is enabled, disable preview on open + // since it has to be posted with a token for + // security reasons + return false; + } + 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; } elseif ( !$this->mTitle->exists() - && isset( $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()] ) - && $wgPreviewOnOpenNamespaces[$this->mTitle->getNamespace()] + && isset( $previewOnOpenNamespaces[$this->mTitle->getNamespace()] ) + && $previewOnOpenNamespaces[$this->mTitle->getNamespace()] ) { // Categories are special return true; @@ -851,8 +909,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' ) ); @@ -866,7 +922,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 @@ -877,8 +933,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 @@ -890,7 +947,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' ); @@ -962,14 +1019,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' ); @@ -1085,7 +1143,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(); @@ -1095,19 +1152,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 ) { @@ -1124,10 +1182,12 @@ class EditPage { * @since 1.21 */ protected function getContentObject( $def_content = null ) { - global $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' ) { @@ -1139,10 +1199,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 ); } @@ -1150,15 +1210,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 ); @@ -1178,8 +1238,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 @@ -1240,7 +1300,7 @@ class EditPage { } if ( $content === false ) { - $content = $this->getOriginalContent( $wgUser ); + $content = $this->getOriginalContent( $user ); } } } @@ -1366,8 +1426,6 @@ class EditPage { * @since 1.21 */ protected function getPreloadedContent( $preload, $params = [] ) { - global $wgUser; - if ( !empty( $this->mPreloadContent ) ) { return $this->mPreloadContent; } @@ -1378,9 +1436,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(); } @@ -1389,14 +1448,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 ) { @@ -1430,10 +1489,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; } @@ -1473,10 +1532,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 ] ); @@ -1488,14 +1545,11 @@ 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; } - $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); - $stats->increment( 'edit.failures.conflict.resolved' ); + $this->getEditConflictHelper()->incrementResolvedStats(); } /** @@ -1508,8 +1562,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; - /** * @todo FIXME: once the interface for internalAttemptSave() is made * nicer, this should use the message in $status @@ -1550,6 +1602,7 @@ class EditPage { case self::AS_CANNOT_USE_CUSTOM_MODEL: case self::AS_PARSE_ERROR: + case self::AS_UNICODE_NOT_SUPPORTED: $out->addWikiText( '
' . "\n" . $status->getWikiText() . '
' ); return true; @@ -1599,7 +1652,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: @@ -1653,7 +1706,7 @@ class EditPage { // Run new style post-section-merge edit filter if ( !Hooks::run( 'EditFilterMergedContent', - [ $this->mArticle->getContext(), $content, $status, $this->summary, + [ $this->context, $content, $status, $this->summary, $user, $this->minoredit ] ) ) { # Error messages etc. could be handled within the hook... @@ -1738,10 +1791,8 @@ class EditPage { * time. */ public function internalAttemptSave( &$result, $bot = false ) { - global $wgUser, $wgRequest, $wgMaxArticleSize; - global $wgContentHandlerUseDB; - $status = Status::newGood(); + $user = $this->context->getUser(); if ( !Hooks::run( 'EditPage::attemptSave', [ $this ] ) ) { wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" ); @@ -1750,11 +1801,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 "' . @@ -1783,9 +1841,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; @@ -1810,7 +1868,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\"" ); @@ -1833,10 +1891,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 ); @@ -1844,15 +1902,17 @@ class EditPage { } $this->contentLength = strlen( $this->textbox1 ); - if ( $this->contentLength > $wgMaxArticleSize * 1024 ) { + $config = $this->context->getConfig(); + $maxArticleSize = $config->get( 'MaxArticleSize' ); + if ( $this->contentLength > $maxArticleSize * 1024 ) { // Error will be displayed by showEditForm() $this->tooBig = true; $status->setResult( false, self::AS_CONTENT_TOO_BIG ); 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,19 +1924,19 @@ class EditPage { $changingContentModel = false; if ( $this->contentModel !== $this->mTitle->getContentModel() ) { - if ( !$wgContentHandlerUseDB ) { + if ( !$config->get( 'ContentHandlerUseDB' ) ) { $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; @@ -1888,7 +1948,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; @@ -1900,8 +1960,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; @@ -1922,7 +1982,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" ); @@ -1946,7 +2006,7 @@ class EditPage { return $status; } - if ( !$this->runPostMergeFilters( $textbox_content, $status, $wgUser ) ) { + if ( !$this->runPostMergeFilters( $textbox_content, $status, $user ) ) { return $status; } @@ -1982,7 +2042,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. @@ -1998,7 +2058,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. @@ -2068,7 +2128,7 @@ class EditPage { return $status; } - if ( !$this->runPostMergeFilters( $content, $status, $wgUser ) ) { + if ( !$this->runPostMergeFilters( $content, $status, $user ) ) { return $status; } @@ -2089,7 +2149,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 ) { @@ -2143,7 +2203,7 @@ class EditPage { // Check for length errors again now that the section is merged in $this->contentLength = strlen( $this->toEditText( $content ) ); - if ( $this->contentLength > $wgMaxArticleSize * 1024 ) { + if ( $this->contentLength > $maxArticleSize * 1024 ) { $this->tooBig = true; $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED ); return $status; @@ -2159,7 +2219,7 @@ class EditPage { $this->summary, $flags, false, - $wgUser, + $user, $content->getDefaultFormat(), $this->changeTags, $this->undidRev @@ -2183,7 +2243,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(); @@ -2192,7 +2252,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 @@ -2226,13 +2286,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... @@ -2346,14 +2404,14 @@ class EditPage { } public function setHeaders() { - global $wgUser, $wgAjaxEditStash; - $out = $this->context->getOutput(); $out->addModules( 'mediawiki.action.edit' ); $out->addModuleStyles( 'mediawiki.action.edit.styles' ); + $out->addModuleStyles( 'mediawiki.editfont.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 @@ -2361,11 +2419,11 @@ class EditPage { $out->addModules( 'mediawiki.toolbar' ); } - if ( $wgUser->getOption( 'uselivepreview' ) ) { + if ( $user->getOption( 'uselivepreview' ) ) { $out->addModules( 'mediawiki.action.edit.preview' ); } - if ( $wgUser->getOption( 'useeditwarning' ) ) { + if ( $user->getOption( 'useeditwarning' ) ) { $out->addModules( 'mediawiki.action.edit.editWarning' ); } @@ -2398,7 +2456,7 @@ class EditPage { # Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys $out->addJsConfigVars( [ 'wgEditMessage' => $msg, - 'wgAjaxEditStash' => $wgAjaxEditStash, + 'wgAjaxEditStash' => $this->context->getConfig()->get( 'AjaxEditStash' ), ] ); } @@ -2406,7 +2464,6 @@ class EditPage { * Show all applicable editing introductions */ protected function showIntro() { - global $wgUser; if ( $this->suppressIntro ) { return; } @@ -2481,7 +2538,7 @@ class EditPage { $helpLink = wfExpandUrl( Skin::makeInternalOrExternalUrl( $this->context->msg( 'helppage' )->inContentLanguage()->text() ) ); - if ( $wgUser->isLoggedIn() ) { + if ( $this->context->getUser()->isLoggedIn() ) { $out->wrapWikiMsg( // Suppress the external link icon, consider the help url an internal one "
\n$1\n
", @@ -2607,8 +2664,6 @@ class EditPage { * use the EditPage::showEditForm:fields hook instead. */ public function showEditForm( $formCallback = null ) { - global $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 @@ -2643,7 +2698,8 @@ class EditPage { $out->addHTML( $this->editFormPageTop ); - if ( $wgUser->getOption( 'previewontop' ) ) { + $user = $this->context->getUser(); + if ( $user->getOption( 'previewontop' ) ) { $this->displayPreviewArea( $previewOutput, true ); } @@ -2680,6 +2736,9 @@ class EditPage { 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 $out->addHTML( Xml::openElement( 'div', [ 'id' => 'antispam-container', 'style' => 'display: none;' ] ) @@ -2774,8 +2833,22 @@ class EditPage { } $out->addHTML( $this->editFormTextBeforeContent ); + if ( $this->isConflict ) { + // In an edit conflict, we turn textbox2 into the user's text, + // and textbox1 into the stored version + $this->textbox2 = $this->textbox1; + + $content = $this->getCurrentContent(); + $this->textbox1 = $this->toEditText( $content ); + + $editConflictHelper = $this->getEditConflictHelper(); + $editConflictHelper->setTextboxes( $this->textbox2, $this->textbox1 ); + $editConflictHelper->setContentModel( $this->contentModel ); + $editConflictHelper->setContentFormat( $this->contentFormat ); + $out->addHTML( $editConflictHelper->getEditFormHtmlBeforeContent() ); + } - if ( !$this->isCssJsSubpage && $showToolbar && $wgUser->getOption( 'showtoolbar' ) ) { + if ( !$this->mTitle->isCssJsSubpage() && $showToolbar && $user->getOption( 'showtoolbar' ) ) { $out->addHTML( self::getEditToolbar( $this->mTitle ) ); } @@ -2788,12 +2861,8 @@ class EditPage { // and fallback to the raw wpTextbox1 since editconflicts can't be // resolved between page source edits and custom ui edits using the // custom edit ui. - $this->textbox2 = $this->textbox1; - - $content = $this->getCurrentContent(); - $this->textbox1 = $this->toEditText( $content ); - $this->showTextbox1(); + $out->addHTML( $editConflictHelper->getEditFormHtmlAfterContent() ); } else { $this->showContentForm(); } @@ -2852,7 +2921,7 @@ class EditPage { $out->addHTML( Html::hidden( 'wpUltimateParam', true ) ); $out->addHTML( $this->editFormTextBottom . "\n\n" ); - if ( !$wgUser->getOption( 'previewontop' ) ) { + if ( !$user->getOption( 'previewontop' ) ) { $this->displayPreviewArea( $previewOutput, false ); } } @@ -2899,10 +2968,8 @@ class EditPage { } protected function showHeader() { - global $wgUser; - global $wgAllowUserCss, $wgAllowUserJs; - $out = $this->context->getOutput(); + $user = $this->context->getUser(); if ( $this->isConflict ) { $this->addExplainConflictHeader( $out ); $this->editRevId = $this->page->getLatest(); @@ -2916,7 +2983,7 @@ class EditPage { } } - $buttonLabel = $this->context->msg( $this->getSaveButtonLabel() )->text(); + $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text(); if ( $this->missingComment ) { $out->wrapWikiMsg( "
\n$1\n
", 'missingcommenttext' ); @@ -2954,16 +3021,12 @@ class EditPage { $out->addWikiText( $this->hookError ); } - if ( !$this->checkUnicodeCompliantBrowser() ) { - $out->addWikiMsg( 'nonunicodebrowser' ); - } - if ( $this->section != 'new' ) { $revision = $this->mArticle->getRevisionFetched(); if ( $revision ) { // Let sysop know that this will make private content public if saved - if ( !$revision->userCan( Revision::DELETED_TEXT, $wgUser ) ) { + if ( !$revision->userCan( Revision::DELETED_TEXT, $user ) ) { $out->wrapWikiMsg( "\n", 'rev-deleted-text-permission' @@ -2994,7 +3057,7 @@ class EditPage { "
\n$1\n
", [ 'readonlywarning', wfReadOnlyReason() ] ); - } elseif ( $wgUser->isAnon() ) { + } elseif ( $user->isAnon() ) { if ( $this->formtype != 'preview' ) { $out->wrapWikiMsg( "
\n$1\n
", @@ -3015,27 +3078,29 @@ class EditPage { ); } } else { - if ( $this->isCssJsSubpage ) { + if ( $this->mTitle->isCssJsSubpage() ) { # Check the skin exists - if ( $this->isWrongCaseCssJsPage ) { + if ( $this->isWrongCaseCssJsPage() ) { $out->wrapWikiMsg( "
\n$1\n
", [ 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ] ); } - if ( $this->getTitle()->isSubpageOf( $wgUser->getUserPage() ) ) { + if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) { + $isCssSubpage = $this->mTitle->isCssSubpage(); $out->wrapWikiMsg( '
$1
', - $this->isCssSubpage ? 'usercssispublic' : 'userjsispublic' + $isCssSubpage ? 'usercssispublic' : 'userjsispublic' ); if ( $this->formtype !== 'preview' ) { - if ( $this->isCssSubpage && $wgAllowUserCss ) { + $config = $this->context->getConfig(); + if ( $isCssSubpage && $config->get( 'AllowUserCss' ) ) { $out->wrapWikiMsg( "
\n$1\n
", [ 'usercssyoucanpreview' ] ); } - if ( $this->isJsSubpage && $wgAllowUserJs ) { + if ( $this->mTitle->isJsSubpage() && $config->get( 'AllowUserJs' ) ) { $out->wrapWikiMsg( "
\n$1\n
", [ 'userjsyoucanpreview' ] @@ -3126,7 +3191,7 @@ class EditPage { */ function getSummaryInputOOUI( $summary = "", $labelText = null, $inputAttrs = null ) { wfDeprecated( __METHOD__, '1.30' ); - $this->getSummaryInputWidget( $summary, $labelText, $inputAttrs ); + return $this->getSummaryInputWidget( $summary, $labelText, $inputAttrs ); } /** @@ -3223,19 +3288,14 @@ class EditPage { protected function showFormBeforeText() { $out = $this->context->getOutput(); - $out->addHTML( Html::hidden( 'wpSection', htmlspecialchars( $this->section ) ) ); + $out->addHTML( Html::hidden( 'wpSection', $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' ] ) ); - - if ( !$this->checkUnicodeCompliantBrowser() ) { - $out->addHTML( Html::hidden( 'safemode', '1' ) ); - } } protected function showFormAfterText() { - global $wgUser; /** * To make it harder for someone to slip a user a page * which submits an edit form to the wiki without their @@ -3249,7 +3309,9 @@ class EditPage { * broken text-mangling proxies. */ $this->context->getOutput()->addHTML( - "\n" . Html::hidden( "wpEditToken", $wgUser->getEditToken() ) . "\n" + "\n" . + Html::hidden( "wpEditToken", $this->context->getUser()->getEditToken() ) . + "\n" ); } @@ -3324,14 +3386,17 @@ class EditPage { } protected function showTextbox( $text, $name, $customAttribs = [] ) { - global $wgUser; - - $wikitext = $this->safeUnicodeOutput( $text ); - $wikitext = $this->addNewLineAtEnd( $wikitext ); - - $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $wgUser ); + $builder = new TextboxBuilder(); + $attribs = $builder->buildTextboxAttribs( + $name, + $customAttribs, + $this->context->getUser(), + $this->mTitle + ); - $this->context->getOutput()->addHTML( Html::textarea( $name, $wikitext, $attribs ) ); + $this->context->getOutput()->addHTML( + Html::textarea( $name, $builder->addNewLineAtEnd( $text ), $attribs ) + ); } protected function displayPreviewArea( $previewOutput, $isOnTop = false ) { @@ -3404,7 +3469,7 @@ class EditPage { * save and then make a comparison. */ public function showDiff() { - global $wgUser, $wgContLang; + global $wgContLang; $oldtitlemsg = 'currentrev'; # if message does not exist, show diff against the preloaded default @@ -3434,8 +3499,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() ) ) { @@ -3450,7 +3516,7 @@ class EditPage { $newContent = $oldContent->getContentHandler()->makeEmptyContent(); } - $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->mArticle->getContext() ); + $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->context ); $de->setContent( $oldContent, $newContent ); $difftext = $de->getDiff( $oldtitle, $newtitle ); @@ -3652,34 +3718,12 @@ class EditPage { if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$out ] ) ) { $this->incrementConflictStats(); - $out->wrapWikiMsg( '

$1

', "yourdiff" ); - - $content1 = $this->toEditContent( $this->textbox1 ); - $content2 = $this->toEditContent( $this->textbox2 ); - - $handler = ContentHandler::getForModelID( $this->contentModel ); - $de = $handler->createDifferenceEngine( $this->mArticle->getContext() ); - $de->setContent( $content2, $content1 ); - $de->showDiff( - $this->context->msg( 'yourtext' )->parse(), - $this->context->msg( 'storedversion' )->text() - ); - - $out->wrapWikiMsg( '

$1

', "yourtext" ); - $this->showTextbox2(); + $this->getEditConflictHelper()->showEditFormTextAfterFooters(); } } protected function incrementConflictStats() { - $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); - $stats->increment( 'edit.failures.conflict' ); - // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics - if ( - $this->mTitle->getNamespace() >= NS_MAIN && - $this->mTitle->getNamespace() <= NS_CATEGORY_TALK - ) { - $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() ); - } + $this->getEditConflictHelper()->incrementConflictStats(); } /** @@ -3795,12 +3839,10 @@ class EditPage { * @return string */ public function getPreviewText() { - global $wgRawHtml, $wgLang; - global $wgAllowUserCss, $wgAllowUserJs; - $out = $this->context->getOutput(); + $config = $this->context->getConfig(); - if ( $wgRawHtml && !$this->mTokenOk ) { + if ( $config->get( 'RawHtml' ) && !$this->mTokenOk ) { // Could be an offsite preview attempt. This is very unsafe if // HTML is enabled, as it could be an attack. $parsedNote = ''; @@ -3831,7 +3873,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 ) { @@ -3862,12 +3905,12 @@ class EditPage { if ( $content->getModel() == CONTENT_MODEL_CSS ) { $format = 'css'; - if ( $level === 'user' && !$wgAllowUserCss ) { + if ( $level === 'user' && !$config->get( 'AllowUserCss' ) ) { $format = false; } } elseif ( $content->getModel() == CONTENT_MODEL_JAVASCRIPT ) { $format = 'js'; - if ( $level === 'user' && !$wgAllowUserJs ) { + if ( $level === 'user' && !$config->get( 'AllowUserJs' ) ) { $format = false; } } else { @@ -3942,7 +3985,7 @@ class EditPage { * @return ParserOptions */ protected function getPreviewParserOptions() { - $parserOptions = $this->page->makeParserOptions( $this->mArticle->getContext() ); + $parserOptions = $this->page->makeParserOptions( $this->context ); $parserOptions->setIsPreview( true ); $parserOptions->setIsSectionPreview( !is_null( $this->section ) && $this->section !== '' ); $parserOptions->enableLimitReport(); @@ -3959,11 +4002,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 @@ -4150,11 +4193,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', @@ -4166,7 +4209,7 @@ class EditPage { ]; } - if ( $wgUser->isLoggedIn() ) { + if ( $user->isLoggedIn() ) { $checkboxes['wpWatchthis'] = [ 'id' => 'wpWatchthis', 'label-message' => 'watchthis', @@ -4194,8 +4237,7 @@ class EditPage { * @return array */ public function getCheckboxes( &$tabindex, $checked ) { - global $wgUseMediaWikiUIEverywhere; - + wfDeprecated( __METHOD__, '1.30' ); $checkboxes = []; $checkboxesDef = $this->getCheckboxesDefinition( $checked ); @@ -4230,10 +4272,6 @@ class EditPage { ' ' . Xml::tags( 'label', $labelAttribs, $label ); - if ( $wgUseMediaWikiUIEverywhere ) { - $checkboxHtml = Html::rawElement( 'div', [ 'class' => 'mw-ui-checkbox' ], $checkboxHtml ); - } - $checkboxes[ $legacyName ] = $checkboxHtml; } @@ -4255,6 +4293,7 @@ class EditPage { * @return array Associative array of string keys to OOUI\FieldLayout instances */ public function getCheckboxesOOUI( &$tabindex, $checked ) { + wfDeprecated( __METHOD__, '1.30' ); return $this->getCheckboxesWidget( $tabindex, $checked ); } @@ -4332,11 +4371,12 @@ class EditPage { /** * Get the message key of the label for the button to save the page * + * @since 1.30 * @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(); @@ -4361,7 +4401,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', @@ -4449,11 +4489,10 @@ class EditPage { * @param string|array|bool $match Text (or array of texts) which triggered one or more filters */ public function spamPageWithContent( $match = false ) { - global $wgLang; $this->textbox2 = $this->textbox1; if ( is_array( $match ) ) { - $match = $wgLang->listToText( $match ); + $match = $this->context->getLanguage()->listToText( $match ); } $out = $this->context->getOutput(); $out->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) ); @@ -4474,138 +4513,31 @@ class EditPage { $out->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; - } - /** * 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; } /** @@ -4641,19 +4573,19 @@ class EditPage { * @since 1.29 */ protected function addLongPageWarningHeader() { - global $wgMaxArticleSize, $wgLang; - if ( $this->contentLength === false ) { $this->contentLength = strlen( $this->textbox1 ); } $out = $this->context->getOutput(); - if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) { + $lang = $this->context->getLanguage(); + $maxArticleSize = $this->context->getConfig()->get( 'MaxArticleSize' ); + if ( $this->tooBig || $this->contentLength > $maxArticleSize * 1024 ) { $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( $maxArticleSize ) ] ); } else { @@ -4661,7 +4593,7 @@ class EditPage { $out->wrapWikiMsg( "
\n$1\n
", [ 'longpage-hint', - $wgLang->formatSize( strlen( $this->textbox1 ) ), + $lang->formatSize( strlen( $this->textbox1 ) ), strlen( $this->textbox1 ) ] ); @@ -4716,9 +4648,8 @@ class EditPage { * @since 1.29 */ protected function addExplainConflictHeader( OutputPage $out ) { - $out->wrapWikiMsg( - "
\n$1\n
", - [ 'explainconflict', $this->context->msg( $this->getSaveButtonLabel() )->text() ] + $out->addHTML( + $this->getEditConflictHelper()->getExplainHeader() ); } @@ -4730,38 +4661,9 @@ class EditPage { * @since 1.29 */ protected function buildTextboxAttribs( $name, array $customAttribs, User $user ) { - $attribs = $customAttribs + [ - 'accesskey' => ',', - 'id' => $name, - 'cols' => 80, - 'rows' => 25, - // Avoid PHP notices when appending preferences - // (appending allows customAttribs['style'] to still work). - 'style' => '' - ]; - - // The following classes can be used here: - // * mw-editfont-default - // * mw-editfont-monospace - // * mw-editfont-sans-serif - // * mw-editfont-serif - $class = 'mw-editfont-' . $user->getOption( 'editfont' ); - - if ( isset( $attribs['class'] ) ) { - if ( is_string( $attribs['class'] ) ) { - $attribs['class'] .= ' ' . $class; - } elseif ( is_array( $attribs['class'] ) ) { - $attribs['class'][] = $class; - } - } else { - $attribs['class'] = $class; - } - - $pageLang = $this->mTitle->getPageLanguage(); - $attribs['lang'] = $pageLang->getHtmlCode(); - $attribs['dir'] = $pageLang->getDir(); - - return $attribs; + return ( new TextboxBuilder() )->buildTextboxAttribs( + $name, $customAttribs, $user, $this->mTitle + ); } /** @@ -4770,15 +4672,7 @@ class EditPage { * @since 1.29 */ protected function addNewLineAtEnd( $wikitext ) { - if ( strval( $wikitext ) !== '' ) { - // Ensure there's a newline at the end, otherwise adding lines - // is awkward. - // But don't add a newline if the text is empty, or Firefox in XHTML - // mode will show an extra newline. A bit annoying. - $wikitext .= "\n"; - return $wikitext; - } - return $wikitext; + return ( new TextboxBuilder() )->addNewLineAtEnd( $wikitext ); } /** @@ -4803,4 +4697,42 @@ class EditPage { // Meanwhile, real browsers get real anchors return $wgParser->guessSectionNameFromWikiText( $text ); } + + /** + * Set a factory function to create an EditConflictHelper + * + * @param callable $factory Factory function + * @since 1.31 + */ + public function setEditConflictHelperFactory( callable $factory ) { + $this->editConflictHelperFactory = $factory; + $this->editConflictHelper = null; + } + + /** + * @return TextConflictHelper + */ + private function getEditConflictHelper() { + if ( !$this->editConflictHelper ) { + $this->editConflictHelper = call_user_func( + $this->editConflictHelperFactory, + $this->getSubmitButtonLabel() + ); + } + + return $this->editConflictHelper; + } + + /** + * @param string $submitButtonLabel + * @return TextConflictHelper + */ + private function newTextConflictHelper( $submitButtonLabel ) { + return new TextConflictHelper( + $this->getTitle(), + $this->getContext()->getOutput(), + MediaWikiServices::getInstance()->getStatsdDataFactory(), + $submitButtonLabel + ); + } }