public function testGetHash()
 {
     $context = self::getResourceLoaderContext();
     $derived = new DerivativeResourceLoaderContext($context);
     $derived->setLanguage('nl');
     // Assert that subclass is able to clear parent class "hash" member
     $this->assertEquals($derived->getHash(), 'nl|fallback|||scripts|||||');
 }
 /**
  * Get a string identifying the current version of this module in a given context.
  *
  * Whenever anything happens that changes the module's response (e.g. scripts, styles, and
  * messages) this value must change. This value is used to store module responses in cache.
  * (Both client-side and server-side.)
  *
  * It is not recommended to override this directly. Use getDefinitionSummary() instead.
  * If overridden, one must call the parent getVersionHash(), append data and re-hash.
  *
  * This method should be quick because it is frequently run by ResourceLoaderStartUpModule to
  * propagate changes to the client and effectively invalidate cache.
  *
  * For backward-compatibility, the following optional data providers are automatically included:
  *
  * - getModifiedTime()
  * - getModifiedHash()
  *
  * @since 1.26
  * @param ResourceLoaderContext $context
  * @return string Hash (should use ResourceLoader::makeHash)
  */
 public function getVersionHash(ResourceLoaderContext $context)
 {
     // The startup module produces a manifest with versions representing the entire module.
     // Typically, the request for the startup module itself has only=scripts. That must apply
     // only to the startup module content, and not to the module version computed here.
     $context = new DerivativeResourceLoaderContext($context);
     $context->setModules(array());
     // Version hash must cover all resources, regardless of startup request itself.
     $context->setOnly(null);
     // Compute version hash based on content, not debug urls.
     $context->setDebug(false);
     // Cache this somewhat expensive operation. Especially because some classes
     // (e.g. startup module) iterate more than once over all modules to get versions.
     $contextHash = $context->getHash();
     if (!array_key_exists($contextHash, $this->versionHash)) {
         if ($this->enableModuleContentVersion()) {
             // Detect changes directly
             $str = json_encode($this->getModuleContent($context));
         } else {
             // Infer changes based on definition and other metrics
             $summary = $this->getDefinitionSummary($context);
             if (!isset($summary['_cacheEpoch'])) {
                 throw new LogicException('getDefinitionSummary must call parent method');
             }
             $str = json_encode($summary);
             $mtime = $this->getModifiedTime($context);
             if ($mtime !== null) {
                 // Support: MediaWiki 1.25 and earlier
                 $str .= strval($mtime);
             }
             $mhash = $this->getModifiedHash($context);
             if ($mhash !== null) {
                 // Support: MediaWiki 1.25 and earlier
                 $str .= strval($mhash);
             }
         }
         $this->versionHash[$contextHash] = ResourceLoader::makeHash($str);
     }
     return $this->versionHash[$contextHash];
 }
 /**
  * Get the load URL of the startup modules.
  *
  * This is a helper for getScript(), but can also be called standalone, such
  * as when generating an AppCache manifest.
  *
  * @param ResourceLoaderContext $context
  * @return string
  */
 public static function getStartupModulesUrl(ResourceLoaderContext $context)
 {
     $rl = $context->getResourceLoader();
     $derivative = new DerivativeResourceLoaderContext($context);
     $derivative->setModules(self::getStartupModules());
     $derivative->setOnly('scripts');
     // Must setModules() before makeVersionQuery()
     $derivative->setVersion($rl->makeVersionQuery($derivative));
     return $rl->createLoaderURL('local', $derivative);
 }
 /**
  * Get the URL or URLs to load for this module's CSS in debug mode.
  * The default behavior is to return a load.php?only=styles URL for
  * the module, but file-based modules will want to override this to
  * load the files directly. See also getScriptURLsForDebug()
  *
  * @param ResourceLoaderContext $context
  * @return array Array( mediaType => array( URL1, URL2, ... ), ... )
  */
 public function getStyleURLsForDebug(ResourceLoaderContext $context)
 {
     $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));
 }
 public function testAccessors()
 {
     $context = self::getContext();
     $derived = new DerivativeResourceLoaderContext($context);
     $this->assertSame($derived->getRequest(), $context->getRequest());
     $this->assertSame($derived->getResourceLoader(), $context->getResourceLoader());
 }
 /**
  * Get the URL or URLs to load for this module's JS in debug mode.
  * @param ResourceLoaderContext $context
  * @return array list of urls
  * @see ResourceLoaderModule::getScriptURLsForDebug
  */
 public function getScriptURLsForDebug(ResourceLoaderContext $context)
 {
     if ($this->hasHackedScriptMode) {
         $derivative = new DerivativeResourceLoaderContext($context);
         $derivative->setDebug(true);
         $derivative->setModules(array($this->getName()));
         // @todo FIXME: Make this templates and update
         // makeModuleResponse so that it only outputs template code.
         // When this is done you can merge with parent array and
         // retain file names.
         $derivative->setOnly('scripts');
         $rl = $derivative->getResourceLoader();
         $urls = array($rl->createLoaderURL($this->getSource(), $derivative));
     } else {
         $urls = parent::getScriptURLsForDebug($context);
     }
     return $urls;
 }