Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -60,6 +60,9 @@ |
61 | 61 | 'float' => 'HTMLFloatField', |
62 | 62 | 'info' => 'HTMLInfoField', |
63 | 63 | 'selectorother' => 'HTMLSelectOrOtherField', |
| 64 | + 'submit' => 'HTMLSubmitField', |
| 65 | + 'hidden' => 'HTMLHiddenField', |
| 66 | + |
64 | 67 | # HTMLTextField will output the correct type="" attribute automagically. |
65 | 68 | # There are about four zillion other HTML 5 input types, like url, but |
66 | 69 | # we don't use those at the moment, so no point in adding all of them. |
— | — | @@ -78,6 +81,9 @@ |
79 | 82 | protected $mSubmitID; |
80 | 83 | protected $mSubmitText; |
81 | 84 | protected $mTitle; |
| 85 | + |
| 86 | + protected $mHiddenFields = array(); |
| 87 | + protected $mButtons = array(); |
82 | 88 | |
83 | 89 | /** |
84 | 90 | * Build a new HTMLForm from an array of field attributes |
— | — | @@ -249,6 +255,19 @@ |
250 | 256 | function setIntro( $msg ) { |
251 | 257 | $this->mIntro = $msg; |
252 | 258 | } |
| 259 | + |
| 260 | + /** |
| 261 | + * Add a hidden field to the output |
| 262 | + * @param $name String field name |
| 263 | + * @param $value String field value |
| 264 | + */ |
| 265 | + public function addHiddenField( $name, $value ){ |
| 266 | + $this->mHiddenFields[ $name ] = $value; |
| 267 | + } |
| 268 | + |
| 269 | + public function addButton( $name, $value, $id=null ){ |
| 270 | + $this->mButtons[] = compact( 'name', 'value', 'id' ); |
| 271 | + } |
253 | 272 | |
254 | 273 | /** |
255 | 274 | * Display the form (sending to wgOut), with an appropriate error |
— | — | @@ -305,6 +324,10 @@ |
306 | 325 | |
307 | 326 | $html .= Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n"; |
308 | 327 | $html .= Html::hidden( 'title', $this->getTitle() ) . "\n"; |
| 328 | + |
| 329 | + foreach( $this->mHiddenFields as $name => $value ){ |
| 330 | + $html .= Html::hidden( $name, $value ) . "\n"; |
| 331 | + } |
309 | 332 | |
310 | 333 | return $html; |
311 | 334 | } |
— | — | @@ -335,6 +358,17 @@ |
336 | 359 | ) . "\n"; |
337 | 360 | } |
338 | 361 | |
| 362 | + foreach( $this->mButtons as $button ){ |
| 363 | + $attrs = array( |
| 364 | + 'type' => 'submit', |
| 365 | + 'name' => $button['name'], |
| 366 | + 'value' => $button['value'] |
| 367 | + ); |
| 368 | + if( isset( $button['id'] ) ) |
| 369 | + $attrs['id'] = $button['id']; |
| 370 | + $html .= Html::element( 'input', $attrs ); |
| 371 | + } |
| 372 | + |
339 | 373 | return $html; |
340 | 374 | } |
341 | 375 | |
— | — | @@ -554,7 +588,7 @@ |
555 | 589 | * that the user-defined callback mValidationCallback is still run |
556 | 590 | * @param $value String the value the field was submitted with |
557 | 591 | * @param $alldata $all the data collected from the form |
558 | | - * @return Bool is the input valid |
| 592 | + * @return Mixed Bool true on success, or String error to display. |
559 | 593 | */ |
560 | 594 | function validate( $value, $alldata ) { |
561 | 595 | if ( isset( $this->mValidationCallback ) ) { |
— | — | @@ -1188,3 +1222,30 @@ |
1189 | 1223 | return false; |
1190 | 1224 | } |
1191 | 1225 | } |
| 1226 | + |
| 1227 | +class HTMLHiddenField extends HTMLFormField { |
| 1228 | + |
| 1229 | + public function getTableRow( $value ){ |
| 1230 | + $this->mParent->addHiddenField( |
| 1231 | + $this->mParams['name'], |
| 1232 | + $this->mParams['default'] |
| 1233 | + ); |
| 1234 | + return ''; |
| 1235 | + } |
| 1236 | + |
| 1237 | + public function getInputHTML( $value ){ return ''; } |
| 1238 | +} |
| 1239 | + |
| 1240 | +class HTMLSubmitField extends HTMLFormField { |
| 1241 | + |
| 1242 | + public function getTableRow( $value ){ |
| 1243 | + $this->mParent->addButton( |
| 1244 | + $this->mParams['name'], |
| 1245 | + $this->mParams['default'], |
| 1246 | + isset($this->mParams['id']) ? $this->mParams['id'] : null |
| 1247 | + ); |
| 1248 | + } |
| 1249 | + |
| 1250 | + public function getInputHTML( $value ){ return ''; } |
| 1251 | +} |
| 1252 | + |
Index: trunk/phase3/includes/specials/SpecialUserlogin.php |
— | — | @@ -192,20 +192,6 @@ |
193 | 193 | array( 'id' => 'languagelinks' ), |
194 | 194 | self::makeLanguageSelector( $this->getTitle(), $this->mReturnTo ) ) |
195 | 195 | : ''; |
196 | | - |
197 | | - # Add a 'mail reset' button if available |
198 | | - $buttons = ''; |
199 | | - if( $wgEnableEmail && $wgAuth->allowPasswordChange() ){ |
200 | | - $buttons = Html::element( |
201 | | - 'input', |
202 | | - array( |
203 | | - 'type' => 'submit', |
204 | | - 'name' => 'wpMailmypassword', |
205 | | - 'value' => wfMsg( 'mailmypassword' ), |
206 | | - 'id' => 'wpMailmypassword', |
207 | | - ) |
208 | | - ); |
209 | | - } |
210 | 196 | |
211 | 197 | # Give authentication and captcha plugins a chance to |
212 | 198 | # modify the form, by hook or by using $wgAuth |
— | — | @@ -237,7 +223,19 @@ |
238 | 224 | $form->setSubmitId( 'wpLoginAttempt' ); |
239 | 225 | $form->suppressReset(); |
240 | 226 | $form->loadData(); |
| 227 | + $form->addHiddenField( 'returnto', $this->mReturnTo ); |
| 228 | + $form->addHiddenField( 'returntoquery', $this->mReturnToQuery ); |
241 | 229 | |
| 230 | + # Add a 'mail reset' button if available |
| 231 | + $buttons = ''; |
| 232 | + if( $wgEnableEmail && $wgAuth->allowPasswordChange() ){ |
| 233 | + $form->addButton( |
| 234 | + 'wpMailmypassword', |
| 235 | + wfMsg( 'mailmypassword' ), |
| 236 | + 'wpMailmypassword' |
| 237 | + ); |
| 238 | + } |
| 239 | + |
242 | 240 | $formContents = '' |
243 | 241 | . Html::rawElement( 'p', array( 'id' => 'userloginlink' ), |
244 | 242 | $link ) |
— | — | @@ -246,10 +244,8 @@ |
247 | 245 | . $this->mFormHeader |
248 | 246 | . $langSelector |
249 | 247 | . $form->getBody() |
| 248 | + . $form->getHiddenFields() |
250 | 249 | . $form->getButtons() |
251 | | - . $buttons |
252 | | - . Xml::hidden( 'returnto', $this->mReturnTo ) |
253 | | - . Xml::hidden( 'returntoquery', $this->mReturnToQuery ) |
254 | 250 | ; |
255 | 251 | |
256 | 252 | $wgOut->setPageTitle( wfMsg( 'login' ) ); |
Index: trunk/phase3/includes/specials/SpecialCreateAccount.php |
— | — | @@ -357,21 +357,7 @@ |
358 | 358 | array( 'id' => 'languagelinks' ), |
359 | 359 | SpecialUserLogin::makeLanguageSelector( $this->getTitle(), $this->mReturnTo ) ) |
360 | 360 | : ''; |
361 | | - |
362 | | - # Add a 'send password by email' button if available |
363 | | - $buttons = ''; |
364 | | - if( $wgEnableEmail && $wgUser->isLoggedIn() ){ |
365 | | - $buttons = Html::element( |
366 | | - 'input', |
367 | | - array( |
368 | | - 'type' => 'submit', |
369 | | - 'name' => 'wpCreateaccountMail', |
370 | | - 'value' => wfMsg( 'createaccountmail' ), |
371 | | - 'id' => 'wpCreateaccountMail', |
372 | | - ) |
373 | | - ); |
374 | | - } |
375 | | - |
| 361 | + |
376 | 362 | # Give authentication and captcha plugins a chance to |
377 | 363 | # modify the form, by hook or by using $wgAuth |
378 | 364 | $wgAuth->modifyUITemplate( $this, 'new' ); |
— | — | @@ -419,17 +405,26 @@ |
420 | 406 | $form->setSubmitId( 'wpCreateaccount' ); |
421 | 407 | $form->suppressReset(); |
422 | 408 | $form->loadData(); |
| 409 | + $form->addHiddenField( 'returnto', $this->mReturnTo ); |
| 410 | + $form->addHiddenField( 'returntoquery', $this->mReturnToQuery ); |
423 | 411 | |
| 412 | + # Add a 'send password by email' button if available |
| 413 | + if( $wgEnableEmail && $wgUser->isLoggedIn() ){ |
| 414 | + $form->addButton( |
| 415 | + 'wpCreateaccountMail', |
| 416 | + wfMsg( 'createaccountmail' ), |
| 417 | + 'wpCreateaccountMail' |
| 418 | + ); |
| 419 | + } |
| 420 | + |
424 | 421 | $formContents = '' |
425 | 422 | . Html::rawElement( 'p', array( 'id' => 'userloginlink' ), |
426 | 423 | $link ) |
427 | 424 | . $this->mFormHeader |
428 | 425 | . $langSelector |
429 | 426 | . $form->getBody() |
| 427 | + . $form->getHiddenFields() |
430 | 428 | . $form->getButtons() |
431 | | - . $buttons |
432 | | - . Xml::hidden( 'returnto', $this->mReturnTo ) |
433 | | - . Xml::hidden( 'returntoquery', $this->mReturnToQuery ) |
434 | 429 | ; |
435 | 430 | |
436 | 431 | $wgOut->setPageTitle( wfMsg( 'createaccount' ) ); |