Merge "EditPage::newSectionSummary should return a value in all code paths"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index f636105..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
@@ -144,17 +170,17 @@ abstract class ResourceLoaderModule {
         * @return array Array of URLs
         */
        public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
-               $url = ResourceLoader::makeLoaderURL(
-                       array( $this->getName() ),
-                       $context->getLanguage(),
-                       $context->getSkin(),
-                       $context->getUser(),
-                       $context->getVersion(),
-                       true, // debug
-                       'scripts', // only
-                       $context->getRequest()->getBool( 'printable' ),
-                       $context->getRequest()->getBool( 'handheld' )
+               $resourceLoader = $context->getResourceLoader();
+               $derivative = new DerivativeResourceLoaderContext( $context );
+               $derivative->setModules( array( $this->getName() ) );
+               $derivative->setOnly( 'scripts' );
+               $derivative->setDebug( true );
+
+               $url = $resourceLoader->createLoaderURL(
+                       $this->getSource(),
+                       $derivative
                );
+
                return array( $url );
        }
 
@@ -188,20 +214,20 @@ abstract class ResourceLoaderModule {
         * load the files directly. See also getScriptURLsForDebug()
         *
         * @param ResourceLoaderContext $context
-        * @return array array( mediaType => array( URL1, URL2, ... ), ... )
+        * @return array Array( mediaType => array( URL1, URL2, ... ), ... )
         */
        public function getStyleURLsForDebug( ResourceLoaderContext $context ) {
-               $url = ResourceLoader::makeLoaderURL(
-                       array( $this->getName() ),
-                       $context->getLanguage(),
-                       $context->getSkin(),
-                       $context->getUser(),
-                       $context->getVersion(),
-                       true, // debug
-                       'styles', // only
-                       $context->getRequest()->getBool( 'printable' ),
-                       $context->getRequest()->getBool( 'handheld' )
+               $resourceLoader = $context->getResourceLoader();
+               $derivative = new DerivativeResourceLoaderContext( $context );
+               $derivative->setModules( array( $this->getName() ) );
+               $derivative->setOnly( 'styles' );
+               $derivative->setDebug( true );
+
+               $url = $resourceLoader->createLoaderURL(
+                       $this->getSource(),
+                       $derivative
                );
+
                return array( 'all' => array( $url ) );
        }
 
@@ -548,7 +574,7 @@ abstract class ResourceLoaderModule {
                return false;
        }
 
-       /** @var JSParser lazy-initialized; use self::javaScriptParser() */
+       /** @var JSParser Lazy-initialized; use self::javaScriptParser() */
        private static $jsParser;
        private static $parseCacheVersion = 1;
 
@@ -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 ) );