Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php |
— | — | @@ -955,15 +955,25 @@ |
956 | 956 | * @return string |
957 | 957 | */ |
958 | 958 | public function getCanonicalName( $username ) { |
959 | | - global $wgLDAPUseFetchedUsername; |
| 959 | + global $wgLDAPUseFetchedUsername, $wgMemc; |
| 960 | + |
960 | 961 | $this->printDebug( "Entering getCanonicalName", NONSENSITIVE ); |
961 | 962 | |
| 963 | + $key = wfMemcKey( 'ldapauthentication', 'canonicalname', $username ); |
| 964 | + $canonicalname = $username; |
962 | 965 | if ( $username != '' ) { |
963 | 966 | $this->printDebug( "Username isn't empty.", NONSENSITIVE ); |
964 | 967 | |
965 | 968 | # Fetch username, so that we can possibly use it. |
966 | 969 | # Only do it if we haven't already fetched it. |
967 | | - if ( !$this->userdn ) { |
| 970 | + $userInfo = $wgMemc->get( $key ); |
| 971 | + if ( is_array( $userInfo ) ) { |
| 972 | + $this->printDebug( "Fetched userInfo from memcache.", NONSENSITIVE ); |
| 973 | + if ( $userInfo["username"] == $username ) { |
| 974 | + $this->printDebug( "Username matched a key in memcache, using the fetched name: " . $userInfo["canonicalname"] ); |
| 975 | + return $userInfo["canonicalname"]; |
| 976 | + } |
| 977 | + } else { |
968 | 978 | $this->connect(); |
969 | 979 | if ( $this->ldapconn ) { |
970 | 980 | $this->printDebug( "Successfully connected", NONSENSITIVE ); |
— | — | @@ -977,29 +987,31 @@ |
978 | 988 | // We want to use the username returned by LDAP |
979 | 989 | // if it exists |
980 | 990 | if ( $this->LDAPUsername != '' ) { |
981 | | - $username = $this->LDAPUsername; |
| 991 | + $canonicalname = $this->LDAPUsername; |
982 | 992 | if ( isset( $wgLDAPUseFetchedUsername[$_SESSION['wsDomain']] ) && $wgLDAPUseFetchedUsername[$_SESSION['wsDomain']] ) { |
983 | | - $username[0] = strtoupper( $username[0] ); |
984 | | - return $username; |
| 993 | + $canonicalname[0] = strtoupper( $canonicalname[0] ); |
| 994 | + $wgMemc->set( $key, array( "username" => $username, "canonicalname" => $canonicalname ), 3600 * 24 ); |
| 995 | + return $canonicalname; |
985 | 996 | } |
986 | | - $this->printDebug( "Using LDAPUsername: $username", NONSENSITIVE ); |
| 997 | + $this->printDebug( "Using LDAPUsername: $canonicalname", NONSENSITIVE ); |
987 | 998 | } |
988 | 999 | |
989 | 1000 | if ( isset( $_SESSION['wsDomain'] ) && 'local' != $_SESSION['wsDomain'] ) { |
990 | 1001 | // Change username to lowercase so that multiple user accounts |
991 | 1002 | // won't be created for the same user. |
992 | 1003 | // But don't do it for the local domain! |
993 | | - $username = strtolower( $username ); |
| 1004 | + $canonicalname = strtolower( $username ); |
994 | 1005 | } |
995 | 1006 | |
996 | 1007 | // The wiki considers an all lowercase name to be invalid; need to |
997 | 1008 | // uppercase the first letter |
998 | | - $username[0] = strtoupper( $username[0] ); |
| 1009 | + $canonicalname[0] = strtoupper( $canonicalname[0] ); |
999 | 1010 | } |
1000 | 1011 | |
1001 | | - $this->printDebug( "Munged username: $username", NONSENSITIVE ); |
| 1012 | + $this->printDebug( "Munged username: $canonicalname", NONSENSITIVE ); |
1002 | 1013 | |
1003 | | - return $username; |
| 1014 | + $wgMemc->set( $key, array( "username" => $username, "canonicalname" => $canonicalname ), 3600 * 24 ); |
| 1015 | + return $canonicalname; |
1004 | 1016 | } |
1005 | 1017 | |
1006 | 1018 | /** |