/** * 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; }
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; }
* (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file * @author Roan Kattouw * @author Trevor Parscal * * modified for mwEmbed Resource Loader requirements by: * @author Michael Dale * */ require_once dirname(__FILE__) . '/includes/MwEmbedWebStartSetup.php'; // Respond to resource loading request $resourceLoader = new MwEmbedResourceLoader(); $output = $resourceLoader->respond(new MwEmbedResourceLoaderContext($resourceLoader, $wgRequest)); /* * For profile info: */ /* arsort( $wgSimpleProfile ); print_r( $wgSimpleProfile ); */