*/
private $config;
+ /**
+ * @var RequestContext
+ */
+ private static $instance = null;
+
/**
* Set the Config object
*
*/
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;
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
*
}
}
- /**
- * @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.
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;
* @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;
}
/**