'ResourceLoaderContext' => __DIR__ . '/includes/resourceloader/ResourceLoaderContext.php',
'ResourceLoaderEditToolbarModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderEditToolbarModule.php',
'ResourceLoaderFileModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderFileModule.php',
- 'ResourceLoaderFilePageModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePageModule.php',
'ResourceLoaderFilePath' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePath.php',
'ResourceLoaderImage' => __DIR__ . '/includes/resourceloader/ResourceLoaderImage.php',
'ResourceLoaderImageModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderImageModule.php',
'ResourceLoaderLanguageDataModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageDataModule.php',
'ResourceLoaderLanguageNamesModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageNamesModule.php',
'ResourceLoaderModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderModule.php',
- 'ResourceLoaderNoscriptModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderNoscriptModule.php',
'ResourceLoaderSiteModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderSiteModule.php',
'ResourceLoaderSkinModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderSkinModule.php',
'ResourceLoaderStartUpModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderStartUpModule.php',
+++ /dev/null
-<?php
-/**
- * Resource loader module for MediaWiki:Filepage.css
- *
- * 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
- */
-
-/**
- * ResourceLoader definition for MediaWiki:Filepage.css
- */
-class ResourceLoaderFilePageModule extends ResourceLoaderWikiModule {
-
- /**
- * @param ResourceLoaderContext $context
- * @return array
- */
- protected function getPages( ResourceLoaderContext $context ) {
- return array(
- 'MediaWiki:Filepage.css' => array( 'type' => 'style' ),
- );
- }
-}
+++ /dev/null
-<?php
-/**
- * Resource loader for site customizations for users without JavaScript enabled.
- *
- * 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 site customizations
- */
-class ResourceLoaderNoscriptModule extends ResourceLoaderWikiModule {
-
- /* Protected Methods */
-
- /**
- * Gets list of pages used by this module. Obviously, it makes absolutely no
- * sense to include JavaScript files here... :D
- *
- * @param ResourceLoaderContext $context
- *
- * @return array List of pages
- */
- protected function getPages( ResourceLoaderContext $context ) {
- return array( 'MediaWiki:Noscript.css' => array( 'type' => 'style' ) );
- }
-
- /* Methods */
-
- /**
- * Gets group name
- *
- * @return string Name of group
- */
- public function getGroup() {
- return 'noscript';
- }
-}
*/
class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
- /* Protected Methods */
-
/**
- * Gets list of pages used by this module
+ * Get list of pages used by this module
*
* @param ResourceLoaderContext $context
- *
* @return array List of pages
*/
protected function getPages( ResourceLoaderContext $context ) {
return $pages;
}
- /* Methods */
-
/**
- * Gets group name
+ * Get group name
*
- * @return string Name of group
+ * @return string
*/
public function getGroup() {
return 'site';
*/
class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
- /* Protected Members */
-
protected $origin = self::ORIGIN_USER_SITEWIDE;
protected $targets = array( 'desktop', 'mobile' );
- /* Protected Methods */
-
/**
* @param ResourceLoaderContext $context
* @return array
return $pages;
}
- /* Methods */
-
/**
+ * Get group name
+ *
* @return string
*/
public function getGroup() {
*/
class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
- /* Protected Members */
-
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
- /* Protected Methods */
-
/**
+ * Get list of pages used by this module
+ *
* @param ResourceLoaderContext $context
- * @return array
+ * @return array List of pages
*/
protected function getPages( ResourceLoaderContext $context ) {
$allowUserJs = $this->getConfig()->get( 'AllowUserJs' );
return $pages;
}
- /* Methods */
-
/**
+ * Get group name
+ *
* @return string
*/
public function getGroup() {
* because of its dependence on the functionality of
* Title::isCssJsSubpage.
*/
-abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
+class ResourceLoaderWikiModule extends ResourceLoaderModule {
- /* Protected Members */
-
- # Origin is user-supplied code
+ // Origin defaults to users with sitewide authority
protected $origin = self::ORIGIN_USER_SITEWIDE;
// In-object cache for title info
protected $titleInfo = array();
- /* Abstract Protected Methods */
+ // List of page names that contain CSS
+ protected $styles = array();
+
+ // List of page names that contain JavaScript
+ protected $scripts = array();
+
+ // Group of module
+ protected $group;
+
+ /**
+ * @param array $options For back-compat, this can be omitted in favour of overwriting getPages.
+ */
+ public function __construct( array $options = null ) {
+ if ( isset( $options['styles'] ) ) {
+ $this->styles = $options['styles'];
+ }
+ if ( isset( $options['scripts'] ) ) {
+ $this->scripts = $options['scripts'];
+ }
+ if ( isset( $options['group'] ) ) {
+ $this->group = $options['group'];
+ }
+ }
/**
* Subclasses should return an associative array of resources in the module.
* @param ResourceLoaderContext $context
* @return array
*/
- abstract protected function getPages( ResourceLoaderContext $context );
+ protected function getPages( ResourceLoaderContext $context ) {
+ $config = $this->getConfig();
+ $pages = array();
+
+ // Filter out pages from origins not allowed by the current wiki configuration.
+ if ( $config->get( 'UseSiteJs' ) ) {
+ foreach ( $this->scripts as $script ) {
+ $pages[$script] = array( 'type' => 'script' );
+ }
+ }
+
+ if ( $config->get( 'UseSiteCss' ) ) {
+ foreach ( $this->styles as $style ) {
+ $pages[$style] = array( 'type' => 'style' );
+ }
+ }
+
+ return $pages;
+ }
- /* Protected Methods */
+ /**
+ * Get group name
+ *
+ * @return string
+ */
+ public function getGroup() {
+ return $this->group;
+ }
/**
* Get the Database object used in getTitleMTimes(). Defaults to the local slave DB
return $content->serialize( $format );
}
- /* Methods */
-
/**
* @param ResourceLoaderContext $context
* @return string
/**
* Special modules who have their own classes
*/
+ 'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
// Scripts managed by the local wiki (stored in the MediaWiki namespace)
'site' => array( 'class' => 'ResourceLoaderSiteModule' ),
- 'noscript' => array( 'class' => 'ResourceLoaderNoscriptModule' ),
- 'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
- 'filepage' => array( 'class' => 'ResourceLoaderFilePageModule' ),
+ 'noscript' => array(
+ 'class' => 'ResourceLoaderWikiModule',
+ 'styles' => array( 'MediaWiki:Noscript.css' ),
+ 'group' => 'noscript',
+ ),
+ 'filepage' => array(
+ 'class' => 'ResourceLoaderWikiModule',
+ 'styles' => array( 'MediaWiki:Filepage.css' ),
+ ),
'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
// Scripts managed by the current user (stored in their user space)
'ResourceLoaderTestCase' => "$testDir/phpunit/ResourceLoaderTestCase.php",
'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
'ResourceLoaderFileModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
- 'ResourceLoaderWikiModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
'TestUser' => "$testDir/phpunit/includes/TestUser.php",
'LessFileCompilationTest' => "$testDir/phpunit/LessFileCompilationTest.php",
class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
}
-
-class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
- // Override expected via PHPUnit mocks and stubs
- protected function getPages( ResourceLoaderContext $context ) {
- return array();
- }
-}
class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
+ /**
+ * @covers ResourceLoaderWikiModule::__construct
+ * @dataProvider provideConstructor
+ */
+ public function testConstructor( $params ) {
+ $module = new ResourceLoaderWikiModule( $params );
+ $this->assertInstanceOf( 'ResourceLoaderWikiModule', $module );
+ }
+
+ public static function provideConstructor() {
+ return array(
+ // Nothing
+ array( null ),
+ array( array() ),
+ // Unrecognized settings
+ array( array( 'foo' => 'baz' ) ),
+ // Real settings
+ array( array( 'scripts' => array( 'MediaWiki:Common.js' ) ) ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetPages
+ * @covers ResourceLoaderWikiModule::getPages
+ */
+ public function testGetPages( $params, Config $config, $expected ) {
+ $module = new ResourceLoaderWikiModule( $params );
+ $module->setConfig( $config );
+
+ // Use getDefinitionSummary because getPages is protected
+ $summary = $module->getDefinitionSummary( ResourceLoaderContext::newDummyContext() );
+ $this->assertEquals(
+ $expected,
+ $summary['pages']
+ );
+ }
+
+ public static function provideGetPages() {
+ $settings = array(
+ 'UseSiteJs' => true,
+ 'UseSiteCss' => true,
+ );
+
+ $params = array(
+ 'styles' => array( 'MediaWiki:Common.css' ),
+ 'scripts' => array( 'MediaWiki:Common.js' ),
+ );
+
+ return array(
+ array( array(), new HashConfig( $settings ), array() ),
+ array( $params, new HashConfig( $settings ), array(
+ 'MediaWiki:Common.js' => array( 'type' => 'script' ),
+ 'MediaWiki:Common.css' => array( 'type' => 'style' )
+ ) ),
+ array( $params, new HashConfig( array( 'UseSiteCss' => false ) + $settings ), array(
+ 'MediaWiki:Common.js' => array( 'type' => 'script' ),
+ ) ),
+ array( $params, new HashConfig( array( 'UseSiteJs' => false ) + $settings ), array(
+ 'MediaWiki:Common.css' => array( 'type' => 'style' ),
+ ) ),
+ array( $params, new HashConfig( array( 'UseSiteJs' => false, 'UseSiteCss' => false ) ), array() ),
+ );
+ }
+
+ /**
+ * @covers ResourceLoaderWikiModule::getGroup
+ * @dataProvider provideGetGroup
+ */
+ public function testGetGroup( $params, $expected ) {
+ $module = new ResourceLoaderWikiModule( $params );
+ $this->assertEquals( $expected, $module->getGroup() );
+ }
+
+ public static function provideGetGroup() {
+ return array(
+ // No group specified
+ array( array(), null ),
+ // A random group
+ array( array( 'group' => 'foobar' ), 'foobar' ),
+ );
+ }
+
/**
* @covers ResourceLoaderWikiModule::isKnownEmpty
* @dataProvider provideIsKnownEmpty
*/
public function testIsKnownEmpty( $titleInfo, $group, $expected ) {
- $module = $this->getMockBuilder( 'ResourceLoaderWikiModuleTestModule' )
+ $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' )
->setMethods( array( 'getTitleInfo', 'getGroup' ) )
->getMock();
$module->expects( $this->any() )