Merge "Fix separated login link so that create account and login are always next...
[lhc/web/wiklou.git] / includes / templates / Userlogin.php
index e2eb19e..a3f6a38 100644 (file)
@@ -1,15 +1,35 @@
 <?php
 /**
- * @addtogroup Templates
+ * Html form for user login.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Templates
  */
-if( !defined( 'MEDIAWIKI' ) ) die( -1 );
 
-/** */
-require_once( 'includes/SkinTemplate.php' );
+/**
+ * @defgroup Templates Templates
+ */
+
+if( !defined( 'MEDIAWIKI' ) ) die( -1 );
 
 /**
  * HTML template for Special:Userlogin form
- * @addtogroup Templates
+ * @ingroup Templates
  */
 class UserloginTemplate extends QuickTemplate {
        function execute() {
@@ -17,7 +37,7 @@ class UserloginTemplate extends QuickTemplate {
 ?>
        <div class="<?php $this->text('messagetype') ?>box">
                <?php if ( $this->data['messagetype'] == 'error' ) { ?>
-                       <h2><?php $this->msg('loginerror') ?>:</h2>
+                       <strong><?php $this->msg( 'loginerror' )?></strong><br />
                <?php } ?>
                <?php $this->html('message') ?>
        </div>
@@ -31,31 +51,44 @@ class UserloginTemplate extends QuickTemplate {
        <p id="userloginlink"><?php $this->html('link') ?></p>
        <?php $this->html('header'); /* pre-table point for form plugins... */ ?>
        <div id="userloginprompt"><?php  $this->msgWiki('loginprompt') ?></div>
-       <?php if( @$this->haveData( 'languages' ) ) { ?><div id="languagelinks"><p><?php $this->html( 'languages' ); ?></p></div><?php } ?>
+       <?php if( $this->haveData( 'languages' ) ) { ?><div id="languagelinks"><p><?php $this->html( 'languages' ); ?></p></div><?php } ?>
        <table>
                <tr>
                        <td class="mw-label"><label for='wpName1'><?php $this->msg('yourname') ?></label></td>
                        <td class="mw-input">
-                               <input type='text' class='loginText' name="wpName" id="wpName1"
-                                       tabindex="1"
-                                       value="<?php $this->text('name') ?>" size='20' />
+                               <?php
+                       echo Html::input( 'wpName', $this->data['name'], 'text', array(
+                               'class' => 'loginText',
+                               'id' => 'wpName1',
+                               'tabindex' => '1',
+                               'size' => '20',
+                               'required'
+                               # Can't do + array( 'autofocus' ) because + for arrays in PHP
+                               # only works right for associative arrays!  Thanks, PHP.
+                       ) + ( $this->data['name'] ? array() : array( 'autofocus' => '' ) ) ); ?>
+
                        </td>
                </tr>
                <tr>
                        <td class="mw-label"><label for='wpPassword1'><?php $this->msg('yourpassword') ?></label></td>
                        <td class="mw-input">
-                               <input type='password' class='loginPassword' name="wpPassword" id="wpPassword1"
-                                       tabindex="2"
-                                       value="" size='20' />
+                               <?php
+                       echo Html::input( 'wpPassword', null, 'password', array(
+                               'class' => 'loginPassword',
+                               'id' => 'wpPassword1',
+                               'tabindex' => '2',
+                               'size' => '20'
+                       ) + ( $this->data['name'] ? array( 'autofocus' ) : array() ) ); ?>
+
                        </td>
                </tr>
-       <?php if( $this->data['usedomain'] ) {
+       <?php if( isset( $this->data['usedomain'] ) && $this->data['usedomain'] ) {
                $doms = "";
                foreach( $this->data['domainnames'] as $dom ) {
                        $doms .= "<option>" . htmlspecialchars( $dom ) . "</option>";
                }
        ?>
-               <tr>
+               <tr id="mw-user-domain-section">
                        <td class="mw-label"><?php $this->msg( 'yourdomainname' ) ?></td>
                        <td class="mw-input">
                                <select name="wpDomain" value="<?php $this->text( 'domain' ) ?>"
@@ -64,157 +97,83 @@ class UserloginTemplate extends QuickTemplate {
                                </select>
                        </td>
                </tr>
-       <?php } ?>
-               <tr>
-                       <td></td>
-                       <td class="mw-input">
-                               <input type='checkbox' name="wpRemember"
-                                       tabindex="4"
-                                       value="1" id="wpRemember"
-                                       <?php if( $this->data['remember'] ) { ?>checked="checked"<?php } ?>
-                                       /> <label for="wpRemember"><?php $this->msg('remembermypassword') ?></label>
-                       </td>
-               </tr>
-               <tr>
-                       <td></td>
-                       <td class="mw-submit">
-                               <input type='submit' name="wpLoginattempt" id="wpLoginattempt" tabindex="5" value="<?php $this->msg('login') ?>" />&nbsp;<?php if( $this->data['useemail'] && $this->data['canreset']) { ?><input type='submit' name="wpMailmypassword" id="wpMailmypassword"
-                                       tabindex="6"
-                                                                       value="<?php $this->msg('mailmypassword') ?>" />
-                               <?php } ?>
-                       </td>
-               </tr>
-       </table>
-<?php if( @$this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?php } ?>
-</form>
-</div>
-<div id="loginend"><?php $this->msgWiki( 'loginend' ); ?></div>
-<?php
+       <?php }
 
+       if( $this->haveData( 'extrafields' ) ) {
+               echo $this->data['extrafields'];
        }
-}
 
-/**
- * @addtogroup Templates
- */
-class UsercreateTemplate extends QuickTemplate {
-       function execute() {
-               if( $this->data['message'] ) {
-?>
-       <div class="<?php $this->text('messagetype') ?>box">
-               <?php if ( $this->data['messagetype'] == 'error' ) { ?>
-                       <h2><?php $this->msg('loginerror') ?>:</h2>
-               <?php } ?>
-               <?php $this->html('message') ?>
-       </div>
-       <div class="visualClear"></div>
-<?php } ?>
-<div id="userlogin">
-
-<form name="userlogin2" id="userlogin2" method="post" action="<?php $this->text('action') ?>">
-       <h2><?php $this->msg('createaccount') ?></h2>
-       <p id="userloginlink"><?php $this->html('link') ?></p>
-       <?php $this->html('header'); /* pre-table point for form plugins... */ ?>
-       <?php if( @$this->haveData( 'languages' ) ) { ?><div id="languagelinks"><p><?php $this->html( 'languages' ); ?></p></div><?php } ?>
-       <table>
-               <tr>
-                       <td class="mw-label"><label for='wpName2'><?php $this->msg('yourname') ?></label></td>
-                       <td class="mw-input">
-                               <input type='text' class='loginText' name="wpName" id="wpName2"
-                                       tabindex="1"
-                                       value="<?php $this->text('name') ?>" size='20' />
-                       </td>
-               </tr>
-               <tr>
-                       <td class="mw-label"><label for='wpPassword2'><?php $this->msg('yourpassword') ?></label></td>
-                       <td class="mw-input">
-                               <input type='password' class='loginPassword' name="wpPassword" id="wpPassword2"
-                                       tabindex="2"
-                                       value="" size='20' />
-                       </td>
-               </tr>
-       <?php if( $this->data['usedomain'] ) {
-               $doms = "";
-               foreach( $this->data['domainnames'] as $dom ) {
-                       $doms .= "<option>" . htmlspecialchars( $dom ) . "</option>";
-               }
-       ?>
+       if( $this->data['canremember'] ) { ?>
                <tr>
-                       <td class="mw-label"><?php $this->msg( 'yourdomainname' ) ?></td>
-                       <td class="mw-input">
-                               <select name="wpDomain" value="<?php $this->text( 'domain' ) ?>"
-                                       tabindex="3">
-                                       <?php echo $doms ?>
-                               </select>
-                       </td>
-               </tr>
-       <?php } ?>
-               <tr>
-                       <td class="mw-label"><label for='wpRetype'><?php $this->msg('yourpasswordagain') ?></label></td>
+                       <td></td>
                        <td class="mw-input">
-                               <input type='password' class='loginPassword' name="wpRetype" id="wpRetype"
-                                       tabindex="4"
-                                       value=""
-                                       size='20' />
+                               <?php
+                               global $wgCookieExpiration;
+                               $expirationDays = ceil( $wgCookieExpiration / ( 3600 * 24 ) );
+                               echo Xml::checkLabel(
+                                       wfMessage( 'remembermypassword' )->numParams( $expirationDays )->text(),
+                                       'wpRemember',
+                                       'wpRemember',
+                                       $this->data['remember'],
+                                       array( 'tabindex' => '8' )
+                               )
+                               ?>
                        </td>
                </tr>
-               <tr>
-                       <?php if( $this->data['useemail'] ) { ?>
-                               <td class="mw-label"><label for='wpEmail'><?php $this->msg('youremail') ?></label></td>
-                               <td class="mw-input">
-                                       <input type='text' class='loginText' name="wpEmail" id="wpEmail"
-                                               tabindex="5"
-                                               value="<?php $this->text('email') ?>" size='20' />
-                                       <div class="prefsectiontip">
-                                               <?php $this->msgWiki('prefs-help-email'); ?>
-                                       </div>
-                               </td>
-                       <?php } ?>
-                       <?php if( $this->data['userealname'] ) { ?>
-                               </tr>
-                               <tr>
-                                       <td class="mw-label"><label for='wpRealName'><?php $this->msg('yourrealname') ?></label></td>
-                                       <td class="mw-input">
-                                               <input type='text' class='loginText' name="wpRealName" id="wpRealName"
-                                                       tabindex="6"
-                                                       value="<?php $this->text('realname') ?>" size='20' />
-                                               <div class="prefsectiontip">
-                                                       <?php $this->msgWiki('prefs-help-realname'); ?>
-                                               </div>
-                                       </td>
-                       <?php } ?>
-               </tr>
+<?php } ?>
+<?php if( $this->data['cansecurelogin'] ) { ?>
                <tr>
                        <td></td>
                        <td class="mw-input">
-                               <input type='checkbox' name="wpRemember"
-                                       tabindex="7"
-                                       value="1" id="wpRemember"
-                                       <?php if( $this->data['remember'] ) { ?>checked="checked"<?php } ?>
-                                       /> <label for="wpRemember"><?php $this->msg('remembermypassword') ?></label>
+                       <?php
+                       echo Xml::checkLabel(
+                               wfMessage( 'securelogin-stick-https' )->text(),
+                               'wpStickHTTPS',
+                               'wpStickHTTPS',
+                               $this->data['stickHTTPS'],
+                               array( 'tabindex' => '9' )
+                       );
+               ?>
                        </td>
                </tr>
+<?php } ?>
                <tr>
                        <td></td>
                        <td class="mw-submit">
-                               <input type='submit' name="wpCreateaccount" id="wpCreateaccount"
-                                       tabindex="8"
-                                       value="<?php $this->msg('createaccount') ?>" />
-                               <?php if( $this->data['createemail'] ) { ?>
-                               <input type='submit' name="wpCreateaccountMail" id="wpCreateaccountMail"
-                                       tabindex="9"
-                                       value="<?php $this->msg('createaccountmail') ?>" />
-                               <?php } ?>
+                               <?php
+               echo Html::input( 'wpLoginAttempt', wfMessage( 'login' )->text(), 'submit', array(
+                       'id' => 'wpLoginAttempt',
+                       'tabindex' => '9'
+               ) );
+               if ( $this->data['useemail'] && $this->data['canreset'] ) {
+                       if( $this->data['resetlink'] === true ){
+                               echo '&#160;';
+                               echo Linker::link(
+                                       SpecialPage::getTitleFor( 'PasswordReset' ),
+                                       wfMessage( 'userlogin-resetlink' )
+                               );
+                       } elseif( $this->data['resetlink'] === null ) {
+                               echo '&#160;';
+                               echo Html::input(
+                                       'wpMailmypassword',
+                                       wfMessage( 'mailmypassword' )->text(),
+                                       'submit', array(
+                                               'id' => 'wpMailmypassword',
+                                               'tabindex' => '10'
+                                       )
+                               );
+                       }
+               } ?>
+
                        </td>
                </tr>
        </table>
-<?php if( @$this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?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 } ?>
 </form>
 </div>
-<div id="signupend"><?php $this->msgWiki( 'signupend' ); ?></div>
+<div id="loginend"><?php $this->html( 'loginend' ); ?></div>
 <?php
 
        }
 }
-
-?>