r49875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49874‎ | r49875 | r49876 >
Date:14:33, 25 April 2009
Author:btongminh
Status:deferred
Tags:
Comment:
Update error handling, among other things.
Modified paths:
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssGroup.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuth.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuthPlugin.php (modified) (history)

Diff [purge]

Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuthPlugin.php
@@ -34,7 +34,7 @@
3535 }
3636
3737 function getDB( $db = DB_LAST ) {
38 - return wfGetDB( $db, array(), $this->wikiName );
 38+ return wfGetDB( $db, array(), $this->wikiNam0e );
3939 }
4040
4141 function userExists( $username ) {
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuth.php
@@ -18,7 +18,7 @@
1919
2020 $wgExtensionCredits['other'][] = array(
2121 'name' => 'NssMySQLAuth',
22 - 'version' => '1.0',
 22+ 'version' => '1.1',
2323 'author' => 'Bryan Tong Minh',
2424 'description' => 'A plugin to authenticate against a libnss-mysql database. Contains an [[Special:AccountManager|account manager]]',
2525 'descriptionmsg' => 'nss-desc',
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssGroup.php
@@ -3,8 +3,8 @@
44 class NssGroup {
55 private static $groupsByGid = array();
66 public static function nameFromGid( $gid ) {
7 - if ( isset( self::$groupsByGid( $gid ) ) )
8 - return self::$groupsByGid( $gid );
 7+ if ( isset( self::$groupsByGid[$gid] ) )
 8+ return self::$groupsByGid[$gid];
99
1010 global $wgAuth;
1111 $dbr = $wgAuth->getDB( DB_READ );
@@ -13,6 +13,6 @@
1414 $row = $res->fetchObject();
1515 self::$groupsByGid[$gid] = $row ? $row->grp_name : strval( $gid );
1616
17 - return self::$groupsByGid( $gid );
 17+ return self::$groupsByGid[$gid];
1818 }
1919 }
\ No newline at end of file
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php
@@ -31,6 +31,10 @@
3232 $this->props = array();
3333 $this->changed = array();
3434 }
 35+
 36+ function get( $name ) {
 37+ return $this->props[$name];
 38+ }
3539 function set( $name, $value ) {
3640 $this->changed[] = $name;
3741 $this->props[$name] = $value;
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php
@@ -24,7 +24,7 @@
2525 // Load the user existence from passwd
2626 $result = $dbr->select( 'passwd',
2727 array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' ),
28 - array( 'pwd_name', $this->name ),
 28+ array( 'pwd_name' => $this->name ),
2929 __METHOD__
3030 );
3131 $row = $result->fetchObject();
@@ -62,9 +62,30 @@
6363 }
6464
6565 function get( $name ) {
66 - return $this->properties->get( $name );
 66+ switch ( $name ) {
 67+ case 'username':
 68+ return $this->name;
 69+ case 'home':
 70+ return $this->home;
 71+ case 'active':
 72+ return $this->active;
 73+ case 'email':
 74+ return $this->email;
 75+ default:
 76+ return $this->properties->get( $name );
 77+ }
6778 }
6879 function set( $name, $value ) {
 80+ switch ( $name ) {
 81+ case 'username':
 82+ return;
 83+ case 'home':
 84+ $this->home = $value;
 85+ case 'active':
 86+ $this->active = $value;
 87+ case 'email':
 88+ $this->email = $value;
 89+ }
6990 return $this->properties->set( $name, $value );
7091 }
7192
@@ -86,7 +107,7 @@
87108 global $wgAuth;
88109 $dbr = $wgAuth->getDB( DB_READ );
89110
90 - $res = $dbr->select( 'passwd', 'pwd_name', __METHOD__ );
 111+ $res = $dbr->select( 'passwd', 'pwd_name', array(), __METHOD__ );
91112
92113 $names = array();
93114 while ( $row = $res->fetchObject() )
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php
@@ -46,11 +46,15 @@
4747 }
4848
4949 function makeRow( $prop ) {
 50+ $label = wfMsg( "am-$prop" );
 51+ if ( wfEmptyMsg( "am-$prop", $label ) )
 52+ $label = "am-$prop";
 53+
5054 return ( "\t<tr><td>" .
51 - Xml::label( wfMsg( "am-$prop" ), "am-$prop" ) .
 55+ Xml::label( $label, "am-$prop" ) .
5256 "</td><td>" .
5357 Xml::input( /* $name */ "am-$prop", /* $size */ false,
54 - /* $value */ $this->get( $prop ),
 58+ /* $value */ $this->user->get( $prop ),
5559 array( 'id' => "am-$prop" ) ) .
5660 "</td></tr>\n"
5761 );
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php
@@ -3,20 +3,77 @@
44 class SpecialAccountManager extends SpecialPage {
55 function __construct() {
66 parent::__construct( 'AccountManager', 'accountmanager', false );
 7+ $this->error = false;
78 }
89
9 - function processData() {
 10+ function processData( $action ) {
1011 global $wgRequest;
 12+ $action = $wgRequest->getVal( 'action' );
 13+ $username = $wgRequest->getVal( 'user' );
1114
 15+ if ( !( $action == 'create' || $action == 'submit' ) )
 16+ return;
1217
 18+ $user = new NssUser( $username );
 19+ $user->load();
 20+
 21+ if ( $action == 'submit' && !$user->exists )
 22+ return;
 23+
 24+ // Extract post data
 25+ $post = $wgRequest->getValues();
 26+ foreach( $post as $key => $value ) {
 27+ if( substr( $key, 0, 3 ) != 'am-' )
 28+ continue;
 29+ $parts = explode( '-', $key, 2 );
 30+ if( count( $parts ) != 2 )
 31+ continue;
 32+
 33+ $keyname = str_replace( '_', '-', strtolower( $parts[1] ) );
 34+ $user->set( $keyname, $value );
 35+ }
 36+
 37+ if ( $action == 'submit' ) {
 38+ $user->commit();
 39+ } else {
 40+ global $wgAuth, $wgPasswordSender;
 41+
 42+ $password = $wgAuth->createAccount( $username );
 43+ $user->insert();
 44+
 45+ $email = wfMsg( 'am-welcome-mail', $username, $password );
 46+ $mailSubject = wfMsg( 'am-welcome-mail-subject' );
 47+ $mailFrom = new MailAddress( $wgPasswordSender );
 48+ $mailTo = new MailAddress( User::newFromName( $username ) );
 49+
 50+ $mailResult = UserMailer::send( $mailTo, $mailFrom, $mailSubject, $email );
 51+
 52+ if ( WikiError::isError( $mailResult ) ) {
 53+ $this->error = $mailResult->getMessage();
 54+ return false;
 55+ }
 56+ }
 57+ $wgAuth->getDB( DB_WRITE )->immediateCommit();
 58+ return true;
 59+
1360 }
1461
1562 function execute() {
16 - global $wgRequest;
 63+ global $wgRequest, $wgUser, $wgOut;
 64+ if( !$this->userCanExecute( $wgUser ) )
 65+ return $this->displayRestrictionError();
 66+ $this->setHeaders();
1767
18 - $action = $wgRequest->getVal( 'action' );
1968 $username = $wgRequest->getVal( 'user' );
2069
 70+ $result = $this->processData();
 71+ if ( $result === true ) {
 72+ $wgOut->addHTML( Xml::element('p', array(), wfMsg( 'am-updated' ) ) );
 73+ } else if ( $result === false ) {
 74+ $wgOut->addHTML( Xml::element( 'p', array( 'class' => 'error' ),
 75+ wfMsg( $this->error ) ) . "\n" );
 76+ }
 77+
2178 $list = new AmUserListView();
2279 $list->execute();
2380

Status & tagging log