r64901 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64900‎ | r64901 | r64902 >
Date:21:10, 10 April 2010
Author:happy-melon
Status:ok (Comments)
Tags:
Comment:
Follow-up to r64866 - add message, and apply the same validation to TextareaField as well.
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -3129,6 +3129,7 @@
31303130 'htmlform-float-invalid',
31313131 'htmlform-int-toolow',
31323132 'htmlform-int-toohigh',
 3133+ 'htmlform-required',
31333134 'htmlform-submit',
31343135 'htmlform-reset',
31353136 'htmlform-selectorother-other',
Index: trunk/phase3/includes/HTMLForm.php
@@ -84,6 +84,7 @@
8585
8686 protected $mPre = '';
8787 protected $mHeader = '';
 88+ protected $mFooter = '';
8889 protected $mPost = '';
8990 protected $mId;
9091
@@ -286,6 +287,12 @@
287288 function addHeaderText( $msg ) { $this->mHeader .= $msg; }
288289
289290 /**
 291+ * Add footer text, inside the form.
 292+ * @param $msg String complete text of message to display
 293+ */
 294+ function addFooterText( $msg ) { $this->mFooter .= $msg; }
 295+
 296+ /**
290297 * Add text to the end of the display.
291298 * @param $msg String complete text of message to display
292299 */
@@ -313,15 +320,13 @@
314321 function displayForm( $submitResult ) {
315322 global $wgOut;
316323
317 - if ( $submitResult !== false ) {
318 - $this->displayErrors( $submitResult );
319 - }
320 -
321324 $html = ''
 325+ . $this->getErrors( $submitResult )
322326 . $this->mHeader
323327 . $this->getBody()
324328 . $this->getHiddenFields()
325329 . $this->getButtons()
 330+ . $this->mFooter
326331 ;
327332
328333 $html = $this->wrapForm( $html );
@@ -438,18 +443,18 @@
439444 /**
440445 * Format and display an error message stack.
441446 * @param $errors Mixed String or Array of message keys
 447+ * @return String
442448 */
443 - function displayErrors( $errors ) {
 449+ function getErrors( $errors ) {
444450 if ( is_array( $errors ) ) {
445451 $errorstr = $this->formatErrors( $errors );
446452 } else {
447453 $errorstr = $errors;
448454 }
449455
450 - $errorstr = Html::rawElement( 'div', array( 'class' => 'error' ), $errorstr );
451 -
452 - global $wgOut;
453 - $wgOut->addHTML( $errorstr );
 456+ return $errorstr
 457+ ? Html::rawElement( 'div', array( 'class' => 'error' ), $errorstr )
 458+ : '';
454459 }
455460
456461 /**
@@ -996,6 +1001,16 @@
9971002
9981003 return Html::element( 'textarea', $attribs, $value );
9991004 }
 1005+
 1006+ public function validate( $value, $alldata ){
 1007+ $p = parent::validate( $value, $alldata );
 1008+ if( $p !== true ) return $p;
 1009+
 1010+ if( isset( $this->mParams['required'] ) && $value === '' ){
 1011+ return wfMsgExt( 'htmlform-required', 'parseinline' );
 1012+ }
 1013+ return true;
 1014+ }
10001015 }
10011016
10021017 /**
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2559,29 +2559,31 @@
25602560 'listgrouprights-removegroup-self-all' => 'Remove all groups from own account',
25612561
25622562 # E-mail user
2563 -'mailnologin' => 'No send address',
2564 -'mailnologintext' => 'You must be [[Special:UserLogin|logged in]] and have a valid e-mail address in your [[Special:Preferences|preferences]] to send e-mail to other users.',
2565 -'emailuser' => 'E-mail this user',
2566 -'emailpage' => 'E-mail user',
2567 -'emailpagetext' => 'You can use the form below to send an e-mail message to this user.
 2563+'mailnologin' => 'No send address',
 2564+'mailnologintext' => 'You must be [[Special:UserLogin|logged in]] and have a valid e-mail address in your [[Special:Preferences|preferences]] to send e-mail to other users.',
 2565+'emailuser' => 'E-mail this user',
 2566+'emailpage' => 'E-mail user',
 2567+'emailpagetext' => 'You can use the form below to send an e-mail message to this user.
25682568 The e-mail address you entered in [[Special:Preferences|your user preferences]] will appear as the "From" address of the e-mail, so the recipient will be able to reply directly to you.',
2569 -'usermailererror' => 'Mail object returned error:',
2570 -'defemailsubject' => '{{SITENAME}} e-mail',
2571 -'noemailtitle' => 'No e-mail address',
2572 -'noemailtext' => 'This user has not specified a valid e-mail address.',
2573 -'nowikiemailtitle' => 'No e-mail allowed',
2574 -'nowikiemailtext' => 'This user has chosen not to receive e-mail from other users.',
2575 -'email-legend' => 'Send an e-mail to another {{SITENAME}} user',
2576 -'emailfrom' => 'From:',
2577 -'emailto' => 'To:',
2578 -'emailsubject' => 'Subject:',
2579 -'emailmessage' => 'Message:',
2580 -'emailsend' => 'Send',
2581 -'emailccme' => 'E-mail me a copy of my message.',
2582 -'emailccsubject' => 'Copy of your message to $1: $2',
2583 -'emailsent' => 'E-mail sent',
2584 -'emailsenttext' => 'Your e-mail message has been sent.',
2585 -'emailuserfooter' => 'This e-mail was sent by $1 to $2 by the "E-mail user" function at {{SITENAME}}.',
 2569+'usermailererror' => 'Mail object returned error:',
 2570+'defemailsubject' => '{{SITENAME}} e-mail',
 2571+'usermaildisabled' => 'User email disabled',
 2572+'usermaildisabledtext' => 'You cannot send email to other users on this wiki',
 2573+'noemailtitle' => 'No e-mail address',
 2574+'noemailtext' => 'This user has not specified a valid e-mail address.',
 2575+'nowikiemailtitle' => 'No e-mail allowed',
 2576+'nowikiemailtext' => 'This user has chosen not to receive e-mail from other users.',
 2577+'email-legend' => 'Send an e-mail to another {{SITENAME}} user',
 2578+'emailfrom' => 'From:',
 2579+'emailto' => 'To:',
 2580+'emailsubject' => 'Subject:',
 2581+'emailmessage' => 'Message:',
 2582+'emailsend' => 'Send',
 2583+'emailccme' => 'E-mail me a copy of my message.',
 2584+'emailccsubject' => 'Copy of your message to $1: $2',
 2585+'emailsent' => 'E-mail sent',
 2586+'emailsenttext' => 'Your e-mail message has been sent.',
 2587+'emailuserfooter' => 'This e-mail was sent by $1 to $2 by the "E-mail user" function at {{SITENAME}}.',
25862588
25872589 # Watchlist
25882590 'watchlist' => 'My watchlist',
@@ -4238,6 +4240,7 @@
42394241 'htmlform-float-invalid' => 'The value you specified is not a number.',
42404242 'htmlform-int-toolow' => 'The value you specified is below the minimum of $1',
42414243 'htmlform-int-toohigh' => 'The value you specified is above the maximum of $1',
 4244+'htmlform-required' => 'This value is required',
42424245 'htmlform-submit' => 'Submit',
42434246 'htmlform-reset' => 'Undo changes',
42444247 'htmlform-selectorother-other' => 'Other',

Follow-up revisions

RevisionCommit summaryAuthorDate
r64903Overhaul Special:EmailUser, use HTMLForm, a SpecialPage-derived class, and ge...happy-melon21:14, 10 April 2010
r64910Follow-up r64901: make "e-mail" consistentraymond21:34, 10 April 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64866Improvements and fixes to HTMLForm:...happy-melon12:03, 10 April 2010

Comments

#Comment by Happy-melon (talk | contribs)   21:12, 10 April 2010

Hmm, this has quite a few other bits muddled in...

Status & tagging log