Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -4804,7 +4804,7 @@ |
4805 | 4805 | |
4806 | 4806 | /** |
4807 | 4807 | * Authentication plugin. |
4808 | | - * @var AuthPlugin |
| 4808 | + * @var $wgAuth AuthPlugin |
4809 | 4809 | */ |
4810 | 4810 | $wgAuth = null; |
4811 | 4811 | |
Index: trunk/phase3/includes/specials/SpecialPasswordReset.php |
— | — | @@ -28,6 +28,16 @@ |
29 | 29 | */ |
30 | 30 | class SpecialPasswordReset extends FormSpecialPage { |
31 | 31 | |
| 32 | + /** |
| 33 | + * @var Message |
| 34 | + */ |
| 35 | + private $email; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var Status |
| 39 | + */ |
| 40 | + private $result; |
| 41 | + |
32 | 42 | public function __construct() { |
33 | 43 | parent::__construct( 'PasswordReset' ); |
34 | 44 | } |
— | — | @@ -69,6 +79,14 @@ |
70 | 80 | ); |
71 | 81 | } |
72 | 82 | |
| 83 | + if( $this->getUser()->isAllowed( 'passwordreset' ) ){ |
| 84 | + $a['Capture'] = array( |
| 85 | + 'type' => 'check', |
| 86 | + 'label-message' => 'passwordreset-capture', |
| 87 | + 'help-message' => 'passwordreset-capture-help', |
| 88 | + ); |
| 89 | + } |
| 90 | + |
73 | 91 | return $a; |
74 | 92 | } |
75 | 93 | |
— | — | @@ -109,6 +127,16 @@ |
110 | 128 | } |
111 | 129 | } |
112 | 130 | |
| 131 | + if( isset( $data['Capture'] ) && !$this->getUser()->isAllowed( 'passwordreset' ) ){ |
| 132 | + // The user knows they don't have the passwordreset permission, but they tried to spoof the form. That's naughty |
| 133 | + throw new PermissionsError( 'passwordreset' ); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @var $firstUser User |
| 138 | + * @var $users User[] |
| 139 | + */ |
| 140 | + |
113 | 141 | if ( isset( $data['Username'] ) && $data['Username'] !== '' ) { |
114 | 142 | $method = 'username'; |
115 | 143 | $users = array( User::newFromName( $data['Username'] ) ); |
— | — | @@ -199,15 +227,15 @@ |
200 | 228 | $password = $user->randomPassword(); |
201 | 229 | $user->setNewpassword( $password ); |
202 | 230 | $user->saveSettings(); |
203 | | - $passwords[] = wfMessage( 'passwordreset-emailelement', $user->getName(), $password ); |
| 231 | + $passwords[] = wfMessage( 'passwordreset-emailelement', $user->getName(), $password )->plain(); // We'll escape the whole thing later |
204 | 232 | } |
205 | 233 | $passwordBlock = implode( "\n\n", $passwords ); |
206 | 234 | |
207 | 235 | // Send in the user's language; which should hopefully be the same |
208 | 236 | $userLanguage = $firstUser->getOption( 'language' ); |
209 | 237 | |
210 | | - $body = wfMessage( $msg )->inLanguage( $userLanguage ); |
211 | | - $body->params( |
| 238 | + $this->email = wfMessage( $msg )->inLanguage( $userLanguage ); |
| 239 | + $this->email->params( |
212 | 240 | $username, |
213 | 241 | $passwordBlock, |
214 | 242 | count( $passwords ), |
— | — | @@ -217,18 +245,38 @@ |
218 | 246 | |
219 | 247 | $title = wfMessage( 'passwordreset-emailtitle' ); |
220 | 248 | |
221 | | - $result = $firstUser->sendMail( $title->text(), $body->text() ); |
| 249 | + $this->result = $firstUser->sendMail( $title->escaped(), $this->email->escaped() ); |
222 | 250 | |
223 | | - if ( $result->isGood() ) { |
| 251 | + // Blank the email if the user is not supposed to see it |
| 252 | + if( !isset( $data['Capture'] ) || !$data['Capture'] ) { |
| 253 | + $this->email = null; |
| 254 | + } |
| 255 | + |
| 256 | + if ( $this->result->isGood() ) { |
224 | 257 | return true; |
| 258 | + } elseif( isset( $data['Capture'] ) && $data['Capture'] ){ |
| 259 | + // The email didn't send, but maybe they knew that and that's why they captured it |
| 260 | + return true; |
225 | 261 | } else { |
226 | 262 | // @todo FIXME: The email didn't send, but we have already set the password throttle |
227 | 263 | // timestamp, so they won't be able to try again until it expires... :( |
228 | | - return array( array( 'mailerror', $result->getMessage() ) ); |
| 264 | + return array( array( 'mailerror', $this->result->getMessage() ) ); |
229 | 265 | } |
230 | 266 | } |
231 | 267 | |
232 | 268 | public function onSuccess() { |
| 269 | + if( $this->getUser()->isAllowed( 'passwordreset' ) && $this->email != null ){ |
| 270 | + // @todo: Logging |
| 271 | + |
| 272 | + if( $this->result->isGood() ){ |
| 273 | + $this->getOutput()->addWikiMsg( 'passwordreset-emailsent-capture' ); |
| 274 | + } else { |
| 275 | + $this->getOutput()->addWikiMsg( 'passwordreset-emailerror-capture', $this->result->getMessage() ); |
| 276 | + } |
| 277 | + |
| 278 | + $this->getOutput()->addHTML( Html::rawElement( 'pre', array(), $this->email->escaped() ) ); |
| 279 | + } |
| 280 | + |
233 | 281 | $this->getOutput()->addWikiMsg( 'passwordreset-emailsent' ); |
234 | 282 | $this->getOutput()->returnToMain(); |
235 | 283 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -1183,6 +1183,8 @@ |
1184 | 1184 | 'passwordreset-pretext' => '{{PLURAL:$1||Enter one of the pieces of data below}}', |
1185 | 1185 | 'passwordreset-username' => 'Username:', |
1186 | 1186 | 'passwordreset-domain' => 'Domain:', |
| 1187 | +'passwordreset-capture' => 'View the resulting email?', |
| 1188 | +'passwordreset-capture-help' => 'If you check this box, the email (with the temporary password) will be shown to you as well as being sent to the user.', |
1187 | 1189 | 'passwordreset-email' => 'E-mail address:', |
1188 | 1190 | 'passwordreset-emailtitle' => 'Account details on {{SITENAME}}', |
1189 | 1191 | 'passwordreset-emailtext-ip' => 'Someone (probably you, from IP address $1) requested a reminder of your |
— | — | @@ -1209,6 +1211,8 @@ |
1210 | 1212 | 'passwordreset-emailelement' => 'Username: $1 |
1211 | 1213 | Temporary password: $2', |
1212 | 1214 | 'passwordreset-emailsent' => 'A reminder e-mail has been sent.', |
| 1215 | +'passwordreset-emailsent-capture' => 'A reminder e-mail has been sent, which is shown below.', |
| 1216 | +'passwordreset-emailerror-capture' => 'A reminder e-mail was generated, which is shown below, but sending it to the user failed: $1', |
1213 | 1217 | |
1214 | 1218 | # Special:ChangeEmail |
1215 | 1219 | 'changeemail' => 'Change E-mail address', |
— | — | @@ -1980,6 +1984,7 @@ |
1981 | 1985 | 'right-siteadmin' => 'Lock and unlock the database', |
1982 | 1986 | 'right-override-export-depth' => 'Export pages including linked pages up to a depth of 5', |
1983 | 1987 | 'right-sendemail' => 'Send e-mail to other users', |
| 1988 | +'right-passwordreset' => 'View password reset emails', |
1984 | 1989 | |
1985 | 1990 | # User rights log |
1986 | 1991 | 'rightslog' => 'User rights log', |