From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- includes/parser/ParserOptions.php | 327 +++++++++++++++++++++++++++++--------- 1 file changed, 256 insertions(+), 71 deletions(-) (limited to 'includes/parser/ParserOptions.php') diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 07752768..57d3a7eb 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -1,58 +1,188 @@ mUseDynamicDates; } @@ -96,7 +226,7 @@ class ParserOptions { * @deprecated since 1.18 Use Linker::* instead */ function getSkin( $title = null ) { - wfDeprecated( __METHOD__ ); + wfDeprecated( __METHOD__, '1.18' ); return new DummyLinker; } @@ -119,12 +249,23 @@ class ParserOptions { * You shouldn't use this. Really. $parser->getFunctionLang() is all you need. * Using this fragments the cache and is discouraged. Yes, {{int: }} uses this, * producing inconsistent tables (Bug 14404). + * + * @return Language object + * @since 1.19 + */ + function getUserLangObj() { + $this->optionUsed( 'userlang' ); + return $this->mUserLang; + } + + /** + * Same as getUserLangObj() but returns a string instead. + * * @return String Language code * @since 1.17 */ function getUserLang() { - $this->optionUsed( 'userlang' ); - return $this->mUserLang; + return $this->getUserLangObj()->getCode(); } function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); } @@ -137,7 +278,9 @@ class ParserOptions { function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); } function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); } function setTidy( $x ) { return wfSetVar( $this->mTidy, $x ); } - function setSkin( $x ) { $this->mSkin = $x; } + + /** @deprecated in 1.19; will be removed in 1.20 */ + function setSkin( $x ) { wfDeprecated( __METHOD__, '1.19' ); } function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x ); } function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage, $x, true ); } function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); } @@ -151,8 +294,8 @@ class ParserOptions { function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); } function setMath( $x ) { return wfSetVar( $this->mMath, $x ); } function setUserLang( $x ) { - if ( $x instanceof Language ) { - $x = $x->getCode(); + if ( is_string( $x ) ) { + $x = Language::factory( $x ); } return wfSetVar( $this->mUserLang, $x ); } @@ -171,41 +314,75 @@ class ParserOptions { $this->mExtraKey .= '!' . $key; } - function __construct( $user = null ) { - $this->initialiseFromUser( $user ); + /** + * Constructor + * @param $user User object + * @param $lang Language object + */ + function __construct( $user = null, $lang = null ) { + if ( $user === null ) { + global $wgUser; + if ( $wgUser === null ) { + $user = new User; + } else { + $user = $wgUser; + } + } + if ( $lang === null ) { + global $wgLang; + if ( !StubObject::isRealObject( $wgLang ) ) { + $wgLang->_unstub(); + } + $lang = $wgLang; + } + $this->initialiseFromUser( $user, $lang ); } /** - * Get parser options + * Get a ParserOptions object from a given user. + * Language will be taken from $wgLang. * * @param $user User object * @return ParserOptions object */ - static function newFromUser( $user ) { + public static function newFromUser( $user ) { return new ParserOptions( $user ); } - /** Get user options */ - function initialiseFromUser( $userInput ) { - global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; - global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize; - global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures; - global $wgExternalLinkTarget, $wgLang; + /** + * Get a ParserOptions object from a given user and language + * + * @param $user User object + * @param $lang Language object + * @return ParserOptions object + */ + public static function newFromUserAndLang( User $user, Language $lang ) { + return new ParserOptions( $user, $lang ); + } - wfProfileIn( __METHOD__ ); + /** + * Get a ParserOptions object from a IContextSource object + * + * @param $context IContextSource object + * @return ParserOptions object + */ + public static function newFromContext( IContextSource $context ) { + return new ParserOptions( $context->getUser(), $context->getLanguage() ); + } - if ( !$userInput ) { - global $wgUser; - if ( isset( $wgUser ) ) { - $user = $wgUser; - } else { - $user = new User; - } - } else { - $user =& $userInput; - } + /** + * Get user options + * + * @param $user User object + * @param $lang Language object + */ + private function initialiseFromUser( $user, $lang ) { + global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages, + $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, + $wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, + $wgCleanSignatures, $wgExternalLinkTarget; - $this->mUser = $user; + wfProfileIn( __METHOD__ ); $this->mUseDynamicDates = $wgUseDynamicDates; $this->mInterwikiMagic = $wgInterwikiMagic; @@ -220,11 +397,12 @@ class ParserOptions { $this->mCleanSignatures = $wgCleanSignatures; $this->mExternalLinkTarget = $wgExternalLinkTarget; + $this->mUser = $user; $this->mNumberHeadings = $user->getOption( 'numberheadings' ); $this->mMath = $user->getOption( 'math' ); $this->mThumbSize = $user->getOption( 'thumbsize' ); $this->mStubThreshold = $user->getStubThreshold(); - $this->mUserLang = $wgLang->getCode(); + $this->mUserLang = $lang; wfProfileOut( __METHOD__ ); } @@ -274,10 +452,12 @@ class ParserOptions { * settings. * * @since 1.17 - * @return \string Page rendering hash + * @param $forOptions Array + * @param $title Title: used to get the content language of the page (since r97636) + * @return string Page rendering hash */ - public function optionsHash( $forOptions ) { - global $wgContLang, $wgRenderHashAppend; + public function optionsHash( $forOptions, $title = null ) { + global $wgRenderHashAppend; $confstr = ''; @@ -308,7 +488,7 @@ class ParserOptions { } if ( in_array( 'userlang', $forOptions ) ) { - $confstr .= '!' . $this->mUserLang; + $confstr .= '!' . $this->mUserLang->getCode(); } else { $confstr .= '!*'; } @@ -321,7 +501,12 @@ class ParserOptions { // add in language specific options, if any // @todo FIXME: This is just a way of retrieving the url/user preferred variant - $confstr .= $wgContLang->getExtraHashOptions(); + if( !is_null( $title ) ) { + $confstr .= $title->getPageLanguage()->getExtraHashOptions(); + } else { + global $wgContLang; + $confstr .= $wgContLang->getExtraHashOptions(); + } $confstr .= $wgRenderHashAppend; -- cgit v1.2.2