r90899 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90898‎ | r90899 | r90900 >
Date:19:23, 27 June 2011
Author:happy-melon
Status:ok
Tags:
Comment:
Revert r85288 (magic accessors for RequestContext); much more trouble than they're worth.
Modified paths:
  • /trunk/phase3/includes/RequestContext.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/RequestContext.php
@@ -1,7 +1,7 @@
22 <?php
33 /**
44 * Group all the pieces relevant to the context of a request into one instance
5 - *
 5+ *
66 * @since 1.18
77 *
88 * @author IAlex
@@ -14,32 +14,32 @@
1515 /**
1616 * @var WebRequest
1717 */
18 - private $mRequest;
 18+ private $request;
1919
2020 /**
2121 * @var Title
2222 */
23 - private $mTitle;
 23+ private $title;
2424
2525 /**
2626 * @var OutputPage
2727 */
28 - private $mOutput;
 28+ private $output;
2929
3030 /**
3131 * @var User
3232 */
33 - private $mUser;
 33+ private $user;
3434
3535 /**
3636 * @var Language
3737 */
38 - private $mLang;
 38+ private $lang;
3939
4040 /**
4141 * @var Skin
4242 */
43 - private $mSkin;
 43+ private $skin;
4444
4545 /**
4646 * Set the WebRequest object
@@ -47,7 +47,7 @@
4848 * @param $r WebRequest object
4949 */
5050 public function setRequest( WebRequest $r ) {
51 - $this->mRequest = $r;
 51+ $this->request = $r;
5252 }
5353
5454 /**
@@ -56,11 +56,11 @@
5757 * @return WebRequest
5858 */
5959 public function getRequest() {
60 - if ( !isset( $this->mRequest ) ) {
 60+ if ( !isset($this->request) ) {
6161 global $wgRequest; # fallback to $wg till we can improve this
62 - $this->mRequest = $wgRequest;
 62+ $this->request = $wgRequest;
6363 }
64 - return $this->mRequest;
 64+ return $this->request;
6565 }
6666
6767 /**
@@ -69,7 +69,7 @@
7070 * @param $t Title object
7171 */
7272 public function setTitle( Title $t ) {
73 - $this->mTitle = $t;
 73+ $this->title = $t;
7474 }
7575
7676 /**
@@ -78,18 +78,18 @@
7979 * @return Title
8080 */
8181 public function getTitle() {
82 - if ( !isset( $this->mTitle ) ) {
 82+ if ( !isset($this->title) ) {
8383 global $wgTitle; # fallback to $wg till we can improve this
84 - $this->mTitle = $wgTitle;
 84+ $this->title = $wgTitle;
8585 }
86 - return $this->mTitle;
 86+ return $this->title;
8787 }
8888
8989 /**
9090 * @param $o OutputPage
9191 */
9292 public function setOutput( OutputPage $o ) {
93 - $this->mOutput = $o;
 93+ $this->output = $o;
9494 }
9595
9696 /**
@@ -98,10 +98,10 @@
9999 * @return OutputPage object
100100 */
101101 public function getOutput() {
102 - if ( !isset( $this->mOutput ) ) {
103 - $this->mOutput = new OutputPage( $this );
 102+ if ( !isset( $this->output ) ) {
 103+ $this->output = new OutputPage( $this );
104104 }
105 - return $this->mOutput;
 105+ return $this->output;
106106 }
107107
108108 /**
@@ -110,7 +110,7 @@
111111 * @param $u User
112112 */
113113 public function setUser( User $u ) {
114 - $this->mUser = $u;
 114+ $this->user = $u;
115115 }
116116
117117 /**
@@ -119,13 +119,13 @@
120120 * @return User
121121 */
122122 public function getUser() {
123 - if ( !isset( $this->mUser ) ) {
 123+ if ( !isset($this->user) ) {
124124 global $wgCommandLineMode;
125 - $this->mUser = $wgCommandLineMode
 125+ $this->user = $wgCommandLineMode
126126 ? new User
127127 : User::newFromSession( $this->getRequest() );
128128 }
129 - return $this->mUser;
 129+ return $this->user;
130130 }
131131
132132 /**
@@ -134,7 +134,7 @@
135135 * @return Language
136136 */
137137 public function getLang() {
138 - if ( !isset( $this->mLang ) ) {
 138+ if ( !isset($this->lang) ) {
139139 global $wgLanguageCode, $wgContLang;
140140 $code = $this->getRequest()->getVal(
141141 'uselang',
@@ -144,21 +144,21 @@
145145 $code = strtolower( $code );
146146
147147 # Validate $code
148 - if ( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) {
 148+ if( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) {
149149 wfDebug( "Invalid user language code\n" );
150150 $code = $wgLanguageCode;
151151 }
152152
153153 wfRunHooks( 'UserGetLanguageObject', array( $this->getUser(), &$code ) );
154154
155 - if ( $code === $wgLanguageCode ) {
156 - $this->mLang = $wgContLang;
 155+ if( $code === $wgLanguageCode ) {
 156+ $this->lang = $wgContLang;
157157 } else {
158158 $obj = Language::factory( $code );
159 - $this->mLang = $obj;
 159+ $this->lang = $obj;
160160 }
161161 }
162 - return $this->mLang;
 162+ return $this->lang;
163163 }
164164
165165 /**
@@ -167,11 +167,11 @@
168168 * @return Skin
169169 */
170170 public function getSkin() {
171 - if ( !isset( $this->mSkin ) ) {
 171+ if ( !isset($this->skin) ) {
172172 wfProfileIn( __METHOD__ . '-createskin' );
173 -
 173+
174174 global $wgHiddenPrefs;
175 - if ( !in_array( 'skin', $wgHiddenPrefs ) ) {
 175+ if( !in_array( 'skin', $wgHiddenPrefs ) ) {
176176 # get the user skin
177177 $userSkin = $this->getUser()->getOption( 'skin' );
178178 $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin );
@@ -181,11 +181,11 @@
182182 $userSkin = $wgDefaultSkin;
183183 }
184184
185 - $this->mSkin = Skin::newFromKey( $userSkin );
186 - $this->mSkin->setContext( $this );
 185+ $this->skin = Skin::newFromKey( $userSkin );
 186+ $this->skin->setContext( $this );
187187 wfProfileOut( __METHOD__ . '-createskin' );
188188 }
189 - return $this->mSkin;
 189+ return $this->skin;
190190 }
191191
192192 /** Helpful methods **/
@@ -210,42 +210,10 @@
211211 */
212212 public static function getMain() {
213213 static $instance = null;
214 - if ( !isset( $instance ) ) {
 214+ if ( !isset($instance) ) {
215215 $instance = new self;
216216 }
217217 return $instance;
218218 }
219 -
220 - /**
221 - * Make these C#-style accessors, so you can do $context->user->getName() which is
222 - * internally mapped to $context->__get('user')->getName() which is mapped to
223 - * $context->getUser()->getName()
224 - *
225 - * @param $name string
226 - *
227 - * @return string
228 - */
229 - public function __get( $name ) {
230 - wfDeprecated( 'RequestContext::__get() is deprecated; use $context->getFoo() instead' );
231 - if ( in_array( $name, array( 'request', 'title', 'output', 'user', 'lang', 'skin' ) ) ) {
232 - $fname = 'get' . ucfirst( $name );
233 - return $this->$fname();
234 - }
235 - trigger_error( "Undefined property {$name}", E_NOTICE );
236 - }
237 -
238 - /**
239 - * @param $name string
240 - * @param $value
241 - * @return string
242 - */
243 - public function __set( $name, $value ) {
244 - wfDeprecated( 'RequestContext::__set() is deprecated; use $context->setFoo() instead' );
245 - if ( in_array( $name, array( 'request', 'title', 'output', 'user', 'lang', 'skin' ) ) ) {
246 - $fname = 'set' . ucfirst( $name );
247 - return $this->$fname( $value );
248 - }
249 - trigger_error( "Undefined property {$name}", E_NOTICE );
250 - }
251219 }
252220

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85288Implement magic accessors for RequestContext variables: you can now just call...happy-melon22:09, 3 April 2011

Status & tagging log