Follow-up to r64866 - add message, and apply the same validation to TextareaField as well.

This commit is contained in:
Happy-melon 2010-04-10 21:10:22 +00:00
parent c77fea8983
commit 2a28ffda5e
3 changed files with 50 additions and 31 deletions

View file

@ -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;
}
}
/**

View file

@ -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',

View file

@ -3129,6 +3129,7 @@ $wgMessageStructure = array(
'htmlform-float-invalid',
'htmlform-int-toolow',
'htmlform-int-toohigh',
'htmlform-required',
'htmlform-submit',
'htmlform-reset',
'htmlform-selectorother-other',