Commit b9a1b503 authored by cicalese's avatar cicalese
Browse files

Fixed whitelist issue for non-English wikis.

Change-Id: I77fe4d8c66df632b8a9c647ab3e69ac7f2fb86be
parent 508ed98e
...@@ -27,15 +27,12 @@ class PluggableAuthHooks { ...@@ -27,15 +27,12 @@ class PluggableAuthHooks {
/** /**
* Implements extension registration callback. * Implements extension registration callback.
* See https://www.mediawiki.org/wiki/Manual:Extension_registration#Customizing_registration * See https://www.mediawiki.org/wiki/Manual:Extension_registration#Customizing_registration
* Removes password providers if local login is not enabled.
* *
* @since 2.0 * @since 2.0
* *
*/ */
public static function onRegistration() { public static function onRegistration() {
if ( !$GLOBALS['wgWhitelistRead'] ) {
$GLOBALS['wgWhitelistRead'] = [];
}
$GLOBALS['wgWhitelistRead'][] = 'Special:PluggableAuthLogin';
if ( $GLOBALS['wgPluggableAuth_EnableLocalLogin'] ) { if ( $GLOBALS['wgPluggableAuth_EnableLocalLogin'] ) {
return; return;
} }
...@@ -54,10 +51,32 @@ class PluggableAuthHooks { ...@@ -54,10 +51,32 @@ class PluggableAuthHooks {
} }
} }
/**
*
* Implements TitleReadWhitelist hook.
* See https://www.mediawiki.org/wiki/Manual:Hooks/TitleReadWhitelist
* Adds PluggableAuth login special pages to whitelist.
*
* @since 2.0
*
*/
public static function onTitleReadWhitelist( $title, $user, &$whitelisted ) {
$loginSpecialPages = ExtensionRegistry::getInstance()->getAttribute(
'PluggableAuthLoginSpecialPages' );
foreach ( $loginSpecialPages as $page ) {
if ( $title->isSpecial( $page ) ) {
$whitelisted = true;
return true;
}
}
return true;
}
/** /**
* *
* Implements AuthChangeFormFields hook. * Implements AuthChangeFormFields hook.
* See https://www.mediawiki.org/wiki/Manual:Hooks/AuthChangeFormFields * See https://www.mediawiki.org/wiki/Manual:Hooks/AuthChangeFormFields
* Moves login button to bottom of form.
* *
* @since 2.0 * @since 2.0
* *
...@@ -76,6 +95,7 @@ class PluggableAuthHooks { ...@@ -76,6 +95,7 @@ class PluggableAuthHooks {
/** /**
* Implements UserLogoutComplete hook. * Implements UserLogoutComplete hook.
* See https://www.mediawiki.org/wiki/Manual:Hooks/UserLogoutComplete * See https://www.mediawiki.org/wiki/Manual:Hooks/UserLogoutComplete
* Calls deauthenticate hook in authentication plugin.
* *
* @since 2.0 * @since 2.0
* *
...@@ -100,6 +120,15 @@ class PluggableAuthHooks { ...@@ -100,6 +120,15 @@ class PluggableAuthHooks {
/** /**
* Implements BeforePageDisplay hook. * Implements BeforePageDisplay hook.
* 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).
* *
* @since 2.0 * @since 2.0
* *
...@@ -107,15 +136,31 @@ class PluggableAuthHooks { ...@@ -107,15 +136,31 @@ class PluggableAuthHooks {
* @param Skin $skin * @param Skin $skin
*/ */
public static function autoLoginInit( &$out, &$skin ) { public static function autoLoginInit( &$out, &$skin ) {
if ( $GLOBALS['wgPluggableAuth_EnableAutoLogin'] ) { if ( !$GLOBALS['wgPluggableAuth_EnableAutoLogin'] ) {
$out->addModules( 'ext.PluggableAuthAutoLogin' ); return true;
} }
if ( !$out->getUser()->isAnon() ) {
return true;
}
$loginSpecialPages = ExtensionRegistry::getInstance()->getAttribute(
'PluggableAuthLoginSpecialPages' );
$title = $out->getTitle();
foreach ( $loginSpecialPages as $page ) {
if ( $title->isSpecial( $page ) ) {
return true;
}
}
if ( !User::isEveryoneAllowed( 'read' ) && $title->userCan( 'read' ) ) {
return true;
}
$out->addModules( 'ext.PluggableAuthAutoLogin' );
return true; return true;
} }
/** /**
* Implements PersonalUrls hook. * Implements PersonalUrls hook.
* See https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls * See https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
* Removes logout link from skin if auto login is enabled.
* *
* @since 1.0 * @since 1.0
* *
...@@ -130,16 +175,4 @@ class PluggableAuthHooks { ...@@ -130,16 +175,4 @@ class PluggableAuthHooks {
} }
return true; return true;
} }
/**
* Implements ResourceLoaderGetConfigVars hook.
* See https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
*
* @since 2.0
*
* @param array &$vars
*/
public static function onResourceLoaderGetConfigVars( array &$vars ) {
$vars['wgWhitelistRead'] = $GLOBALS['wgWhitelistRead'];
}
} }
...@@ -21,56 +21,35 @@ ...@@ -21,56 +21,35 @@
*/ */
( function ( mw ) { ( function ( mw ) {
// Are we already logged in?
if ( mw.config.get( 'wgUserName' ) !== null ) {
return;
}
var pageName = mw.config.get( 'wgPageName' );
var namespace = mw.config.get( 'wgCanonicalNamespace' );
if ( namespace === 'Special' ) {
var specialPageName = mw.config.get( 'wgCanonicalSpecialPageName' );
if ( specialPageName === 'Userlogin' || pageName === 'Special:UserLogin' ) {
return;
} else if ( specialPageName === 'Badtitle' || pageName === 'Special:Badtitle' ) {
pageName = null;
} else {
pageName = namespace + ':' + specialPageName;
}
}
// Is this page whitelisted?
var whitelist = mw.config.get( 'wgWhitelistRead' );
for ( i = 0; i < whitelist.length; i++ ) {
if ( whitelist[i] === pageName ) {
return;
}
}
// Redirect to Special:UserLogin
mw.loader.using( [ 'mediawiki.Uri', 'mediawiki.Title' ], function () { mw.loader.using( [ 'mediawiki.Uri', 'mediawiki.Title' ], function () {
var pageName = mw.config.get( 'wgPageName' );
var uri = new mw.Uri(); var uri = new mw.Uri();
if ( pageName === null ) { if ( mw.config.get( 'wgCanonicalNamespace' ) === 'Special' ) {
if ( uri.query.title === undefined ) { var specialPageName = mw.config.get( 'wgCanonicalSpecialPageName' );
var articlePath = mw.config.get( 'wgArticlePath' ); if ( specialPageName === 'Userlogin' ) {
articlePath = articlePath.replace( '$1', '(.*)' ); return;
var re = new RegExp( articlePath ); } else if ( specialPageName === 'Badtitle' ) {
var path = uri.path; if ( uri.query.title === undefined ) {
var matches = path.match( re ); var articlePath = mw.config.get( 'wgArticlePath' );
if ( matches.length > 1 ) { articlePath = articlePath.replace( '$1', '(.*)' );
pageName = matches[1]; var re = new RegExp( articlePath );
var path = uri.path;
var matches = path.match( re );
if ( matches.length > 1 ) {
pageName = matches[1];
} else {
pageName = mw.config.get( 'wgMainPageName' );
}
} else { } else {
pageName = mw.config.get( 'wgMainPageName' ); pageName = uri.query.title;
} }
} else {
pageName = uri.query.title;
} }
} }
delete uri.query.title; delete uri.query.title;
var query = uri.getQueryString(); var query = uri.getQueryString();
var loginPageName = "Special:Userlogin"; var namespace = mw.config.get( 'wgNamespaceIds' ).special;
var loginUrl = new mw.Title( loginPageName ).getUrl( var title = mw.Title.makeTitle( namespace, 'Userlogin' );
{ returnto: pageName, returntoquery: query } ); var loginUrl = title.getUrl( { returnto: pageName, returntoquery: query } );
window.location = loginUrl; window.location = loginUrl;
} ); } );
}( mediaWiki ) ); }( mediaWiki ) );
...@@ -41,11 +41,11 @@ ...@@ -41,11 +41,11 @@
}, },
"callback": "PluggableAuthHooks::onRegistration", "callback": "PluggableAuthHooks::onRegistration",
"Hooks": { "Hooks": {
"TitleReadWhitelist": "PluggableAuthHooks::onTitleReadWhitelist",
"UserLogoutComplete": "PluggableAuthHooks::deauthenticate", "UserLogoutComplete": "PluggableAuthHooks::deauthenticate",
"AuthChangeFormFields": "PluggableAuthHooks::onAuthChangeFormFields", "AuthChangeFormFields": "PluggableAuthHooks::onAuthChangeFormFields",
"BeforePageDisplay": "PluggableAuthHooks::autoLoginInit", "BeforePageDisplay": "PluggableAuthHooks::autoLoginInit",
"PersonalUrls": "PluggableAuthHooks::modifyLoginURLs", "PersonalUrls": "PluggableAuthHooks::modifyLoginURLs"
"ResourceLoaderGetConfigVars": "PluggableAuthHooks::onResourceLoaderGetConfigVars"
}, },
"AuthManagerAutoConfig": { "AuthManagerAutoConfig": {
"primaryauth": { "primaryauth": {
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
} }
} }
}, },
"PluggableAuthLoginSpecialPages": [
"PluggableAuthLogin"
],
"config": { "config": {
"PluggableAuth_EnableAutoLogin": false, "PluggableAuth_EnableAutoLogin": false,
"PluggableAuth_EnableLocalLogin": false "PluggableAuth_EnableLocalLogin": false
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment