r42752 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42751‎ | r42752 | r42753 >
Date:23:01, 28 October 2008
Author:btongminh
Status:old
Tags:
Comment:
Added Special:Userrights support
Modified paths:
  • /trunk/extensions/NssMySQLAuth/NssMySQLAuthPlugin.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NssMySQLAuth/NssMySQLAuthPlugin.php
@@ -18,7 +18,9 @@
1919 $wgHooks['UserEffectiveGroups'][] = array( $wgAuth, 'onUserEffectiveGroups' );
2020 $wgHooks['UserGetEmail'][] = array( $wgAuth, 'onUserGetEmail' );
2121 $wgHooks['UserSetEmail'][] = array( $wgAuth, 'onUserSetEmail' );
 22+ $wgHooks['UserRights'][] = array( $wgAuth, 'onUserRights' );
2223
 24+
2325 wfLoadExtensionMessages( 'nssmysqlauth' );
2426 }
2527
@@ -32,15 +34,23 @@
3335 }
3436
3537 function userExists( $username ) {
36 - if( isset( $this->users[$username] ))
37 - return $this->users[$username];
38 -
 38+ $this->loadUser( $username );
 39+ return $this->users[$username] !== false;
 40+ }
 41+ function getUid( $username ) {
 42+ $this->loadUser( $username );
 43+ return $this->users[$username];
 44+ }
 45+
 46+ function loadUser( $username ) {
 47+ if ( isset( $this->users[$username] ) )
 48+ return;
3949 $dbr = $this->getDB( DB_READ );
40 - return $this->users[$username] =
41 - false !== $dbr->select(
42 - 'passwd', 1, array( 'pwd_name' => $username ),
 50+ $row = $dbr->selectRow(
 51+ 'passwd', 'pwd_uid', array( 'pwd_name' => $username ),
4352 __METHOD__
4453 );
 54+ $this->users[$username] = ($row === false ? false : $row->pwd_uid);
4555 }
4656
4757 function authenticate( $username, $password ) {
@@ -148,6 +158,35 @@
149159 );
150160 }
151161
 162+ function onUserRights( &$user, $addgroup, $removegroup ) {
 163+ $uid = $this->getUid( $user->getName() );
 164+ if( $uid === false )
 165+ return true;
 166+
 167+ $dbr = $this->getDB( DB_READ );
 168+ $res = $dbr->select( 'groups', 'grp_name', array(), __METHOD__ );
 169+ $groups = array();
 170+ while ( $row = $res->fetchObject() )
 171+ $groups[] = $row->grp_name;
 172+ $res->free();
 173+
 174+ $addgroup = array_intersect( $groups, $addgroup );
 175+ $removegroup = array_intersect( $groups, $removegroup );
 176+
 177+ $dbw = $this->getDB( DB_WRITE );
 178+ foreach ( $addgroup as $group )
 179+ $dbw->insert( 'group_membership', array(
 180+ 'gm_user' => $uid,
 181+ 'gm_group' => $group,
 182+ ), __METHOD__, 'IGNORE' );
 183+ foreach ( $removegroup as $group )
 184+ $dbw->delete( 'group_membership', array(
 185+ 'gm_user' => $uid,
 186+ 'gm_group' => $group,
 187+ ), __METHOD__ );
 188+ return true;
 189+ }
 190+
152191 /**
153192 * Create an account, returning a random password
154193 */

Status & tagging log