Improve HTMLForm's support for adding content in and around the form, to improve...
authorHappy-melon <happy-melon@users.mediawiki.org>
Thu, 24 Sep 2009 21:25:33 +0000 (21:25 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Thu, 24 Sep 2009 21:25:33 +0000 (21:25 +0000)
Also change the wrapping on both forms to use a <fieldset>, 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
includes/specials/SpecialCreateAccount.php
includes/specials/SpecialUserlogin.php
languages/messages/MessagesEn.php
skins/monobook/main.css

index 25067ed..50683a4 100644 (file)
@@ -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 <fieldset> 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 <fieldset>, with
+        * this text as its <legend> element.
+        * @param $legend String HTML to go inside the <legend> element.
+        *     Will be escaped
+        */
+       public function setWrapperLegend( $legend ){ $this->mWrapperLegend = $legend; }
 
        /**
         * Set the prefix for various default messages
index 2d59f2b..e449d0e 100644 (file)
@@ -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 );
                
        }
 
index 6be4038..dd98c1b 100644 (file)
@@ -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( '' );
        }       
 
        /**
index 47d77ad..42e0d93 100644 (file)
@@ -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.',
index 727355b..e7f2009 100644 (file)
@@ -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: