r25164 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25163‎ | r25164 | r25165 >
Date:17:04, 26 August 2007
Author:tlaqua
Status:old
Tags:
Comment:
Borrowed ChangePassword::main() text f/ DB abstraction.
Complete support f/ Internationalization.
Updated ExtensionCreds.
Modified paths:
  • /trunk/extensions/PasswordReset/PasswordReset.i18n.php (modified) (history)
  • /trunk/extensions/PasswordReset/PasswordReset.php (modified) (history)
  • /trunk/extensions/PasswordReset/PasswordReset_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PasswordReset/PasswordReset_body.php
@@ -1,4 +1,16 @@
22 <?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+ */
315 class PasswordReset extends SpecialPage
416 {
517 function PasswordReset() {
@@ -27,13 +39,13 @@
2840
2941 if ( !is_object( $objUser ) || $userID == 0 ) {
3042 $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" );
3244 } else {
3345 $validUser = true;
3446 }
3547 } else {
3648 $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" );
3850 }
3951
4052 $newpass = $wgRequest->getText( 'newpass' );
@@ -45,13 +57,13 @@
4658 } else {
4759 //Passwords DO NOT match
4860 $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" );
5062 }
5163
5264 if (!$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
5365 $validUser = false;
5466 $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" );
5668
5769 }
5870 }
@@ -63,20 +75,20 @@
6476 <form id='passwordresetform' method='post' action=\"$action\">
6577 <table>
6678 <tr>
67 - <td align='right'>Username</td>
 79+ <td align='right'>" . wfMsgForContent('passwordreset-username') . "</td>
6880 <td align='left'><input tabindex='1' type='text' size='20' name='username' id='username' value=\"$username_text\" onFocus=\"document.getElementById('username').select;\" /></td>
6981 </tr>
7082 <tr>
71 - <td align='right'>New Password</td>
 83+ <td align='right'>" . wfMsgForContent('passwordreset-newpass') . "</td>
7284 <td align='left'><input tabindex='2' type='password' size='20' name='newpass' id='newpass' value=\"$newpass\" onFocus=\"document.getElementById('newpass').select;\" /></td>
7385 </tr>
7486 <tr>
75 - <td align='right'>Confirm Password</td>
 87+ <td align='right'>" . wfMsgForContent('passwordreset-confirmpass') . "</td>
7688 <td align='left'><input tabindex='3' type='password' size='20' name='confirmpass' id='confirmpass' value=\"$confirmpass\" onFocus=\"document.getElementById('confirmpass').select;\" /></td>
7789 </tr>
7890 <tr>
7991 <td>&nbsp;</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>
8193 </tr>
8294 </table>
8395 <input type='hidden' name='token' value='$token' />
@@ -90,19 +102,18 @@
91103 }
92104 }
93105
94 - function resetPassword( $userID, $newpass ) {
 106+ private function resetPassword( $userID, $newpass ) {
95107 $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);
107118 }
108119
109120 function loadMessages() {
@@ -116,6 +127,6 @@
117128 $wgMessageCache->addMessages( $langMessages, $lang );
118129 }
119130
120 - return true;
 131+ return true;
121132 }
122133 }
Index: trunk/extensions/PasswordReset/PasswordReset.i18n.php
@@ -1,7 +1,20 @@
22 <?php
 3+/** \file
 4+* \brief Internationalization file for the Password Reset Extension.
 5+*/
 6+
37 $allMessages = array(
48 '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'
619 ),
720 'de' => array(
821 'passwordreset' => 'Passwort zurücksetzen',
Index: trunk/extensions/PasswordReset/PasswordReset.php
@@ -1,4 +1,8 @@
22 <?php
 3+/** \file
 4+* \brief Contains setup code for the Password Reset Extension.
 5+*/
 6+
37 # Not a valid entry point, skip unless MEDIAWIKI is defined
48 if (!defined('MEDIAWIKI')) {
59 echo "Password Reset extension";
@@ -8,9 +12,9 @@
913 $wgExtensionCredits['specialpage'][] = array(
1014 'name'=>'Password Reset',
1115 'url'=>'http://www.mediawiki.org/wiki/Extension:Password_Reset',
12 - 'author'=>'Tim Laqua, t.laqua at gmail dot com',
 16+ 'author'=>'Tim Laqua',
1317 'description'=>"Resets Wiki user's passwords - requires 'userrights' privileges",
14 - 'version'=>'1.0'
 18+ 'version'=>'1.1'
1519 );
1620
1721 $wgAutoloadClasses['PasswordReset'] = dirname(__FILE__) . '/PasswordReset_body.php';

Status & tagging log