Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/288055
Change subject: [WIP] resourceloader: Merge 'user.groups' into 'user' module
......................................................................
[WIP] 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
---
M autoload.php
M includes/OutputPage.php
D includes/resourceloader/ResourceLoaderUserGroupsModule.php
M includes/resourceloader/ResourceLoaderUserModule.php
M resources/Resources.php
5 files changed, 30 insertions(+), 89 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/55/288055/1
diff --git a/autoload.php b/autoload.php
index 1e656e4..5163021 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1095,7 +1095,6 @@
'ResourceLoaderStartUpModule' => __DIR__ .
'/includes/resourceloader/ResourceLoaderStartUpModule.php',
'ResourceLoaderUserCSSPrefsModule' => __DIR__ .
'/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php',
'ResourceLoaderUserDefaultsModule' => __DIR__ .
'/includes/resourceloader/ResourceLoaderUserDefaultsModule.php',
- 'ResourceLoaderUserGroupsModule' => __DIR__ .
'/includes/resourceloader/ResourceLoaderUserGroupsModule.php',
'ResourceLoaderUserModule' => __DIR__ .
'/includes/resourceloader/ResourceLoaderUserModule.php',
'ResourceLoaderUserOptionsModule' => __DIR__ .
'/includes/resourceloader/ResourceLoaderUserOptionsModule.php',
'ResourceLoaderUserTokensModule' => __DIR__ .
'/includes/resourceloader/ResourceLoaderUserTokensModule.php',
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index c724207..bb2b58e 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -3096,12 +3096,6 @@
$links[] = $this->makeResourceLoaderLink( 'user',
ResourceLoaderModule::TYPE_COMBINED );
}
- // Group JS is only enabled if site JS is enabled.
- $links[] = $this->makeResourceLoaderLink(
- 'user.groups',
- ResourceLoaderModule::TYPE_COMBINED
- );
-
return self::getHtmlFromLoaderLinks( $links );
}
@@ -3667,7 +3661,6 @@
// Per-site custom styles
$moduleStyles[] = 'site';
$moduleStyles[] = 'noscript';
- $moduleStyles[] = 'user.groups';
// Per-user custom styles
if ( $this->getConfig()->get( 'AllowUserCss' ) &&
$this->getTitle()->isCssSubpage()
diff --git a/includes/resourceloader/ResourceLoaderUserGroupsModule.php
b/includes/resourceloader/ResourceLoaderUserGroupsModule.php
deleted file mode 100644
index b225185..0000000
--- a/includes/resourceloader/ResourceLoaderUserGroupsModule.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * ResourceLoader module for user customizations.
- *
- * 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
- */
-
-/**
- * Module for user customizations
- */
-class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
-
- protected $origin = self::ORIGIN_USER_SITEWIDE;
- protected $targets = [ 'desktop', 'mobile' ];
-
- /**
- * @param ResourceLoaderContext $context
- * @return array
- */
- protected function getPages( ResourceLoaderContext $context ) {
- $useSiteJs = $this->getConfig()->get( 'UseSiteJs' );
- $useSiteCss = $this->getConfig()->get( 'UseSiteCss' );
- if ( !$useSiteJs && !$useSiteCss ) {
- return [];
- }
-
- $user = $context->getUserObj();
- if ( $user->isAnon() ) {
- return [];
- }
-
- $pages = [];
- foreach ( $user->getEffectiveGroups() as $group ) {
- if ( $group == '*' ) {
- continue;
- }
- if ( $useSiteJs ) {
- $pages["MediaWiki:Group-$group.js"] = [ 'type'
=> 'script' ];
- }
- if ( $useSiteCss ) {
- $pages["MediaWiki:Group-$group.css"] = [ 'type'
=> 'style' ];
- }
- }
- return $pages;
- }
-
- /**
- * Get group name
- *
- * @return string
- */
- public function getGroup() {
- return 'user';
- }
-}
diff --git a/includes/resourceloader/ResourceLoaderUserModule.php
b/includes/resourceloader/ResourceLoaderUserModule.php
index c38f8d8..221fa6e 100644
--- a/includes/resourceloader/ResourceLoaderUserModule.php
+++ b/includes/resourceloader/ResourceLoaderUserModule.php
@@ -28,6 +28,7 @@
class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
+ protected $targets = [ 'desktop', 'mobile' ];
/**
* Get list of pages used by this module
@@ -36,28 +37,41 @@
* @return array List of pages
*/
protected function getPages( ResourceLoaderContext $context ) {
- $allowUserJs = $this->getConfig()->get( 'AllowUserJs' );
- $allowUserCss = $this->getConfig()->get( 'AllowUserCss' );
- if ( !$allowUserJs && !$allowUserCss ) {
- return [];
- }
-
+ $config = $this->getConfig();
$user = $context->getUserObj();
if ( $user->isAnon() ) {
return [];
}
- // Needed so $excludepages works
+ // Use localised/normalised variant to ensure $excludepage
matches
$userPage = $user->getUserPage()->getPrefixedDBkey();
-
$pages = [];
- if ( $allowUserJs ) {
+
+ if ( $config->get( 'AllowUserJs' ) ) {
$pages["$userPage/common.js"] = [ 'type' => 'script' ];
$pages["$userPage/" . $context->getSkin() . '.js'] = [
'type' => 'script' ];
}
- if ( $allowUserCss ) {
+
+ if ( $config->get( 'AllowUserCss' ) ) {
$pages["$userPage/common.css"] = [ 'type' => 'style' ];
$pages["$userPage/" . $context->getSkin() . '.css'] = [
'type' => 'style' ];
+ }
+
+ $useSiteJs = $this->getConfig()->get( 'UseSiteJs' );
+ $useSiteCss = $this->getConfig()->get( 'UseSiteCss' );
+ // User group pages are maintained site-wide and enabled with
site JS/CSS.
+ if ( $useSiteJs || $useSiteCss ) {
+ foreach ( $user->getEffectiveGroups() as $group ) {
+ if ( $group == '*' ) {
+ continue;
+ }
+ if ( $useSiteJs ) {
+ $pages["MediaWiki:Group-$group.js"] = [
'type' => 'script' ];
+ }
+ if ( $useSiteCss ) {
+ $pages["MediaWiki:Group-$group.css"] =
[ 'type' => 'style' ];
+ }
+ }
}
// Hack for bug 26283: if we're on a preview page for a CSS/JS
page,
@@ -69,6 +83,7 @@
// just like the keys in $pages[] above
unset( $pages[$excludepage] );
}
+
return $pages;
}
diff --git a/resources/Resources.php b/resources/Resources.php
index cf2abdb..4daa617 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -43,7 +43,11 @@
'class' => 'ResourceLoaderWikiModule',
'styles' => [ 'MediaWiki:Filepage.css' ],
],
- 'user.groups' => [ 'class' => 'ResourceLoaderUserGroupsModule' ],
+ 'user.groups' => [
+ // Merged into 'user' since MediaWiki 1.28 - kept for
back-compat
+ 'dependencies' => 'user',
+ 'targets' => [ 'desktop', 'mobile' ],
+ ],
// Scripts managed by the current user (stored in their user space)
'user' => [ 'class' => 'ResourceLoaderUserModule' ],
--
To view, visit https://gerrit.wikimedia.org/r/288055
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits