function outputInlineScript($moduleList) { $o = ""; $modules = array(); $resolvedModuleDependencyList = $this->getModuleDependencyList($moduleList); // "Fake" the request headers as ResourceLoaderContext derives it's data for module resolving from them $_GET['only'] = NULL; $_GET['modules'] = ResourceLoader::makePackedModulesString($resolvedModuleDependencyList); $fauxRequest = new WebRequest(); $resourceLoader = new MwEmbedResourceLoader(); foreach ($resolvedModuleDependencyList as $moduleName) { $modules[$moduleName] = $resourceLoader->getModule($moduleName); } $s = $resourceLoader->makeModuleResponse(new MwEmbedResourceLoaderContext($resourceLoader, $fauxRequest), $modules, array()); $o .= 'window.inlineScript = true;'; $o .= $s; $o .= ResourceLoader::makeLoaderStateScript(array_fill_keys($resolvedModuleDependencyList, 'ready')); return $o; }
/** * Get the mwEmbed Startup script as inline js */ private function getMwEmbedStartInline() { global $wgEnableScriptDebug, $wgScriptCacheDirectory, $wgMwEmbedVersion, $wgResourceLoaderMinifierStatementsOnOwnLine, $wgDefaultSkin, $wgHTTPProtocol; // set request param $_GET['modules'] = 'startup'; $_GET['only'] = 'scripts'; // check if we are overriding the skin: $_GET['skin'] = $wgDefaultSkin; if ($this->getCustomSkinUrl()) { $_GET['skin'] = 'custom'; } // check for language key: $_GET['lang'] = $this->getLangKey(); // include skin and language in cache path, as a custom param needed for startup $cachePath = $wgScriptCacheDirectory . '/startup.' . $wgMwEmbedVersion . $_GET['skin'] . $_GET['lang'] . $wgHTTPProtocol . '.' . $_SERVER['SERVER_NAME'] . '.min.js'; // check for cached startup: if (!$wgEnableScriptDebug) { if (is_file($cachePath)) { return file_get_contents($cachePath); } } $fauxRequest = new WebRequest(); $resourceLoader = new MwEmbedResourceLoader(); $modules = array(); $modules['startup'] = $resourceLoader->getModule('startup'); $s = $resourceLoader->makeModuleResponse(new MwEmbedResourceLoaderContext($resourceLoader, $fauxRequest), $modules, array()); // check if we should minify and cache: if (!$wgEnableScriptDebug) { $s = JavaScriptMinifier::minify($s, $wgResourceLoaderMinifierStatementsOnOwnLine); // try to store the cached file: @file_put_contents($cachePath, $s); } return $s; }
private function getMwEmbedStartInline() { global $wgEnableScriptDebug, $wgScriptCacheDirectory, $wgMwEmbedVersion, $wgResourceLoaderMinifierStatementsOnOwnLine; $cachePath = $wgScriptCacheDirectory . '/startup.' . $wgMwEmbedVersion . '.min.js'; // startup module is not compressed by default: if (!$wgEnableScriptDebug) { // check for cached version: if (is_file($cachePath)) { return file_get_contents($cachePath); } } // set request param $_GET['modules'] = 'startup'; $_GET['only'] = 'scripts'; $fauxRequest = new WebRequest(); $resourceLoader = new MwEmbedResourceLoader(); $modules = array(); $modules['startup'] = $resourceLoader->getModule('startup'); $s = $resourceLoader->makeModuleResponse(new MwEmbedResourceLoaderContext($resourceLoader, $fauxRequest), $modules, array()); // check if we should minify and cache: if (!$wgEnableScriptDebug) { $s = JavaScriptMinifier::minify($s, $wgResourceLoaderMinifierStatementsOnOwnLine); // try to store the cached file: @file_put_contents($cachePath, $s); } return $s; }