OutputPage: Support foreign module sources in makeResourceLoaderLink
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 819bf5a..00d245c 100644 (file)
@@ -26,7 +26,6 @@
  * Abstraction for resource loader modules, with name registration and maxage functionality.
  */
 abstract class ResourceLoaderModule {
-
        # Type of resource
        const TYPE_SCRIPTS = 'scripts';
        const TYPE_STYLES = 'styles';
@@ -145,17 +144,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 );
        }
 
@@ -192,17 +191,17 @@ abstract class ResourceLoaderModule {
         * @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 ) );
        }
 
@@ -294,6 +293,24 @@ abstract class ResourceLoaderModule {
                return $this->targets;
        }
 
+       /**
+        * Get the skip function.
+        *
+        * Modules that provide fallback functionality can provide a "skip function". This
+        * function, if provided, will be passed along to the module registry on the client.
+        * When this module is loaded (either directly or as a dependency of another module),
+        * then this function is executed first. If the function returns true, the module will
+        * instantly be considered "ready" without requesting the associated module resources.
+        *
+        * The value returned here must be valid javascript for execution in a private function.
+        * It must not contain the "function () {" and "}" wrapper though.
+        *
+        * @return string|null A JavaScript function body returning a boolean value, or null
+        */
+       public function getSkipFunction() {
+               return null;
+       }
+
        /**
         * Get the files this module depends on indirectly for a given skin.
         * Currently these are only image files referenced by the module's CSS.
@@ -441,6 +458,8 @@ abstract class ResourceLoaderModule {
        /**
         * Helper method for calculating when this module's definition summary was last changed.
         *
+        * @since 1.23
+        *
         * @return int UNIX timestamp or 0 if no definition summary was provided
         *  by getDefinitionSummary()
         */
@@ -474,7 +493,8 @@ abstract class ResourceLoaderModule {
                        return $data;
                }
 
-               wfDebugLog( 'resourceloader', __METHOD__ . ": New definition hash for module {$this->getName()} in context {$context->getHash()}: $hash." );
+               wfDebugLog( 'resourceloader', __METHOD__ . ": New definition hash for module "
+                       . "{$this->getName()} in context {$context->getHash()}: $hash." );
 
                $timestamp = time();
                $cache->set( $key, $timestamp );
@@ -505,6 +525,8 @@ abstract class ResourceLoaderModule {
         * contain arrays and scalars as values (avoid object instances) which means
         * it requires abstraction.
         *
+        * @since 1.23
+        *
         * @return array|null
         */
        public function getDefinitionSummary( ResourceLoaderContext $context ) {