r41684 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41683‎ | r41684 | r41685 >
Date:02:45, 5 October 2008
Author:aaron
Status:old
Tags:
Comment:
Partial revert of r41527. Do this in a cleaner way.
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthPlugin.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/phase3/includes/AuthPlugin.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -253,23 +253,6 @@
254254 }
255255 wfProfileOut( __METHOD__ );
256256 }
257 -
258 - protected function callAuthPlugin( $fname /* $args */ ) {
259 - $args = func_get_args();
260 - array_shift( $args );
261 - // Load auth plugin conterpart functions for User functions
262 - if( !$this->mAuthLoaded ) {
263 - global $wgAuth;
264 - $this->mAuthCallbacks = array();
265 - $wgAuth->setUserCallbacks( $this, $this->mAuthCallbacks );
266 - $this->mAuthLoaded = true;
267 - }
268 - // Try to call the auth plugin version of this function
269 - if( isset($this->mAuthCallbacks[$fname]) && is_callable($this->mAuthCallbacks[$fname]) ) {
270 - return call_user_func_array( $this->mAuthCallbacks[$fname], $args );
271 - }
272 - return NULL;
273 - }
274257
275258 /**
276259 * Load user table data, given mId has already been set.
@@ -1347,7 +1330,9 @@
13481331 if( $this->mLocked !== null ) {
13491332 return $this->mLocked;
13501333 }
1351 - $this->mLocked = (bool)$this->callAuthPlugin( __FUNCTION__ );
 1334+ global $wgAuth;
 1335+ $authUser = $wgAuth->getUserInstance( $this );
 1336+ $this->mLocked = (bool)$authUser->isLocked();
13521337 return $this->mLocked;
13531338 }
13541339
@@ -1362,7 +1347,9 @@
13631348 }
13641349 $this->getBlockedStatus();
13651350 if( !$this->mHideName ) {
1366 - $this->mHideName = (bool)$this->callAuthPlugin( __FUNCTION__ );
 1351+ global $wgAuth;
 1352+ $authUser = $wgAuth->getUserInstance( $this );
 1353+ $this->mHideName = (bool)$authUser->isHidden();
13671354 }
13681355 return $this->mHideName;
13691356 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -17,6 +17,7 @@
1818 'Article' => 'includes/Article.php',
1919 'AtomFeed' => 'includes/Feed.php',
2020 'AuthPlugin' => 'includes/AuthPlugin.php',
 21+ 'AuthPluginUser' => 'includes/AuthPlugin.php',
2122 'Autopromote' => 'includes/Autopromote.php',
2223 'BagOStuff' => 'includes/BagOStuff.php',
2324 'Block' => 'includes/Block.php',
Index: trunk/phase3/includes/AuthPlugin.php
@@ -38,9 +38,8 @@
3939 *
4040 * @param $username String: username.
4141 * @return bool
42 - * @public
4342 */
44 - function userExists( $username ) {
 43+ public function userExists( $username ) {
4544 # Override this!
4645 return false;
4746 }
@@ -54,9 +53,8 @@
5554 * @param $username String: username.
5655 * @param $password String: user password.
5756 * @return bool
58 - * @public
5957 */
60 - function authenticate( $username, $password ) {
 58+ public function authenticate( $username, $password ) {
6159 # Override this!
6260 return false;
6361 }
@@ -65,9 +63,8 @@
6664 * Modify options in the login template.
6765 *
6866 * @param $template UserLoginTemplate object.
69 - * @public
7067 */
71 - function modifyUITemplate( &$template ) {
 68+ public function modifyUITemplate( &$template ) {
7269 # Override this!
7370 $template->set( 'usedomain', false );
7471 }
@@ -76,9 +73,8 @@
7774 * Set the domain this plugin is supposed to use when authenticating.
7875 *
7976 * @param $domain String: authentication domain.
80 - * @public
8177 */
82 - function setDomain( $domain ) {
 78+ public function setDomain( $domain ) {
8379 $this->domain = $domain;
8480 }
8581
@@ -87,9 +83,8 @@
8884 *
8985 * @param $domain String: authentication domain.
9086 * @return bool
91 - * @public
9287 */
93 - function validDomain( $domain ) {
 88+ public function validDomain( $domain ) {
9489 # Override this!
9590 return true;
9691 }
@@ -103,9 +98,8 @@
10499 * forget the & on your function declaration.
105100 *
106101 * @param User $user
107 - * @public
108102 */
109 - function updateUser( &$user ) {
 103+ public function updateUser( &$user ) {
110104 # Override this and do something
111105 return true;
112106 }
@@ -123,9 +117,8 @@
124118 * This is just a question, and shouldn't perform any actions.
125119 *
126120 * @return bool
127 - * @public
128121 */
129 - function autoCreate() {
 122+ public function autoCreate() {
130123 return false;
131124 }
132125
@@ -134,7 +127,7 @@
135128 *
136129 * @return bool
137130 */
138 - function allowPasswordChange() {
 131+ public function allowPasswordChange() {
139132 return true;
140133 }
141134
@@ -149,9 +142,8 @@
150143 * @param $user User object.
151144 * @param $password String: password.
152145 * @return bool
153 - * @public
154146 */
155 - function setPassword( $user, $password ) {
 147+ public function setPassword( $user, $password ) {
156148 return true;
157149 }
158150
@@ -161,9 +153,8 @@
162154 *
163155 * @param $user User object.
164156 * @return bool
165 - * @public
166157 */
167 - function updateExternalDB( $user ) {
 158+ public function updateExternalDB( $user ) {
168159 return true;
169160 }
170161
@@ -171,9 +162,8 @@
172163 * Check to see if external accounts can be created.
173164 * Return true if external accounts can be created.
174165 * @return bool
175 - * @public
176166 */
177 - function canCreateAccounts() {
 167+ public function canCreateAccounts() {
178168 return false;
179169 }
180170
@@ -186,9 +176,8 @@
187177 * @param string $email
188178 * @param string $realname
189179 * @return bool
190 - * @public
191180 */
192 - function addUser( $user, $password, $email='', $realname='' ) {
 181+ public function addUser( $user, $password, $email='', $realname='' ) {
193182 return true;
194183 }
195184
@@ -200,9 +189,8 @@
201190 * This is just a question, and shouldn't perform any actions.
202191 *
203192 * @return bool
204 - * @public
205193 */
206 - function strict() {
 194+ public function strict() {
207195 return false;
208196 }
209197
@@ -212,9 +200,8 @@
213201 *
214202 * @param $username String: username.
215203 * @return bool
216 - * @public
217204 */
218 - function strictUserAuth( $username ) {
 205+ public function strictUserAuth( $username ) {
219206 return false;
220207 }
221208
@@ -228,9 +215,8 @@
229216 *
230217 * @param $user User object.
231218 * @param $autocreate bool True if user is being autocreated on login
232 - * @public
233219 */
234 - function initUser( &$user, $autocreate=false ) {
 220+ public function initUser( &$user, $autocreate=false ) {
235221 # Override this to do something.
236222 }
237223
@@ -238,14 +224,33 @@
239225 * If you want to munge the case of an account name before the final
240226 * check, now is your chance.
241227 */
242 - function getCanonicalName( $username ) {
 228+ public function getCanonicalName( $username ) {
243229 return $username;
244230 }
245231
246232 /**
247 - * Adds any functionality to a User object in context of the auth system
 233+ * Get an instance of a User object
 234+ *
 235+ * @param $user User
 236+ * @public
248237 */
249 - function setUserCallbacks( $user, &$callbacks ) {
250 - return true;
 238+ public function getUserInstance( User &$user ) {
 239+ return new AuthPluginUser( $user );
251240 }
252241 }
 242+
 243+class AuthPluginUser {
 244+ function __construct( $username ) {
 245+ $this->mName = $username;
 246+ }
 247+
 248+ public function isLocked() {
 249+ # Override this!
 250+ return false;
 251+ }
 252+
 253+ public function isHidden() {
 254+ # Override this!
 255+ return false;
 256+ }
 257+}
Index: trunk/extensions/CentralAuth/CentralAuthPlugin.php
@@ -245,9 +245,7 @@
246246 }
247247 }
248248
249 - function setUserCallbacks( $user, &$callbacks ) {
250 - $central = CentralAuthUser::getInstance( $user );
251 - $callbacks['isLocked'] = array( $central, 'isLocked' );
252 - $callbacks['isHidden'] = array( $central, 'isHidden' );
 249+ public function getUserInstance( User &$user ) {
 250+ return CentralAuthUser::getInstance( $user );
253251 }
254252 }
Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -11,7 +11,7 @@
1212
1313 */
1414
15 -class CentralAuthUser {
 15+class CentralAuthUser extends AuthPluginUser {
1616
1717 /**
1818 * The username of the current user.

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41527* Pull isLocked() and isHidden() up to User using callbacks...aaron01:12, 2 October 2008

Status & tagging log