コード例 #1
0
 /**
  * Gets registration code for all modules
  *
  * @param $context ResourceLoaderContext object
  * @return String: JavaScript code for registering all modules with the client loader
  */
 public static function getModuleRegistrations(ResourceLoaderContext $context)
 {
     global $wgCacheEpoch;
     wfProfileIn(__METHOD__);
     $out = '';
     $registrations = array();
     $resourceLoader = $context->getResourceLoader();
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         // Support module loader scripts
         $loader = $module->getLoaderScript();
         if ($loader !== false) {
             $deps = $module->getDependencies();
             $group = $module->getGroup();
             $version = wfTimestamp(TS_ISO_8601_BASIC, round($module->getModifiedTime($context), -2));
             $out .= ResourceLoader::makeCustomLoaderScript($name, $version, $deps, $group, $loader);
         } else {
             $mtime = max($module->getModifiedTime($context), wfTimestamp(TS_UNIX, $wgCacheEpoch));
             // Modules without dependencies or a group pass two arguments (name, timestamp) to
             // mediaWiki.loader.register()
             if (!count($module->getDependencies() && $module->getGroup() === null)) {
                 $registrations[] = array($name, $mtime);
             } else {
                 if ($module->getGroup() === null) {
                     $registrations[] = array($name, $mtime, $module->getDependencies());
                 } else {
                     $registrations[] = array($name, $mtime, $module->getDependencies(), $module->getGroup());
                 }
             }
         }
     }
     $out .= ResourceLoader::makeLoaderRegisterScript($registrations);
     wfProfileOut(__METHOD__);
     return $out;
 }
コード例 #2
0
 /**
  * Gets registration code for all modules
  *
  * @param $context ResourceLoaderContext object
  * @return String: JavaScript code for registering all modules with the client loader
  */
 public static function getModuleRegistrations(ResourceLoaderContext $context)
 {
     global $wgCacheEpoch;
     wfProfileIn(__METHOD__);
     $out = '';
     $registrations = array();
     $resourceLoader = $context->getResourceLoader();
     // Register sources
     $out .= ResourceLoader::makeLoaderSourcesScript($resourceLoader->getSources());
     // Register modules
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         // Support module loader scripts
         $loader = $module->getLoaderScript();
         if ($loader !== false) {
             $deps = $module->getDependencies();
             $group = $module->getGroup();
             $source = $module->getSource();
             $version = wfTimestamp(TS_ISO_8601_BASIC, $module->getModifiedTime($context));
             $out .= ResourceLoader::makeCustomLoaderScript($name, $version, $deps, $group, $source, $loader);
         } else {
             // 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));
             // Wikia - change begin - @author: wladek
             $flags = $module->getFlag($module->getFlagNames());
             if (!empty($flags)) {
                 $registrations[] = array($name, $mtime, $module->getDependencies(), $module->getGroup(), $module->getSource(), $flags);
             } else {
                 // Wikia - change end
                 // Modules without dependencies, a group or a foreign source pass two arguments (name, timestamp) to
                 // mw.loader.register()
                 if (!count($module->getDependencies()) && $module->getGroup() === null && $module->getSource() === 'local') {
                     $registrations[] = array($name, $mtime);
                 } elseif ($module->getGroup() === null && $module->getSource() === 'local') {
                     $registrations[] = array($name, $mtime, $module->getDependencies());
                 } elseif ($module->getSource() === 'local') {
                     $registrations[] = array($name, $mtime, $module->getDependencies(), $module->getGroup());
                 } else {
                     $registrations[] = array($name, $mtime, $module->getDependencies(), $module->getGroup(), $module->getSource());
                 }
             }
         }
     }
     $out .= ResourceLoader::makeLoaderRegisterScript($registrations);
     wfProfileOut(__METHOD__);
     return $out;
 }
コード例 #3
0
 /**
  * Gets registration code for all modules
  *
  * @param $context ResourceLoaderContext object
  * @return String: JavaScript code for registering all modules with the client loader
  */
 public static function getModuleRegistrations(ResourceLoaderContext $context)
 {
     global $wgCacheEpoch;
     wfProfileIn(__METHOD__);
     $out = '';
     $registrations = array();
     $resourceLoader = $context->getResourceLoader();
     $target = $context->getRequest()->getVal('target', 'desktop');
     // Register sources
     $out .= ResourceLoader::makeLoaderSourcesScript($resourceLoader->getSources());
     // Register modules
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         $moduleTargets = $module->getTargets();
         if (!in_array($target, $moduleTargets)) {
             continue;
         }
         $deps = $module->getDependencies();
         $group = $module->getGroup();
         $source = $module->getSource();
         // Support module loader scripts
         $loader = $module->getLoaderScript();
         if ($loader !== false) {
             $version = wfTimestamp(TS_ISO_8601_BASIC, $module->getModifiedTime($context));
             $out .= ResourceLoader::makeCustomLoaderScript($name, $version, $deps, $group, $source, $loader);
             continue;
         }
         // Automatically register module
         // 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));
         // Modules without dependencies, a group or a foreign source pass two arguments (name, timestamp) to
         // mw.loader.register()
         if (!count($deps) && $group === null && $source === 'local') {
             $registrations[] = array($name, $mtime);
         } elseif ($group === null && $source === 'local') {
             $registrations[] = array($name, $mtime, $deps);
         } elseif ($source === 'local') {
             $registrations[] = array($name, $mtime, $deps, $group);
         } else {
             $registrations[] = array($name, $mtime, $deps, $group, $source);
         }
     }
     $out .= ResourceLoader::makeLoaderRegisterScript($registrations);
     wfProfileOut(__METHOD__);
     return $out;
 }
コード例 #4
0
 /**
  * Gets registration code for all modules
  *
  * @param $context ResourceLoaderContext object
  * @return String: JavaScript code for registering all modules with the client loader
  */
 public static function getModuleRegistrations(ResourceLoaderContext $context)
 {
     global $wgCacheEpoch;
     wfProfileIn(__METHOD__);
     $out = '';
     $registrations = array();
     $resourceLoader = $context->getResourceLoader();
     // Register sources
     $out .= $resourceLoader->makeLoaderSourcesScript($resourceLoader->getSources());
     // Register modules
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         // Support module loader scripts
         //die("get loader code@!");
         $loader = $module->getLoaderScript();
         if ($loader !== false) {
             $deps = $module->getDependencies();
             $group = $module->getGroup();
             $source = $module->getSource();
             $version = wfTimestamp(TS_ISO_8601_BASIC, $module->getModifiedTime($context));
             $out .= ResourceLoader::makeCustomLoaderScript($name, $version, $deps, $group, $source, $loader);
         } else {
             // 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 = $moduleMtime;
             // Modules without dependencies, a group or a foreign source pass two arguments (name, timestamp) to
             // mw.loader.register()
             if (!count($module->getDependencies() && $module->getGroup() === null && $module->getSource() === 'local')) {
                 $registrations[] = array($name, $mtime);
             } elseif ($module->getGroup() === null && $module->getSource() === 'local') {
                 $registrations[] = array($name, $mtime, $module->getDependencies());
             } elseif ($module->getSource() === 'local') {
                 $registrations[] = array($name, $mtime, $module->getDependencies(), $module->getGroup());
             } else {
                 $registrations[] = array($name, $mtime, $module->getDependencies(), $module->getGroup(), $module->getSource());
             }
         }
     }
     global $wgScriptCacheDirectory, $wgMwEmbedVersion;
     $cachePath = $wgScriptCacheDirectory . '/registrations.' . $wgMwEmbedVersion . $_GET['skin'] . $_GET['lang'] . '.min.json';
     @file_put_contents($cachePath, json_encode($registrations));
     $out .= ResourceLoader::makeLoaderRegisterScript($registrations);
     wfProfileOut(__METHOD__);
     return $out;
 }
コード例 #5
0
 /**
  * Get registration code for all modules.
  *
  * @param ResourceLoaderContext $context object
  * @return string JavaScript code for registering all modules with the client loader
  */
 public static function getModuleRegistrations(ResourceLoaderContext $context)
 {
     global $wgCacheEpoch;
     wfProfileIn(__METHOD__);
     $resourceLoader = $context->getResourceLoader();
     $target = $context->getRequest()->getVal('target', 'desktop');
     $out = '';
     $registryData = array();
     // Get registry data
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         $moduleTargets = $module->getTargets();
         if (!in_array($target, $moduleTargets)) {
             continue;
         }
         // 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));
         // FIXME: Convert to numbers, wfTimestamp always gives us stings, even for TS_UNIX
         $registryData[$name] = array('version' => $mtime, 'dependencies' => $module->getDependencies(), 'group' => $module->getGroup(), 'source' => $module->getSource(), 'loader' => $module->getLoaderScript());
     }
     // Register sources
     $out .= ResourceLoader::makeLoaderSourcesScript($resourceLoader->getSources());
     // Concatenate module loader scripts and figure out the different call
     // signatures for mw.loader.register
     $registrations = array();
     foreach ($registryData as $name => $data) {
         if ($data['loader'] !== false) {
             $out .= ResourceLoader::makeCustomLoaderScript($name, wfTimestamp(TS_ISO_8601_BASIC, $data['version']), $data['dependencies'], $data['group'], $data['source'], $data['loader']);
             continue;
         }
         if (!count($data['dependencies']) && $data['group'] === null && $data['source'] === 'local') {
             // Modules without dependencies, a group or a foreign source;
             // call mw.loader.register(name, timestamp)
             $registrations[] = array($name, $data['version']);
         } elseif ($data['group'] === null && $data['source'] === 'local') {
             // Modules with dependencies but no group or foreign source;
             // call mw.loader.register(name, timestamp, dependencies)
             $registrations[] = array($name, $data['version'], $data['dependencies']);
         } elseif ($data['source'] === 'local') {
             // Modules with a group but no foreign source;
             // call mw.loader.register(name, timestamp, dependencies, group)
             $registrations[] = array($name, $data['version'], $data['dependencies'], $data['group']);
         } else {
             // Modules with a foreign source;
             // call mw.loader.register(name, timestamp, dependencies, group, source)
             $registrations[] = array($name, $data['version'], $data['dependencies'], $data['group'], $data['source']);
         }
     }
     // Register modules
     $out .= ResourceLoader::makeLoaderRegisterScript($registrations);
     wfProfileOut(__METHOD__);
     return $out;
 }
コード例 #6
0
 /**
  * Get registration code for all modules.
  *
  * @param ResourceLoaderContext $context
  * @return string JavaScript code for registering all modules with the client loader
  */
 public function getModuleRegistrations(ResourceLoaderContext $context)
 {
     $resourceLoader = $context->getResourceLoader();
     $target = $context->getRequest()->getVal('target', 'desktop');
     // Bypass target filter if this request is from a unit test context. To prevent misuse in
     // production, this is only allowed if testing is enabled server-side.
     $byPassTargetFilter = $this->getConfig()->get('EnableJavaScriptTest') && $target === 'test';
     $out = '';
     $registryData = array();
     // Get registry data
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         $moduleTargets = $module->getTargets();
         if (!$byPassTargetFilter && !in_array($target, $moduleTargets)) {
             continue;
         }
         if ($module->isRaw()) {
             // Don't register "raw" modules (like 'jquery' and 'mediawiki') client-side because
             // depending on them is illegal anyway and would only lead to them being reloaded
             // causing any state to be lost (like jQuery plugins, mw.config etc.)
             continue;
         }
         $versionHash = $module->getVersionHash($context);
         if (strlen($versionHash) !== 8) {
             // Module implementation either broken or deviated from ResourceLoader::makeHash
             // Asserted by tests/phpunit/structure/ResourcesTest.
             $versionHash = ResourceLoader::makeHash($versionHash);
         }
         $skipFunction = $module->getSkipFunction();
         if ($skipFunction !== null && !ResourceLoader::inDebugMode()) {
             $skipFunction = $resourceLoader->filter('minify-js', $skipFunction, false);
         }
         $registryData[$name] = array('version' => $versionHash, 'dependencies' => $module->getDependencies($context), 'group' => $module->getGroup(), 'source' => $module->getSource(), 'loader' => $module->getLoaderScript(), 'skip' => $skipFunction);
     }
     self::compileUnresolvedDependencies($registryData);
     // Register sources
     $out .= ResourceLoader::makeLoaderSourcesScript($resourceLoader->getSources());
     // Concatenate module loader scripts and figure out the different call
     // signatures for mw.loader.register
     $registrations = array();
     foreach ($registryData as $name => $data) {
         if ($data['loader'] !== false) {
             $out .= ResourceLoader::makeCustomLoaderScript($name, $data['version'], $data['dependencies'], $data['group'], $data['source'], $data['loader']);
             continue;
         }
         // Call mw.loader.register(name, version, dependencies, group, source, skip)
         $registrations[] = array($name, $data['version'], $data['dependencies'], $data['group'], $data['source'] === 'local' ? null : $data['source'], $data['skip']);
     }
     // Register modules
     $out .= "\n" . ResourceLoader::makeLoaderRegisterScript($registrations);
     return $out;
 }
コード例 #7
0
 /**
  * Get registration code for all modules.
  *
  * @param ResourceLoaderContext $context
  * @return string JavaScript code for registering all modules with the client loader
  */
 public function getModuleRegistrations(ResourceLoaderContext $context)
 {
     wfProfileIn(__METHOD__);
     $resourceLoader = $context->getResourceLoader();
     $target = $context->getRequest()->getVal('target', 'desktop');
     $out = '';
     $registryData = array();
     // Get registry data
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         $moduleTargets = $module->getTargets();
         if (!in_array($target, $moduleTargets)) {
             continue;
         }
         if ($module->isRaw()) {
             // Don't register "raw" modules (like 'jquery' and 'mediawiki') client-side because
             // depending on them is illegal anyway and would only lead to them being reloaded
             // causing any state to be lost (like jQuery plugins, mw.config etc.)
             continue;
         }
         // 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, $this->getConfig()->get('CacheEpoch')));
         // FIXME: Convert to numbers, wfTimestamp always gives us stings, even for TS_UNIX
         $skipFunction = $module->getSkipFunction();
         if ($skipFunction !== null && !ResourceLoader::inDebugMode()) {
             $skipFunction = $resourceLoader->filter('minify-js', $skipFunction, false);
         }
         $registryData[$name] = array('version' => $mtime, 'dependencies' => $module->getDependencies(), 'group' => $module->getGroup(), 'source' => $module->getSource(), 'loader' => $module->getLoaderScript(), 'skip' => $skipFunction);
     }
     self::compileUnresolvedDependencies($registryData);
     // Register sources
     $out .= ResourceLoader::makeLoaderSourcesScript($resourceLoader->getSources());
     // Concatenate module loader scripts and figure out the different call
     // signatures for mw.loader.register
     $registrations = array();
     foreach ($registryData as $name => $data) {
         if ($data['loader'] !== false) {
             $out .= ResourceLoader::makeCustomLoaderScript($name, wfTimestamp(TS_ISO_8601_BASIC, $data['version']), $data['dependencies'], $data['group'], $data['source'], $data['loader']);
             continue;
         }
         if (!count($data['dependencies']) && $data['group'] === null && $data['source'] === 'local' && $data['skip'] === null) {
             // Modules with no dependencies, group, foreign source or skip function;
             // call mw.loader.register(name, timestamp)
             $registrations[] = array($name, $data['version']);
         } elseif ($data['group'] === null && $data['source'] === 'local' && $data['skip'] === null) {
             // Modules with dependencies but no group, foreign source or skip function;
             // call mw.loader.register(name, timestamp, dependencies)
             $registrations[] = array($name, $data['version'], $data['dependencies']);
         } elseif ($data['source'] === 'local' && $data['skip'] === null) {
             // Modules with a group but no foreign source or skip function;
             // call mw.loader.register(name, timestamp, dependencies, group)
             $registrations[] = array($name, $data['version'], $data['dependencies'], $data['group']);
         } elseif ($data['skip'] === null) {
             // Modules with a foreign source but no skip function;
             // call mw.loader.register(name, timestamp, dependencies, group, source)
             $registrations[] = array($name, $data['version'], $data['dependencies'], $data['group'], $data['source']);
         } else {
             // Modules with a skip function;
             // call mw.loader.register(name, timestamp, dependencies, group, source, skip)
             $registrations[] = array($name, $data['version'], $data['dependencies'], $data['group'], $data['source'], $data['skip']);
         }
     }
     // Register modules
     $out .= ResourceLoader::makeLoaderRegisterScript($registrations);
     wfProfileOut(__METHOD__);
     return $out;
 }
コード例 #8
0
 /**
  * Get registration code for all modules.
  *
  * @param ResourceLoaderContext $context
  * @return string JavaScript code for registering all modules with the client loader
  */
 public function getModuleRegistrations(ResourceLoaderContext $context)
 {
     $resourceLoader = $context->getResourceLoader();
     $target = $context->getRequest()->getVal('target', 'desktop');
     $out = '';
     $registryData = array();
     // Get registry data
     foreach ($resourceLoader->getModuleNames() as $name) {
         $module = $resourceLoader->getModule($name);
         $moduleTargets = $module->getTargets();
         if (!in_array($target, $moduleTargets)) {
             continue;
         }
         if ($module->isRaw()) {
             // Don't register "raw" modules (like 'jquery' and 'mediawiki') client-side because
             // depending on them is illegal anyway and would only lead to them being reloaded
             // causing any state to be lost (like jQuery plugins, mw.config etc.)
             continue;
         }
         // Coerce module timestamp to UNIX timestamp.
         // getModifiedTime() is supposed to return a UNIX timestamp, but custom implementations
         // might forget. TODO: Maybe emit warning?
         $moduleMtime = wfTimestamp(TS_UNIX, $module->getModifiedTime($context));
         $skipFunction = $module->getSkipFunction();
         if ($skipFunction !== null && !ResourceLoader::inDebugMode()) {
             $skipFunction = $resourceLoader->filter('minify-js', $skipFunction, false);
         }
         $mtime = max($moduleMtime, wfTimestamp(TS_UNIX, $this->getConfig()->get('CacheEpoch')));
         $registryData[$name] = array('version' => (int) $mtime, 'dependencies' => $module->getDependencies(), 'group' => $module->getGroup(), 'source' => $module->getSource(), 'loader' => $module->getLoaderScript(), 'skip' => $skipFunction);
     }
     self::compileUnresolvedDependencies($registryData);
     // Register sources
     $out .= ResourceLoader::makeLoaderSourcesScript($resourceLoader->getSources());
     // Concatenate module loader scripts and figure out the different call
     // signatures for mw.loader.register
     $registrations = array();
     foreach ($registryData as $name => $data) {
         if ($data['loader'] !== false) {
             $out .= ResourceLoader::makeCustomLoaderScript($name, $data['version'], $data['dependencies'], $data['group'], $data['source'], $data['loader']);
             continue;
         }
         // Call mw.loader.register(name, timestamp, dependencies, group, source, skip)
         $registrations[] = array($name, $data['version'], $data['dependencies'], $data['group'], $data['source'] === 'local' ? null : $data['source'], $data['skip']);
     }
     // Register modules
     $out .= ResourceLoader::makeLoaderRegisterScript($registrations);
     return $out;
 }