From e5a74e5ff74b7ab1642035290e55359e45d8361a Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Thu, 24 Sep 2009 21:25:33 +0000 Subject: [PATCH] Improve HTMLForm's support for adding content in and around the form, to improve versatility. Groundwork for being able to validate, filter and submit the CreateAccount input via HTMLForm::trySubmit(), which will give extensions huge flexibility to play with the form input. Also change the wrapping on both forms to use a
, which is visually more consistent with the other forms we have floating around the site. Add visualClear to all HTMLForm forms, and remove all the redundant CSS for the login form, quite a bit of which has been dead for a while. --- includes/HTMLForm.php | 75 ++++++++++++++++------ includes/specials/SpecialCreateAccount.php | 62 +++++++++--------- includes/specials/SpecialUserlogin.php | 58 ++++++++--------- languages/messages/MessagesEn.php | 4 +- skins/monobook/main.css | 49 -------------- 5 files changed, 116 insertions(+), 132 deletions(-) diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index 25067edd25..50683a4b19 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -73,17 +73,24 @@ class HTMLForm { protected $mMessagePrefix; protected $mFlatFields; protected $mFieldTree; - protected $mShowReset; + protected $mShowReset = false; public $mFieldData; + protected $mSubmitCallback; protected $mValidationErrorMessage; - protected $mIntro; + + protected $mPre = ''; + protected $mHeader = ''; + protected $mPost = ''; + protected $mSubmitID; protected $mSubmitText; protected $mTitle; protected $mHiddenFields = array(); protected $mButtons = array(); + + protected $mWrapperLegend = false; /** * Build a new HTMLForm from an array of field attributes @@ -127,8 +134,6 @@ class HTMLForm { } $this->mFieldTree = $loadedDescriptor; - - $this->mShowReset = true; } /** @@ -247,14 +252,30 @@ class HTMLForm { function setValidationErrorMessage( $msg ) { $this->mValidationErrorMessage = $msg; } + + /** + * Set the introductory message, overwriting any existing message. + * @param $msg String complete text of message to display + */ + function setIntro( $msg ) { $this->mPre = $msg; } /** - * Set the introductory message + * Add introductory text. * @param $msg String complete text of message to display */ - function setIntro( $msg ) { - $this->mIntro = $msg; - } + function addPreText( $msg ) { $this->mPre .= $msg; } + + /** + * Add header text, inside the form. + * @param $msg String complete text of message to display + */ + function addHeaderText( $msg ) { $this->mHeader .= $msg; } + + /** + * Add text to the end of the display. + * @param $msg String complete text of message to display + */ + function addPostText( $msg ) { $this->mPost .= $msg; } /** * Add a hidden field to the output @@ -281,21 +302,20 @@ class HTMLForm { $this->displayErrors( $submitResult ); } - if ( isset( $this->mIntro ) ) { - $wgOut->addHTML( $this->mIntro ); - } - - $html = $this->getBody(); - - // Hidden fields - $html .= $this->getHiddenFields(); - - // Buttons - $html .= $this->getButtons(); + $html = '' + . $this->mHeader + . $this->getBody() + . $this->getHiddenFields() + . $this->getButtons() + ; $html = $this->wrapForm( $html ); - $wgOut->addHTML( $html ); + $wgOut->addHTML( '' + . $this->mPre + . $html + . $this->mPost + ); } /** @@ -304,11 +324,18 @@ class HTMLForm { * @return String wrapped HTML. */ function wrapForm( $html ) { + + # Include a
wrapper for style, if requested. + if( $this->mWrapperLegend !== false ){ + $html = Xml::fieldset( $this->mWrapperLegend, $html ); + } + return Html::rawElement( 'form', array( 'action' => $this->getTitle()->getFullURL(), 'method' => 'post', + 'class' => 'visualClear', ), $html ); @@ -447,6 +474,14 @@ class HTMLForm { function setSubmitID( $t ) { $this->mSubmitID = $t; } + + /** + * Prompt the whole form to be wrapped in a
, with + * this text as its element. + * @param $legend String HTML to go inside the element. + * Will be escaped + */ + public function setWrapperLegend( $legend ){ $this->mWrapperLegend = $legend; } /** * Set the prefix for various default messages diff --git a/includes/specials/SpecialCreateAccount.php b/includes/specials/SpecialCreateAccount.php index 2d59f2bf0e..e449d0e640 100644 --- a/includes/specials/SpecialCreateAccount.php +++ b/includes/specials/SpecialCreateAccount.php @@ -377,10 +377,10 @@ class SpecialCreateAccount extends SpecialPage { unset( $this->mFormFields['Email'] ); } else { if( $wgEmailConfirmToEdit ){ - $this->mFormFields['Email']['label-help'] = 'prefs-help-email-required'; + $this->mFormFields['Email']['help-message'] = 'prefs-help-email-required'; $this->mFormFields['Email']['required'] = ''; } else { - $this->mFormFields['Email']['label-help'] = 'prefs-help-email'; + $this->mFormFields['Email']['help-message'] = 'prefs-help-email'; } } @@ -399,15 +399,39 @@ class SpecialCreateAccount extends SpecialPage { $this->mFormFields['Remember']['checked'] = '1'; } - $form = new HTMLForm( $this->mFormFields, '' ); + $form = new HTMLForm( $this->mFormFields ); + $form->setTitle( $this->getTitle() ); $form->setSubmitText( wfMsg( 'createaccount' ) ); $form->setSubmitId( 'wpCreateaccount' ); $form->suppressReset(); - $form->loadData(); + $form->setWrapperLegend( wfMsg( 'createaccount' ) ); + $form->addHiddenField( 'returnto', $this->mReturnTo ); $form->addHiddenField( 'returntoquery', $this->mReturnToQuery ); + $form->addHeaderText( '' + . Html::rawElement( 'p', array( 'id' => 'userloginlink' ), + $link ) + . $this->mFormHeader + . $langSelector + ); + $form->addPreText( '' + . $msg + . Html::rawElement( + 'div', + array( 'id' => 'signupstart' ), + wfMsgExt( 'loginstart', array( 'parseinline' ) ) + ) + ); + $form->addPostText( + Html::rawElement( + 'div', + array( 'id' => 'signupend' ), + wfMsgExt( 'loginend', array( 'parseinline' ) ) + ) + ); + # Add a 'send password by email' button if available if( $wgEnableEmail && $wgUser->isLoggedIn() ){ $form->addButton( @@ -417,39 +441,15 @@ class SpecialCreateAccount extends SpecialPage { ); } - $formContents = '' - . Html::rawElement( 'p', array( 'id' => 'userloginlink' ), - $link ) - . $this->mFormHeader - . $langSelector - . $form->getBody() - . $form->getHiddenFields() - . $form->getButtons() - ; + $form->loadData(); $wgOut->setPageTitle( wfMsg( 'createaccount' ) ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->setArticleRelated( false ); $wgOut->disallowUserJs(); # Stop malicious userscripts sniffing passwords - $wgOut->addHTML( - Html::rawElement( - 'div', - array( 'id' => 'loginstart' ), - wfMsgExt( 'loginstart', array( 'parseinline' ) ) - ) . - $msg . - Html::rawElement( - 'div', - array( 'id' => 'userloginForm' ), - $form->wrapForm( $formContents ) - ) . - Html::rawElement( - 'div', - array( 'id' => 'loginend' ), - wfMsgExt( 'loginend', array( 'parseinline' ) ) - ) - ); + + $form->displayForm( false ); } diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 6be40387c1..dd98c1b8dd 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -222,10 +222,35 @@ class SpecialUserLogin extends SpecialPage { $form->setSubmitText( wfMsg( 'login' ) ); $form->setSubmitId( 'wpLoginAttempt' ); $form->suppressReset(); - $form->loadData(); + $form->setWrapperLegend( wfMsg( 'userlogin' ) ); + $form->addHiddenField( 'returnto', $this->mReturnTo ); $form->addHiddenField( 'returntoquery', $this->mReturnToQuery ); + $form->addHeaderText( '' + . Html::rawElement( 'p', array( 'id' => 'userloginlink' ), + $link ) + . Html::rawElement( 'div', array( 'id' => 'userloginprompt' ), + wfMsgExt( 'loginprompt', array( 'parseinline' ) ) ) + . $this->mFormHeader + . $langSelector + ); + $form->addPreText( '' + . $msg + . Html::rawElement( + 'div', + array( 'id' => 'loginstart' ), + wfMsgExt( 'loginstart', array( 'parseinline' ) ) + ) + ); + $form->addPostText( + Html::rawElement( + 'div', + array( 'id' => 'loginend' ), + wfMsgExt( 'loginend', array( 'parseinline' ) ) + ) + ); + # Add a 'mail reset' button if available $buttons = ''; if( $wgEnableEmail && $wgAuth->allowPasswordChange() ){ @@ -236,41 +261,14 @@ class SpecialUserLogin extends SpecialPage { ); } - $formContents = '' - . Html::rawElement( 'p', array( 'id' => 'userloginlink' ), - $link ) - . Html::rawElement( 'div', array( 'id' => 'userloginprompt' ), - wfMsgExt( 'loginprompt', array( 'parseinline' ) ) ) - . $this->mFormHeader - . $langSelector - . $form->getBody() - . $form->getHiddenFields() - . $form->getButtons() - ; + $form->loadData(); $wgOut->setPageTitle( wfMsg( 'login' ) ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->setArticleRelated( false ); $wgOut->disallowUserJs(); # Stop malicious userscripts sniffing passwords - $wgOut->addHTML( - Html::rawElement( - 'div', - array( 'id' => 'loginstart' ), - wfMsgExt( 'loginstart', array( 'parseinline' ) ) - ) . - $msg . - Html::rawElement( - 'div', - array( 'id' => 'userloginForm' ), - $form->wrapForm( $formContents ) - ) . - Html::rawElement( - 'div', - array( 'id' => 'loginend' ), - wfMsgExt( 'loginend', array( 'parseinline' ) ) - ) - ); + $form->displayForm( '' ); } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 47d77ad384..42e0d93b48 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1048,10 +1048,10 @@ Do not forget to change your [[Special:Preferences|{{SITENAME}} preferences]].', 'logout' => 'Log out', 'userlogout' => 'Log out', 'notloggedin' => 'Not logged in', -'nologin' => "Don't have an account? $1.", +'nologin' => "Don't have an account? '''$1'''.", 'nologinlink' => 'Create an account', 'createaccount' => 'Create account', -'gotaccount' => 'Already have an account? $1.', +'gotaccount' => "Already have an account? '''$1'''.", 'gotaccountlink' => 'Log in', 'createaccountmail' => 'by e-mail', 'badretype' => 'The passwords you entered do not match.', diff --git a/skins/monobook/main.css b/skins/monobook/main.css index 727355bb77..e7f2009abb 100644 --- a/skins/monobook/main.css +++ b/skins/monobook/main.css @@ -1015,59 +1015,10 @@ td.htmlform-tip { margin-top: 2em; } -div#userloginForm form, -div#userlogin form#userlogin2 { - margin: 0 3em 1em 0; - border: 1px solid #aaa; - clear: both; - padding: 1.5em 2em; - background-color: #f9f9f9; - float: left; -} -.rtl div#userloginForm form, -.rtl div#userlogin form#userlogin2 { - float: right; -} - -div#userloginForm table, -div#userlogin form#userlogin2 table { - background-color: #f9f9f9; -} - -div#userloginForm h2, -div#userlogin form#userlogin2 h2 { - padding-top: 0; -} - -div#userlogin .captcha, -div#userloginForm .captcha { - border: 1px solid #bbb; - padding: 1.5em 2em; - background-color: white; -} - -#loginend, #signupend { - clear: both; -} - #userloginprompt, #languagelinks { font-size: 85%; } -#login-sectiontip { - font-size: 85%; - line-height: 1.2; - padding-top: 2em; -} - -#userlogin .loginText, #userlogin .loginPassword { - width: 12em; -} - -#userloginlink a, #wpLoginattempt, #wpCreateaccount { - font-weight: bold; -} - /* ** IE/Mac fixes, hope to find a validating way to move this ** to a separate stylesheet. This would work but doesn't validate: -- 2.20.1