Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/167834

Change subject: Allow passing pages to ResourceLoaderWikiModule via constructor 
parameters
......................................................................

Allow passing pages to ResourceLoaderWikiModule via constructor parameters

This makes it easier to subclasses to use ResourceLoaderWikiModule. Currently
many subclasses of this simply just need to override the getPages() function.

The module also includes checks for the 'UseSiteJs', and 'UseSiteCss' config
settings, which many subclasses do not do, but should.

Change-Id: I388531398671afacfec36c6c5746d72267b5bdac
---
M includes/AutoLoader.php
D includes/resourceloader/ResourceLoaderFilePageModule.php
D includes/resourceloader/ResourceLoaderNoscriptModule.php
M includes/resourceloader/ResourceLoaderWikiModule.php
M resources/Resources.php
M tests/phpunit/ResourceLoaderTestCase.php
M tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
7 files changed, 57 insertions(+), 107 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/34/167834/1

diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index c835007..21ba4d2 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -893,10 +893,8 @@
        'ResourceLoaderContext' => 
'includes/resourceloader/ResourceLoaderContext.php',
        'ResourceLoaderEditToolbarModule' => 
'includes/resourceloader/ResourceLoaderEditToolbarModule.php',
        'ResourceLoaderFileModule' => 
'includes/resourceloader/ResourceLoaderFileModule.php',
-       'ResourceLoaderFilePageModule' => 
'includes/resourceloader/ResourceLoaderFilePageModule.php',
        'ResourceLoaderFilePath' => 
'includes/resourceloader/ResourceLoaderFilePath.php',
        'ResourceLoaderModule' => 
'includes/resourceloader/ResourceLoaderModule.php',
-       'ResourceLoaderNoscriptModule' => 
'includes/resourceloader/ResourceLoaderNoscriptModule.php',
        'ResourceLoaderSiteModule' => 
'includes/resourceloader/ResourceLoaderSiteModule.php',
        'ResourceLoaderSkinModule' => 
'includes/resourceloader/ResourceLoaderSkinModule.php',
        'ResourceLoaderStartUpModule' => 
'includes/resourceloader/ResourceLoaderStartUpModule.php',
diff --git a/includes/resourceloader/ResourceLoaderFilePageModule.php 
b/includes/resourceloader/ResourceLoaderFilePageModule.php
deleted file mode 100644
index 8c7fbe7..0000000
--- a/includes/resourceloader/ResourceLoaderFilePageModule.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?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' ),
-               );
-       }
-}
diff --git a/includes/resourceloader/ResourceLoaderNoscriptModule.php 
b/includes/resourceloader/ResourceLoaderNoscriptModule.php
deleted file mode 100644
index 61927d7..0000000
--- a/includes/resourceloader/ResourceLoaderNoscriptModule.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?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';
-       }
-}
diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php 
b/includes/resourceloader/ResourceLoaderWikiModule.php
index 2a1736d..e209ecd 100644
--- a/includes/resourceloader/ResourceLoaderWikiModule.php
+++ b/includes/resourceloader/ResourceLoaderWikiModule.php
@@ -29,7 +29,7 @@
  * because of its dependence on the functionality of
  * Title::isCssJsSubpage.
  */
-abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
+class ResourceLoaderWikiModule extends ResourceLoaderModule {
 
        /* Protected Members */
 
@@ -39,7 +39,31 @@
        // 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 With 'styles' and 'scripts' keys, optional for 
back-compat
+        */
+       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'];
+               }
+       }
+
+       /* Protected Methods */
 
        /**
         * Subclasses should return an associative array of resources in the 
module.
@@ -57,9 +81,28 @@
         * @param ResourceLoaderContext $context
         * @return array
         */
-       abstract protected function getPages( ResourceLoaderContext $context );
+       protected function getPages( ResourceLoaderContext $context ) {
+               $config = $context->getResourceLoader()->getConfig();
+               $pages = array();
 
-       /* Protected Methods */
+               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;
+       }
+
+       public function getGroup() {
+               return $this->group;
+       }
 
        /**
         * Get the Database object used in getTitleMTimes(). Defaults to the 
local slave DB
diff --git a/resources/Resources.php b/resources/Resources.php
index ca90efa..4412757 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -32,9 +32,16 @@
 
        // Scripts managed by the local wiki (stored in the MediaWiki namespace)
        'site' => array( 'class' => 'ResourceLoaderSiteModule' ),
-       'noscript' => array( 'class' => 'ResourceLoaderNoscriptModule' ),
+       'noscript' => array(
+               'class' => 'ResourceLoaderWikiModule',
+               'styles' => array( 'MediaWiki:Noscript.css' ),
+               'group' => 'noscript',
+       ),
        'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
-       'filepage' => array( 'class' => 'ResourceLoaderFilePageModule' ),
+       '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)
diff --git a/tests/phpunit/ResourceLoaderTestCase.php 
b/tests/phpunit/ResourceLoaderTestCase.php
index f5f302e..ef897df 100644
--- a/tests/phpunit/ResourceLoaderTestCase.php
+++ b/tests/phpunit/ResourceLoaderTestCase.php
@@ -86,10 +86,3 @@
 
 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
 }
-
-class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
-       // Override expected via PHPUnit mocks and stubs
-       protected function getPages( ResourceLoaderContext $context ) {
-               return array();
-       }
-}
diff --git 
a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php 
b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
index 9dc1805..4abf6bb 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
@@ -7,7 +7,7 @@
         * @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() )

-- 
To view, visit https://gerrit.wikimedia.org/r/167834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I388531398671afacfec36c6c5746d72267b5bdac
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to