Follow-up to r85240:
authorHappy-melon <happy-melon@users.mediawiki.org>
Sun, 3 Apr 2011 20:40:27 +0000 (20:40 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Sun, 3 Apr 2011 20:40:27 +0000 (20:40 +0000)
* 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.

includes/AutoLoader.php
includes/OutputPage.php
includes/Setup.php
includes/StubObject.php

index 004e7aa..1ce8c49 100644 (file)
@@ -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',
index 9b006de..4c7b2e9 100644 (file)
@@ -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();
index 076541e..37d9a47 100644 (file)
@@ -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
index f2a8b33..d1055e1 100644 (file)
@@ -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;
+               }
        }
-       
 }
-