'float' => 'HTMLFloatField',
'info' => 'HTMLInfoField',
'selectorother' => 'HTMLSelectOrOtherField',
+ 'submit' => 'HTMLSubmitField',
+ 'hidden' => 'HTMLHiddenField',
+
# HTMLTextField will output the correct type="" attribute automagically.
# There are about four zillion other HTML 5 input types, like url, but
# we don't use those at the moment, so no point in adding all of them.
protected $mSubmitID;
protected $mSubmitText;
protected $mTitle;
+
+ protected $mHiddenFields = array();
+ protected $mButtons = array();
/**
* Build a new HTMLForm from an array of field attributes
function setIntro( $msg ) {
$this->mIntro = $msg;
}
+
+ /**
+ * Add a hidden field to the output
+ * @param $name String field name
+ * @param $value String field value
+ */
+ public function addHiddenField( $name, $value ){
+ $this->mHiddenFields[ $name ] = $value;
+ }
+
+ public function addButton( $name, $value, $id=null ){
+ $this->mButtons[] = compact( 'name', 'value', 'id' );
+ }
/**
* Display the form (sending to wgOut), with an appropriate error
$html .= Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n";
$html .= Html::hidden( 'title', $this->getTitle() ) . "\n";
+
+ foreach( $this->mHiddenFields as $name => $value ){
+ $html .= Html::hidden( $name, $value ) . "\n";
+ }
return $html;
}
) . "\n";
}
+ foreach( $this->mButtons as $button ){
+ $attrs = array(
+ 'type' => 'submit',
+ 'name' => $button['name'],
+ 'value' => $button['value']
+ );
+ if( isset( $button['id'] ) )
+ $attrs['id'] = $button['id'];
+ $html .= Html::element( 'input', $attrs );
+ }
+
return $html;
}
* that the user-defined callback mValidationCallback is still run
* @param $value String the value the field was submitted with
* @param $alldata $all the data collected from the form
- * @return Bool is the input valid
+ * @return Mixed Bool true on success, or String error to display.
*/
function validate( $value, $alldata ) {
if ( isset( $this->mValidationCallback ) ) {
return false;
}
}
+
+class HTMLHiddenField extends HTMLFormField {
+
+ public function getTableRow( $value ){
+ $this->mParent->addHiddenField(
+ $this->mParams['name'],
+ $this->mParams['default']
+ );
+ return '';
+ }
+
+ public function getInputHTML( $value ){ return ''; }
+}
+
+class HTMLSubmitField extends HTMLFormField {
+
+ public function getTableRow( $value ){
+ $this->mParent->addButton(
+ $this->mParams['name'],
+ $this->mParams['default'],
+ isset($this->mParams['id']) ? $this->mParams['id'] : null
+ );
+ }
+
+ public function getInputHTML( $value ){ return ''; }
+}
+
array( 'id' => 'languagelinks' ),
SpecialUserLogin::makeLanguageSelector( $this->getTitle(), $this->mReturnTo ) )
: '';
-
- # Add a 'send password by email' button if available
- $buttons = '';
- if( $wgEnableEmail && $wgUser->isLoggedIn() ){
- $buttons = Html::element(
- 'input',
- array(
- 'type' => 'submit',
- 'name' => 'wpCreateaccountMail',
- 'value' => wfMsg( 'createaccountmail' ),
- 'id' => 'wpCreateaccountMail',
- )
- );
- }
-
+
# Give authentication and captcha plugins a chance to
# modify the form, by hook or by using $wgAuth
$wgAuth->modifyUITemplate( $this, 'new' );
$form->setSubmitId( 'wpCreateaccount' );
$form->suppressReset();
$form->loadData();
+ $form->addHiddenField( 'returnto', $this->mReturnTo );
+ $form->addHiddenField( 'returntoquery', $this->mReturnToQuery );
+
+ # Add a 'send password by email' button if available
+ if( $wgEnableEmail && $wgUser->isLoggedIn() ){
+ $form->addButton(
+ 'wpCreateaccountMail',
+ wfMsg( 'createaccountmail' ),
+ 'wpCreateaccountMail'
+ );
+ }
$formContents = ''
. Html::rawElement( 'p', array( 'id' => 'userloginlink' ),
. $this->mFormHeader
. $langSelector
. $form->getBody()
+ . $form->getHiddenFields()
. $form->getButtons()
- . $buttons
- . Xml::hidden( 'returnto', $this->mReturnTo )
- . Xml::hidden( 'returntoquery', $this->mReturnToQuery )
;
$wgOut->setPageTitle( wfMsg( 'createaccount' ) );
array( 'id' => 'languagelinks' ),
self::makeLanguageSelector( $this->getTitle(), $this->mReturnTo ) )
: '';
-
- # Add a 'mail reset' button if available
- $buttons = '';
- if( $wgEnableEmail && $wgAuth->allowPasswordChange() ){
- $buttons = Html::element(
- 'input',
- array(
- 'type' => 'submit',
- 'name' => 'wpMailmypassword',
- 'value' => wfMsg( 'mailmypassword' ),
- 'id' => 'wpMailmypassword',
- )
- );
- }
# Give authentication and captcha plugins a chance to
# modify the form, by hook or by using $wgAuth
$form->setSubmitId( 'wpLoginAttempt' );
$form->suppressReset();
$form->loadData();
+ $form->addHiddenField( 'returnto', $this->mReturnTo );
+ $form->addHiddenField( 'returntoquery', $this->mReturnToQuery );
+
+ # Add a 'mail reset' button if available
+ $buttons = '';
+ if( $wgEnableEmail && $wgAuth->allowPasswordChange() ){
+ $form->addButton(
+ 'wpMailmypassword',
+ wfMsg( 'mailmypassword' ),
+ 'wpMailmypassword'
+ );
+ }
$formContents = ''
. Html::rawElement( 'p', array( 'id' => 'userloginlink' ),
. $this->mFormHeader
. $langSelector
. $form->getBody()
+ . $form->getHiddenFields()
. $form->getButtons()
- . $buttons
- . Xml::hidden( 'returnto', $this->mReturnTo )
- . Xml::hidden( 'returntoquery', $this->mReturnToQuery )
;
$wgOut->setPageTitle( wfMsg( 'login' ) );