From: Happy-melon Date: Mon, 27 Jun 2011 19:23:54 +0000 (+0000) Subject: Revert r85288 (magic accessors for RequestContext); much more trouble than they're... X-Git-Tag: 1.31.0-rc.0~29245 X-Git-Url: http://git.cyclocoop.org/wiki/Target_page?a=commitdiff_plain;h=1c6dcbb71d421aec8a01c76ef81a3c12e7f6f4e0;p=lhc%2Fweb%2Fwiklou.git Revert r85288 (magic accessors for RequestContext); much more trouble than they're worth. --- diff --git a/includes/RequestContext.php b/includes/RequestContext.php index 3ea083581e..3481bb5e5e 100644 --- a/includes/RequestContext.php +++ b/includes/RequestContext.php @@ -1,7 +1,7 @@ mRequest = $r; + $this->request = $r; } /** @@ -56,11 +56,11 @@ class RequestContext { * @return WebRequest */ public function getRequest() { - if ( !isset( $this->mRequest ) ) { + if ( !isset($this->request) ) { global $wgRequest; # fallback to $wg till we can improve this - $this->mRequest = $wgRequest; + $this->request = $wgRequest; } - return $this->mRequest; + return $this->request; } /** @@ -69,7 +69,7 @@ class RequestContext { * @param $t Title object */ public function setTitle( Title $t ) { - $this->mTitle = $t; + $this->title = $t; } /** @@ -78,18 +78,18 @@ class RequestContext { * @return Title */ public function getTitle() { - if ( !isset( $this->mTitle ) ) { + if ( !isset($this->title) ) { global $wgTitle; # fallback to $wg till we can improve this - $this->mTitle = $wgTitle; + $this->title = $wgTitle; } - return $this->mTitle; + return $this->title; } /** * @param $o OutputPage */ public function setOutput( OutputPage $o ) { - $this->mOutput = $o; + $this->output = $o; } /** @@ -98,10 +98,10 @@ class RequestContext { * @return OutputPage object */ public function getOutput() { - if ( !isset( $this->mOutput ) ) { - $this->mOutput = new OutputPage( $this ); + if ( !isset( $this->output ) ) { + $this->output = new OutputPage( $this ); } - return $this->mOutput; + return $this->output; } /** @@ -110,7 +110,7 @@ class RequestContext { * @param $u User */ public function setUser( User $u ) { - $this->mUser = $u; + $this->user = $u; } /** @@ -119,13 +119,13 @@ class RequestContext { * @return User */ public function getUser() { - if ( !isset( $this->mUser ) ) { + if ( !isset($this->user) ) { global $wgCommandLineMode; - $this->mUser = $wgCommandLineMode + $this->user = $wgCommandLineMode ? new User : User::newFromSession( $this->getRequest() ); } - return $this->mUser; + return $this->user; } /** @@ -134,7 +134,7 @@ class RequestContext { * @return Language */ public function getLang() { - if ( !isset( $this->mLang ) ) { + if ( !isset($this->lang) ) { global $wgLanguageCode, $wgContLang; $code = $this->getRequest()->getVal( 'uselang', @@ -144,21 +144,21 @@ class RequestContext { $code = strtolower( $code ); # Validate $code - if ( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) { + if( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) { wfDebug( "Invalid user language code\n" ); $code = $wgLanguageCode; } wfRunHooks( 'UserGetLanguageObject', array( $this->getUser(), &$code ) ); - if ( $code === $wgLanguageCode ) { - $this->mLang = $wgContLang; + if( $code === $wgLanguageCode ) { + $this->lang = $wgContLang; } else { $obj = Language::factory( $code ); - $this->mLang = $obj; + $this->lang = $obj; } } - return $this->mLang; + return $this->lang; } /** @@ -167,11 +167,11 @@ class RequestContext { * @return Skin */ public function getSkin() { - if ( !isset( $this->mSkin ) ) { + if ( !isset($this->skin) ) { wfProfileIn( __METHOD__ . '-createskin' ); - + global $wgHiddenPrefs; - if ( !in_array( 'skin', $wgHiddenPrefs ) ) { + if( !in_array( 'skin', $wgHiddenPrefs ) ) { # get the user skin $userSkin = $this->getUser()->getOption( 'skin' ); $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin ); @@ -181,11 +181,11 @@ class RequestContext { $userSkin = $wgDefaultSkin; } - $this->mSkin = Skin::newFromKey( $userSkin ); - $this->mSkin->setContext( $this ); + $this->skin = Skin::newFromKey( $userSkin ); + $this->skin->setContext( $this ); wfProfileOut( __METHOD__ . '-createskin' ); } - return $this->mSkin; + return $this->skin; } /** Helpful methods **/ @@ -210,42 +210,10 @@ class RequestContext { */ public static function getMain() { static $instance = null; - if ( !isset( $instance ) ) { + if ( !isset($instance) ) { $instance = new self; } return $instance; } - - /** - * Make these C#-style accessors, so you can do $context->user->getName() which is - * internally mapped to $context->__get('user')->getName() which is mapped to - * $context->getUser()->getName() - * - * @param $name string - * - * @return string - */ - public function __get( $name ) { - wfDeprecated( 'RequestContext::__get() is deprecated; use $context->getFoo() instead' ); - if ( in_array( $name, array( 'request', 'title', 'output', 'user', 'lang', 'skin' ) ) ) { - $fname = 'get' . ucfirst( $name ); - return $this->$fname(); - } - trigger_error( "Undefined property {$name}", E_NOTICE ); - } - - /** - * @param $name string - * @param $value - * @return string - */ - public function __set( $name, $value ) { - wfDeprecated( 'RequestContext::__set() is deprecated; use $context->setFoo() instead' ); - if ( in_array( $name, array( 'request', 'title', 'output', 'user', 'lang', 'skin' ) ) ) { - $fname = 'set' . ucfirst( $name ); - return $this->$fname( $value ); - } - trigger_error( "Undefined property {$name}", E_NOTICE ); - } }