Index: trunk/extensions/PasswordReset/PasswordReset_body.php |
— | — | @@ -1,4 +1,16 @@ |
2 | 2 | <?php |
| 3 | +/** \file |
| 4 | +* \brief Contains code for the PasswordReset Class (extends SpecialPage). |
| 5 | +*/ |
| 6 | + |
| 7 | +///Special page class for the Password Reset extension |
| 8 | +/** |
| 9 | + * Special page that allows sysops to reset local MW user's |
| 10 | + * passwords |
| 11 | + * |
| 12 | + * @addtogroup Extensions |
| 13 | + * @author Tim Laqua <t.laqua@gmail.com> |
| 14 | + */ |
3 | 15 | class PasswordReset extends SpecialPage |
4 | 16 | { |
5 | 17 | function PasswordReset() { |
— | — | @@ -27,13 +39,13 @@ |
28 | 40 | |
29 | 41 | if ( !is_object( $objUser ) || $userID == 0 ) { |
30 | 42 | $validUser = false; |
31 | | - $wgOut->addHTML( "<span style=\"color: red;\">Invalid Username</span><br>\n" ); |
| 43 | + $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsgForContent('passwordreset-invalidusername') . "</span><br>\n" ); |
32 | 44 | } else { |
33 | 45 | $validUser = true; |
34 | 46 | } |
35 | 47 | } else { |
36 | 48 | $validUser = false; |
37 | | - $wgOut->addHTML( "<span style=\"color: red;\">Empty Username</span><br>\n" ); |
| 49 | + $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsgForContent('passwordreset-emptyusername') . "</span><br>\n" ); |
38 | 50 | } |
39 | 51 | |
40 | 52 | $newpass = $wgRequest->getText( 'newpass' ); |
— | — | @@ -45,13 +57,13 @@ |
46 | 58 | } else { |
47 | 59 | //Passwords DO NOT match |
48 | 60 | $passMatch = false; |
49 | | - $wgOut->addHTML( "<span style=\"color: red;\">Passwords do not match.</span><br>\n" ); |
| 61 | + $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsgForContent('passwordreset-nopassmatch') . "</span><br>\n" ); |
50 | 62 | } |
51 | 63 | |
52 | 64 | if (!$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) { |
53 | 65 | $validUser = false; |
54 | 66 | $passMatch = false; |
55 | | - $wgOut->addHTML( "<span style=\"color: red;\">Invalid Edit Token.</span><br>\n" ); |
| 67 | + $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsgForContent('passwordreset-badtoken') . "</span><br>\n" ); |
56 | 68 | |
57 | 69 | } |
58 | 70 | } |
— | — | @@ -63,20 +75,20 @@ |
64 | 76 | <form id='passwordresetform' method='post' action=\"$action\"> |
65 | 77 | <table> |
66 | 78 | <tr> |
67 | | - <td align='right'>Username</td> |
| 79 | + <td align='right'>" . wfMsgForContent('passwordreset-username') . "</td> |
68 | 80 | <td align='left'><input tabindex='1' type='text' size='20' name='username' id='username' value=\"$username_text\" onFocus=\"document.getElementById('username').select;\" /></td> |
69 | 81 | </tr> |
70 | 82 | <tr> |
71 | | - <td align='right'>New Password</td> |
| 83 | + <td align='right'>" . wfMsgForContent('passwordreset-newpass') . "</td> |
72 | 84 | <td align='left'><input tabindex='2' type='password' size='20' name='newpass' id='newpass' value=\"$newpass\" onFocus=\"document.getElementById('newpass').select;\" /></td> |
73 | 85 | </tr> |
74 | 86 | <tr> |
75 | | - <td align='right'>Confirm Password</td> |
| 87 | + <td align='right'>" . wfMsgForContent('passwordreset-confirmpass') . "</td> |
76 | 88 | <td align='left'><input tabindex='3' type='password' size='20' name='confirmpass' id='confirmpass' value=\"$confirmpass\" onFocus=\"document.getElementById('confirmpass').select;\" /></td> |
77 | 89 | </tr> |
78 | 90 | <tr> |
79 | 91 | <td> </td> |
80 | | - <td align='right'><input type='submit' name='submit' value=\"Reset Password\" /></td> |
| 92 | + <td align='right'><input type='submit' name='submit' value=\"" . wfMsgForContent('passwordreset-submit') . "\" /></td> |
81 | 93 | </tr> |
82 | 94 | </table> |
83 | 95 | <input type='hidden' name='token' value='$token' /> |
— | — | @@ -90,19 +102,18 @@ |
91 | 103 | } |
92 | 104 | } |
93 | 105 | |
94 | | - function resetPassword( $userID, $newpass ) { |
| 106 | + private function resetPassword( $userID, $newpass ) { |
95 | 107 | $dbw =& wfGetDB( DB_MASTER ); |
96 | | - |
97 | | - $userTable = $dbw->tableName('user'); |
98 | | - $sql = "update $userTable set user_password=MD5(CONCAT('$userID-',MD5('$newpass'))) WHERE user_id=$userID"; |
99 | | - |
100 | | - $res = $dbw->query($sql); |
101 | | - |
102 | | - if ( $res > 0 ) { |
103 | | - return "Password has been reset for user_id: $userID"; |
104 | | - } else { |
105 | | - return "Unable to reset password for user_id: $userID"; |
106 | | - } |
| 108 | + |
| 109 | + $dbw->update( 'user', |
| 110 | + array( |
| 111 | + 'user_password' => wfEncryptPassword( $userID, $newpass ) |
| 112 | + ), |
| 113 | + array( |
| 114 | + 'user_id' => $userID |
| 115 | + ) |
| 116 | + ); |
| 117 | + return wfMsgForContent('passwordreset-success', $userID); |
107 | 118 | } |
108 | 119 | |
109 | 120 | function loadMessages() { |
— | — | @@ -116,6 +127,6 @@ |
117 | 128 | $wgMessageCache->addMessages( $langMessages, $lang ); |
118 | 129 | } |
119 | 130 | |
120 | | - return true; |
| 131 | + return true; |
121 | 132 | } |
122 | 133 | } |
Index: trunk/extensions/PasswordReset/PasswordReset.i18n.php |
— | — | @@ -1,7 +1,20 @@ |
2 | 2 | <?php |
| 3 | +/** \file |
| 4 | +* \brief Internationalization file for the Password Reset Extension. |
| 5 | +*/ |
| 6 | + |
3 | 7 | $allMessages = array( |
4 | 8 | 'en' => array( |
5 | | - 'passwordreset' => 'Password Reset' |
| 9 | + 'passwordreset' => 'Password Reset', |
| 10 | + 'passwordreset-invalidusername' => 'Invalid Username', |
| 11 | + 'passwordreset-emptyusername' => 'Empty Username', |
| 12 | + 'passwordreset-nopassmatch' => 'Passwords do not match', |
| 13 | + 'passwordreset-badtoken' => 'Invalid Edit Token', |
| 14 | + 'passwordreset-username' => 'Username', |
| 15 | + 'passwordreset-newpass' => 'New Password', |
| 16 | + 'passwordreset-confirmpass' => 'Confirm Password', |
| 17 | + 'passwordreset-submit' => 'Reset Password', |
| 18 | + 'passwordreset-success' => 'Password has been reset for user_id: $1' |
6 | 19 | ), |
7 | 20 | 'de' => array( |
8 | 21 | 'passwordreset' => 'Passwort zurücksetzen', |
Index: trunk/extensions/PasswordReset/PasswordReset.php |
— | — | @@ -1,4 +1,8 @@ |
2 | 2 | <?php |
| 3 | +/** \file |
| 4 | +* \brief Contains setup code for the Password Reset Extension. |
| 5 | +*/ |
| 6 | + |
3 | 7 | # Not a valid entry point, skip unless MEDIAWIKI is defined |
4 | 8 | if (!defined('MEDIAWIKI')) { |
5 | 9 | echo "Password Reset extension"; |
— | — | @@ -8,9 +12,9 @@ |
9 | 13 | $wgExtensionCredits['specialpage'][] = array( |
10 | 14 | 'name'=>'Password Reset', |
11 | 15 | 'url'=>'http://www.mediawiki.org/wiki/Extension:Password_Reset', |
12 | | - 'author'=>'Tim Laqua, t.laqua at gmail dot com', |
| 16 | + 'author'=>'Tim Laqua', |
13 | 17 | 'description'=>"Resets Wiki user's passwords - requires 'userrights' privileges", |
14 | | - 'version'=>'1.0' |
| 18 | + 'version'=>'1.1' |
15 | 19 | ); |
16 | 20 | |
17 | 21 | $wgAutoloadClasses['PasswordReset'] = dirname(__FILE__) . '/PasswordReset_body.php'; |