Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/218662

Change subject: Add a new option to move the button to the right side
......................................................................

Add a new option to move the button to the right side

Also use HTMLForm to built an own form above the "normal" login form
to get rid of the wgAuth hack use.

Change-Id: I7660e5d5cf34ca78feb69844abf85174e7bd40b3
---
M GoogleLogin.php
M includes/GoogleLogin.body.php
D includes/GoogleLoginAuth.php
M includes/specials/SpecialGoogleLogin.php
A style/ext.GoogleLogin.right.css
5 files changed, 106 insertions(+), 101 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GoogleLogin 
refs/changes/62/218662/1

diff --git a/GoogleLogin.php b/GoogleLogin.php
index 5e62d12..bedf258 100644
--- a/GoogleLogin.php
+++ b/GoogleLogin.php
@@ -45,31 +45,17 @@
                'license-name' => "MIT",
        );
 
-       $dir = __DIR__;
-
        // Autoload Classes
-       $wgAutoloadClasses[ 'GoogleLogin' ] = $dir . 
'/includes/GoogleLogin.body.php';
-       $wgAutoloadClasses[ 'SpecialGoogleLogin' ] = $dir . 
'/includes/specials/SpecialGoogleLogin.php';
-       $wgAutoloadClasses[ 'SpecialManageGoogleLogin' ] = $dir . 
'/includes/specials/SpecialManageGoogleLogin.php';
-       $wgAutoloadClasses[ 'GoogleLoginHooks' ] = $dir . 
'/includes/GoogleLogin.hooks.php';
-       $wgAutoloadClasses[ 'GoogleLoginDB' ] = $dir . 
'/includes/GoogleLoginDB.php';
-       $wgAutoloadClasses[ 'GoogleLoginAuth' ] = $dir . 
'/includes/GoogleLoginAuth.php';
-       $wgAutoloadClasses[ 'ApiGoogleLoginInfo' ] = $dir . 
'/includes/api/ApiGoogleLoginInfo.php';
-
-       $wgExtensionFunctions[] = 'efGoogleLoginSetup';
-
-       function efGoogleLoginSetup() {
-               global $wgAuth;
-               // check if we can load wgAuth automatically
-               if ( class_exists( 'GoogleLoginAuth' ) ) {
-                       // load $wgAuth
-                       $wgAuth = new GoogleLoginAuth;
-               }
-       }
+       $wgAutoloadClasses[ 'GoogleLogin' ] = __DIR__ . 
'/includes/GoogleLogin.body.php';
+       $wgAutoloadClasses[ 'SpecialGoogleLogin' ] = __DIR__ . 
'/includes/specials/SpecialGoogleLogin.php';
+       $wgAutoloadClasses[ 'SpecialManageGoogleLogin' ] = __DIR__ . 
'/includes/specials/SpecialManageGoogleLogin.php';
+       $wgAutoloadClasses[ 'GoogleLoginHooks' ] = __DIR__ . 
'/includes/GoogleLogin.hooks.php';
+       $wgAutoloadClasses[ 'GoogleLoginDB' ] = __DIR__ . 
'/includes/GoogleLoginDB.php';
+       $wgAutoloadClasses[ 'ApiGoogleLoginInfo' ] = __DIR__ . 
'/includes/api/ApiGoogleLoginInfo.php';
 
        // i18n directory and aliases
-       $wgExtensionMessagesFiles[ 'GoogleLoginAlias' ] = $dir . 
'/GoogleLogin.alias.php';
-       $wgMessagesDirs['GoogleLogin'] = $dir . '/i18n';
+       $wgExtensionMessagesFiles[ 'GoogleLoginAlias' ] = __DIR__ . 
'/GoogleLogin.alias.php';
+       $wgMessagesDirs['GoogleLogin'] = __DIR__ . '/i18n';
 
        // new user rights for this extension
        $wgGroupPermissions['sysop']['managegooglelogin'] = true;
@@ -103,10 +89,16 @@
                'remoteExtPath' => 'GoogleLogin'
        );
 
-       $wgResourceModules['ext.GoogleLogin.style'] = $wgGLResourcePath + array(
-               'styles' => 'style/ext.GoogleLogin.css',
-               'position' => 'top',
-               'targets' => array( 'desktop', 'mobile' ),
+       $wgResourceModules += array(
+               'ext.GoogleLogin.style' => $wgGLResourcePath + array(
+                       'styles' => 'style/ext.GoogleLogin.css',
+                       'position' => 'top',
+                       'targets' => array( 'desktop', 'mobile' ),
+               ),
+               'ext.GoogleLogin.right.style' => $wgGLResourcePath + array(
+                       'styles' => 'style/ext.GoogleLogin.right.css',
+                       'position' => 'top',
+               ),
        );
 
        $wgResourceModules['ext.GoogleLogin.specialManage.scripts'] = 
$wgGLResourcePath + array(
@@ -199,3 +191,9 @@
         * Key for public API access. Used only for admin actions to check, if 
the user has a plus profile or not.
         */
        $wgGLAPIKey = '';
+
+       /**
+        * If set to true, the Google Login button will be added to the right 
side of the login form, instead
+        * above the normal login form.
+        */
+       $wgGLShowRight = false;
diff --git a/includes/GoogleLogin.body.php b/includes/GoogleLogin.body.php
index 1843127..ddfd3e2 100644
--- a/includes/GoogleLogin.body.php
+++ b/includes/GoogleLogin.body.php
@@ -522,74 +522,75 @@
                        return true;
                }
 
-               /**
-                * Redirects to GoogleLogin login page if called. Actually used 
for AuthPlugin
-                * @todo: kill if better solution as AuthPlugin is found
-                */
-               public static function externalLoginAttempt() {
-                       global $wgOut, $wgRequest;
-                       if (
-                               $wgRequest->getVal( 'googlelogin-submit' ) !== 
null &&
-                               $wgRequest->getVal( 'wpPassword' ) === ''
-                       ) {
-                               $googleLogin = new GoogleLogin;
-                               $googleLogin->setLoginParameter( $wgRequest );
-                               $client = $googleLogin->getClient();
-                               $authUrl = $client->createAuthUrl();
-                               $wgOut->redirect( $authUrl );
-                               $wgOut->output();
-                       }
-               }
-
                public static function getLoginCreateForm( &$tpl, $login = true 
) {
                        $glConfig = 
ConfigFactory::getDefaultInstance()->makeConfig( 'googlelogin' );
-                       // we don't want to delete the output of other 
extensions, so "extend" header
-                       $header = $tpl->get( 'header' );
-
-                       // add css module
                        $out = $tpl->getSkin()->getOutput();
-                       $out->addModules( 'ext.GoogleLogin.style' );
+                       // actual styling doesn't work on create account page, 
there's already a nice div using the space
+                       $showRight = $login ? $glConfig->get( 'GLShowRight' ) : 
false;
 
-                       $keepLogin = '';
+                       // add default css module
+                       $modules = array( 'ext.GoogleLogin.style' );
+                       // if the administrator requested to show the form at 
the right side,
+                       // add this module, too
+                       if ( $showRight ) {
+                               $modules[] = 'ext.GoogleLogin.right.style';
+                       }
+                       $out->addModules( $modules );
+
+                       // keep login is only added, if enabled in the 
configuration
+                       $keepLogin = array();
                        if ( $glConfig->get( 'GLShowKeepLogin' ) && $login ) {
-                               $keepLogin = Html::openElement( 'div', array( 
'class' => 'mw-ui-vform-field' ) ) .
-                               Html::openElement( 'div', array( 'class' => 
'mw-ui-checkbox' ) ) .
-                               Html::input(
-                                       'wpGoogleLoginRemember',
-                                       '1',
-                                       'checkbox',
-                                       array( 'id' => 'wpGoogleLoginRemember' )
-                               ) . ' ' .
-                               Html::element(
-                                       'label',
-                                       array( 'for' => 'wpGoogleLoginRemember' 
),
-                                       $tpl->getMsg( 
'userlogin-remembermypassword' )->escaped()
-                               ) .
-                               Html::closeElement( 'div') .
-                               Html::closeElement( 'div');
+                               $keepLogin = array(
+                                       'wpGoogleLoginRemember' => array(
+                                               'type' => 'check',
+                                               'value' => '1',
+                                               'id' => 'wpGoogleLoginRemember',
+                                               'name' => 
'wpGoogleLoginRemember',
+                                               'label' => $tpl->getMsg( 
'userlogin-remembermypassword' )->escaped()
+                                       )
+                               );
                        }
 
+                       // get the correct button value
                        if ( $login ) {
+                               // login form value
                                $buttonMsg = $tpl->getMsg( 'googlelogin' 
)->escaped();
                        } else {
+                               // create form value
                                $buttonMsg = $tpl->getMsg( 'googlelogin-create' 
)->escaped();
                        }
-                       $header .=
-                               $keepLogin .
-                               Html::openElement( 'div', array( 'class' => 
'mw-ui-vform-field' ) ) .
-                               Html::element( 'input', array(
-                                               'class' => 'mw-ui-button 
mw-ui-destructive',
-                                               'style' => 'width:100%;',
-                                               'type' => 'submit',
-                                               'name' => 'googlelogin-submit',
-                                               'value' => $buttonMsg
-                                       ), ''
-                               ) .
-                               Html::closeElement( 'div' ) .
-                               Html::openElement( 'fieldset', array( 'class' 
=> 'loginSeperator' ) ) .
-                               Html::element( 'legend', array(), $tpl->getMsg( 
'googlelogin-or' )->escaped() ) .
-                               Html::closeElement( 'fieldset' );
 
-                       $tpl->set( 'header', $header );
+                       // google login form button
+                       $fields = array(
+                               'googleLoginButton' => array(
+                                       'type' => 'submit',
+                                       'name' => 'googlelogin-submit',
+                                       'cssclass' => 'mw-ui-destructive',
+                                       'default' => $buttonMsg,
+                               )
+                       ) + $keepLogin;
+
+                       // allow other extensions to add fields, too (e.g. 
other buttons)
+                       // FIXME: Should this live in GoogleLogin? Not really!
+                       Hooks::run( 'GoogleLoginFormFields', array( &$fields ) 
);
+
+                       // create a separate vform above the "normal" user 
login form
+                       $htmlForm = HTMLForm::factory( 'vform', $fields, 
$tpl->getSkin()->getContext() );
+                       // we don't need (and want) a separate submit button
+                       $htmlForm->suppressDefaultSubmit();
+                       $htmlForm->setId( 'googleloginForm' );
+                       // the target isn't Special:UserLogin, set it to be 
Special:GoogleLogin
+                       $htmlForm->setAction( SpecialPage::getTitleFor( 
'GoogleLogin' )->getLocalUrl() );
+                       // show the form
+                       $htmlForm->prepareForm()->displayForm( false );
+
+                       // if the form is above the login form, show a separator
+                       if ( !$showRight ) {
+                               $out->addHtml(
+                                       Html::openElement( 'fieldset', array( 
'class' => 'loginSeperator mw-ui-vform' ) ) .
+                                       Html::element( 'legend', array(), 
$tpl->getMsg( 'googlelogin-or' )->escaped() ) .
+                                       Html::closeElement( 'fieldset' )
+                               );
+                       }
                }
        }
diff --git a/includes/GoogleLoginAuth.php b/includes/GoogleLoginAuth.php
deleted file mode 100644
index 6e86d7e..0000000
--- a/includes/GoogleLoginAuth.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-       // handles only the redirect to Special:GoogleLogin if needed
-       class GoogleLoginAuth extends AuthPlugin {
-               /**
-                * Normally this handles the check if a domain is valid. We use 
this
-                * to get into the login process in an early process to check, 
if the user
-                * clicks the Login with Google button or the MediaWiki login 
button.
-                *
-                * @param string $domain Domain name (unneeded)
-                * @return boolean Always false, we don't check anything here
-                */
-               public function validDomain( $domain ) {
-                       GoogleLogin::externalLoginAttempt();
-                       return true;
-               }
-       }
diff --git a/includes/specials/SpecialGoogleLogin.php 
b/includes/specials/SpecialGoogleLogin.php
index 0bf2e20..aa89b68 100644
--- a/includes/specials/SpecialGoogleLogin.php
+++ b/includes/specials/SpecialGoogleLogin.php
@@ -15,8 +15,22 @@
                 * @param SubPage $par Subpage submitted to this Special page.
                 */
                function execute( $par ) {
+                       $this->mGoogleLogin = $googleLogin = new GoogleLogin;
+                       $request = $this->getRequest();
+                       $out = $this->getOutput();
+
                        if ( session_id() == '' ) {
                                wfSetupSession();
+                       }
+
+                       // Check, if a user clicked the login button on the 
login/create form
+                       if ( $request->getVal( 'googlelogin-submit' ) !== null 
) {
+                               $googleLogin->setLoginParameter( $request );
+                               $client = $googleLogin->getClient();
+                               $authUrl = $client->createAuthUrl();
+                               $out->redirect( $authUrl );
+                               $out->output();
+                               return;
                        }
 
                        $config = $this->getConfig();
@@ -24,10 +38,7 @@
                        set_error_handler( 
'GoogleLogin::catchableFatalHandler', E_RECOVERABLE_ERROR );
 
                        $this->setHeaders();
-                       $request = $this->getRequest();
-                       $out = $this->getOutput();
                        $db = new GoogleLoginDB;
-                       $this->mGoogleLogin = $googleLogin = new GoogleLogin;
 
                        // add module styles
                        $out->addModules( 'ext.GoogleLogin.style' );
diff --git a/style/ext.GoogleLogin.right.css b/style/ext.GoogleLogin.right.css
new file mode 100644
index 0000000..f2aa491
--- /dev/null
+++ b/style/ext.GoogleLogin.right.css
@@ -0,0 +1,11 @@
+#googleloginForm {
+       position: absolute;
+       /* Fixed width of login form vform + 15px margin */
+       left: 305px;
+       /* margin between separator and form, same as left - width (of 
loginform) */
+       padding-left: 15px;
+       /* line-height of first label */
+       padding-top: 1.6em;
+       height: 90%;
+       border-left: 1px solid lightgrey;
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/218662
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7660e5d5cf34ca78feb69844abf85174e7bd40b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GoogleLogin
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.wel...@t-online.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to