Merge "Use interwiki cache directly to resolve transwiki import sources"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 5b030d7..fcda87b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Abstraction for resource loader modules.
+ * Abstraction for ResourceLoader modules.
  *
  * 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
@@ -23,7 +23,7 @@
  */
 
 /**
- * Abstraction for resource loader modules, with name registration and maxage functionality.
+ * Abstraction for ResourceLoader modules, with name registration and maxage functionality.
  */
 abstract class ResourceLoaderModule {
        # Type of resource
@@ -67,10 +67,6 @@ abstract class ResourceLoaderModule {
        // In-object cache for module content
        protected $contents = array();
 
-       // Whether the position returned by getPosition() is defined in the module configuration
-       // and not a default value
-       protected $isPositionDefined = false;
-
        /**
         * @var Config
         */
@@ -291,19 +287,6 @@ abstract class ResourceLoaderModule {
                return 'bottom';
        }
 
-       /**
-        * Whether the position returned by getPosition() is a default value or comes from the module
-        * definition. This method is meant to be short-lived, and is only useful until classes added
-        * via addModuleStyles with a default value define an explicit position. See getModuleStyles()
-        * in OutputPage for the related migration warning.
-        *
-        * @return bool
-        * @since  1.26
-        */
-       public function isPositionDefault() {
-               return !$this->isPositionDefined;
-       }
-
        /**
         * Whether this module's JS expects to work without the client-side ResourceLoader module.
         * Returning true from this function will prevent mw.loader.state() call from being
@@ -315,25 +298,12 @@ abstract class ResourceLoaderModule {
                return false;
        }
 
-       /**
-        * Get the loader JS for this module, if set.
-        *
-        * @return mixed JavaScript loader code as a string or boolean false if no custom loader set
-        */
-       public function getLoaderScript() {
-               // Stub, override expected
-               return false;
-       }
-
        /**
         * Get a list of modules this module depends on.
         *
         * Dependency information is taken into account when loading a module
         * on the client side.
         *
-        * To add dependencies dynamically on the client side, use a custom
-        * loader script, see getLoaderScript()
-        *
         * Note: It is expected that $context will be made non-optional in the near
         * future.
         *
@@ -423,7 +393,7 @@ abstract class ResourceLoaderModule {
        /**
         * Set the files this module depends on indirectly for a given skin.
         *
-        * @since 1.26
+        * @since 1.27
         * @param ResourceLoaderContext $context
         * @param array $localFileRefs List of files
         */
@@ -457,11 +427,11 @@ abstract class ResourceLoaderModule {
         * This is used to make file paths safe for storing in a database without the paths
         * becoming stale or incorrect when MediaWiki is moved or upgraded (T111481).
         *
-        * @since 1.26
+        * @since 1.27
         * @param array $filePaths
         * @return array
         */
-       protected static function getRelativePaths( Array $filePaths ) {
+       public static function getRelativePaths( Array $filePaths ) {
                global $IP;
                return array_map( function ( $path ) use ( $IP ) {
                        return RelPath\getRelativePath( $path, $IP );
@@ -471,11 +441,11 @@ abstract class ResourceLoaderModule {
        /**
         * Expand directories relative to $IP.
         *
-        * @since 1.26
+        * @since 1.27
         * @param array $filePaths
         * @return array
         */
-       protected static function expandRelativePaths( Array $filePaths ) {
+       public static function expandRelativePaths( Array $filePaths ) {
                global $IP;
                return array_map( function ( $path ) use ( $IP ) {
                        return RelPath\joinPath( $IP, $path );
@@ -527,7 +497,7 @@ abstract class ResourceLoaderModule {
        /**
         * Get module-specific LESS variables, if any.
         *
-        * @since 1.26
+        * @since 1.27
         * @param ResourceLoaderContext $context
         * @return array Module-specific LESS variables.
         */
@@ -619,11 +589,11 @@ abstract class ResourceLoaderModule {
                                                                foreach ( $style as $cssText ) {
                                                                        if ( is_string( $cssText ) ) {
                                                                                $stylePairs[$media][] =
-                                                                                       $rl->filter( 'minify-css', $cssText );
+                                                                                       ResourceLoader::filter( 'minify-css', $cssText );
                                                                        }
                                                                }
                                                        } elseif ( is_string( $style ) ) {
-                                                               $stylePairs[$media] = $rl->filter( 'minify-css', $style );
+                                                               $stylePairs[$media] = ResourceLoader::filter( 'minify-css', $style );
                                                        }
                                                }
                                        }
@@ -874,14 +844,13 @@ abstract class ResourceLoaderModule {
        protected function validateScriptFile( $fileName, $contents ) {
                if ( $this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
                        // Try for cache hit
-                       // Use CACHE_ANYTHING since parsing JS is much slower than a DB query
-                       $key = wfMemcKey(
+                       $cache = ObjectCache::getMainWANInstance();
+                       $key = $cache->makeKey(
                                'resourceloader',
                                'jsparse',
                                self::$parseCacheVersion,
                                md5( $contents )
                        );
-                       $cache = wfGetCache( CACHE_ANYTHING );
                        $cacheEntry = $cache->get( $key );
                        if ( is_string( $cacheEntry ) ) {
                                return $cacheEntry;