Index: trunk/extensions/NssMySQLAuth/NssMySQLAuth.i18n.php |
— | — | @@ -1,14 +1,23 @@ |
2 | 2 | <?php |
| 3 | +/* |
| 4 | + * Internationalization for NssMySQLAuth extension. |
| 5 | + */ |
3 | 6 | |
4 | 7 | $messages = array(); |
5 | 8 | |
| 9 | +/** |
| 10 | + * English |
| 11 | + * @author Bryan Tong Minh |
| 12 | + */ |
6 | 13 | $messages['en'] = array( |
7 | 14 | 'accountmanager' => 'Account manager', |
8 | 15 | |
9 | 16 | 'am-username' => 'username', |
10 | | - 'am-email' => 'email', |
| 17 | + 'am-email' => 'e-mail', |
11 | 18 | 'am-active' => 'active', |
12 | | - |
| 19 | + 'am-updated' => 'Your changes have been saved successfully', |
| 20 | + |
| 21 | + 'nss-desc' => 'A plugin to authenticate against a libnss-mysql database. Contains an [[Special:AccountManager|account manager]]', |
13 | 22 | 'nss-save-changes' => 'Save changes', |
14 | 23 | 'nss-create-account-header' => 'Create new account', |
15 | 24 | 'nss-create-account' => 'Create account', |
Index: trunk/extensions/NssMySQLAuth/NssMySQLAuthPlugin.php |
— | — | @@ -14,14 +14,14 @@ |
15 | 15 | global $wgAuth, $wgHooks; |
16 | 16 | global $wgNssMySQLAuthDB; |
17 | 17 | $wgAuth = new self( $wgNssMySQLAuthDB ); |
18 | | - |
| 18 | + |
19 | 19 | $wgHooks['UserEffectiveGroups'][] = array( $wgAuth, 'onUserEffectiveGroups' ); |
20 | 20 | $wgHooks['UserGetEmail'][] = array( $wgAuth, 'onUserGetEmail' ); |
21 | 21 | $wgHooks['UserSetEmail'][] = array( $wgAuth, 'onUserSetEmail' ); |
22 | | - |
| 22 | + |
23 | 23 | wfLoadExtensionMessages( 'nssmysqlauth' ); |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | function __construct( $wikiName = false ) { |
27 | 27 | $this->wikiName = $wikiName; |
28 | 28 | $this->users = array(); |
— | — | @@ -30,22 +30,22 @@ |
31 | 31 | function getDB( $db = DB_LAST ) { |
32 | 32 | return wfGetDB( $db, array(), $this->wikiName ); |
33 | 33 | } |
34 | | - |
| 34 | + |
35 | 35 | function userExists( $username ) { |
36 | 36 | if( isset( $this->users[$username] )) |
37 | 37 | return $this->users[$username]; |
38 | 38 | |
39 | 39 | $dbr = $this->getDB( DB_READ ); |
40 | | - return $this->users[$username] = |
41 | | - false !== $dbr->select( |
| 40 | + return $this->users[$username] = |
| 41 | + false !== $dbr->select( |
42 | 42 | 'passwd', 1, array( 'pwd_name' => $username ), |
43 | 43 | __METHOD__ |
44 | 44 | ); |
45 | 45 | } |
46 | | - |
| 46 | + |
47 | 47 | function authenticate( $username, $password ) { |
48 | 48 | $dbr = $this->getDB( DB_READ ); |
49 | | - $res = $dbr->selectRow( |
| 49 | + $res = $dbr->selectRow( |
50 | 50 | 'passwd', |
51 | 51 | array( 'pwd_name', 'pwd_password' ), |
52 | 52 | array( 'pwd_name' => $username ), |
— | — | @@ -56,56 +56,56 @@ |
57 | 57 | return Md5crypt::encryptPassword( $password, $res->pwd_password ) |
58 | 58 | == $res->pwd_password; |
59 | 59 | } |
60 | | - |
| 60 | + |
61 | 61 | function updateUser( &$user ) { |
62 | 62 | $dbr = $this->getDB( DB_READ ); |
63 | 63 | $res = $dbr->selectRow( |
64 | | - 'passwd', |
| 64 | + 'passwd', |
65 | 65 | array( 'pwd_email' ), |
66 | 66 | array( 'pwd_name' => $user->getName() ), |
67 | 67 | __METHOD__ |
68 | 68 | ); |
69 | | - |
| 69 | + |
70 | 70 | if( $res === false ) return true; |
71 | | - |
72 | | - $user->setEmail( $res->pwd_email ); |
| 71 | + |
| 72 | + $user->setEmail( $res->pwd_email ); |
73 | 73 | return true; |
74 | 74 | } |
75 | | - |
| 75 | + |
76 | 76 | function autoCreate() { |
77 | 77 | return true; |
78 | 78 | } |
79 | 79 | function setPassword( $user, $password ) { |
80 | 80 | $encryptedPassword = Md5crypt::encryptPassword( $password ); |
81 | 81 | $dbw = $this->getDB( DB_WRITE ); |
82 | | - return true == $dbw->update( |
83 | | - 'passwd', |
84 | | - array( |
| 82 | + return true == $dbw->update( |
| 83 | + 'passwd', |
| 84 | + array( |
85 | 85 | 'pwd_password' => $encryptedPassword, |
86 | 86 | 'pwd_password_lastchange' => wfTimestamp( TS_UNIX ), |
87 | | - ), |
| 87 | + ), |
88 | 88 | array( 'pwd_name' => $user->getName() ), |
89 | 89 | __METHOD__ |
90 | 90 | ); |
91 | 91 | } |
92 | | - |
| 92 | + |
93 | 93 | function updateExternalDB( $user ) { |
94 | 94 | // Email updated via hook |
95 | 95 | return true; |
96 | 96 | } |
97 | | - |
| 97 | + |
98 | 98 | function canCreateAccounts() { |
99 | 99 | return false; |
100 | 100 | } |
101 | | - |
| 101 | + |
102 | 102 | function addUser( $user, $password, $email='', $realname='' ) { |
103 | 103 | return false; |
104 | 104 | } |
105 | | - |
| 105 | + |
106 | 106 | function strict() { |
107 | 107 | return false; |
108 | 108 | } |
109 | | - |
| 109 | + |
110 | 110 | function onUserEffectiveGroups( &$user, &$groups ) { |
111 | 111 | if( !$this->userExists( $user->getName() ) ) |
112 | 112 | return true; |
— | — | @@ -119,68 +119,67 @@ |
120 | 120 | ); |
121 | 121 | while( $row = $res->fetchObject() ) |
122 | 122 | $groups[] = $row->gm_group; |
123 | | - |
| 123 | + |
124 | 124 | return true; |
125 | 125 | } |
126 | | - |
| 126 | + |
127 | 127 | function onUserGetEmail( $user, &$address ) { |
128 | 128 | if( !$this->userExists( $user->getName() ) ) |
129 | 129 | return true; |
130 | 130 | |
131 | 131 | $dbr = $this->getDB( DB_READ ); |
132 | | - $row = $dbr->selectRow( 'passwd' , 'pwd_email', |
| 132 | + $row = $dbr->selectRow( 'passwd' , 'pwd_email', |
133 | 133 | array( 'pwd_name' => $user->getName() ) ); |
134 | 134 | if( $row ) $address = $row->pwd_email; |
135 | 135 | return true; |
136 | 136 | |
137 | 137 | } |
138 | | - |
| 138 | + |
139 | 139 | function onUserSetEmail( $user, &$address ) { |
140 | 140 | if( !$this->userExists( $user->getName() ) ) |
141 | 141 | return true; |
142 | 142 | |
143 | 143 | $dbw = $this->getDB( DB_WRITE ); |
144 | 144 | return true == $dbw->update( |
145 | | - 'passwd', |
| 145 | + 'passwd', |
146 | 146 | array( 'pwd_email' => $address ), |
147 | 147 | array( 'pwd_name' => $user->getName() ), |
148 | 148 | __METHOD__ |
149 | 149 | ); |
150 | 150 | } |
151 | | - |
| 151 | + |
152 | 152 | /** |
153 | | - * Create an account, returning a random password |
154 | | - */ |
155 | | - function createAccount( $username, $options ) { |
156 | | - global $wgDefaultGid, $wgHomeDirectory; |
157 | | - $password = User::randomPassword(); |
158 | | - |
159 | | - $insert = array( |
160 | | - 'pwd_name' => strtolower( $username ), |
161 | | - 'pwd_password' => Md5crypt::encryptPassword( $password ), |
162 | | - 'pwd_password_lastchange' => wfTimestamp( TS_UNIX ), |
163 | | - 'pwd_gid' => $wgDefaultGid, |
164 | | - 'pwd_home' => str_replace( '$1', strtolower( $username ), $wgHomeDirectory ) |
165 | | - ); |
166 | | - |
167 | | - // $options is something that is passed to user_props |
168 | | - $insert['pwd_email'] = $options['email']; |
169 | | - $insert['pwd_active'] = $options['active']; |
170 | | - |
171 | | - // Guess a nice uid. We actually need a lock here |
172 | | - $dbw = $this->getDB( DB_MASTER ); |
173 | | - $row = $dbw->selectRow( 'passwd', 'MAX(pwd_uid) + 1 AS uid', array(), __METHOD__ ); |
174 | | - $uid = $row->uid; |
175 | | - if ( function_exists( 'posix_getpwuid' ) ) { |
176 | | - while( posix_getpwuid( $uid ) ) |
177 | | - $uid++; |
178 | | - } |
179 | | - |
180 | | - $insert['pwd_uid'] = $uid; |
181 | | - |
182 | | - $dbw->insert( 'passwd', $insert, __METHOD__ ); |
183 | | - |
184 | | - return $password; |
185 | | - } |
| 153 | + * Create an account, returning a random password |
| 154 | + */ |
| 155 | + function createAccount( $username, $options ) { |
| 156 | + global $wgDefaultGid, $wgHomeDirectory; |
| 157 | + $password = User::randomPassword(); |
186 | 158 | |
| 159 | + $insert = array( |
| 160 | + 'pwd_name' => strtolower( $username ), |
| 161 | + 'pwd_password' => Md5crypt::encryptPassword( $password ), |
| 162 | + 'pwd_password_lastchange' => wfTimestamp( TS_UNIX ), |
| 163 | + 'pwd_gid' => $wgDefaultGid, |
| 164 | + 'pwd_home' => str_replace( '$1', strtolower( $username ), $wgHomeDirectory ) |
| 165 | + ); |
| 166 | + |
| 167 | + // $options is something that is passed to user_props |
| 168 | + $insert['pwd_email'] = $options['email']; |
| 169 | + $insert['pwd_active'] = $options['active']; |
| 170 | + |
| 171 | + // Guess a nice uid. We actually need a lock here |
| 172 | + $dbw = $this->getDB( DB_MASTER ); |
| 173 | + $row = $dbw->selectRow( 'passwd', 'MAX(pwd_uid) + 1 AS uid', array(), __METHOD__ ); |
| 174 | + $uid = $row->uid; |
| 175 | + if ( function_exists( 'posix_getpwuid' ) ) { |
| 176 | + while( posix_getpwuid( $uid ) ) |
| 177 | + $uid++; |
| 178 | + } |
| 179 | + |
| 180 | + $insert['pwd_uid'] = $uid; |
| 181 | + |
| 182 | + $dbw->insert( 'passwd', $insert, __METHOD__ ); |
| 183 | + |
| 184 | + return $password; |
| 185 | + } |
187 | 186 | } |
Index: trunk/extensions/NssMySQLAuth/NssMySQLAuth.php |
— | — | @@ -8,28 +8,38 @@ |
9 | 9 | * or any later version. |
10 | 10 | * |
11 | 11 | */ |
12 | | - |
| 12 | + |
13 | 13 | ### READ BEFORE USING ### |
14 | | - /* |
15 | | - * This plugin allows authentication against an libnss-mysql database and thus |
16 | | - * allows the use of the same login for MediaWiki as for shell. |
17 | | - * |
18 | | - */ |
19 | | - |
| 14 | +/* |
| 15 | + * This plugin allows authentication against an libnss-mysql database and thus |
| 16 | + * allows the use of the same login for MediaWiki as for shell. |
| 17 | + * |
| 18 | + */ |
20 | 19 | |
21 | | -$wgAutoloadClasses['NssMySQLAuthPlugin'] = dirname( __FILE__ ) . '/NssMySQLAuthPlugin.php'; |
22 | | -$wgAutoloadClasses['Md5crypt'] = dirname( __FILE__ ) . '/Md5crypt.php'; |
23 | | -$wgAutoloadClasses['SpecialAccountManager'] = dirname( __FILE__ ) . '/SpecialAccountManager.php'; |
| 20 | +$wgExtensionCredits['other'][] = array( |
| 21 | + 'name' => 'NssMySQLAuth', |
| 22 | + 'version' => '1.0', |
| 23 | + 'author' => 'Bryan Tong Minh', |
| 24 | + 'description' => 'A plugin to authenticate against a libnss-mysql database. Contains an [[Special:AccountManager|account manager]]', |
| 25 | + 'descriptionmsg' => 'nss-desc', |
| 26 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:NssMySQLAuth', |
| 27 | +); |
| 28 | + |
| 29 | +$dir = dirname( __FILE__ ) . '/'; |
| 30 | +$wgExtensionMessagesFiles['nssmysqlauth'] = $dir . 'NssMySQLAuth.i18n.php'; |
| 31 | +$wgExtensionAliasFiles['nssmysqlauth'] = $dir . 'NssMySQLAuth.alias.php'; |
| 32 | + |
| 33 | +$wgAutoloadClasses['NssMySQLAuthPlugin'] = $dir . 'NssMySQLAuthPlugin.php'; |
| 34 | +$wgAutoloadClasses['Md5crypt'] = $dir . 'Md5crypt.php'; |
| 35 | +$wgAutoloadClasses['SpecialAccountManager'] = $dir . 'SpecialAccountManager.php'; |
24 | 36 | $wgSpecialPages['AccountManager'] = 'SpecialAccountManager'; |
25 | 37 | |
26 | 38 | $wgNssMySQLAuthDB = false; |
27 | 39 | |
28 | 40 | $wgExtensionFunctions[] = array( 'NssMySQLAuthPlugin', 'initialize' ); |
29 | 41 | |
30 | | -$wgExtensionMessagesFiles['nssmysqlauth'] = dirname( __FILE__ ).'/NssMySQLAuth.i18n.php'; |
31 | | - |
32 | 42 | $wgUserProperties = array( 'address', 'city' ); |
33 | 43 | $wgActivityModes = array( 'active', 'inactive' ); |
34 | 44 | |
35 | 45 | $wgDefaultGid = 1001; |
36 | | -$wgHomeDirectory = '/home/$1'; |
\ No newline at end of file |
| 46 | +$wgHomeDirectory = '/home/$1'; |
Index: trunk/extensions/NssMySQLAuth/tables.sql |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | pwd_shell varchar(255) default '/bin/sh', |
14 | 14 | pwd_active varchar(15) default 1, |
15 | 15 | pwd_email varchar(255) not null, |
16 | | - |
| 16 | + |
17 | 17 | PRIMARY KEY (pwd_uid), |
18 | 18 | UNIQUE INDEX (pwd_name) |
19 | 19 | ) character set ascii collate ascii_general_ci; |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | grp_gid int not null, |
23 | 23 | grp_name varchar(255), |
24 | 24 | grp_password varchar(255) not null, |
25 | | - |
| 25 | + |
26 | 26 | PRIMARY KEY(grp_gid), |
27 | 27 | INDEX (grp_name) |
28 | 28 | ) character set ascii collate ascii_general_ci; |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | CREATE TABLE group_membership ( |
31 | 31 | gm_user int not null, |
32 | 32 | gm_group varchar(255), |
33 | | - |
| 33 | + |
34 | 34 | PRIMARY KEY (gm_user, gm_group), |
35 | 35 | KEY (gm_group) |
36 | 36 | ) character set ascii collate ascii_general_ci; |
— | — | @@ -57,4 +57,3 @@ |
58 | 58 | GRANT SELECT (pwd_uid, pwd_name, pwd_gid, pwd_home, pwd_shell, pwd_active) ON nss_auth.passwd TO `nss-user`@`localhost`; |
59 | 59 | GRANT SELECT ON nss_auth.groups TO `nss-user`@`localhost`; |
60 | 60 | GRANT SELECT ON nss_auth.group_membership TO `nss-user`@`localhost`; |
61 | | - |
Index: trunk/extensions/NssMySQLAuth/NssMySQLAuth.alias.php |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for special pages |
| 5 | + */ |
| 6 | + |
| 7 | +$aliases = array(); |
| 8 | + |
| 9 | +/** English |
| 10 | + * @author Bryan Tong Minh |
| 11 | + */ |
| 12 | +$aliases['en'] = array( |
| 13 | + 'AccountManager' => array( 'AccountManager' ), |
| 14 | +); |
Property changes on: trunk/extensions/NssMySQLAuth/NssMySQLAuth.alias.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 15 | + native |
Added: svn:keywords |
2 | 16 | + Id |
Index: trunk/extensions/NssMySQLAuth/libnss-mysql.cfg |
— | — | @@ -8,9 +8,9 @@ |
9 | 9 | getgrent SELECT grp_name, grp_password, grp_gid FROM groups |
10 | 10 | memsbygid SELECT pwd_name FROM group_membership, groups, passwd WHERE gm_group = grp_name AND gm_user = pwd_uid AND grp_gid = '%1$u' |
11 | 11 | gidsbymem SELECT grp_gid FROM group_membership, groups, passwd WHERE gm_group = grp_name AND gm_user = pwd_uid AND pwd_name = '%1$s' |
12 | | - |
13 | | -host localhost |
14 | | -database nss_auth |
15 | | -username nss-user |
| 12 | + |
| 13 | +host localhost |
| 14 | +database nss_auth |
| 15 | +username nss-user |
16 | 16 | password publiclyviewablepassword |
17 | | -socket /var/run/mysqld/mysqld.sock |
| 17 | +socket /var/run/mysqld/mysqld.sock |
Index: trunk/extensions/NssMySQLAuth/Md5crypt.php |
— | — | @@ -49,13 +49,13 @@ |
50 | 50 | */ |
51 | 51 | |
52 | 52 | class Md5crypt { |
53 | | - private static $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 53 | + private static $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
54 | 54 | |
55 | 55 | static function to64($v, $n) { |
56 | 56 | $ret = ''; |
57 | | - |
| 57 | + |
58 | 58 | while(--$n >= 0) { |
59 | | - $ret .= self::$itoa64{$v & 0x3f}; |
| 59 | + $ret .= self::$itoa64{$v & 0x3f}; |
60 | 60 | $v = $v >> 6; |
61 | 61 | } |
62 | 62 | return $ret; |
— | — | @@ -73,29 +73,29 @@ |
74 | 74 | } else { |
75 | 75 | $salt = ''; |
76 | 76 | mt_srand((double)(microtime() * 10000000)); |
77 | | - |
| 77 | + |
78 | 78 | while(strlen($salt) < 8) { |
79 | 79 | $salt .= self::$itoa64{mt_rand(0, strlen(self::$itoa64))}; |
80 | 80 | } |
81 | 81 | } |
82 | | - |
| 82 | + |
83 | 83 | $ctx = $pw . $Magic . $salt; |
84 | | - |
| 84 | + |
85 | 85 | $final = pack('H*', md5($pw . $salt . $pw)); |
86 | | - |
| 86 | + |
87 | 87 | for ($pl = strlen($pw); $pl > 0; $pl -= 16) { |
88 | 88 | $ctx .= substr($final, 0, ($pl > 16) ? 16 : $pl); |
89 | 89 | } |
90 | | - |
| 90 | + |
91 | 91 | // Now the 'weird' xform |
92 | | - for($i = strlen($pw); $i; $i >>= 1) { |
| 92 | + for($i = strlen($pw); $i; $i >>= 1) { |
93 | 93 | if($i & 1) { // This comes from the original version, |
94 | | - $ctx .= pack("C", 0); // where a memset() is done to $final |
| 94 | + $ctx .= pack("C", 0); // where a memset() is done to $final |
95 | 95 | } else { // before this loop |
96 | 96 | $ctx .= $pw{0}; |
97 | 97 | } |
98 | 98 | } |
99 | | - |
| 99 | + |
100 | 100 | $final = pack('H*', md5($ctx)); // The following is supposed to make |
101 | 101 | // things run slower |
102 | 102 | |
— | — | @@ -135,10 +135,10 @@ |
136 | 136 | |(intval(ord($final{9})) << 8) |
137 | 137 | |(intval(ord($final{15}))), 4); |
138 | 138 | $passwd .= self::to64((intval(ord($final{4}) << 16) |
139 | | - |(intval(ord($final{10})) << 8) |
| 139 | + |(intval(ord($final{10})) << 8) |
140 | 140 | |(intval(ord($final{5})))), 4); |
141 | 141 | $passwd .= self::to64((intval(ord($final{11}))), 2); |
142 | | - |
| 142 | + |
143 | 143 | // Return the final string |
144 | 144 | return $Magic . $salt . '$' . $passwd; |
145 | 145 | } |
Index: trunk/extensions/NssMySQLAuth/migrateUser.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | 'pwd_email' => $email |
27 | 27 | ), __METHOD__ ) ) |
28 | 28 | return false; |
29 | | - if ( false == $dbw->insert( 'user_props', array( |
| 29 | + if ( false == $dbw->insert( 'user_props', array( |
30 | 30 | 'up_timestamp' => $dbw->timestamp(), |
31 | 31 | 'up_user' => $username, |
32 | 32 | 'up_name' => 'email', |
Index: trunk/extensions/NssMySQLAuth/SpecialAccountManager.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | parent::__construct( 'AccountManager', 'accountmanager', false ); |
7 | 7 | $this->mErrors = array(); |
8 | 8 | } |
9 | | - |
| 9 | + |
10 | 10 | function execute() { |
11 | 11 | global $wgUser; |
12 | 12 | if( !$this->userCanExecute( $wgUser ) ) |
— | — | @@ -18,16 +18,16 @@ |
19 | 19 | $this->showSuccess(); |
20 | 20 | if( $this->processCreateAccount() === true ) |
21 | 21 | $this->showSuccessCreate(); |
22 | | - |
| 22 | + |
23 | 23 | $this->showErrors(); |
24 | | - |
| 24 | + |
25 | 25 | $this->constructForm(); |
26 | 26 | $this->constructCreateForm(); |
27 | 27 | } |
28 | 28 | |
29 | 29 | function showSuccess() { |
30 | 30 | global $wgOut; |
31 | | - $wgOut->addHTML( Xml::element('p', array(), 'Your changes have been successfully updated' ) ); |
| 31 | + $wgOut->addHTML( Xml::element('p', array(), wfMsg( 'am-updated' ) ) ); |
32 | 32 | } |
33 | 33 | function showSuccessCreate() { |
34 | 34 | return $this->showSuccess(); |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | "</th><th>".wfMsgHtml( 'am-active' )."</th>"); |
51 | 51 | foreach( $wgUserProperties as $i ) { |
52 | 52 | $msg = 'am-'.$i; |
53 | | - $wgOut->addHTML( Xml::element( 'th', null, |
| 53 | + $wgOut->addHTML( Xml::element( 'th', null, |
54 | 54 | wfEmptyMsg( $msg, wfMsg( $msg ) ) ? $i : wfMsgHtml( $msg ) ) ); |
55 | 55 | } |
56 | 56 | $wgOut->addHTML("</tr>\n\n"); |
— | — | @@ -68,14 +68,14 @@ |
69 | 69 | $props = $user->getProps(); |
70 | 70 | foreach( $wgUserProperties as $key ) { |
71 | 71 | $value = isset( $props[$key] ) ? $props[$key] : ''; |
72 | | - $row .= "<td>".Xml::input( |
| 72 | + $row .= "<td>".Xml::input( |
73 | 73 | "am-{$name}-{$key}", 40, $value |
74 | 74 | )."</td>"; |
75 | 75 | } |
76 | 76 | $row .= "</tr>\n"; |
77 | 77 | $wgOut->addHTML( $row ); |
78 | 78 | } |
79 | | - |
| 79 | + |
80 | 80 | $wgOut->addHTML( "</table>\n" ); |
81 | 81 | $wgOut->addHTML( "<div id=\"userprops-submit\">\n". |
82 | 82 | Xml::hidden( 'action', 'submit' ). |
— | — | @@ -83,10 +83,10 @@ |
84 | 84 | 'type' => 'submit', |
85 | 85 | 'value' => wfMsg( 'nss-save-changes' ) |
86 | 86 | ) ). |
87 | | - "</div>\n</form>" |
| 87 | + "</div>\n</form>" |
88 | 88 | ); |
89 | 89 | } |
90 | | - |
| 90 | + |
91 | 91 | function constructCreateForm() { |
92 | 92 | global $wgOut, $wgScript; |
93 | 93 | global $wgUserProperties, $wgActivityModes; |
— | — | @@ -95,11 +95,11 @@ |
96 | 96 | 'action' => $this->getTitle()->getLocalURL(), |
97 | 97 | 'method' => 'post' ) |
98 | 98 | ) ); |
99 | | - |
| 99 | + |
100 | 100 | $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'nss-create-account-header' ) )."\n" ); |
101 | 101 | |
102 | 102 | $wgOut->addHTML( "<table border=\"1\" id=\"newuser\">\n" ); |
103 | | - |
| 103 | + |
104 | 104 | $props = array_merge( array( 'username', 'email' ), $wgUserProperties ); |
105 | 105 | foreach( $props as $i ) { |
106 | 106 | $msg = 'am-'.$i; |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | "</td></tr>\n" |
111 | 111 | ); |
112 | 112 | } |
113 | | - |
| 113 | + |
114 | 114 | global $wgActivityModes; |
115 | 115 | $select = new XmlSelect( "am-active" ); |
116 | 116 | $select->setDefault( 'active' ); |
— | — | @@ -118,7 +118,7 @@ |
119 | 119 | $select->addOption( $key ); |
120 | 120 | $wgOut->addHTML( "\t<tr><th>".wfMsgHtml( 'am-active' ). |
121 | 121 | "</th><td>".$select->getHTML()."</td></tr>\n" ); |
122 | | - |
| 122 | + |
123 | 123 | $wgOut->addHTML( "</table>\n" ); |
124 | 124 | $wgOut->addHTML( "<div id=\"newaccount-submit\">\n". |
125 | 125 | Xml::hidden( 'action', 'create' ). |
— | — | @@ -126,8 +126,8 @@ |
127 | 127 | 'type' => 'submit', |
128 | 128 | 'value' => wfMsg( 'nss-create-account' ) |
129 | 129 | ) ). |
130 | | - "</div>\n</form>" |
131 | | - ); |
| 130 | + "</div>\n</form>" |
| 131 | + ); |
132 | 132 | } |
133 | 133 | |
134 | 134 | function processData() { |
— | — | @@ -145,13 +145,13 @@ |
146 | 146 | |
147 | 147 | $username = strtolower( $parts[1] ); |
148 | 148 | $keyname = strtolower( $parts[2] ); |
149 | | - |
| 149 | + |
150 | 150 | if( !isset( $this->users[$username] ) ) |
151 | 151 | continue; |
152 | 152 | |
153 | 153 | if( !in_array( $keyname, $wgUserProperties ) ) |
154 | 154 | continue; |
155 | | - |
| 155 | + |
156 | 156 | $this->users[$username]->set( $keyname, $value ); |
157 | 157 | } |
158 | 158 | |
— | — | @@ -159,14 +159,14 @@ |
160 | 160 | $user->update(); |
161 | 161 | return true; |
162 | 162 | } |
163 | | - |
| 163 | + |
164 | 164 | function processCreateAccount() { |
165 | 165 | global $wgRequest, $wgUserProperties; |
166 | 166 | if( !$wgRequest->wasPosted() || $wgRequest->getVal('action') != 'create' ) |
167 | 167 | return; |
168 | 168 | |
169 | 169 | $options = array(); |
170 | | - |
| 170 | + |
171 | 171 | $post = $wgRequest->getValues(); |
172 | 172 | foreach( $post as $key => $value ) { |
173 | 173 | if( substr( $key, 0, 3 ) != 'am-' ) |
— | — | @@ -179,22 +179,22 @@ |
180 | 180 | $options[$keyname] = $value; |
181 | 181 | } |
182 | 182 | if( empty( $options['username'] ) ) { |
183 | | - $this->mErrors[] = 'noname'; |
| 183 | + $this->mErrors[] = 'noname'; |
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | $username = $options['username']; |
187 | 187 | unset( $options['username'] ); |
188 | | - |
| 188 | + |
189 | 189 | global $wgAuth; |
190 | 190 | $password = $wgAuth->createAccount($username, $options); |
191 | | - |
| 191 | + |
192 | 192 | $userprops = UserProps::loadFromDb( $username ); |
193 | 193 | if ( !$userprops ) { |
194 | 194 | $this->mErrors[] = 'nss-db-error'; |
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | $this->users[$userprops->getName()] = $userprops; |
198 | | - |
| 198 | + |
199 | 199 | global $wgPasswordSender; |
200 | 200 | $email = wfMsg( 'nss-welcome-mail', $username, $password ); |
201 | 201 | $mailSubject = wfMsg( 'nss-welcome-mail-subject' ); |
— | — | @@ -210,13 +210,13 @@ |
211 | 211 | |
212 | 212 | return true; |
213 | 213 | } |
214 | | - |
| 214 | + |
215 | 215 | function showErrors() { |
216 | 216 | if ( !$this->mErrors ) |
217 | 217 | return; |
218 | 218 | global $wgOut; |
219 | 219 | foreach( $this->mErrors as $error ) |
220 | | - $wgOut->addHTML( |
| 220 | + $wgOut->addHTML( |
221 | 221 | Xml::element( 'p', |
222 | 222 | array( 'class' => 'error' ), |
223 | 223 | wfMsg( $error ) |
— | — | @@ -240,11 +240,11 @@ |
241 | 241 | static function loadFromDb( $username ) { |
242 | 242 | $res = self::select( $username ); |
243 | 243 | $row = $res->fetchObject(); |
244 | | - if ( !$row ) |
| 244 | + if ( !$row ) |
245 | 245 | return false; |
246 | 246 | return new self( $row->pwd_name, $row->pwd_email, $row->pwd_active ); |
247 | 247 | } |
248 | | - |
| 248 | + |
249 | 249 | function __construct( $username, $email = null, $active = null ) { |
250 | 250 | $this->username = $username; |
251 | 251 | $this->props = array(); |
— | — | @@ -267,7 +267,7 @@ |
268 | 268 | return $this->active; |
269 | 269 | } |
270 | 270 | function setActive( $active ) { |
271 | | - $this->active = $active; |
| 271 | + $this->active = $active; |
272 | 272 | } |
273 | 273 | |
274 | 274 | static function select($username = null) { |
— | — | @@ -278,7 +278,7 @@ |
279 | 279 | return $dbr->select( |
280 | 280 | array( 'user_props', 'passwd' ), |
281 | 281 | array( 'up_name', 'up_value', 'pwd_name', 'pwd_email', 'pwd_active' ), |
282 | | - $where, |
| 282 | + $where, |
283 | 283 | __METHOD__, |
284 | 284 | array( 'ORDER BY' => 'pwd_name ASC, up_timestamp ASC' ), |
285 | 285 | array( 'passwd' => array( 'RIGHT JOIN', 'pwd_name = up_user' ) ) |
— | — | @@ -301,7 +301,7 @@ |
302 | 302 | $diff = array_diff_assoc($this->props, $this->old_props); |
303 | 303 | if( !count( $diff ) ) return; |
304 | 304 | |
305 | | - |
| 305 | + |
306 | 306 | global $wgAuth; |
307 | 307 | $dbw = $wgAuth->getDB( DB_WRITE ); |
308 | 308 | $timestamp = $dbw->timestamp(); |
— | — | @@ -309,8 +309,8 @@ |
310 | 310 | if( isset( $diff['email'] ) || isset( $diff['active'] ) ) { |
311 | 311 | if ( isset( $diff['email'] ) ) $this->email = $diff['email']; |
312 | 312 | if ( isset( $diff['active'] ) ) $this->active = $diff['active']; |
313 | | - $dbw->update( 'passwd', |
314 | | - array( 'pwd_email' => $this->email, 'pwd_active' => $this->active ), |
| 313 | + $dbw->update( 'passwd', |
| 314 | + array( 'pwd_email' => $this->email, 'pwd_active' => $this->active ), |
315 | 315 | array( 'pwd_user' => $this->username ), |
316 | 316 | __METHOD__ |
317 | 317 | ); |