wiki.techinc.nl/includes/resourceloader/ResourceLoaderUserModule.php

84 lines
2.5 KiB
PHP
Raw Normal View History

<?php
/**
* 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
* @author Trevor Parscal
* @author Roan Kattouw
*/
use MediaWiki\MediaWikiServices;
/**
* Module for user customizations scripts.
*
* @ingroup ResourceLoader
* @internal
*/
class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
protected $targets = [ 'desktop', 'mobile' ];
/**
* @param ResourceLoaderContext $context
* @return array[]
*/
protected function getPages( ResourceLoaderContext $context ) {
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
$config = $this->getConfig();
$user = $context->getUserObj();
if ( !$user->isRegistered() ) {
return [];
}
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
// Use localised/normalised variant to ensure $excludepage matches
$userPage = $user->getUserPage()->getPrefixedDBkey();
$pages = [];
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
if ( $config->get( 'AllowUserJs' ) ) {
$pages["$userPage/common.js"] = [ 'type' => 'script' ];
$pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
}
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
// User group pages are maintained site-wide and enabled with site JS/CSS.
if ( $config->get( 'UseSiteJs' ) ) {
$userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager();
foreach ( $userGroupManager->getUserEffectiveGroups( $user ) as $group ) {
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
if ( $group == '*' ) {
continue;
}
$pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
}
}
// This is obsolete since 1.32 (T112474). It was formerly used by
// OutputPage to implement previewing of user CSS and JS.
// @todo: Remove it once we're sure nothing else is using the parameter
$excludepage = $context->getRequest()->getVal( 'excludepage' );
unset( $pages[$excludepage] );
resourceloader: Merge 'user.groups' into 'user' module This is with T92459 in mind to simplify the process of splitting the 'user' module for the styles-only queue. Consequences: * Cached HTML isn't relevant in practice since there is no caching for logged-in users and this module is only for logged-in users. Even then, cached HTML will work and may happen as browsers re-use HTML responses when revisiting a privately cached page (after 304 Not Modified). Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups' if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups. - Old style queue request will continue to ask for user.groups which is now a FileModule with no styles (simply concats the empty string to the bundle) - Old load() request will resolve with an empty function. * The are no known dependants of 'user.groups'. If there are, they will work by proxy of it now being an empty module that just ensures 'user' is loaded. * The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user' is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE previously received user.groups, but won't anymore. This should be fine as OutputPage::reduceAllowedModules() is mainly used to either allow everything or restrict all the way down to CORE. The only exception is disallowUserJs() if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was made for Common.css, not Group-*.css. Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-10 19:47:04 +00:00
return $pages;
}
/**
* Get group name
*
* @return string
*/
public function getGroup() {
return 'user';
}
}