r56782 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56781‎ | r56782 | r56783 >
Date:20:05, 22 September 2009
Author:happy-melon
Status:reverted
Tags:
Comment:
Allow extra buttons and hidden fields to be included in HTMLForm. Accessible either before Form construction (as HTMLFormField subclasses that can be passed in the Descriptor array as for other input) or after (as methods addHiddenField() and addButton(), respectively).
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialCreateAccount.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -60,6 +60,9 @@
6161 'float' => 'HTMLFloatField',
6262 'info' => 'HTMLInfoField',
6363 'selectorother' => 'HTMLSelectOrOtherField',
 64+ 'submit' => 'HTMLSubmitField',
 65+ 'hidden' => 'HTMLHiddenField',
 66+
6467 # HTMLTextField will output the correct type="" attribute automagically.
6568 # There are about four zillion other HTML 5 input types, like url, but
6669 # we don't use those at the moment, so no point in adding all of them.
@@ -78,6 +81,9 @@
7982 protected $mSubmitID;
8083 protected $mSubmitText;
8184 protected $mTitle;
 85+
 86+ protected $mHiddenFields = array();
 87+ protected $mButtons = array();
8288
8389 /**
8490 * Build a new HTMLForm from an array of field attributes
@@ -249,6 +255,19 @@
250256 function setIntro( $msg ) {
251257 $this->mIntro = $msg;
252258 }
 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+ }
253272
254273 /**
255274 * Display the form (sending to wgOut), with an appropriate error
@@ -305,6 +324,10 @@
306325
307326 $html .= Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n";
308327 $html .= Html::hidden( 'title', $this->getTitle() ) . "\n";
 328+
 329+ foreach( $this->mHiddenFields as $name => $value ){
 330+ $html .= Html::hidden( $name, $value ) . "\n";
 331+ }
309332
310333 return $html;
311334 }
@@ -335,6 +358,17 @@
336359 ) . "\n";
337360 }
338361
 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+
339373 return $html;
340374 }
341375
@@ -554,7 +588,7 @@
555589 * that the user-defined callback mValidationCallback is still run
556590 * @param $value String the value the field was submitted with
557591 * @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.
559593 */
560594 function validate( $value, $alldata ) {
561595 if ( isset( $this->mValidationCallback ) ) {
@@ -1188,3 +1222,30 @@
11891223 return false;
11901224 }
11911225 }
 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 @@
193193 array( 'id' => 'languagelinks' ),
194194 self::makeLanguageSelector( $this->getTitle(), $this->mReturnTo ) )
195195 : '';
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 - }
210196
211197 # Give authentication and captcha plugins a chance to
212198 # modify the form, by hook or by using $wgAuth
@@ -237,7 +223,19 @@
238224 $form->setSubmitId( 'wpLoginAttempt' );
239225 $form->suppressReset();
240226 $form->loadData();
 227+ $form->addHiddenField( 'returnto', $this->mReturnTo );
 228+ $form->addHiddenField( 'returntoquery', $this->mReturnToQuery );
241229
 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+
242240 $formContents = ''
243241 . Html::rawElement( 'p', array( 'id' => 'userloginlink' ),
244242 $link )
@@ -246,10 +244,8 @@
247245 . $this->mFormHeader
248246 . $langSelector
249247 . $form->getBody()
 248+ . $form->getHiddenFields()
250249 . $form->getButtons()
251 - . $buttons
252 - . Xml::hidden( 'returnto', $this->mReturnTo )
253 - . Xml::hidden( 'returntoquery', $this->mReturnToQuery )
254250 ;
255251
256252 $wgOut->setPageTitle( wfMsg( 'login' ) );
Index: trunk/phase3/includes/specials/SpecialCreateAccount.php
@@ -357,21 +357,7 @@
358358 array( 'id' => 'languagelinks' ),
359359 SpecialUserLogin::makeLanguageSelector( $this->getTitle(), $this->mReturnTo ) )
360360 : '';
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+
376362 # Give authentication and captcha plugins a chance to
377363 # modify the form, by hook or by using $wgAuth
378364 $wgAuth->modifyUITemplate( $this, 'new' );
@@ -419,17 +405,26 @@
420406 $form->setSubmitId( 'wpCreateaccount' );
421407 $form->suppressReset();
422408 $form->loadData();
 409+ $form->addHiddenField( 'returnto', $this->mReturnTo );
 410+ $form->addHiddenField( 'returntoquery', $this->mReturnToQuery );
423411
 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+
424421 $formContents = ''
425422 . Html::rawElement( 'p', array( 'id' => 'userloginlink' ),
426423 $link )
427424 . $this->mFormHeader
428425 . $langSelector
429426 . $form->getBody()
 427+ . $form->getHiddenFields()
430428 . $form->getButtons()
431 - . $buttons
432 - . Xml::hidden( 'returnto', $this->mReturnTo )
433 - . Xml::hidden( 'returntoquery', $this->mReturnToQuery )
434429 ;
435430
436431 $wgOut->setPageTitle( wfMsg( 'createaccount' ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r56937Revert broken rewrite of login system; totally broken....brion00:49, 26 September 2009

Status & tagging log