Cicalese has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/369585 )
Change subject: Add earlier hook to avoid JS redirect
......................................................................
Add earlier hook to avoid JS redirect
Note that we have to pass in $title by ref because we will replace the object.
Change-Id: I3eff5988c95738ef6de5fd8404ad3becba09b0c8
---
M PluggableAuthHooks.php
D ext.PluggableAuthAutoLogin.js
M extension.json
3 files changed, 28 insertions(+), 78 deletions(-)
Approvals:
Cicalese: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/PluggableAuthHooks.php b/PluggableAuthHooks.php
index a82d024..325dc6f 100644
--- a/PluggableAuthHooks.php
+++ b/PluggableAuthHooks.php
@@ -120,24 +120,22 @@
}
/**
- * Implements BeforePageDisplay hook.
- * See https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
- * Adds auto login JavaScript module if all of the following are true:
- * - auto login is enabled
- * - no user is already logged in
- * - the current page is not a PluggableAuth login special page (which
would
- * cause an infinite loop)
- * - if the wiki requires login to read, the current page is
whitelisted (in
- * other words, users than cannot login to a wiki that requires login
to
- * read will still be able to read whitelisted pages, since those
pages
- * will not trigger auto login).
+ * Grab the page request early
+ * See https://www.mediawiki.org/wiki/Manual:Hooks/BeforeInitialize
+ * Redirects ASAP to login
+ * @param Title &$title being used for request
+ * @param null $article unused
+ * @param OutputPage $out object
+ * @param User $user current user
+ * @param WebRequest $request why we're here
+ * @param MediaWiki $mw object
*
- * @since 2.0
- *
- * @param OutputPage &$out output page obj
- * @param Skin &$skin will be used to generate the page
+ * Note that $title has to be passed by ref so we can replace it.
*/
- public static function autoLoginInit( &$out, &$skin ) {
+ public static function doBeforeInitialize(
+ Title &$title, $article, OutputPage $out, User $user,
+ WebRequest $request, MediaWiki $mw
+ ) {
if ( !$GLOBALS['wgPluggableAuth_EnableAutoLogin'] ) {
return;
}
@@ -148,14 +146,20 @@
return;
}
$loginSpecialPages =
ExtensionRegistry::getInstance()->getAttribute(
- 'PluggableAuthLoginSpecialPages' );
- $title = $out->getTitle();
+ 'PluggableAuthLoginSpecialPages'
+ );
foreach ( $loginSpecialPages as $page ) {
if ( $title->isSpecial( $page ) ) {
return;
}
}
- $out->addModules( 'ext.PluggableAuthAutoLogin' );
+
+ $oldTitle = $title;
+ $title = Title::newFromText( "UserLogin", NS_SPECIAL );
+ $out->redirect( $title->getFullURL( [
+ 'returnto' => $oldTitle,
+ 'returntoquery' => $request->getRawQueryString()
+ ] ) );
}
/**
diff --git a/ext.PluggableAuthAutoLogin.js b/ext.PluggableAuthAutoLogin.js
deleted file mode 100644
index 864f816..0000000
--- a/ext.PluggableAuthAutoLogin.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2016 The MITRE Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-( function ( mw ) {
- mw.loader.using( [ 'mediawiki.Uri', 'mediawiki.Title' ], function () {
- var pageName = mw.config.get( 'wgPageName' );
- var uri = new mw.Uri();
- if ( mw.config.get( 'wgCanonicalNamespace' ) === 'Special' ) {
- var specialPageName = mw.config.get(
'wgCanonicalSpecialPageName' );
- if ( specialPageName === 'Userlogin' ) {
- return;
- } else if ( specialPageName === 'Badtitle' ) {
- if ( uri.query.title === undefined ) {
- var articlePath = mw.config.get(
'wgArticlePath' );
- articlePath = articlePath.replace(
'$1', '(.*)' );
- var re = new RegExp( articlePath );
- var path = uri.path;
- var matches = path.match( re );
- if ( matches && matches.length > 1 ) {
- pageName = matches[1];
- } else {
- pageName = mw.config.get(
'wgMainPageName' );
- }
- } else {
- pageName = uri.query.title;
- }
- }
- }
- delete uri.query.title;
- var query = uri.getQueryString();
- var namespace = mw.config.get( 'wgNamespaceIds' ).special;
- var title = mw.Title.makeTitle( namespace, 'Userlogin' );
- var loginUrl = title.getUrl( { returnto: pageName,
returntoquery: query } );
- window.location = loginUrl;
- } );
-}( mediaWiki ) );
diff --git a/extension.json b/extension.json
index abd41de..1e9c2bd 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
{
"name": "PluggableAuth",
- "version": "5.1",
+ "version": "5.2",
"author": [
"[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy
Cicalese]"
],
@@ -47,8 +47,8 @@
"TitleReadWhitelist":
"PluggableAuthHooks::onTitleReadWhitelist",
"UserLogoutComplete": "PluggableAuthHooks::deauthenticate",
"AuthChangeFormFields":
"PluggableAuthHooks::onAuthChangeFormFields",
- "BeforePageDisplay": "PluggableAuthHooks::autoLoginInit",
- "PersonalUrls": "PluggableAuthHooks::modifyLoginURLs"
+ "PersonalUrls": "PluggableAuthHooks::modifyLoginURLs",
+ "BeforeInitialize": "PluggableAuthHooks::doBeforeInitialize"
},
"AuthManagerAutoConfig": {
"primaryauth": {
@@ -59,7 +59,8 @@
}
},
"PluggableAuthLoginSpecialPages": [
- "PluggableAuthLogin"
+ "PluggableAuthLogin",
+ "Userlogin"
],
"config": {
"PluggableAuth_EnableAutoLogin": false,
--
To view, visit https://gerrit.wikimedia.org/r/369585
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3eff5988c95738ef6de5fd8404ad3becba09b0c8
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/PluggableAuth
Gerrit-Branch: master
Gerrit-Owner: MarkAHershberger <[email protected]>
Gerrit-Reviewer: Cicalese <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits