From c2f29a2efcc6007de624ec88490d21c220f1ab8a Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 26 Jul 2018 15:37:13 +0300 Subject: [PATCH] Update Parser to use ContentLanguage Bug: T200246 Change-Id: Ie54677706ec175189c3ff52342a9d8ac2f5d90d8 --- includes/parser/Parser.php | 56 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 2778ea6965..5be38d63b9 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -51,9 +51,6 @@ use Wikimedia\ScopedCallback; * - Parser::getPreloadText() * removes sections and tags * - * Globals used: - * object: $wgContLang - * * @warning $wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away! * * @par Settings: @@ -967,6 +964,16 @@ class Parser { return $this->magicWordFactory; } + /** + * Get the content language that this Parser is using + * + * @since 1.32 + * @return Language + */ + public function getContentLanguage() { + return $this->magicWordFactory->getContentLanguage(); + } + /** * Replaces all occurrences of HTML-style comments and the given tags * in the text with a random marker and returns the next text. The output @@ -2146,8 +2153,7 @@ class Parser { if ( $useLinkPrefixExtension ) { # Match the end of a line for a word that's not followed by whitespace, # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched - global $wgContLang; - $charset = $wgContLang->linkPrefixCharset(); + $charset = $this->getContentLanguage()->linkPrefixCharset(); $e2 = "/^((?>.*[^$charset]|))(.+)$/sDu"; } @@ -2508,7 +2514,7 @@ class Parser { * @return string */ public function getVariableValue( $index, $frame = false ) { - global $wgContLang, $wgSitename, $wgServer, $wgServerName; + global $wgSitename, $wgServer, $wgServerName; global $wgArticlePath, $wgScriptPath, $wgStylePath; if ( is_null( $this->mTitle ) ) { @@ -2702,10 +2708,12 @@ class Parser { $value = $this->getRevisionSize(); break; case 'namespace': - $value = str_replace( '_', ' ', $wgContLang->getNsText( $this->mTitle->getNamespace() ) ); + $value = str_replace( '_', ' ', + $this->getContentLanguage()->getNsText( $this->mTitle->getNamespace() ) ); break; case 'namespacee': - $value = wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) ); + $value = wfUrlencode( $this->getContentLanguage()-> + getNsText( $this->mTitle->getNamespace() ) ); break; case 'namespacenumber': $value = $this->mTitle->getNamespace(); @@ -2848,15 +2856,13 @@ class Parser { * @return string */ private function getRevisionTimestampSubstring( $start, $len, $mtts, $variable ) { - global $wgContLang; - # Get the timezone-adjusted timestamp to be used for this revision $resNow = substr( $this->getRevisionTimestamp(), $start, $len ); # Possibly set vary-revision if there is not yet an associated revision if ( !$this->getRevisionObject() ) { # Get the timezone-adjusted timestamp $mtts seconds in the future $resThen = substr( - $wgContLang->userAdjust( wfTimestamp( TS_MW, time() + $mtts ), '' ), + $this->getContentLanguage()->userAdjust( wfTimestamp( TS_MW, time() + $mtts ), '' ), $start, $len ); @@ -3403,14 +3409,12 @@ class Parser { * @return array */ public function callParserFunction( $frame, $function, array $args = [] ) { - global $wgContLang; - # Case sensitive functions if ( isset( $this->mFunctionSynonyms[1][$function] ) ) { $function = $this->mFunctionSynonyms[1][$function]; } else { # Case insensitive functions - $function = $wgContLang->lc( $function ); + $function = $this->getContentLanguage()->lc( $function ); if ( isset( $this->mFunctionSynonyms[0][$function] ) ) { $function = $this->mFunctionSynonyms[0][$function]; } else { @@ -3675,8 +3679,8 @@ class Parser { break; } } elseif ( $title->getNamespace() == NS_MEDIAWIKI ) { - global $wgContLang; - $message = wfMessage( $wgContLang->lcfirst( $title->getText() ) )->inContentLanguage(); + $message = wfMessage( MediaWikiServices::getInstance()->getContentLanguage()-> + lcfirst( $title->getText() ) )->inContentLanguage(); if ( !$message->exists() ) { $text = false; break; @@ -4513,19 +4517,15 @@ class Parser { * @return string */ private function pstPass2( $text, $user ) { - global $wgContLang; - - # Note: This is the timestamp saved as hardcoded wikitext to - # the database, we use $wgContLang here in order to give - # everyone the same signature and use the default one rather - # than the one selected in each user's preferences. - # (see also T14815) + # Note: This is the timestamp saved as hardcoded wikitext to the database, we use + # $this->getContentLanguage() here in order to give everyone the same signature and use the + # default one rather than the one selected in each user's preferences. (see also T14815) $ts = $this->mOptions->getTimestamp(); $timestamp = MWTimestamp::getLocalInstance( $ts ); $ts = $timestamp->format( 'YmdHis' ); $tzMsg = $timestamp->getTimezoneMessage()->inContentLanguage()->text(); - $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tzMsg)"; + $d = $this->getContentLanguage()->timeanddate( $ts, false, false ) . " ($tzMsg)"; # Variable replacement # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags @@ -4876,8 +4876,6 @@ class Parser { * @return string|callable The old callback function for this name, if any */ public function setFunctionHook( $id, callable $callback, $flags = 0 ) { - global $wgContLang; - $oldVal = isset( $this->mFunctionHooks[$id] ) ? $this->mFunctionHooks[$id][0] : null; $this->mFunctionHooks[$id] = [ $callback, $flags ]; @@ -4893,7 +4891,7 @@ class Parser { foreach ( $synonyms as $syn ) { # Case if ( !$sensitive ) { - $syn = $wgContLang->lc( $syn ); + $syn = $this->getContentLanguage()->lc( $syn ); } # Add leading hash if ( !( $flags & self::SFH_NO_HASH ) ) { @@ -5729,8 +5727,6 @@ class Parser { */ public function getRevisionTimestamp() { if ( is_null( $this->mRevisionTimestamp ) ) { - global $wgContLang; - $revObject = $this->getRevisionObject(); $timestamp = $revObject ? $revObject->getTimestamp() : wfTimestampNow(); @@ -5739,7 +5735,7 @@ class Parser { # Since this value will be saved into the parser cache, served # to other users, and potentially even used inside links and such, # it needs to be consistent for all visitors. - $this->mRevisionTimestamp = $wgContLang->userAdjust( $timestamp, '' ); + $this->mRevisionTimestamp = $this->getContentLanguage()->userAdjust( $timestamp, '' ); } return $this->mRevisionTimestamp; -- 2.20.1