r83093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83092‎ | r83093 | r83094 >
Date:15:52, 2 March 2011
Author:reedy
Status:deferred
Tags:
Comment:
Run it through stylize
Modified paths:
  • /trunk/extensions/Auth_remoteuser/Auth_remoteuser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Auth_remoteuser/Auth_remoteuser.php
@@ -60,21 +60,21 @@
6161 // You probably want to edit the initUser function to set the users real name
6262 // and email address properly for your configuration.
6363
64 -//Extension credits that show up on Special:Version
 64+// Extension credits that show up on Special:Version
6565 $wgExtensionCredits['other'][] = array(
6666 'name' => 'AutomaticREMOTE USER',
6767 'version' => '1.1.3',
68 - 'author' => array('Otheus Shelling', 'Rusty Burchfield', 'James Kinsman', 'Daniel Thomas', 'Ian Ward Comfort'),
 68+ 'author' => array( 'Otheus Shelling', 'Rusty Burchfield', 'James Kinsman', 'Daniel Thomas', 'Ian Ward Comfort' ),
6969 'url' => 'http://www.mediawiki.org/wiki/Extension:AutomaticREMOTE_USER',
7070 'description' => 'Automatically logs users using the REMOTE_USER environment variable.',
7171 );
7272
73 -//We must allow zero length passwords. This extension does not work in MW 1.16 without this.
 73+// We must allow zero length passwords. This extension does not work in MW 1.16 without this.
7474 $wgMinimalPasswordLength = 0;
7575
7676 // The Auth_remoteuser class is an AuthPlugin so make sure we have this
7777 // included.
78 -require_once('AuthPlugin.php');
 78+require_once( 'AuthPlugin.php' );
7979
8080 /**
8181 * This hook is registered by the Auth_remoteuser constructor. It will be
@@ -101,29 +101,29 @@
102102 global $wgAuthRemoteuserDomain;
103103
104104 // For a few special pages, don't do anything.
105 - $title = $wgRequest->getVal('title');
106 - if (($title == Title::makeName(NS_SPECIAL, 'UserLogout')) ||
107 - ($title == Title::makeName(NS_SPECIAL, 'UserLogin'))) {
 105+ $title = $wgRequest->getVal( 'title' );
 106+ if ( ( $title == Title::makeName( NS_SPECIAL, 'UserLogout' ) ) ||
 107+ ( $title == Title::makeName( NS_SPECIAL, 'UserLogin' ) ) ) {
108108 return;
109109 }
110110
111 - //Process the username if required
112 - if (!isset($_SERVER['REMOTE_USER']))
 111+ // Process the username if required
 112+ if ( !isset( $_SERVER['REMOTE_USER'] ) )
113113 {
114114 return;
115115 }
116 - if (isset($wgAuthRemoteuserDomain) && strlen($wgAuthRemoteuserDomain))
 116+ if ( isset( $wgAuthRemoteuserDomain ) && strlen( $wgAuthRemoteuserDomain ) )
117117 {
118 - $username = str_replace("$wgAuthRemoteuserDomain\\","",$_SERVER['REMOTE_USER']);
119 - $username = str_replace("@$wgAuthRemoteuserDomain","",$username);
 118+ $username = str_replace( "$wgAuthRemoteuserDomain\\", "", $_SERVER['REMOTE_USER'] );
 119+ $username = str_replace( "@$wgAuthRemoteuserDomain", "", $username );
120120 } else {
121121 $username = $_SERVER['REMOTE_USER'];
122122 }
123123
124124 // Check for valid session
125125 $user = User::newFromSession();
126 - if (!$user->isAnon()) {
127 - if ($user->getName() == Auth_remoteuser::getCanonicalName($username)) {
 126+ if ( !$user->isAnon() ) {
 127+ if ( $user->getName() == Auth_remoteuser::getCanonicalName( $username ) ) {
128128 return; // Correct user is already logged in.
129129 } else {
130130 $user->doLogout(); // Logout mismatched user.
@@ -131,37 +131,37 @@
132132 }
133133
134134 // Copied from includes/SpecialUserlogin.php
135 - if(!isset($wgCommandLineMode) && !isset($_COOKIE[session_name()])) {
 135+ if ( !isset( $wgCommandLineMode ) && !isset( $_COOKIE[session_name()] ) ) {
136136 wfSetupSession();
137137 }
138138
139139 // If the login form returns NEED_TOKEN try once more with the right token
140 - $tryagain=false;
141 - $trycount=0;
 140+ $tryagain = false;
 141+ $trycount = 0;
142142 $token = '';
143143 do
144144 {
145 - $tryagain=false;
 145+ $tryagain = false;
146146 // Submit a fake login form to authenticate the user.
147 - $params = new FauxRequest(array(
 147+ $params = new FauxRequest( array(
148148 'wpName' => $username,
149149 'wpPassword' => '',
150150 'wpDomain' => '',
151151 'wpLoginToken' => $token,
152152 'wpRemember' => ''
153 - ));
 153+ ) );
154154
155155 // Authenticate user data will automatically create new users.
156 - $loginForm = new LoginForm($params);
 156+ $loginForm = new LoginForm( $params );
157157 $result = $loginForm->authenticateUserData();
158 - switch ($result) {
 158+ switch ( $result ) {
159159 case LoginForm :: SUCCESS :
160 - $wgUser->setOption('rememberpassword', 1);
 160+ $wgUser->setOption( 'rememberpassword', 1 );
161161 $wgUser->setCookies();
162162 break;
163163 case LoginForm :: NEED_TOKEN:
164164 $token = $loginForm->getLoginToken();
165 - $tryagain=($trycount==0);
 165+ $tryagain = ( $trycount == 0 );
166166 break;
167167 case LoginForm :: WRONG_TOKEN:
168168 $errormessage = 'WrongToken';
@@ -189,12 +189,12 @@
190190 break;
191191 }
192192
193 - if ($result != LoginForm::SUCCESS && $result != LoginForm::NEED_TOKEN ) {
194 - error_log('Unexpected REMOTE_USER authentication failure. Login Error was:'.$errormessage);
 193+ if ( $result != LoginForm::SUCCESS && $result != LoginForm::NEED_TOKEN ) {
 194+ error_log( 'Unexpected REMOTE_USER authentication failure. Login Error was:' . $errormessage );
195195 }
196196 $trycount++;
197197 }
198 - while ($tryagain);
 198+ while ( $tryagain );
199199
200200 return;
201201 }
@@ -204,15 +204,15 @@
205205 function Auth_remoteuser() {
206206 // Register our hook function. This hook will be executed on every page
207207 // load. Its purpose is to automatically log the user in, if necessary.
208 - if (isset($_SERVER['REMOTE_USER']) && strlen($_SERVER['REMOTE_USER'])) {
 208+ if ( isset( $_SERVER['REMOTE_USER'] ) && strlen( $_SERVER['REMOTE_USER'] ) ) {
209209 global $wgExtensionFunctions;
210 - if (!isset($wgExtensionFunctions)) {
 210+ if ( !isset( $wgExtensionFunctions ) ) {
211211 $wgExtensionFunctions = array();
212212 }
213 - else if (!is_array($wgExtensionFunctions)) {
 213+ else if ( !is_array( $wgExtensionFunctions ) ) {
214214 $wgExtensionFunctions = array( $wgExtensionFunctions );
215215 }
216 - array_push($wgExtensionFunctions, 'Auth_remote_user_hook');
 216+ array_push( $wgExtensionFunctions, 'Auth_remote_user_hook' );
217217 }
218218 return;
219219 }
@@ -235,7 +235,7 @@
236236 * @return bool
237237 * @public
238238 */
239 - function setPassword($user, $password) {
 239+ function setPassword( $user, $password ) {
240240 return false;
241241 }
242242
@@ -246,7 +246,7 @@
247247 * @return bool
248248 * @public
249249 */
250 - function updateExternalDB($user) {
 250+ function updateExternalDB( $user ) {
251251 return true;
252252 }
253253
@@ -269,7 +269,7 @@
270270 * @return bool
271271 * @public
272272 */
273 - function addUser($user, $password) {
 273+ function addUser( $user, $password ) {
274274 return false;
275275 }
276276
@@ -282,7 +282,7 @@
283283 * @return bool
284284 * @public
285285 */
286 - function userExists($username) {
 286+ function userExists( $username ) {
287287 return true;
288288 }
289289
@@ -296,30 +296,30 @@
297297 * @return bool
298298 * @public
299299 */
300 - function authenticate($username, $password) {
 300+ function authenticate( $username, $password ) {
301301 global $_SERVER;
302302 global $wgAuthRemoteuserAuthz;
303303 global $wgAuthRemoteuserDomain;
304304
305 - if (isset($wgAuthRemoteuserAuthz) && $wgAuthRemoteuserAuthz != true)
 305+ if ( isset( $wgAuthRemoteuserAuthz ) && $wgAuthRemoteuserAuthz != true )
306306 return false;
307307
308 - if (isset($_SERVER['REMOTE_USER']) == false)
 308+ if ( isset( $_SERVER['REMOTE_USER'] ) == false )
309309 {
310310 $_SERVER['REMOTE_USER'] = "";
311311 }
312 - if (!isset($_SERVER['REMOTE_USER']))
 312+ if ( !isset( $_SERVER['REMOTE_USER'] ) )
313313 {
314314 return false;
315315 }
316 - if (isset($wgAuthRemoteuserDomain) && strlen($wgAuthRemoteuserDomain)>0) {
317 - $usertest = str_replace("$wgAuthRemoteuserDomain\\","",$_SERVER['REMOTE_USER']);
318 - $usertest = str_replace("@$wgAuthRemoteuserDomain","",$usertest);
 316+ if ( isset( $wgAuthRemoteuserDomain ) && strlen( $wgAuthRemoteuserDomain ) > 0 ) {
 317+ $usertest = str_replace( "$wgAuthRemoteuserDomain\\", "", $_SERVER['REMOTE_USER'] );
 318+ $usertest = str_replace( "@$wgAuthRemoteuserDomain", "", $usertest );
319319 } else {
320320 $usertest = $_SERVER['REMOTE_USER'];
321321 }
322322
323 - return (strtolower($username) == strtolower($usertest));
 323+ return ( strtolower( $username ) == strtolower( $usertest ) );
324324 }
325325
326326 /**
@@ -329,7 +329,7 @@
330330 * @return bool
331331 * @public
332332 */
333 - function validDomain($domain) {
 333+ function validDomain( $domain ) {
334334 return true;
335335 }
336336
@@ -344,7 +344,7 @@
345345 * @param User $user
346346 * @public
347347 */
348 - function updateUser(&$user) {
 348+ function updateUser( &$user ) {
349349 // We only set this stuff when accounts are created.
350350 return true;
351351 }
@@ -380,7 +380,7 @@
381381 * @param $user User object.
382382 * @public
383383 */
384 - function initUser(&$user) {
 384+ function initUser( &$user ) {
385385 global $_SERVER;
386386 global $wgAuthRemoteuserName;
387387 global $wgAuthRemoteuserMail;
@@ -388,35 +388,35 @@
389389 global $wgAuthRemoteuserNotify;
390390 global $wgAuthRemoteuserDomain;
391391
392 - if (isset($wgAuthRemoteuserDomain) && strlen($wgAuthRemoteuserDomain))
 392+ if ( isset( $wgAuthRemoteuserDomain ) && strlen( $wgAuthRemoteuserDomain ) )
393393 {
394 - $username = str_replace("$wgAuthRemoteuserDomain\\","",$_SERVER['REMOTE_USER']);
395 - $username = str_replace("@$wgAuthRemoteuserDomain","",$username);
 394+ $username = str_replace( "$wgAuthRemoteuserDomain\\", "", $_SERVER['REMOTE_USER'] );
 395+ $username = str_replace( "@$wgAuthRemoteuserDomain", "", $username );
396396 } else {
397397 $username = $_SERVER['REMOTE_USER'];
398398 }
399399
400 - if (isset($wgAuthRemoteuserName))
401 - $user->setRealName($wgAuthRemoteuserName);
 400+ if ( isset( $wgAuthRemoteuserName ) )
 401+ $user->setRealName( $wgAuthRemoteuserName );
402402 else
403 - $user->setRealName('');
 403+ $user->setRealName( '' );
404404
405 - if (isset($wgAuthRemoteuserMail))
406 - $user->setEmail($wgAuthRemoteuserMail);
407 - elseif (isset($wgAuthRemoteuserMailDomain))
408 - $user->setEmail($username . '@' . $wgAuthRemoteuserMailDomain);
 405+ if ( isset( $wgAuthRemoteuserMail ) )
 406+ $user->setEmail( $wgAuthRemoteuserMail );
 407+ elseif ( isset( $wgAuthRemoteuserMailDomain ) )
 408+ $user->setEmail( $username . '@' . $wgAuthRemoteuserMailDomain );
409409 else
410 - $user->setEmail($username . "@example.com");
 410+ $user->setEmail( $username . "@example.com" );
411411
412412 $user->mEmailAuthenticated = wfTimestampNow();
413413 $user->setToken();
414414
415 - //turn on e-mail notifications
416 - if (isset($wgAuthRemoteuserNotify) && $wgAuthRemoteuserNotify) {
417 - $user->setOption('enotifwatchlistpages', 1);
418 - $user->setOption('enotifusertalkpages', 1);
419 - $user->setOption('enotifminoredits', 1);
420 - $user->setOption('enotifrevealaddr', 1);
 415+ // turn on e-mail notifications
 416+ if ( isset( $wgAuthRemoteuserNotify ) && $wgAuthRemoteuserNotify ) {
 417+ $user->setOption( 'enotifwatchlistpages', 1 );
 418+ $user->setOption( 'enotifusertalkpages', 1 );
 419+ $user->setOption( 'enotifminoredits', 1 );
 420+ $user->setOption( 'enotifrevealaddr', 1 );
421421 }
422422
423423 $user->saveSettings();
@@ -429,14 +429,14 @@
430430 * @param $template UserLoginTemplate object.
431431 * @public
432432 */
433 - function modifyUITemplate(&$template) {
434 - //disable the mail new password box
435 - $template->set('useemail', false);
436 - //disable 'remember me' box
437 - $template->set('remember', false);
438 - $template->set('create', false);
439 - $template->set('domain', false);
440 - $template->set('usedomain', false);
 433+ function modifyUITemplate( &$template ) {
 434+ // disable the mail new password box
 435+ $template->set( 'useemail', false );
 436+ // disable 'remember me' box
 437+ $template->set( 'remember', false );
 438+ $template->set( 'create', false );
 439+ $template->set( 'domain', false );
 440+ $template->set( 'usedomain', false );
441441 }
442442
443443 /**
@@ -447,11 +447,11 @@
448448 * @return string
449449 * @public
450450 */
451 - function getCanonicalName($username) {
 451+ function getCanonicalName( $username ) {
452452 // lowercase the username
453 - $username = strtolower($username);
 453+ $username = strtolower( $username );
454454 // uppercase first letter to make MediaWiki happy
455 - $username = ucfirst($username);
 455+ $username = ucfirst( $username );
456456 return $username;
457457 }
458458 }

Status & tagging log