wiki.techinc.nl/includes/resourceloader/ResourceLoaderUserModule.php
Timo Tijhof 1c657b06e8 resourceloader: Remove 'user.styles' dependency from 'user' module
Follows-up c3f200849b, which made isKnownEmpty() return false
for modules that have dependencies.

This had the side-effect of causing the 'user' module to be loaded
in its own HTTP request on all page views, even for logged-out users
and for registered users without scripts, because it has a dependency
on the 'user.styles' module.

This commit fixes that regression by removing the dependency so
that the 'user' module can, once again, be considered "empty".

The dependency isn't needed. It was only added for the transitional
period after the 'user' module was split up so that existing cached
views for logged-in users (in theory, e.g. 304 Not Modified) would
still trigger a load for the styles.

But that transition ended over a year ago. Now, both modules act
independently and are always queued separately, with user.styles
explicitly added as a style module (as it should be).

Even for the case of an AJAX preview (if it is somehow possible for
the 'user' module to not be loaded already), the API would respond
with a module list that contains both 'user' and 'user.styles'.

Bug: T195380
Change-Id: I9852516af1bd55c84a9213628c7796e2c2168745
2018-05-23 15:53:33 +01:00

80 lines
2.3 KiB
PHP

<?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
*/
/**
* Module for user customizations scripts
*/
class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
protected $targets = [ 'desktop', 'mobile' ];
/**
* @param ResourceLoaderContext $context
* @return array List of pages
*/
protected function getPages( ResourceLoaderContext $context ) {
$config = $this->getConfig();
$user = $context->getUserObj();
if ( $user->isAnon() ) {
return [];
}
// Use localised/normalised variant to ensure $excludepage matches
$userPage = $user->getUserPage()->getPrefixedDBkey();
$pages = [];
if ( $config->get( 'AllowUserJs' ) ) {
$pages["$userPage/common.js"] = [ 'type' => 'script' ];
$pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
}
// User group pages are maintained site-wide and enabled with site JS/CSS.
if ( $config->get( 'UseSiteJs' ) ) {
foreach ( $user->getEffectiveGroups() as $group ) {
if ( $group == '*' ) {
continue;
}
$pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
}
}
// 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' );
if ( isset( $pages[$excludepage] ) ) {
unset( $pages[$excludepage] );
}
return $pages;
}
/**
* Get group name
*
* @return string
*/
public function getGroup() {
return 'user';
}
}