From: Happy-melon Date: Sun, 3 Apr 2011 20:40:27 +0000 (+0000) Subject: Follow-up to r85240: X-Git-Tag: 1.31.0-rc.0~31048 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=4a0500a514231090917cb13d0cc6f96aac76c100;p=lhc%2Fweb%2Fwiklou.git Follow-up to r85240: * Don't stub RequestContext. The chances of us getting away without needing to access *any* of the six major globals is nil, and in the meantime it's screwing up strong function typing and throwing catchable fatals everywhere. * Stop stubbing $wgOut. The only path where we can avoid unstubbing it is if we immediately die due to maxlag overflow, and that's a) a pretty uncommon code path, and b) a DB issue which won't be affected by a tiny bit of extra apache load. That allows us to do strong typing on function parameters with it, which is a Good Thing (TM). Also make OutputPage::getContext() private; I'm not convinced that a context belongs here (it's *part of* the context, not a consumer of it), let's work through it a it more before we advertise its existence. --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 004e7aa8b1..1ce8c495d0 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -233,8 +233,8 @@ $wgAutoloadLocalClasses = array( 'SquidPurgeClientPool' => 'includes/SquidPurgeClient.php', 'Status' => 'includes/Status.php', 'StubContLang' => 'includes/StubObject.php', + 'StubUserLang' => 'includes/StubObject.php', 'StubObject' => 'includes/StubObject.php', - 'StubRequestContext' => 'includes/StubObject.php', 'StringUtils' => 'includes/StringUtils.php', 'TablePager' => 'includes/Pager.php', 'TitleDependency' => 'includes/CacheDependency.php', diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 9b006de5c8..4c7b2e9440 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -765,7 +765,7 @@ class OutputPage { * * @return RequestContext */ - public function getContext() { + private function getContext() { if ( !isset($this->mContext) ) { wfDebug( __METHOD__ . " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" ); $this->mContext = RequestContext::getMain(); diff --git a/includes/Setup.php b/includes/Setup.php index 076541e1c2..37d9a4732e 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -365,17 +365,17 @@ $wgContLang = new StubContLang; // Now that variant lists may be available... $wgRequest->interpolateTitle(); -$wgUser = new StubRequestContext( 'wgUser', 'getUser' ); +$wgUser = $wgCommandLineMode ? new User : User::newFromSession(); /** * @var Language */ -$wgLang = new StubRequestContext( 'wgLang', 'getLang' ); +$wgLang = new StubUserLang; /** * @var OutputPage */ -$wgOut = new StubRequestContext( 'wgOut', 'getOutput' ); +$wgOut = new OutputPage; /** * @var Parser diff --git a/includes/StubObject.php b/includes/StubObject.php index f2a8b3327e..d1055e10f5 100644 --- a/includes/StubObject.php +++ b/includes/StubObject.php @@ -131,44 +131,39 @@ class StubContLang extends StubObject { } /** - * Stub object for the $wg globals replaced by RequestContext + * Stub object for the user language. It depends of the user preferences and + * "uselang" parameter that can be passed to index.php. This object have to be + * in $wgLang global. */ -class StubRequestContext extends StubObject { - - private $method = null; - - function __construct( $global, $method ) { - parent::__construct( $global, 'RequestContext' ); - $this->method = $method; +class StubUserLang extends StubObject { + + function __construct() { + parent::__construct( 'wgLang' ); } - + function __call( $name, $args ) { return $this->_call( $name, $args ); } - - function __get( $name ) { - // __get doesn't seam to play nice with _unstub - return RequestContext::getMain()->{$this->method}()->{$name}; - } - function __set( $name, $val ) { - // __set doesn't seam to play nice with _unstub - RequestContext::getMain()->{$this->method}()->{$name} = $val; - } - - function __isset( $name ) { - // __isset doesn't seam to play nice with _unstub - return isset( RequestContext::getMain()->{$this->method}()->{$name} ); - } + function _newObject() { + global $wgLanguageCode, $wgRequest, $wgUser, $wgContLang; + $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) ); + // BCP 47 - letter case MUST NOT carry meaning + $code = strtolower( $code ); + + # Validate $code + if( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) { + wfDebug( "Invalid user language code\n" ); + $code = $wgLanguageCode; + } - function __unset( $name ) { - // __unset doesn't seam to play nice with _unstub - unset( RequestContext::getMain()->{$this->method}()->{$name} ); - } + wfRunHooks( 'UserGetLanguageObject', array( $wgUser, &$code ) ); - function _newObject() { - return RequestContext::getMain()->{$this->method}(); + if( $code === $wgLanguageCode ) { + return $wgContLang; + } else { + $obj = Language::factory( $code ); + return $obj; + } } - } -