r78427 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78426‎ | r78427 | r78428 >
Date:01:30, 15 December 2010
Author:laner
Status:deferred (Comments)
Tags:
Comment:
Clean up getPreferences, and ensure attributes are always lowercase.
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -1126,30 +1126,28 @@
11271127 $this->printDebug( "Retrieving preferences", NONSENSITIVE );
11281128 $prefs = $wgLDAPPreferences[$_SESSION['wsDomain']];
11291129 foreach ( array_keys( $prefs ) as $key ) {
 1130+ $attr = strtolower( $prefs[$key] );
 1131+ if ( isset( $this->userInfo[0][$attr] ) ) {
 1132+ $value = $this->userInfo[0][$attr];
 1133+ } else {
 1134+ continue;
 1135+ }
11301136 switch ( $key ) {
11311137 case "email":
1132 - if ( isset( $this->userInfo[0]["$prefs[$key]"] ) ) {
1133 - $this->email = $this->userInfo[0]["$prefs[$key]"][0];
1134 - $this->printDebug( "Retrieved email ($this->email) using attribute ($prefs[$key])", NONSENSITIVE );
1135 - }
 1138+ $this->email = $value;
 1139+ $this->printDebug( "Retrieved email ($this->email) using attribute ($attr)", NONSENSITIVE );
11361140 break;
11371141 case "language":
1138 - if ( isset( $this->userInfo[0]["$prefs[$key]"] ) ) {
1139 - $this->lang = $this->userInfo[0][$prefs[$key]][0];
1140 - $this->printDebug( "Retrieved language ($this->lang) using attribute ($prefs[$key])", NONSENSITIVE );
1141 - }
 1142+ $this->lang = $value;
 1143+ $this->printDebug( "Retrieved language ($this->lang) using attribute ($attr)", NONSENSITIVE );
11421144 break;
11431145 case "nickname":
1144 - if ( isset( $this->userInfo[0]["$prefs[$key]"] ) ) {
1145 - $this->nickname = $this->userInfo[0]["$prefs[$key]"][0];
1146 - $this->printDebug( "Retrieved nickname ($this->nickname) using attribute ($prefs[$key])", NONSENSITIVE );
1147 - }
 1146+ $this->nickname = $value;
 1147+ $this->printDebug( "Retrieved nickname ($this->nickname) using attribute ($attr)", NONSENSITIVE );
11481148 break;
11491149 case "realname":
1150 - if ( isset( $this->userInfo[0]["$prefs[$key]"] ) ) {
1151 - $this->realname = $this->userInfo[0]["$prefs[$key]"][0];
1152 - $this->printDebug( "Retrieved realname ($this->realname) using attribute ($prefs[$key])", NONSENSITIVE );
1153 - }
 1150+ $this->realname = $value;
 1151+ $this->printDebug( "Retrieved realname ($this->realname) using attribute ($attr)", NONSENSITIVE );
11541152 break;
11551153 }
11561154 }
@@ -1384,7 +1382,7 @@
13851383
13861384 $this->userLDAPGroups = $groups;
13871385 } else {
1388 - $this->printDebug( "memberOf attribute isn't set:", NONSENSITIVE );
 1386+ $this->printDebug( "memberOf attribute isn't set", NONSENSITIVE );
13891387 }
13901388 } else {
13911389 $this->printDebug( "Searching for the groups", NONSENSITIVE );

Follow-up revisions

RevisionCommit summaryAuthorDate
r78444Fixing errors introducted and pointed out in the code review for r78427.laner17:58, 15 December 2010
r79577Again fixing issue reported for r78427laner13:47, 4 January 2011

Comments

#Comment by Fomafix (talk | contribs)   12:23, 15 December 2010

$value is the array, instead of the first element of the array:

- $value = $this->userInfo[0][$attr];
+ $value = $this->userInfo[0][$attr][0];
#Comment by Fomafix (talk | contribs)   12:35, 15 December 2010

The log file should get the original case $prefs[$key] instead of strtolower($prefs[$key]).

#Comment by Ryan lane (talk | contribs)   17:58, 15 December 2010

Good catch. Thanks. Fixed in r78444.

#Comment by Fomafix (talk | contribs)   09:32, 16 December 2010

In r78444 you changed $attr to $prefs[$key] only for realname. The log for email, language and nickname should also use $prefs[$key] without strtolower.

#Comment by Ryan lane (talk | contribs)   13:48, 4 January 2011

Fixed in r79577.

Status & tagging log