r50458 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50457‎ | r50458 | r50459 >
Date:20:13, 10 May 2009
Author:btongminh
Status:deferred
Tags:
Comment:
HTML fixes and an actually working data submission.
Modified paths:
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AccountManager.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.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)

Diff [purge]

Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php
@@ -36,8 +36,11 @@
3737 return $this->props[$name];
3838 }
3939 function set( $name, $value ) {
 40+ if ( $this->props[$name] == $value )
 41+ return false;
4042 $this->changed[] = $name;
4143 $this->props[$name] = $value;
 44+ return true;
4245 }
4346
4447 function commit() {
@@ -47,12 +50,12 @@
4851 $insert = array();
4952 $timestamp = $dbw->timestamp();
5053
51 - foreach ( $this->props as $name => $value ) {
 54+ foreach ( $this->changed as $name ) {
5255 $insert[] = array(
5356 'up_timestamp' => $timestamp,
5457 'up_user' => $this->name,
5558 'up_name' => $name,
56 - 'up_value' => $value
 59+ 'up_value' => $this->props[$name]
5760 );
5861 }
5962 $dbw->insert( 'user_props', $insert, __METHOD__ );
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php
@@ -36,10 +36,10 @@
3737 if ($this->exists) {
3838 // Extract props from row
3939 $this->uid = $row->pwd_uid;
40 - $this->gid = $row->pwd_home;
 40+ $this->gid = $row->pwd_gid;
4141 $this->home = $row->pwd_home;
4242 $this->active = $row->pwd_active;
43 - $this->email = $row->pwd_home;
 43+ $this->email = $row->pwd_email;
4444
4545 $this->group = NssGroup::nameFromGid( $this->gid );
4646 $this->properties = NssProperties::forUser( $this->name );
@@ -81,10 +81,13 @@
8282 return;
8383 case 'home':
8484 $this->home = $value;
 85+ break;
8586 case 'active':
8687 $this->active = $value;
 88+ break;
8789 case 'email':
8890 $this->email = $value;
 91+ break;
8992 }
9093 return $this->properties->set( $name, $value );
9194 }
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AccountManager.php
@@ -1,8 +1,8 @@
22 <?php
33 $dir = dirname( __FILE__ ) . '/';
44
5 -$wgExtensionMessagesFiles['AccountManager'] = $dir . 'AccountManager.i18n.php';
6 -$wgExtensionAliasesFiles['AccountManager'] = $dir . 'AccountManager.alias.php';
 5+$wgExtensionMessagesFiles['accountmanager'] = $dir . 'AccountManager.i18n.php';
 6+$wgExtensionAliasesFiles['accountmanager'] = $dir . 'AccountManager.alias.php';
77
88 $wgAutoloadClasses['NssUser'] = $dir . 'NssUser.php';
99 $wgAutoloadClasses['NssGroup'] = $dir . 'NssGroup.php';
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php
@@ -33,29 +33,30 @@
3434 function createHeader() {
3535 global $wgOut;
3636
37 - $wgOut->addHtml( Xml::element( 'form', array(
 37+ $wgOut->addHtml( Xml::openElement( 'form', array(
3838 'action' => $this->title->getLocalUrl( array(
3939 'action' => $this->action,
4040 'user' => $this->username,
4141 ) ),
4242 'method' => 'post',
4343 ) ) . "\n" );
44 - $wgOut->addHtml( Xml::element( 'table', array(
 44+ $wgOut->addHtml( Xml::openElement( 'table', array(
4545 'class' => "am-{$this->action}"
4646 ) ) . "\n" );
4747 }
4848
4949 function makeRow( $prop ) {
50 - $label = wfMsg( "am-$prop" );
51 - if ( wfEmptyMsg( "am-$prop", $label ) )
52 - $label = "am-$prop";
 50+ $amName = 'am-'.str_replace( ' ', '-', $prop );
 51+ $label = wfMsg( $amName );
 52+ if ( wfEmptyMsg( $amName, $label ) )
 53+ $label = $prop;
5354
5455 return ( "\t<tr><td>" .
55 - Xml::label( $label, "am-$prop" ) .
 56+ Xml::label( $label, $amName ) .
5657 "</td><td>" .
57 - Xml::input( /* $name */ "am-$prop", /* $size */ false,
 58+ Xml::input( /* $name */ $amName, /* $size */ false,
5859 /* $value */ $this->user->get( $prop ),
59 - array( 'id' => "am-$prop" ) ) .
 60+ array( 'id' => $amName ) ) .
6061 "</td></tr>\n"
6162 );
6263 }
@@ -63,7 +64,7 @@
6465 function createFooter() {
6566 global $wgOut;
6667 $wgOut->addHtml( "</table>\n" .
67 - Xml::element( 'p', array(
 68+ Xml::openElement( 'p', array(
6869 'id' => ''
6970 ) ) );
7071 $wgOut->addHtml( Xml::submitButton( wfMsg( 'am-save-changes' ) ) );
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php
@@ -2,16 +2,18 @@
33
44 class SpecialAccountManager extends SpecialPage {
55 function __construct() {
 6+ wfLoadExtensionMessages( 'accountmanager' );
 7+
68 parent::__construct( 'AccountManager', 'accountmanager', false );
79 $this->error = false;
810 }
911
10 - function processData( $action ) {
11 - global $wgRequest;
 12+ function processData() {
 13+ global $wgRequest, $wgAuth;
1214 $action = $wgRequest->getVal( 'action' );
1315 $username = $wgRequest->getVal( 'user' );
1416
15 - if ( !( $action == 'create' || $action == 'submit' ) )
 17+ if ( !( $action == 'create' || $action == 'submit' ) || !$wgRequest->wasPosted() )
1618 return;
1719
1820 $user = new NssUser( $username );
@@ -23,20 +25,18 @@
2426 // Extract post data
2527 $post = $wgRequest->getValues();
2628 foreach( $post as $key => $value ) {
27 - if( substr( $key, 0, 3 ) != 'am-' )
 29+ // Only am-* data is proper data
 30+ if( substr( $key, 0, 3 ) != 'am-' || strlen( $key ) <= 3 )
2831 continue;
29 - $parts = explode( '-', $key, 2 );
30 - if( count( $parts ) != 2 )
31 - continue;
32 -
33 - $keyname = str_replace( '_', '-', strtolower( $parts[1] ) );
 32+ // Split off the am- prefix
 33+ $keyname = str_replace( '-', ' ', strtolower( substr( $key, 3 ) ) );
3434 $user->set( $keyname, $value );
3535 }
3636
3737 if ( $action == 'submit' ) {
3838 $user->commit();
3939 } else {
40 - global $wgAuth, $wgPasswordSender;
 40+ global $wgPasswordSender;
4141
4242 $password = $wgAuth->createAccount( $username );
4343 $user->insert();

Status & tagging log