Userlogin.php: Tweaks and corrections
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 15 Jan 2015 18:30:14 +0000 (10:30 -0800)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 15 Jan 2015 18:46:01 +0000 (18:46 +0000)
* Correct nesting of the block generating "Forgot your password?" link
  – it would be mistakenly only generated if the user could create an
  account.
* Use ->escaped() rather than ->parse() for 'userlogin-resetpassword-link',
  as it is used inside a link and allowing wikitext could lead to
  undesirable side-effects.
* Remove unused $extraAttrs variable.
* Remove pointless 'size' => '20' for some fields (they are displayed
  full-width using CSS).
* Remove pointless .mw-ui-block class, as its styles are always used
  for buttons in a VForm.
* Prettify code for hidden fields generation.

Change-Id: If749620bf2eaf58f815cae559383e1a1c842b870

includes/templates/Userlogin.php

index 69266c8..8bbbfa6 100644 (file)
@@ -70,12 +70,10 @@ class UserloginTemplate extends BaseTemplate {
                                        ?>
                                </label>
                                <?php
-                               $extraAttrs = array();
                                echo Html::input( 'wpName', $this->data['name'], 'text', array(
                                        'class' => 'loginText mw-ui-input',
                                        'id' => 'wpName1',
                                        'tabindex' => '1',
-                                       'size' => '20',
                                        // 'required' is blacklisted for now in Html.php due to browser issues.
                                        // Keeping here in case that changes.
                                        'required' => true,
@@ -97,7 +95,6 @@ class UserloginTemplate extends BaseTemplate {
                                        'class' => 'loginPassword mw-ui-input',
                                        'id' => 'wpPassword1',
                                        'tabindex' => '2',
-                                       'size' => '20',
                                        // Set focus to this field if username is filled in.
                                        'autofocus' => (bool)$this->data['name'],
                                        'placeholder' => $this->getMsg( 'userlogin-yourpassword-ph' )->text()
@@ -146,7 +143,7 @@ class UserloginTemplate extends BaseTemplate {
                                        'tabindex' => '6',
                                );
                                $modifiers = array(
-                                       'mw-ui-big', 'mw-ui-block', 'mw-ui-constructive',
+                                       'mw-ui-big', 'mw-ui-constructive',
                                );
                                echo Html::submitButton( $this->getMsg( 'pt-login-button' )->text(), $attrs, $modifiers );
                                ?>
@@ -166,33 +163,50 @@ class UserloginTemplate extends BaseTemplate {
                                ?>
                        </div>
                        <?php
+
+                       if ( $this->data['useemail'] && $this->data['canreset'] && $this->data['resetlink'] === true ) {
+                               echo Html::rawElement(
+                                       'div',
+                                       array(
+                                               'class' => 'mw-ui-vform-field mw-form-related-link-container',
+                                       ),
+                                       Linker::link(
+                                               SpecialPage::getTitleFor( 'PasswordReset' ),
+                                               $this->getMsg( 'userlogin-resetpassword-link' )->escaped()
+                                       )
+                               );
+                       }
+
                        if ( $this->haveData( 'createOrLoginHref' ) ) {
-                               if ( $this->data['useemail'] && $this->data['canreset'] && $this->data['resetlink'] === true ) {
-                                       echo Html::openElement( 'div',
-                                                       array(
-                                                               'class' => 'mw-ui-vform-field mw-form-related-link-container',
-                                                       )
-                                               ) .
-                                               Linker::link(
-                                                       SpecialPage::getTitleFor( 'PasswordReset' ),
-                                                       $this->getMsg( 'userlogin-resetpassword-link' )->parse()
-                                               ) .
-                                               Html::closeElement( 'div' );
-                               }
                                if ( $this->data['loggedin'] ) { ?>
-                                       <div id="mw-createaccount-another" class="mw-form-related-link-container mw-ui-vform-field">
+                                       <div class="mw-form-related-link-container mw-ui-vform-field">
                                                <a href="<?php $this->text( 'createOrLoginHref' ); ?>" id="mw-createaccount-join" tabindex="7"><?php $this->msg( 'userlogin-createanother' ); ?></a>
                                        </div>
                                <?php } else { ?>
                                        <div id="mw-createaccount-cta" class="mw-form-related-link-container mw-ui-vform-field">
-                                               <?php $this->msg( 'userlogin-noaccount' ); ?><a href="<?php $this->text( 'createOrLoginHref' ); ?>" id="mw-createaccount-join" tabindex="7"  class="mw-ui-button mw-ui-progressive"><?php $this->msg( 'userlogin-joinproject' ); ?></a>
+                                               <?php $this->msg( 'userlogin-noaccount' ); ?><a href="<?php $this->text( 'createOrLoginHref' ); ?>" id="mw-createaccount-join" tabindex="7" class="mw-ui-button mw-ui-progressive"><?php $this->msg( 'userlogin-joinproject' ); ?></a>
                                        </div>
-                               <?php } ?>
-                       <?php } ?>
-                       <?php if ( $this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?php } ?>
-                       <?php if ( $this->haveData( 'token' ) ) { ?><input type="hidden" name="wpLoginToken" value="<?php $this->text( 'token' ); ?>" /><?php } ?>
-                       <?php if ( $this->data['cansecurelogin'] ) {?><input type="hidden" name="wpForceHttps" value="<?php $this->text( 'stickhttps' ); ?>" /><?php } ?>
-                       <?php if ( $this->data['cansecurelogin'] && $this->haveData( 'fromhttp' )) {?><input type="hidden" name="wpFromhttp" value="<?php $this->text( 'fromhttp' ); ?>" /><?php } ?>
+                               <?php
+                               }
+                       }
+
+                       // Hidden fields
+                       $fields = '';
+                       if ( $this->haveData( 'uselang' ) ) {
+                               $fields .= Html::hidden( 'uselang', $this->data['uselang'] );
+                       }
+                       if ( $this->haveData( 'token' ) ) {
+                               $fields .= Html::hidden( 'wpLoginToken', $this->data['token'] );
+                       }
+                       if ( $this->data['cansecurelogin'] ) {
+                               $fields .= Html::hidden( 'wpForceHttps', $this->data['stickhttps'] );
+                       }
+                       if ( $this->data['cansecurelogin'] && $this->haveData( 'fromhttp' ) ) {
+                               $fields .= Html::hidden( 'wpFromhttp', $this->data['fromhttp'] );
+                       }
+                       echo $fields;
+
+                       ?>
                </form>
        </div>
 </div>