jenkins-bot has submitted this change and it was merged.
Change subject: Get rid of subclassing for user and site modules
......................................................................
Get rid of subclassing for user and site modules
When the modules were split into separate script and style modules, the
PHP classes were also split. The new classes only had to implement one
function, much of which was boilerplate. This merges the separate CSS
and JS modules back together.
Change-Id: I170b78400385e147e84160018e6c03e507c35fe9
---
M GlobalCssJs.hooks.php
M ResourceLoaderGlobalModule.php
D ResourceLoaderGlobalSiteCssModule.php
D ResourceLoaderGlobalSiteJsModule.php
M ResourceLoaderGlobalSiteModule.php
D ResourceLoaderGlobalUserCssModule.php
D ResourceLoaderGlobalUserJsModule.php
M ResourceLoaderGlobalUserModule.php
M extension.json
M tests/ResourceLoaderGlobalSiteModuleTest.php
M tests/ResourceLoaderGlobalUserModuleTest.php
11 files changed, 74 insertions(+), 202 deletions(-)
Approvals:
Krinkle: Looks good to me, approved
Jforrester: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/GlobalCssJs.hooks.php b/GlobalCssJs.hooks.php
index 04d5d3c..a4b8ce1 100644
--- a/GlobalCssJs.hooks.php
+++ b/GlobalCssJs.hooks.php
@@ -58,24 +58,28 @@
}
$userJs = array(
- 'class' => 'ResourceLoaderGlobalUserJsModule',
+ 'class' => 'ResourceLoaderGlobalUserModule',
+ 'type' => 'script',
) + $config;
$resourceLoader->register( 'ext.globalCssJs.user', $userJs );
$userCss = array(
'position' => 'top',
- 'class' => 'ResourceLoaderGlobalUserCssModule',
+ 'class' => 'ResourceLoaderGlobalUserModule',
+ 'type' => 'style',
) + $config;
$resourceLoader->register( 'ext.globalCssJs.user.styles',
$userCss );
$siteJs = array(
- 'class' => 'ResourceLoaderGlobalSiteJsModule',
+ 'class' => 'ResourceLoaderGlobalSiteModule',
+ 'type' => 'script',
) + $config;
$resourceLoader->register( 'ext.globalCssJs.site', $siteJs );
$siteCss = array(
'position' => 'top',
- 'class' => 'ResourceLoaderGlobalSiteCssModule',
+ 'class' => 'ResourceLoaderGlobalSiteModule',
+ 'type' => 'style',
) + $config;
$resourceLoader->register( 'ext.globalCssJs.site.styles',
$siteCss );
diff --git a/ResourceLoaderGlobalModule.php b/ResourceLoaderGlobalModule.php
index 7117f88..46511ea 100644
--- a/ResourceLoaderGlobalModule.php
+++ b/ResourceLoaderGlobalModule.php
@@ -43,6 +43,13 @@
/** @var string Position on the page to load this module at */
protected $position = 'bottom';
+ /**
+ * Either 'style' or 'script'
+ *
+ * @var string
+ */
+ protected $type;
+
public function __construct( $options ) {
foreach ( $options as $member => $option ) {
switch ( $member ) {
@@ -53,6 +60,12 @@
case 'source':
$this->{$member} = (string)$option;
break;
+ case 'type':
+ if ( $option !== 'style' && $option !==
'script' ) {
+ throw new
InvalidArgumentException( "type must be either 'style' or 'script', not
'$option'" );
+ }
+ $this->type = $option;
+ break;
}
}
}
diff --git a/ResourceLoaderGlobalSiteCssModule.php
b/ResourceLoaderGlobalSiteCssModule.php
deleted file mode 100644
index 7ecf5f6..0000000
--- a/ResourceLoaderGlobalSiteCssModule.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * ResourceLoader module for global site 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
- * @author Kunal Mehta
- */
-
-/**
- * Module for sitewide global CSS customizations
- */
-class ResourceLoaderGlobalSiteCssModule extends ResourceLoaderGlobalSiteModule
{
- protected function doGetPages( ResourceLoaderContext $context ) {
- $pages = array();
-
- $config = $context->getResourceLoader()->getConfig();
-
- if ( $config->get( 'UseSiteCss' ) ) {
- $pages["MediaWiki:Global.css"] = array( 'type' =>
'style' );
- $pages['MediaWiki:Global-' . $context->getSkin() .
'.css'] = array( 'type' => 'style' );
- }
-
- return $pages;
- }
-}
diff --git a/ResourceLoaderGlobalSiteJsModule.php
b/ResourceLoaderGlobalSiteJsModule.php
deleted file mode 100644
index d079fb2..0000000
--- a/ResourceLoaderGlobalSiteJsModule.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * ResourceLoader module for global site 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
- * @author Kunal Mehta
- */
-
-/**
- * Module for sitewide global JS customizations
- */
-class ResourceLoaderGlobalSiteJsModule extends ResourceLoaderGlobalSiteModule {
- protected function doGetPages( ResourceLoaderContext $context ) {
- $pages = array();
-
- $config = $context->getResourceLoader()->getConfig();
-
- if ( $config->get( 'UseSiteJs' ) ) {
- $pages["MediaWiki:Global.js"] = array( 'type' =>
'script' );
- $pages['MediaWiki:Global-' . $context->getSkin() .
'.js'] = array( 'type' => 'script' );
- }
-
- return $pages;
- }
-}
diff --git a/ResourceLoaderGlobalSiteModule.php
b/ResourceLoaderGlobalSiteModule.php
index 061ae72..8fafa18 100644
--- a/ResourceLoaderGlobalSiteModule.php
+++ b/ResourceLoaderGlobalSiteModule.php
@@ -24,7 +24,7 @@
/**
* Module for sitewide global customizations
*/
-abstract class ResourceLoaderGlobalSiteModule extends
ResourceLoaderGlobalModule {
+class ResourceLoaderGlobalSiteModule extends ResourceLoaderGlobalModule {
protected $origin = self::ORIGIN_USER_SITEWIDE;
@@ -37,10 +37,19 @@
return array();
}
- return $this->doGetPages( $context );
- }
+ $config = $context->getResourceLoader()->getConfig();
+ $pages = array();
- abstract protected function doGetPages( ResourceLoaderContext $context
);
+ if ( $this->type === 'style' && $config->get( 'UseSiteCss' ) ) {
+ $pages["MediaWiki:Global.css"] = array( 'type' =>
'style' );
+ $pages['MediaWiki:Global-' . $context->getSkin() .
'.css'] = array( 'type' => 'style' );
+ } elseif ( $this->type === 'script' && $config->get(
'UseSiteJs' ) ) {
+ $pages["MediaWiki:Global.js"] = array( 'type' =>
'script' );
+ $pages['MediaWiki:Global-' . $context->getSkin() .
'.js'] = array( 'type' => 'script' );
+ }
+
+ return $pages;
+ }
/**
* @return string
diff --git a/ResourceLoaderGlobalUserCssModule.php
b/ResourceLoaderGlobalUserCssModule.php
deleted file mode 100644
index e393730..0000000
--- a/ResourceLoaderGlobalUserCssModule.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * ResourceLoader module for global 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
- * @author Szymon Świerkosz
- * @author Kunal Mehta
- */
-
-/**
- * Module for user CSS customizations - runs on all wikis
- */
-class ResourceLoaderGlobalUserCssModule extends ResourceLoaderGlobalUserModule
{
- protected function doGetPages( ResourceLoaderContext $context,
$userpage ) {
- $pages = array();
-
- $config = $context->getResourceLoader()->getConfig();
-
- if ( $config->get( 'AllowUserCss' ) ) {
- $pages["User:$userpage/global.css"] = array( 'type' =>
'style' );
- }
-
- return $pages;
- }
-}
diff --git a/ResourceLoaderGlobalUserJsModule.php
b/ResourceLoaderGlobalUserJsModule.php
deleted file mode 100644
index 932a014..0000000
--- a/ResourceLoaderGlobalUserJsModule.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * ResourceLoader module for global 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
- * @author Szymon Świerkosz
- * @author Kunal Mehta
- */
-
-/**
- * Module for user JS customizations - runs on all wikis
- */
-class ResourceLoaderGlobalUserJsModule extends ResourceLoaderGlobalUserModule {
- protected function doGetPages( ResourceLoaderContext $context,
$userpage ) {
- $pages = array();
-
- $config = $context->getResourceLoader()->getConfig();
-
- if ( $config->get( 'AllowUserJs' ) ) {
- $pages["User:$userpage/global.js"] = array( 'type' =>
'script' );
- }
-
- return $pages;
- }
-}
diff --git a/ResourceLoaderGlobalUserModule.php
b/ResourceLoaderGlobalUserModule.php
index 6d30c55..19e378a 100644
--- a/ResourceLoaderGlobalUserModule.php
+++ b/ResourceLoaderGlobalUserModule.php
@@ -25,7 +25,7 @@
/**
* Module for user customizations - runs on all wikis
*/
-abstract class ResourceLoaderGlobalUserModule extends
ResourceLoaderGlobalModule {
+class ResourceLoaderGlobalUserModule extends ResourceLoaderGlobalModule {
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
@@ -52,11 +52,17 @@
}
$userpage = $user->getUserPage()->getDBkey();
+ $config = $context->getResourceLoader()->getConfig();
+ $pages = array();
- return $this->doGetPages( $context, $userpage );
+ if ( $this->type === 'style' && $config->get( 'AllowUserCss' )
) {
+ $pages["User:$userpage/global.css"] = array( 'type' =>
'style' );
+ } elseif ( $this->type === 'script' && $config->get(
'AllowUserJs' ) ) {
+ $pages["User:$userpage/global.js"] = array( 'type' =>
'script' );
+ }
+
+ return $pages;
}
-
- abstract protected function doGetPages( ResourceLoaderContext $context,
$userpage );
/**
* @return string
diff --git a/extension.json b/extension.json
index 5435450..dfee762 100644
--- a/extension.json
+++ b/extension.json
@@ -46,11 +46,7 @@
"AutoloadClasses": {
"ResourceLoaderGlobalModule": "ResourceLoaderGlobalModule.php",
"ResourceLoaderGlobalSiteModule":
"ResourceLoaderGlobalSiteModule.php",
- "ResourceLoaderGlobalSiteCssModule":
"ResourceLoaderGlobalSiteCssModule.php",
- "ResourceLoaderGlobalSiteJsModule":
"ResourceLoaderGlobalSiteJsModule.php",
"ResourceLoaderGlobalUserModule":
"ResourceLoaderGlobalUserModule.php",
- "ResourceLoaderGlobalUserCssModule":
"ResourceLoaderGlobalUserCssModule.php",
- "ResourceLoaderGlobalUserJsModule":
"ResourceLoaderGlobalUserJsModule.php",
"GlobalCssJsHooks": "GlobalCssJs.hooks.php",
"ResourceLoaderGlobalModuleTestCase":
"tests/ResourceLoaderGlobalModuleTestCase.php"
},
diff --git a/tests/ResourceLoaderGlobalSiteModuleTest.php
b/tests/ResourceLoaderGlobalSiteModuleTest.php
index c713e1b..b7bdb2a 100644
--- a/tests/ResourceLoaderGlobalSiteModuleTest.php
+++ b/tests/ResourceLoaderGlobalSiteModuleTest.php
@@ -4,10 +4,10 @@
public static function provideGetPages() {
- // format: array( array( config => value ), $expectedPages,
$skin, $description )
+ // format: array( $type, array( config => value ),
$expectedPages, $skin, $description )
return array(
array(
- 'ResourceLoaderGlobalSiteCssModule',
+ 'style',
array(),
array(
'MediaWiki:Global.css',
'MediaWiki:Global-skinname.css'
@@ -16,7 +16,7 @@
'With default settings, 2 CSS global pages are
loaded'
),
array(
- 'ResourceLoaderGlobalSiteJsModule',
+ 'script',
array(),
array(
'MediaWiki:Global.js',
'MediaWiki:Global-skinname.js',
@@ -25,21 +25,21 @@
'With default settings, 2 JS global pages are
loaded'
),
array(
- 'ResourceLoaderGlobalSiteCssModule',
+ 'style',
array( 'wgUseGlobalSiteCssJs' => false),
array(),
'skinname',
'No CSS pages are loaded with
$wgUseGlobalSiteCssJs = false'
),
array(
- 'ResourceLoaderGlobalSiteJsModule',
+ 'script',
array( 'wgUseGlobalSiteCssJs' => false),
array(),
'skinname',
'No JS pages are loaded with
$wgUseGlobalSiteCssJs = false'
),
array(
- 'ResourceLoaderGlobalSiteJsModule',
+ 'script',
array( 'wgUseSiteCss' => false ),
array(
'MediaWiki:Global.js',
'MediaWiki:Global-skinname.js',
@@ -48,7 +48,7 @@
'JS pages are loaded if $wgUseSiteCss = false'
),
array(
- 'ResourceLoaderGlobalSiteCssModule',
+ 'style',
array( 'wgUseSiteJs' => false ),
array(
'MediaWiki:Global.css',
'MediaWiki:Global-skinname.css',
@@ -57,21 +57,21 @@
'CSS pages are loaded if $wgUseSiteJs = false'
),
array(
- 'ResourceLoaderGlobalSiteCssModule',
+ 'style',
array( 'wgUseSiteJs' => false, 'wgUseSiteCss'
=> false ),
array(),
'skinname',
'No CSS pages loaded if $wgUseSiteJs and
$wgUseSiteCss are false'
),
array(
- 'ResourceLoaderGlobalSiteJsModule',
+ 'script',
array( 'wgUseSiteJs' => false, 'wgUseSiteCss'
=> false ),
array(),
'skinname',
'No JS pages loaded if $wgUseSiteJs and
$wgUseSiteCss are false'
),
array(
- 'ResourceLoaderGlobalSiteCssModule',
+ 'style',
array(),
array(
'MediaWiki:Global.css',
'MediaWiki:Global-monobook.css'
@@ -80,7 +80,7 @@
'Global-monobook.css pages are loaded if
monobook is set as the skin'
),
array(
- 'ResourceLoaderGlobalSiteJsModule',
+ 'script',
array(),
array(
'MediaWiki:Global.js',
'MediaWiki:Global-monobook.js'
@@ -94,19 +94,21 @@
/**
* @covers ResourceLoaderGlobalSiteModule::getPages
* @dataProvider provideGetPages
- * @param $class
+ * @param $type
* @param $configOverrides
* @param $expectedPages
* @param $skin
* @param $desc
*/
- public function testGetPages( $class, $configOverrides, $expectedPages,
$skin, $desc ) {
+ public function testGetPages( $type, $configOverrides, $expectedPages,
$skin, $desc ) {
// First set default config options
$this->setMwGlobals( array_merge(
$this->getDefaultGlobalSettings( $skin ),
$configOverrides
) );
- $module = new $class( $this->getFakeOptions() );
+ $module = new ResourceLoaderGlobalSiteModule(
+ array( 'type' => $type ) + $this->getFakeOptions()
+ );
$context = $this->getContext( array( 'skin' => $skin ) );
$getPages = new ReflectionMethod( $module , 'getPages' );
$getPages->setAccessible( true );
diff --git a/tests/ResourceLoaderGlobalUserModuleTest.php
b/tests/ResourceLoaderGlobalUserModuleTest.php
index df52681..de95e28 100644
--- a/tests/ResourceLoaderGlobalUserModuleTest.php
+++ b/tests/ResourceLoaderGlobalUserModuleTest.php
@@ -14,17 +14,17 @@
public static function provideGetPages() {
- // format: array( array( config => value ), $expectedPages,
$description )
+ // format: array( $type, array( config => value ),
$expectedPages, $description )
return array(
array(
- 'ResourceLoaderGlobalUserCssModule',
+ 'style',
array(),
array(),
'TestUser',
'With default settings, no pages are loaded'
),
array(
- 'ResourceLoaderGlobalUserJsModule',
+ 'script',
array( 'wgAllowUserJs' => true ),
array(
'User:TestUser/global.js',
@@ -33,7 +33,7 @@
'JS page is loaded if $wgAllowUserJs = true'
),
array(
- 'ResourceLoaderGlobalUserCssModule',
+ 'style',
array( 'wgAllowUserCss' => true ),
array(
'User:TestUser/global.css',
@@ -42,35 +42,35 @@
'CSS page is loaded if $wgAllowUserCss = true'
),
array(
- 'ResourceLoaderGlobalUserCssModule',
+ 'style',
array( 'wgLanguageCode' => 'zh',
'wgAllowUserCss' => true, 'wgAllowUserJs' => true ),
array( 'User:TestUser/global.css' ),
'TestUser',
'User: namespace used in page titles even if
$wgLanguageCode != "en"'
),
array(
- 'ResourceLoaderGlobalUserJsModule',
+ 'script',
array( 'wgGlobalCssJsConfig' => array( 'wiki'
=> false ) ),
array(),
'TestUser',
"If \$wgGlobalCssJsConfig['wiki'] = false, no
pages are loaded",
),
array(
- 'ResourceLoaderGlobalUserCssModule',
+ 'style',
array( 'wgAllowUserCss' => true,
'wgAllowUserJs' => true ),
array(),
null,
'No pages loaded if $username = null',
),
array(
- 'ResourceLoaderGlobalUserJsModule',
+ 'script',
array( 'wgAllowUserCss' => true,
'wgAllowUserJs' => true ),
array(),
'[Invalid@Username]',
'No pages loaded if username is invalid',
),
array(
- 'ResourceLoaderGlobalUserCssModule',
+ 'style',
array( 'wgAllowUserCss' => true,
'wgAllowUserJs' => true ),
array(),
'UserThatHopefullyDoesntExist12',
@@ -82,19 +82,21 @@
/**
* @covers ResourceLoaderGlobalUserModule::getPages
* @dataProvider provideGetPages
- * @param $class
+ * @param $type
* @param $configOverrides
* @param $expectedPages
* @param $user
* @param $desc
*/
- public function testGetPages( $class, $configOverrides, $expectedPages,
$user, $desc ) {
+ public function testGetPages( $type, $configOverrides, $expectedPages,
$user, $desc ) {
// First set default config options
$this->setMwGlobals( array_merge(
$this->getDefaultGlobalSettings(),
$configOverrides
) );
- $module = new $class( $this->getFakeOptions() );
+ $module = new ResourceLoaderGlobalUserModule(
+ array( 'type' => $type ) + $this->getFakeOptions()
+ );
$context = $this->getContext( array( 'user' => $user ) );
$getPages = new ReflectionMethod( $module , 'getPages' );
$getPages->setAccessible( true );
--
To view, visit https://gerrit.wikimedia.org/r/219855
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I170b78400385e147e84160018e6c03e507c35fe9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GlobalCssJs
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits