Merge "Make the global objects documentation consistent in Setup.php"
[lhc/web/wiklou.git] / includes / context / RequestContext.php
index 4291e44..d4bf0b4 100644 (file)
@@ -68,6 +68,11 @@ class RequestContext implements IContextSource {
         */
        private $config;
 
+       /**
+        * @var RequestContext
+        */
+       private static $instance = null;
+
        /**
         * Set the Config object
         *
@@ -84,7 +89,9 @@ class RequestContext implements IContextSource {
         */
        public function getConfig() {
                if ( $this->config === null ) {
-                       $this->config = Config::factory();
+                       // @todo In the future, we could move this to WebStart.php so
+                       // the Config object is ready for when initialization happens
+                       $this->config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
                }
 
                return $this->config;
@@ -266,17 +273,6 @@ class RequestContext implements IContextSource {
                return $code;
        }
 
-       /**
-        * Set the Language object
-        *
-        * @deprecated since 1.19 Use setLanguage instead
-        * @param Language|string $l Language instance or language code
-        */
-       public function setLang( $l ) {
-               wfDeprecated( __METHOD__, '1.19' );
-               $this->setLanguage( $l );
-       }
-
        /**
         * Set the Language object
         *
@@ -296,16 +292,6 @@ class RequestContext implements IContextSource {
                }
        }
 
-       /**
-        * @deprecated since 1.19 Use getLanguage instead
-        * @return Language
-        */
-       public function getLang() {
-               wfDeprecated( __METHOD__, '1.19' );
-
-               return $this->getLanguage();
-       }
-
        /**
         * Get the Language object.
         * Initialization of user or request objects can depend on this.
@@ -327,22 +313,28 @@ class RequestContext implements IContextSource {
 
                        global $wgLanguageCode, $wgContLang;
 
-                       $request = $this->getRequest();
-                       $user = $this->getUser();
+                       try {
+                               $request = $this->getRequest();
+                               $user = $this->getUser();
 
-                       $code = $request->getVal( 'uselang', $user->getOption( 'language' ) );
-                       $code = self::sanitizeLangCode( $code );
+                               $code = $request->getVal( 'uselang', $user->getOption( 'language' ) );
+                               $code = self::sanitizeLangCode( $code );
 
-                       wfRunHooks( 'UserGetLanguageObject', array( $user, &$code, $this ) );
+                               wfRunHooks( 'UserGetLanguageObject', array( $user, &$code, $this ) );
 
-                       if ( $code === $wgLanguageCode ) {
-                               $this->lang = $wgContLang;
-                       } else {
-                               $obj = Language::factory( $code );
-                               $this->lang = $obj;
-                       }
+                               if ( $code === $wgLanguageCode ) {
+                                       $this->lang = $wgContLang;
+                               } else {
+                                       $obj = Language::factory( $code );
+                                       $this->lang = $obj;
+                               }
 
-                       unset( $this->recursion );
+                               unset( $this->recursion );
+                       }
+                       catch ( Exception $ex ) {
+                               unset( $this->recursion );
+                               throw $ex;
+                       }
                }
 
                return $this->lang;
@@ -424,12 +416,21 @@ class RequestContext implements IContextSource {
         * @return RequestContext
         */
        public static function getMain() {
-               static $instance = null;
-               if ( $instance === null ) {
-                       $instance = new self;
+               if ( self::$instance === null ) {
+                       self::$instance = new self;
                }
 
-               return $instance;
+               return self::$instance;
+       }
+
+       /**
+        * Resets singleton returned by getMain(). Should be called only from unit tests.
+        */
+       public static function resetMain() {
+               if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
+                       throw new MWException( __METHOD__ . '() should be called only from unit tests!' );
+               }
+               self::$instance = null;
        }
 
        /**