MediaWiki
REL1_19
|
00001 <?php 00052 class ExternalUser_MediaWiki extends ExternalUser { 00053 private $mRow; 00054 00058 private $mDb; 00059 00064 protected function initFromName( $name ) { 00065 # We might not need the 'usable' bit, but let's be safe. Theoretically 00066 # this might return wrong results for old versions, but it's probably 00067 # good enough. 00068 $name = User::getCanonicalName( $name, 'usable' ); 00069 00070 if ( !is_string( $name ) ) { 00071 return false; 00072 } 00073 00074 return $this->initFromCond( array( 'user_name' => $name ) ); 00075 } 00076 00081 protected function initFromId( $id ) { 00082 return $this->initFromCond( array( 'user_id' => $id ) ); 00083 } 00084 00089 private function initFromCond( $cond ) { 00090 global $wgExternalAuthConf; 00091 00092 $this->mDb = DatabaseBase::factory( $wgExternalAuthConf['DBtype'], 00093 array( 00094 'host' => $wgExternalAuthConf['DBserver'], 00095 'user' => $wgExternalAuthConf['DBuser'], 00096 'password' => $wgExternalAuthConf['DBpassword'], 00097 'dbname' => $wgExternalAuthConf['DBname'], 00098 'tablePrefix' => $wgExternalAuthConf['DBprefix'], 00099 ) 00100 ); 00101 00102 $row = $this->mDb->selectRow( 00103 'user', 00104 array( 00105 'user_name', 'user_id', 'user_password', 'user_email', 00106 'user_email_authenticated' 00107 ), 00108 $cond, 00109 __METHOD__ 00110 ); 00111 if ( !$row ) { 00112 return false; 00113 } 00114 $this->mRow = $row; 00115 00116 return true; 00117 } 00118 00119 # TODO: Implement initFromCookie(). 00120 00121 public function getId() { 00122 return $this->mRow->user_id; 00123 } 00124 00128 public function getName() { 00129 return $this->mRow->user_name; 00130 } 00131 00132 public function authenticate( $password ) { 00133 # This might be wrong if anyone actually uses the UserComparePasswords hook 00134 # (on either end), so don't use this if you those are incompatible. 00135 return User::comparePasswords( $this->mRow->user_password, $password, 00136 $this->mRow->user_id ); 00137 } 00138 00139 public function getPref( $pref ) { 00140 # @todo FIXME: Return other prefs too. Lots of global-riddled code that does 00141 # this normally. 00142 if ( $pref === 'emailaddress' 00143 && $this->row->user_email_authenticated !== null ) { 00144 return $this->mRow->user_email; 00145 } 00146 return null; 00147 } 00148 00152 public function getGroups() { 00153 # @todo FIXME: Untested. 00154 $groups = array(); 00155 $res = $this->mDb->select( 00156 'user_groups', 00157 'ug_group', 00158 array( 'ug_user' => $this->mRow->user_id ), 00159 __METHOD__ 00160 ); 00161 foreach ( $res as $row ) { 00162 $groups[] = $row->ug_group; 00163 } 00164 return $groups; 00165 } 00166 00167 # TODO: Implement setPref(). 00168 }