Revised design of Special:Userlogin
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 17c8ec9..a86c356 100644 (file)
@@ -50,12 +50,23 @@ class LoginForm extends SpecialPage {
        var $mType, $mReason, $mRealName;
        var $mAbortLoginErrorMsg = 'login-abort-generic';
        private $mLoaded = false;
+       private $mSecureLoginUrl;
+       // TODO Remove old forms and mShowVForm gating after all WMF wikis have
+       // adapted messages and help links to new versions.
+       private $mShowVForm;
 
        /**
         * @ var WebRequest
         */
        private $mOverrideRequest = null;
 
+       /**
+        * Effective request; set at the beginning of load
+        *
+        * @var WebRequest $mRequest
+        */
+       private $mRequest = null;
+
        /**
         * @param WebRequest $request
         */
@@ -81,6 +92,7 @@ class LoginForm extends SpecialPage {
                } else {
                        $request = $this->mOverrideRequest;
                }
+               $this->mRequest = $request;
 
                $this->mType = $request->getText( 'type' );
                $this->mUsername = $request->getText( 'wpName' );
@@ -129,11 +141,23 @@ class LoginForm extends SpecialPage {
                        $this->mReturnTo = '';
                        $this->mReturnToQuery = '';
                }
+
+               $this->mShowVForm = $this->shouldShowVForm();
        }
 
        function getDescription() {
-               return $this->msg( $this->getUser()->isAllowed( 'createaccount' ) ?
-                       'userlogin' : 'userloginnocreate' )->text();
+               if ( !$this->getUser()->isAllowed( 'createaccount' ) ) {
+                       return $this->msg( 'userloginnocreate' )->text();
+               }
+               if ( $this->mShowVForm ) {
+                       if ( $this->mType === 'signup' ) {
+                               return $this->msg( 'createaccount' )->text();
+                       } else {
+                               return $this->msg( 'login' )->text();
+                       }
+               } else {
+                       return $this->msg( 'userlogin' )->text();
+               }
        }
 
        public function execute( $par ) {
@@ -144,10 +168,14 @@ class LoginForm extends SpecialPage {
                $this->load();
                $this->setHeaders();
 
+               if ( $par == 'signup' ) { # Check for [[Special:Userlogin/signup]]
+                       $this->mType = 'signup';
+               }
+
+               // If logging in and not on HTTPS, either redirect to it or offer a link.
                global $wgSecureLogin;
                if (
                        $this->mType !== 'signup' &&
-                       $wgSecureLogin &&
                        WebRequest::detectProtocol() !== 'https'
                ) {
                        $title = $this->getFullTitle();
@@ -157,12 +185,17 @@ class LoginForm extends SpecialPage {
                                'wpStickHTTPS' => $this->mStickHTTPS
                        );
                        $url = $title->getFullURL( $query, false, PROTO_HTTPS );
-                       $this->getOutput()->redirect( $url );
-                       return;
-               }
-
-               if ( $par == 'signup' ) { # Check for [[Special:Userlogin/signup]]
-                       $this->mType = 'signup';
+                       if ( $wgSecureLogin ) {
+                               $this->getOutput()->redirect( $url );
+                               return;
+                       } else {
+                               // A wiki without HTTPS login support should set $wgServer to
+                               // http://somehost, in which case the secure URL generated
+                               // above won't actually start with https://
+                               if ( substr( $url, 0, 8 ) === 'https://' ) {
+                                       $this->mSecureLoginUrl = $url;
+                               }
+                       }
                }
 
                if ( !is_null( $this->mCookieCheck ) ) {
@@ -978,6 +1011,22 @@ class LoginForm extends SpecialPage {
                }
        }
 
+       /**
+        * Whether to show new vertically laid out login form.
+        * ?useNew=1 forces new style, ?useNew=0 forces old style,
+        * otherwise consult $wgUseVFormUserLogin.
+        * @return Boolean
+        */
+       private function shouldShowVForm() {
+               global $wgUseVFormUserLogin;
+
+               if ( $this->mType == 'signup' ) {
+                       return false;
+               } else {
+                       return $this->mRequest->getBool( 'useNew', $wgUseVFormUserLogin );
+               }
+       }
+
        /**
         * @private
         */
@@ -989,6 +1038,7 @@ class LoginForm extends SpecialPage {
 
                $titleObj = $this->getTitle();
                $user = $this->getUser();
+               $out = $this->getOutput();
 
                if ( $this->mType == 'signup' ) {
                        // Block signup here if in readonly. Keeps user from
@@ -1019,9 +1069,17 @@ class LoginForm extends SpecialPage {
                        $q = 'action=submitlogin&type=signup';
                        $linkq = 'type=login';
                        $linkmsg = 'gotaccount';
-                       $this->getOutput()->addModules( 'mediawiki.special.userlogin.signup' );
+                       $out->addModules( 'mediawiki.special.userlogin.signup' );
                } else {
-                       $template = new UserloginTemplate();
+                       if ( $this->mShowVForm ) {
+                               $template = new UserloginTemplateVForm();
+                               $out->addModuleStyles( array(
+                                       'mediawiki.ui',
+                                       'mediawiki.special.userlogin.vform'
+                               ) );
+                       } else {
+                               $template = new UserloginTemplate();
+                       }
                        $q = 'action=submitlogin&type=login';
                        $linkq = 'type=signup';
                        $linkmsg = 'nologin';
@@ -1037,16 +1095,23 @@ class LoginForm extends SpecialPage {
                        $linkq .= $returnto;
                }
 
-               # Don't show a "create account" link if the user can't
+               # Don't show a "create account" link if the user can't.
                if( $this->showCreateOrLoginLink( $user ) ) {
                        # Pass any language selection on to the mode switch link
                        if( $wgLoginLanguageSelector && $this->mLanguage ) {
                                $linkq .= '&uselang=' . $this->mLanguage;
                        }
-                       $link = Html::element( 'a', array( 'href' => $titleObj->getLocalURL( $linkq ) ),
-                               $this->msg( $linkmsg . 'link' )->text() ); # Calling either 'gotaccountlink' or 'nologinlink'
+                       if ( !$this->mShowVForm ) {
+                               $link = Html::element( 'a', array( 'href' => $titleObj->getLocalURL( $linkq ) ),
+                                       $this->msg( $linkmsg . 'link' )->text() ); # Calling either 'gotaccountlink' or 'nologinlink'
+
+                                       $template->set( 'link', $this->msg( $linkmsg )->rawParams( $link )->parse() );
 
-                       $template->set( 'link', $this->msg( $linkmsg )->rawParams( $link )->parse() );
+                       } else {
+                               // Supply URL, login template creates the button.
+                               // (The template 'link' key, passed above, is obsolete in the VForm design.)
+                               $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
+                       }
                } else {
                        $template->set( 'link', '' );
                }
@@ -1106,8 +1171,9 @@ class LoginForm extends SpecialPage {
                        }
                }
 
+               $template->set( 'secureLoginUrl', $this->mSecureLoginUrl );
                // Use loginend-https for HTTPS requests if it's not blank, loginend otherwise
-               // Ditto for signupend
+               // Ditto for signupend.  New forms use neither.
                $usingHTTPS = WebRequest::detectProtocol() == 'https';
                $loginendHTTPS = $this->msg( 'loginend-https' );
                $signupendHTTPS = $this->msg( 'signupend-https' );
@@ -1130,7 +1196,6 @@ class LoginForm extends SpecialPage {
                        wfRunHooks( 'UserLoginForm', array( &$template ) );
                }
 
-               $out = $this->getOutput();
                $out->disallowUserJs(); // just in case...
                $out->addTemplate( $template );
        }