includes/resourceloader/: Use Config instead of globals
authorKunal Mehta <legoktm@gmail.com>
Thu, 7 Aug 2014 10:25:56 +0000 (11:25 +0100)
committerKunal Mehta <legoktm@gmail.com>
Thu, 7 Aug 2014 17:47:34 +0000 (18:47 +0100)
Change-Id: Iaa1f4ae9c397575c9bb86dacbc342456e6f5f532

14 files changed:
docs/hooks.txt
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderContext.php
includes/resourceloader/ResourceLoaderFileModule.php
includes/resourceloader/ResourceLoaderModule.php
includes/resourceloader/ResourceLoaderSiteModule.php
includes/resourceloader/ResourceLoaderStartUpModule.php
includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
includes/resourceloader/ResourceLoaderUserGroupsModule.php
includes/resourceloader/ResourceLoaderUserModule.php
includes/resourceloader/ResourceLoaderWikiModule.php
tests/phpunit/LessFileCompilationTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderLESSTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderStartupModuleTest.php

index 25f5ad8..7510129 100644 (file)
@@ -2148,7 +2148,7 @@ $oldSessionID: old session id
 $newSessionID: new session id
 
 'ResourceLoaderGetConfigVars': Called at the end of
-ResourceLoaderStartUpModule::getConfig(). Use this to export static
+ResourceLoaderStartUpModule::getConfigSettings(). Use this to export static
 configuration variables to JavaScript. Things that depend on the current page
 or request state must be added through MakeGlobalVariablesScript instead.
 &$vars: array( variable name => value )
index 21e6435..354264c 100644 (file)
@@ -44,6 +44,9 @@ class ResourceLoader {
        /** @var array Associative array mapping module name to info associative array */
        protected $moduleInfos = array();
 
+       /** @var Config $config */
+       private $config;
+
        /**
         * @var array Associative array mapping framework ids to a list of names of test suite modules
         *      like array( 'qunit' => array( 'mediawiki.tests.qunit.suites', 'ext.foo.tests', .. ), .. )
@@ -152,7 +155,6 @@ class ResourceLoader {
         * @return string Filtered data, or a comment containing an error message
         */
        public function filter( $filter, $data, $cacheReport = true ) {
-               global $wgResourceLoaderMinifierStatementsOnOwnLine, $wgResourceLoaderMinifierMaxLineLength;
                wfProfileIn( __METHOD__ );
 
                // For empty/whitespace-only data or for unknown filters, don't perform
@@ -180,8 +182,8 @@ class ResourceLoader {
                        switch ( $filter ) {
                                case 'minify-js':
                                        $result = JavaScriptMinifier::minify( $data,
-                                               $wgResourceLoaderMinifierStatementsOnOwnLine,
-                                               $wgResourceLoaderMinifierMaxLineLength
+                                               $this->config->get( 'ResourceLoaderMinifierStatementsOnOwnLine' ),
+                                               $this->config->get( 'ResourceLoaderMinifierMaxLineLength' )
                                        );
                                        if ( $cacheReport ) {
                                                $result .= "\n/* cache key: $key */";
@@ -215,33 +217,47 @@ class ResourceLoader {
        /**
         * Register core modules and runs registration hooks.
         */
-       public function __construct() {
-               global $IP, $wgResourceModules, $wgResourceLoaderSources, $wgLoadScript, $wgEnableJavaScriptTest;
+       public function __construct( Config $config = null ) {
+               global $IP;
 
                wfProfileIn( __METHOD__ );
 
+               if ( $config === null ) {
+                       wfDebug( __METHOD__ . ' was called without providing a Config instance' );
+                       $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+               }
+
+               $this->config = $config;
+
                // Add 'local' source first
                $this->addSource(
                        'local',
-                       array( 'loadScript' => $wgLoadScript, 'apiScript' => wfScript( 'api' ) )
+                       array( 'loadScript' => wfScript( 'load' ), 'apiScript' => wfScript( 'api' ) )
                );
 
                // Add other sources
-               $this->addSource( $wgResourceLoaderSources );
+               $this->addSource( $config->get( 'ResourceLoaderSources' ) );
 
                // Register core modules
                $this->register( include "$IP/resources/Resources.php" );
                // Register extension modules
                wfRunHooks( 'ResourceLoaderRegisterModules', array( &$this ) );
-               $this->register( $wgResourceModules );
+               $this->register( $config->get( 'ResourceModules' ) );
 
-               if ( $wgEnableJavaScriptTest === true ) {
+               if ( $config->get( 'EnableJavaScriptTest' ) === true ) {
                        $this->registerTestModules();
                }
 
                wfProfileOut( __METHOD__ );
        }
 
+       /**
+        * @return Config
+        */
+       public function getConfig() {
+               return $this->config;
+       }
+
        /**
         * Register a module with the ResourceLoader system.
         *
@@ -298,8 +314,7 @@ class ResourceLoader {
 
                        // Apply custom skin-defined styles to existing modules.
                        if ( $this->isFileModule( $name ) ) {
-                               global $wgResourceModuleSkinStyles;
-                               foreach ( $wgResourceModuleSkinStyles as $skinName => $skinStyles ) {
+                               foreach ( $this->config->get( 'ResourceModuleSkinStyles' ) as $skinName => $skinStyles ) {
                                        // If this module already defines skinStyles for this skin, ignore $wgResourceModuleSkinStyles.
                                        if ( isset( $this->moduleInfos[$name]['skinStyles'][$skinName] ) ) {
                                                continue;
@@ -342,9 +357,9 @@ class ResourceLoader {
        /**
         */
        public function registerTestModules() {
-               global $IP, $wgEnableJavaScriptTest;
+               global $IP;
 
-               if ( $wgEnableJavaScriptTest !== true ) {
+               if ( $this->config->get( 'EnableJavaScriptTest' ) !== true ) {
                        throw new MWException( 'Attempt to register JavaScript test modules '
                                . 'but <code>$wgEnableJavaScriptTest</code> is false. '
                                . 'Edit your <code>LocalSettings.php</code> to enable it.' );
@@ -480,7 +495,9 @@ class ResourceLoader {
                                } else {
                                        $class = $info['class'];
                                }
+                               /** @var ResourceLoaderModule $object */
                                $object = new $class( $info );
+                               $object->setConfig( $this->getConfig() );
                        }
                        $object->setName( $name );
                        $this->modules[$name] = $object;
@@ -537,10 +554,8 @@ class ResourceLoader {
         * @param ResourceLoaderContext $context Context in which a response should be formed
         */
        public function respond( ResourceLoaderContext $context ) {
-               global $wgCacheEpoch, $wgUseFileCache;
-
                // Use file cache if enabled and available...
-               if ( $wgUseFileCache ) {
+               if ( $this->config->get( 'UseFileCache' ) ) {
                        $fileCache = ResourceFileCache::newFromContext( $context );
                        if ( $this->tryRespondFromFileCache( $fileCache, $context ) ) {
                                return; // output handled
@@ -596,7 +611,7 @@ class ResourceLoader {
 
                // To send Last-Modified and support If-Modified-Since, we need to detect
                // the last modified time
-               $mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch );
+               $mtime = wfTimestamp( TS_UNIX, $this->config->get( 'CacheEpoch' ) );
                foreach ( $modules as $module ) {
                        /**
                         * @var $module ResourceLoaderModule
@@ -664,18 +679,18 @@ class ResourceLoader {
         * @return void
         */
        protected function sendResponseHeaders( ResourceLoaderContext $context, $mtime, $errors ) {
-               global $wgResourceLoaderMaxage;
+               $rlMaxage = $this->config->get( 'ResourceLoaderMaxage' );
                // If a version wasn't specified we need a shorter expiry time for updates
                // to propagate to clients quickly
                // If there were errors, we also need a shorter expiry time so we can recover quickly
                if ( is_null( $context->getVersion() ) || $errors ) {
-                       $maxage = $wgResourceLoaderMaxage['unversioned']['client'];
-                       $smaxage = $wgResourceLoaderMaxage['unversioned']['server'];
+                       $maxage = $rlMaxage['unversioned']['client'];
+                       $smaxage = $rlMaxage['unversioned']['server'];
                // If a version was specified we can use a longer expiry time since changing
                // version numbers causes cache misses
                } else {
-                       $maxage = $wgResourceLoaderMaxage['versioned']['client'];
-                       $smaxage = $wgResourceLoaderMaxage['versioned']['server'];
+                       $maxage = $rlMaxage['versioned']['client'];
+                       $smaxage = $rlMaxage['versioned']['server'];
                }
                if ( $context->getOnly() === 'styles' ) {
                        header( 'Content-Type: text/css; charset=utf-8' );
@@ -743,13 +758,13 @@ class ResourceLoader {
        protected function tryRespondFromFileCache(
                ResourceFileCache $fileCache, ResourceLoaderContext $context
        ) {
-               global $wgResourceLoaderMaxage;
+               $rlMaxage = $this->config->get( 'ResourceLoaderMaxage' );
                // Buffer output to catch warnings.
                ob_start();
                // Get the maximum age the cache can be
                $maxage = is_null( $context->getVersion() )
-                       ? $wgResourceLoaderMaxage['unversioned']['server']
-                       : $wgResourceLoaderMaxage['versioned']['server'];
+                       ? $rlMaxage['unversioned']['server']
+                       : $rlMaxage['versioned']['server'];
                // Minimum timestamp the cache file must have
                $good = $fileCache->isCacheGood( wfTimestamp( TS_MW, time() - $maxage ) );
                if ( !$good ) {
@@ -1443,12 +1458,12 @@ class ResourceLoader {
        /**
         * Returns LESS compiler set up for use with MediaWiki
         *
+        * @param Config $config
+        * @throws MWException
         * @since 1.22
         * @return lessc
         */
-       public static function getLessCompiler() {
-               global $wgResourceLoaderLESSFunctions, $wgResourceLoaderLESSImportPaths;
-
+       public static function getLessCompiler( Config $config ) {
                // When called from the installer, it is possible that a required PHP extension
                // is missing (at least for now; see bug 47564). If this is the case, throw an
                // exception (caught by the installer) to prevent a fatal error later on.
@@ -1458,9 +1473,9 @@ class ResourceLoader {
 
                $less = new lessc();
                $less->setPreserveComments( true );
-               $less->setVariables( self::getLESSVars() );
-               $less->setImportDir( $wgResourceLoaderLESSImportPaths );
-               foreach ( $wgResourceLoaderLESSFunctions as $name => $func ) {
+               $less->setVariables( self::getLESSVars( $config ) );
+               $less->setImportDir( $config->get( 'ResourceLoaderLESSImportPaths' ) );
+               foreach ( $config->get( 'ResourceLoaderLESSFunctions' ) as $name => $func ) {
                        $less->registerFunction( $name, $func );
                }
                return $less;
@@ -1469,13 +1484,12 @@ class ResourceLoader {
        /**
         * Get global LESS variables.
         *
-        * $since 1.22
+        * @param Config $config
+        * @since 1.22
         * @return array Map of variable names to string CSS values.
         */
-       public static function getLESSVars() {
-               global $wgResourceLoaderLESSVars;
-
-               $lessVars = $wgResourceLoaderLESSVars;
+       public static function getLESSVars( Config $config ) {
+               $lessVars = $config->get( 'ResourceLoaderLESSVars' );
                // Sort by key to ensure consistent hashing for cache lookups.
                ksort( $lessVars );
                return $lessVars;
index 8994c0e..a725aab 100644 (file)
@@ -49,8 +49,6 @@ class ResourceLoaderContext {
         * @param WebRequest $request
         */
        public function __construct( $resourceLoader, WebRequest $request ) {
-               global $wgDefaultSkin, $wgResourceLoaderDebug;
-
                $this->resourceLoader = $resourceLoader;
                $this->request = $request;
 
@@ -61,7 +59,9 @@ class ResourceLoaderContext {
                // Various parameters
                $this->skin = $request->getVal( 'skin' );
                $this->user = $request->getVal( 'user' );
-               $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
+               $this->debug = $request->getFuzzyBool(
+                       'debug', $resourceLoader->getConfig()->get( 'ResourceLoaderDebug' )
+               );
                $this->only = $request->getVal( 'only' );
                $this->version = $request->getVal( 'version' );
                $this->raw = $request->getFuzzyBool( 'raw' );
@@ -69,7 +69,7 @@ class ResourceLoaderContext {
                $skinnames = Skin::getSkinNames();
                // If no skin is specified, or we don't recognize the skin, use the default skin
                if ( !$this->skin || !isset( $skinnames[$this->skin] ) ) {
-                       $this->skin = $wgDefaultSkin;
+                       $this->skin = $resourceLoader->getConfig()->get( 'DefaultSkin' );
                }
        }
 
index c3a36e4..4b2094f 100644 (file)
@@ -475,13 +475,12 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        return null;
                }
 
-               global $wgResourceLoaderValidateStaticJS;
                $localPath = $this->getLocalPath( $this->skipFunction );
                if ( !file_exists( $localPath ) ) {
                        throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" );
                }
                $contents = file_get_contents( $localPath );
-               if ( $wgResourceLoaderValidateStaticJS ) {
+               if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
                        $contents = $this->validateScriptFile( $fileName, $contents );
                }
                return $contents;
@@ -792,7 +791,6 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @return string Concatenated and remapped JavaScript data from $scripts
         */
        protected function readScriptFiles( array $scripts ) {
-               global $wgResourceLoaderValidateStaticJS;
                if ( empty( $scripts ) ) {
                        return '';
                }
@@ -803,7 +801,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                throw new MWException( __METHOD__ . ": script file not found: \"$localPath\"" );
                        }
                        $contents = file_get_contents( $localPath );
-                       if ( $wgResourceLoaderValidateStaticJS ) {
+                       if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
                                // Static files don't really need to be checked as often; unlike
                                // on-wiki module they shouldn't change unexpectedly without
                                // admin interference.
@@ -911,8 +909,8 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @param string $fileName File name of root LESS file.
         * @return string Cache key
         */
-       protected static function getLESSCacheKey( $fileName ) {
-               $vars = json_encode( ResourceLoader::getLESSVars() );
+       protected function getLESSCacheKey( $fileName ) {
+               $vars = json_encode( ResourceLoader::getLESSVars( $this->getConfig() ) );
                $hash = md5( $fileName . $vars );
                return wfMemcKey( 'resourceloader', 'less', $hash );
        }
@@ -933,7 +931,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @return string CSS source
         */
        protected function compileLESSFile( $fileName ) {
-               $key = self::getLESSCacheKey( $fileName );
+               $key = $this->getLESSCacheKey( $fileName );
                $cache = wfGetCache( CACHE_ANYTHING );
 
                // The input to lessc. Either an associative array representing the
@@ -944,7 +942,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        $source = $fileName;
                }
 
-               $compiler = ResourceLoader::getLessCompiler();
+               $compiler = ResourceLoader::getLessCompiler( $this->getConfig() );
                $result = null;
 
                $result = $compiler->cachedCompile( $source );
index 0ace76a..ba37f42 100644 (file)
@@ -64,6 +64,11 @@ abstract class ResourceLoaderModule {
        // In-object cache for message blob mtime
        protected $msgBlobMtime = array();
 
+       /**
+        * @var Config
+        */
+       protected $config;
+
        /* Methods */
 
        /**
@@ -129,6 +134,27 @@ abstract class ResourceLoaderModule {
                return '';
        }
 
+       /**
+        * @return Config
+        * @since 1.24
+        */
+       public function getConfig() {
+               if ( $this->config === null ) {
+                       // Ugh, fall back to default
+                       $this->config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+               }
+
+               return $this->config;
+       }
+
+       /**
+        * @param Config $config
+        * @since 1.24
+        */
+       public function setConfig( Config $config ) {
+               $this->config = $config;
+       }
+
        /**
         * Get the URL or URLs to load for this module's JS in debug mode.
         * The default behavior is to return a load.php?only=scripts URL for
@@ -561,8 +587,7 @@ abstract class ResourceLoaderModule {
         * @return string JS with the original, or a replacement error
         */
        protected function validateScriptFile( $fileName, $contents ) {
-               global $wgResourceLoaderValidateJS;
-               if ( $wgResourceLoaderValidateJS ) {
+               if ( $this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
                        // Try for cache hit
                        // Use CACHE_ANYTHING since filtering is very slow compared to DB queries
                        $key = wfMemcKey( 'resourceloader', 'jsparse', self::$parseCacheVersion, md5( $contents ) );
index d28f40f..1d9721a 100644 (file)
@@ -37,14 +37,12 @@ class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
         * @return array List of pages
         */
        protected function getPages( ResourceLoaderContext $context ) {
-               global $wgUseSiteJs, $wgUseSiteCss;
-
                $pages = array();
-               if ( $wgUseSiteJs ) {
+               if ( $this->getConfig()->get( 'UseSiteJs' ) ) {
                        $pages['MediaWiki:Common.js'] = array( 'type' => 'script' );
                        $pages['MediaWiki:' . ucfirst( $context->getSkin() ) . '.js'] = array( 'type' => 'script' );
                }
-               if ( $wgUseSiteCss ) {
+               if ( $this->getConfig()->get( 'UseSiteCss' ) ) {
                        $pages['MediaWiki:Common.css'] = array( 'type' => 'style' );
                        $pages['MediaWiki:' . ucfirst( $context->getSkin() ) . '.css'] = array( 'type' => 'style' );
 
index 2c0f8df..7cfc81d 100644 (file)
@@ -36,22 +36,14 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         * @param ResourceLoaderContext $context
         * @return array
         */
-       protected function getConfig( $context ) {
+       protected function getConfigSettings( $context ) {
 
                $hash = $context->getHash();
                if ( isset( $this->configVars[$hash] ) ) {
                        return $this->configVars[$hash];
                }
 
-               global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension,
-                       $wgArticlePath, $wgScriptPath, $wgServer, $wgServerName,
-                       $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion,
-                       $wgEnableAPI, $wgEnableWriteAPI, $wgDBname,
-                       $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath,
-                       $wgCookiePrefix, $wgCookieDomain, $wgCookiePath,
-                       $wgCookieExpiration, $wgResourceLoaderMaxQueryLength,
-                       $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion,
-                       $wgSearchType;
+               global $wgContLang;
 
                $mainPage = Title::newMainPage();
 
@@ -69,51 +61,52 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        }
                }
 
+               $conf = $this->getConfig();
                // Build list of variables
                $vars = array(
-                       'wgLoadScript' => $wgLoadScript,
+                       'wgLoadScript' => wfScript( 'load' ),
                        'debug' => $context->getDebug(),
                        'skin' => $context->getSkin(),
-                       'stylepath' => $wgStylePath,
+                       'stylepath' => $conf->get( 'StylePath' ),
                        'wgUrlProtocols' => wfUrlProtocols(),
-                       'wgArticlePath' => $wgArticlePath,
-                       'wgScriptPath' => $wgScriptPath,
-                       'wgScriptExtension' => $wgScriptExtension,
-                       'wgScript' => $wgScript,
-                       'wgSearchType' => $wgSearchType,
-                       'wgVariantArticlePath' => $wgVariantArticlePath,
+                       'wgArticlePath' => $conf->get( 'ArticlePath' ),
+                       'wgScriptPath' => $conf->get( 'ScriptPath' ),
+                       'wgScriptExtension' => $conf->get( 'ScriptExtension' ),
+                       'wgScript' => wfScript(),
+                       'wgSearchType' => $conf->get( 'SearchType' ),
+                       'wgVariantArticlePath' => $conf->get( 'VariantArticlePath' ),
                        // Force object to avoid "empty" associative array from
                        // becoming [] instead of {} in JS (bug 34604)
-                       'wgActionPaths' => (object)$wgActionPaths,
-                       'wgServer' => $wgServer,
-                       'wgServerName' => $wgServerName,
+                       'wgActionPaths' => (object)$conf->get( 'ActionPaths' ),
+                       'wgServer' => $conf->get( 'Server' ),
+                       'wgServerName' => $conf->get( 'ServerName' ),
                        'wgUserLanguage' => $context->getLanguage(),
                        'wgContentLanguage' => $wgContLang->getCode(),
-                       'wgVersion' => $wgVersion,
-                       'wgEnableAPI' => $wgEnableAPI,
-                       'wgEnableWriteAPI' => $wgEnableWriteAPI,
+                       'wgVersion' => $conf->get( 'Version' ),
+                       'wgEnableAPI' => $conf->get( 'EnableAPI' ),
+                       'wgEnableWriteAPI' => $conf->get( 'EnableWriteAPI' ),
                        'wgMainPageTitle' => $mainPage->getPrefixedText(),
                        'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
                        'wgNamespaceIds' => $namespaceIds,
                        'wgContentNamespaces' => MWNamespace::getContentNamespaces(),
-                       'wgSiteName' => $wgSitename,
-                       'wgFileExtensions' => array_values( array_unique( $wgFileExtensions ) ),
-                       'wgDBname' => $wgDBname,
+                       'wgSiteName' => $conf->get( 'Sitename' ),
+                       'wgFileExtensions' => array_values( array_unique( $conf->get( 'FileExtensions' ) ) ),
+                       'wgDBname' => $conf->get( 'DBname' ),
                        // This sucks, it is only needed on Special:Upload, but I could
                        // not find a way to add vars only for a certain module
                        'wgFileCanRotate' => BitmapHandler::canRotate(),
                        'wgAvailableSkins' => Skin::getSkinNames(),
-                       'wgExtensionAssetsPath' => $wgExtensionAssetsPath,
+                       'wgExtensionAssetsPath' => $conf->get( 'ExtensionAssetsPath' ),
                        // MediaWiki sets cookies to have this prefix by default
-                       'wgCookiePrefix' => $wgCookiePrefix,
-                       'wgCookieDomain' => $wgCookieDomain,
-                       'wgCookiePath' => $wgCookiePath,
-                       'wgCookieExpiration' => $wgCookieExpiration,
-                       'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength,
+                       'wgCookiePrefix' => $conf->get( 'CookiePrefix' ),
+                       'wgCookieDomain' => $conf->get( 'CookieDomain' ),
+                       'wgCookiePath' => $conf->get( 'CookiePath' ),
+                       'wgCookieExpiration' => $conf->get( 'CookieExpiration' ),
+                       'wgResourceLoaderMaxQueryLength' => $conf->get( 'ResourceLoaderMaxQueryLength' ),
                        'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces,
                        'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass( Title::legalChars() ),
-                       'wgResourceLoaderStorageVersion' => $wgResourceLoaderStorageVersion,
-                       'wgResourceLoaderStorageEnabled' => $wgResourceLoaderStorageEnabled,
+                       'wgResourceLoaderStorageVersion' => $conf->get( 'ResourceLoaderStorageVersion' ),
+                       'wgResourceLoaderStorageEnabled' => $conf->get( 'ResourceLoaderStorageEnabled' ),
                );
 
                wfRunHooks( 'ResourceLoaderGetConfigVars', array( &$vars ) );
@@ -197,8 +190,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         * @param ResourceLoaderContext $context
         * @return string JavaScript code for registering all modules with the client loader
         */
-       public static function getModuleRegistrations( ResourceLoaderContext $context ) {
-               global $wgCacheEpoch;
+       public function getModuleRegistrations( ResourceLoaderContext $context ) {
                wfProfileIn( __METHOD__ );
 
                $resourceLoader = $context->getResourceLoader();
@@ -218,7 +210,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        // getModifiedTime() is supposed to return a UNIX timestamp, but it doesn't always
                        // seem to do that, and custom implementations might forget. Coerce it to TS_UNIX
                        $moduleMtime = wfTimestamp( TS_UNIX, $module->getModifiedTime( $context ) );
-                       $mtime = max( $moduleMtime, wfTimestamp( TS_UNIX, $wgCacheEpoch ) );
+                       $mtime = max( $moduleMtime, wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) ) );
 
                        // FIXME: Convert to numbers, wfTimestamp always gives us stings, even for TS_UNIX
 
@@ -373,19 +365,19 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         * @return string
         */
        public function getScript( ResourceLoaderContext $context ) {
-               global $IP, $wgLegacyJavaScriptGlobals;
+               global $IP;
 
                $out = file_get_contents( "$IP/resources/src/startup.js" );
                if ( $context->getOnly() === 'scripts' ) {
 
                        // Startup function
-                       $configuration = $this->getConfig( $context );
-                       $registrations = self::getModuleRegistrations( $context );
+                       $configuration = $this->getConfigSettings( $context );
+                       $registrations = $this->getModuleRegistrations( $context );
                        // Fix indentation
                        $registrations = str_replace( "\n", "\n\t", trim( $registrations ) );
                        $out .= "var startUp = function () {\n" .
                                "\tmw.config = new " .
-                               Xml::encodeJsCall( 'mw.Map', array( $wgLegacyJavaScriptGlobals ) ) . "\n" .
+                               Xml::encodeJsCall( 'mw.Map', array( $this->getConfig()->get( 'LegacyJavaScriptGlobals' ) ) ) . "\n" .
                                "\t$registrations\n" .
                                "\t" . Xml::encodeJsCall( 'mw.config.set', array( $configuration ) ) .
                                "};\n";
@@ -412,7 +404,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         * @return array|mixed
         */
        public function getModifiedTime( ResourceLoaderContext $context ) {
-               global $IP, $wgCacheEpoch;
+               global $IP;
 
                $hash = $context->getHash();
                if ( isset( $this->modifiedTime[$hash] ) ) {
@@ -425,7 +417,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                $loader->preloadModuleInfo( $loader->getModuleNames(), $context );
 
                $time = max(
-                       wfTimestamp( TS_UNIX, $wgCacheEpoch ),
+                       wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) ),
                        filemtime( "$IP/resources/src/startup.js" ),
                        $this->getHashMtime( $context )
                );
@@ -455,11 +447,9 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
         * @return string Hash
         */
        public function getModifiedHash( ResourceLoaderContext $context ) {
-               global $wgLegacyJavaScriptGlobals;
-
                $data = array(
-                       'vars' => $this->getConfig( $context ),
-                       'wgLegacyJavaScriptGlobals' => $wgLegacyJavaScriptGlobals,
+                       'vars' => $this->getConfigSettings( $context ),
+                       'wgLegacyJavaScriptGlobals' => $this->getConfig()->get( 'LegacyJavaScriptGlobals' ),
                );
 
                return md5( serialize( $data ) );
index 082a65c..40274c6 100644 (file)
@@ -54,9 +54,9 @@ class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
         * @return array
         */
        public function getStyles( ResourceLoaderContext $context ) {
-               global $wgAllowUserCssPrefs, $wgUser;
+               global $wgUser;
 
-               if ( !$wgAllowUserCssPrefs ) {
+               if ( !$this->getConfig()->get( 'AllowUserCssPrefs' ) ) {
                        return array();
                }
 
index 680c74c..7cf1942 100644 (file)
@@ -37,13 +37,16 @@ class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
         * @return array
         */
        protected function getPages( ResourceLoaderContext $context ) {
-               global $wgUser, $wgUseSiteJs, $wgUseSiteCss;
+               global $wgUser;
 
                $userName = $context->getUser();
                if ( $userName === null ) {
                        return array();
                }
-               if ( !$wgUseSiteJs && !$wgUseSiteCss ) {
+
+               $useSiteJs = $this->getConfig()->get( 'UseSiteJs' );
+               $useSiteCss = $this->getConfig()->get( 'UseSiteCss' );
+               if ( !$useSiteJs && !$useSiteCss ) {
                        return array();
                }
 
@@ -62,10 +65,10 @@ class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
                        if ( $group == '*' ) {
                                continue;
                        }
-                       if ( $wgUseSiteJs ) {
+                       if ( $useSiteJs ) {
                                $pages["MediaWiki:Group-$group.js"] = array( 'type' => 'script' );
                        }
-                       if ( $wgUseSiteCss ) {
+                       if ( $useSiteCss ) {
                                $pages["MediaWiki:Group-$group.css"] = array( 'type' => 'style' );
                        }
                }
index 90b4838..1b6d1de 100644 (file)
@@ -38,13 +38,16 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
         * @return array
         */
        protected function getPages( ResourceLoaderContext $context ) {
-               global $wgAllowUserJs, $wgAllowUserCss;
                $username = $context->getUser();
 
                if ( $username === null ) {
                        return array();
                }
-               if ( !$wgAllowUserJs && !$wgAllowUserCss ) {
+
+               $allowUserJs = $this->getConfig()->get( 'AllowUserJs' );
+               $allowUserCss = $this->getConfig()->get( 'AllowUserCss' );
+
+               if ( !$allowUserJs && !$allowUserCss ) {
                        return array();
                }
 
@@ -58,11 +61,11 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
                $userpage = $userpageTitle->getPrefixedDBkey(); // Needed so $excludepages works
 
                $pages = array();
-               if ( $wgAllowUserJs ) {
+               if ( $allowUserJs ) {
                        $pages["$userpage/common.js"] = array( 'type' => 'script' );
                        $pages["$userpage/" . $context->getSkin() . '.js'] = array( 'type' => 'script' );
                }
-               if ( $wgAllowUserCss ) {
+               if ( $allowUserCss ) {
                        $pages["$userpage/common.css"] = array( 'type' => 'style' );
                        $pages["$userpage/" . $context->getSkin() . '.css'] = array( 'type' => 'style' );
                }
index bfb3c42..d9ed91d 100644 (file)
@@ -136,8 +136,6 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
         * @return array
         */
        public function getStyles( ResourceLoaderContext $context ) {
-               global $wgScriptPath;
-
                $styles = array();
                foreach ( $this->getPages( $context ) as $titleText => $options ) {
                        if ( $options['type'] !== 'style' ) {
@@ -155,7 +153,7 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
                        if ( $this->getFlip( $context ) ) {
                                $style = CSSJanus::transform( $style, true, false );
                        }
-                       $style = CSSMin::remap( $style, false, $wgScriptPath, true );
+                       $style = CSSMin::remap( $style, false, $this->getConfig()->get( 'ScriptPath' ), true );
                        if ( !isset( $styles[$media] ) ) {
                                $styles[$media] = array();
                        }
index 6ebbcb2..62157d2 100644 (file)
@@ -38,7 +38,7 @@ class LessFileCompilationTest extends MediaWikiTestCase {
                        "$thisString must refer to a readable file"
                );
 
-               $compiler = ResourceLoader::getLessCompiler();
+               $compiler = ResourceLoader::getLessCompiler( RequestContext::getMain()->getConfig() );
                $this->assertNotNull( $compiler->compileFile( $this->file ) );
        }
 
index 75e54d3..a3d73e5 100644 (file)
@@ -22,7 +22,8 @@ class ResourceLoaderLESSTest extends MediaWikiTestCase {
 
                $expect = file_get_contents( $cssFile );
                $content = file_get_contents( $lessFile );
-               $result = ResourceLoader::getLessCompiler()->compile( $content, $lessFile );
+               $result = ResourceLoader::getLessCompiler( RequestContext::getMain()->getConfig() )
+                       ->compile( $content, $lessFile );
                $this->assertEquals( $expect, $result );
        }
 }
index df08972..0c250bd 100644 (file)
@@ -332,9 +332,10 @@ mw.loader.addSource( {
 
                $rl->register( $case['modules'] );
 
+               $module = new ResourceLoaderStartUpModule();
                $this->assertEquals(
                        ltrim( $case['out'], "\n" ),
-                       ResourceLoaderStartUpModule::getModuleRegistrations( $context ),
+                       $module->getModuleRegistrations( $context ),
                        $case['msg']
                );
        }
@@ -366,6 +367,7 @@ mw.loader.addSource( {
                $context = self::getResourceLoaderContext();
                $rl = $context->getResourceLoader();
                $rl->register( $modules );
+               $module = new ResourceLoaderStartUpModule();
                $this->assertEquals(
 'mw.loader.addSource({"local":{"loadScript":"/w/load.php","apiScript":"/w/api.php"}});'
 . 'mw.loader.register(['
@@ -373,7 +375,7 @@ mw.loader.addSource( {
 . '["test.min","1388534400",["test.blank"],null,"local",'
 . '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
 . ']]);',
-                       ResourceLoaderStartUpModule::getModuleRegistrations( $context ),
+                       $module->getModuleRegistrations( $context ),
                        'Minified output'
                );
        }
@@ -385,6 +387,7 @@ mw.loader.addSource( {
                $context = self::getResourceLoaderContext();
                $rl = $context->getResourceLoader();
                $rl->register( $modules );
+               $module = new ResourceLoaderStartUpModule();
                $this->assertEquals(
 'mw.loader.addSource( {
     "local": {
@@ -407,7 +410,7 @@ mw.loader.addSource( {
         "return !!(    window.JSON \u0026\u0026    JSON.parse \u0026\u0026    JSON.stringify);"
     ]
 ] );',
-                       ResourceLoaderStartUpModule::getModuleRegistrations( $context ),
+                       $module->getModuleRegistrations( $context ),
                        'Unminified output'
                );
        }