From 2a28ffda5ee5bfe3aaa50b112904af63b8d3e4e6 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Sat, 10 Apr 2010 21:10:22 +0000 Subject: [PATCH] Follow-up to r64866 - add message, and apply the same validation to TextareaField as well. --- includes/HTMLForm.php | 33 ++++++++++++++++------ languages/messages/MessagesEn.php | 47 ++++++++++++++++--------------- maintenance/language/messages.inc | 1 + 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index e629155d63..e798611c31 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -84,6 +84,7 @@ class HTMLForm { protected $mPre = ''; protected $mHeader = ''; + protected $mFooter = ''; protected $mPost = ''; protected $mId; @@ -285,6 +286,12 @@ class HTMLForm { */ function addHeaderText( $msg ) { $this->mHeader .= $msg; } + /** + * Add footer text, inside the form. + * @param $msg String complete text of message to display + */ + function addFooterText( $msg ) { $this->mFooter .= $msg; } + /** * Add text to the end of the display. * @param $msg String complete text of message to display @@ -313,15 +320,13 @@ class HTMLForm { function displayForm( $submitResult ) { global $wgOut; - if ( $submitResult !== false ) { - $this->displayErrors( $submitResult ); - } - $html = '' + . $this->getErrors( $submitResult ) . $this->mHeader . $this->getBody() . $this->getHiddenFields() . $this->getButtons() + . $this->mFooter ; $html = $this->wrapForm( $html ); @@ -438,18 +443,18 @@ class HTMLForm { /** * Format and display an error message stack. * @param $errors Mixed String or Array of message keys + * @return String */ - function displayErrors( $errors ) { + function getErrors( $errors ) { if ( is_array( $errors ) ) { $errorstr = $this->formatErrors( $errors ); } else { $errorstr = $errors; } - $errorstr = Html::rawElement( 'div', array( 'class' => 'error' ), $errorstr ); - - global $wgOut; - $wgOut->addHTML( $errorstr ); + return $errorstr + ? Html::rawElement( 'div', array( 'class' => 'error' ), $errorstr ) + : ''; } /** @@ -996,6 +1001,16 @@ class HTMLTextAreaField extends HTMLFormField { return Html::element( 'textarea', $attribs, $value ); } + + public function validate( $value, $alldata ){ + $p = parent::validate( $value, $alldata ); + if( $p !== true ) return $p; + + if( isset( $this->mParams['required'] ) && $value === '' ){ + return wfMsgExt( 'htmlform-required', 'parseinline' ); + } + return true; + } } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 9e619b500a..27ac04a616 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2559,29 +2559,31 @@ There may be [[{{MediaWiki:Listgrouprights-helppage}}|additional information]] a 'listgrouprights-removegroup-self-all' => 'Remove all groups from own account', # E-mail user -'mailnologin' => 'No send address', -'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.', -'emailuser' => 'E-mail this user', -'emailpage' => 'E-mail user', -'emailpagetext' => 'You can use the form below to send an e-mail message to this user. +'mailnologin' => 'No send address', +'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.', +'emailuser' => 'E-mail this user', +'emailpage' => 'E-mail user', +'emailpagetext' => 'You can use the form below to send an e-mail message to this user. 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.', -'usermailererror' => 'Mail object returned error:', -'defemailsubject' => '{{SITENAME}} e-mail', -'noemailtitle' => 'No e-mail address', -'noemailtext' => 'This user has not specified a valid e-mail address.', -'nowikiemailtitle' => 'No e-mail allowed', -'nowikiemailtext' => 'This user has chosen not to receive e-mail from other users.', -'email-legend' => 'Send an e-mail to another {{SITENAME}} user', -'emailfrom' => 'From:', -'emailto' => 'To:', -'emailsubject' => 'Subject:', -'emailmessage' => 'Message:', -'emailsend' => 'Send', -'emailccme' => 'E-mail me a copy of my message.', -'emailccsubject' => 'Copy of your message to $1: $2', -'emailsent' => 'E-mail sent', -'emailsenttext' => 'Your e-mail message has been sent.', -'emailuserfooter' => 'This e-mail was sent by $1 to $2 by the "E-mail user" function at {{SITENAME}}.', +'usermailererror' => 'Mail object returned error:', +'defemailsubject' => '{{SITENAME}} e-mail', +'usermaildisabled' => 'User email disabled', +'usermaildisabledtext' => 'You cannot send email to other users on this wiki', +'noemailtitle' => 'No e-mail address', +'noemailtext' => 'This user has not specified a valid e-mail address.', +'nowikiemailtitle' => 'No e-mail allowed', +'nowikiemailtext' => 'This user has chosen not to receive e-mail from other users.', +'email-legend' => 'Send an e-mail to another {{SITENAME}} user', +'emailfrom' => 'From:', +'emailto' => 'To:', +'emailsubject' => 'Subject:', +'emailmessage' => 'Message:', +'emailsend' => 'Send', +'emailccme' => 'E-mail me a copy of my message.', +'emailccsubject' => 'Copy of your message to $1: $2', +'emailsent' => 'E-mail sent', +'emailsenttext' => 'Your e-mail message has been sent.', +'emailuserfooter' => 'This e-mail was sent by $1 to $2 by the "E-mail user" function at {{SITENAME}}.', # Watchlist 'watchlist' => 'My watchlist', @@ -4238,6 +4240,7 @@ This site is experiencing technical difficulties.', 'htmlform-float-invalid' => 'The value you specified is not a number.', 'htmlform-int-toolow' => 'The value you specified is below the minimum of $1', 'htmlform-int-toohigh' => 'The value you specified is above the maximum of $1', +'htmlform-required' => 'This value is required', 'htmlform-submit' => 'Submit', 'htmlform-reset' => 'Undo changes', 'htmlform-selectorother-other' => 'Other', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index a99bd4278e..07c650f25b 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -3129,6 +3129,7 @@ $wgMessageStructure = array( 'htmlform-float-invalid', 'htmlform-int-toolow', 'htmlform-int-toohigh', + 'htmlform-required', 'htmlform-submit', 'htmlform-reset', 'htmlform-selectorother-other', -- 2.20.1