/** * @param $context ResourceLoaderContext * @return array */ protected function getPages(ResourceLoaderContext $context) { $username = $context->getUser(); if ($username === null) { return array(); } // Get the normalized title of the user's user page $userpageTitle = Title::makeTitleSafe(NS_USER, $username); if (!$userpageTitle instanceof Title) { return array(); } $userpage = $userpageTitle->getPrefixedDBkey(); // Needed so $excludepages works $pages = array("{$userpage}/common.js" => array('type' => 'script'), "{$userpage}/" . $context->getSkin() . '.js' => array('type' => 'script'), "{$userpage}/common.css" => array('type' => 'style'), "{$userpage}/" . $context->getSkin() . '.css' => array('type' => 'style')); // Hack for bug 26283: if we're on a preview page for a CSS/JS page, // we need to exclude that page from this module. In that case, the excludepage // parameter will be set to the name of the page we need to exclude. $excludepage = $context->getRequest()->getVal('excludepage'); if (isset($pages[$excludepage])) { // This works because $excludepage is generated with getPrefixedDBkey(), // just like the keys in $pages[] above unset($pages[$excludepage]); } return $pages; }
/** * Get list of pages used by this module * * @param ResourceLoaderContext $context * @return array List of pages */ protected function getPages(ResourceLoaderContext $context) { $allowUserJs = $this->getConfig()->get('AllowUserJs'); $allowUserCss = $this->getConfig()->get('AllowUserCss'); if (!$allowUserJs && !$allowUserCss) { return array(); } $user = $context->getUserObj(); if (!$user || $user->isAnon()) { return array(); } // Needed so $excludepages works $userPage = $user->getUserPage()->getPrefixedDBkey(); $pages = array(); if ($allowUserJs) { $pages["{$userPage}/common.js"] = array('type' => 'script'); $pages["{$userPage}/" . $context->getSkin() . '.js'] = array('type' => 'script'); } if ($allowUserCss) { $pages["{$userPage}/common.css"] = array('type' => 'style'); $pages["{$userPage}/" . $context->getSkin() . '.css'] = array('type' => 'style'); } // Hack for bug 26283: if we're on a preview page for a CSS/JS page, // we need to exclude that page from this module. In that case, the excludepage // parameter will be set to the name of the page we need to exclude. $excludepage = $context->getRequest()->getVal('excludepage'); if (isset($pages[$excludepage])) { // This works because $excludepage is generated with getPrefixedDBkey(), // just like the keys in $pages[] above unset($pages[$excludepage]); } return $pages; }
protected function getPages(ResourceLoaderContext $context) { if ($context->getUser()) { $username = $context->getUser(); return array("User:{$username}/common.js" => array('type' => 'script'), "User:{$username}/" . $context->getSkin() . '.js' => array('type' => 'script'), "User:{$username}/common.css" => array('type' => 'style'), "User:{$username}/" . $context->getSkin() . '.css' => array('type' => 'style')); } return array(); }
/** * Gets list of pages used by this module * * @param $context ResourceLoaderContext * * @return Array: List of pages */ protected function getPages(ResourceLoaderContext $context) { global $wgHandheldStyle; $pages = array('MediaWiki:Common.js' => array('type' => 'script'), 'MediaWiki:Common.css' => array('type' => 'style'), 'MediaWiki:' . ucfirst($context->getSkin()) . '.js' => array('type' => 'script'), 'MediaWiki:' . ucfirst($context->getSkin()) . '.css' => array('type' => 'style'), 'MediaWiki:Print.css' => array('type' => 'style', 'media' => 'print')); if ($wgHandheldStyle) { $pages['MediaWiki:Handheld.css'] = array('type' => 'style', 'media' => 'handheld'); } return $pages; }
/** * Get list of pages used by this module * * @param ResourceLoaderContext $context * @return array List of pages */ protected function getPages(ResourceLoaderContext $context) { $pages = array(); if ($this->getConfig()->get('UseSiteJs')) { $pages['MediaWiki:Common.js'] = array('type' => 'script'); $pages['MediaWiki:' . ucfirst($context->getSkin()) . '.js'] = array('type' => 'script'); } if ($this->getConfig()->get('UseSiteCss')) { $pages['MediaWiki:Common.css'] = array('type' => 'style'); $pages['MediaWiki:' . ucfirst($context->getSkin()) . '.css'] = array('type' => 'style'); $pages['MediaWiki:Print.css'] = array('type' => 'style', 'media' => 'print'); } return $pages; }
/** * Gets list of pages used by this module * * @param $context ResourceLoaderContext * * @return Array: List of pages */ protected function getPages(ResourceLoaderContext $context) { global $wgUseSiteJs, $wgUseSiteCss; $pages = array(); if ($wgUseSiteJs) { $pages['MediaWiki:Common.js'] = array('type' => 'script'); $pages['MediaWiki:' . ucfirst($context->getSkin()) . '.js'] = array('type' => 'script'); } if ($wgUseSiteCss) { $pages['MediaWiki:Common.css'] = array('type' => 'style'); $pages['MediaWiki:' . ucfirst($context->getSkin()) . '.css'] = array('type' => 'style'); } $pages['MediaWiki:Print.css'] = array('type' => 'style', 'media' => 'print'); return $pages; }
/** * @param ResourceLoaderContext $context * @return array */ protected function getConfigSettings($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgContLang; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } $conf = $this->getConfig(); // Build list of variables $vars = array('wgLoadScript' => wfScript('load'), 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $conf->get('StylePath'), 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $conf->get('ArticlePath'), 'wgScriptPath' => $conf->get('ScriptPath'), 'wgScriptExtension' => $conf->get('ScriptExtension'), 'wgScript' => wfScript(), 'wgSearchType' => $conf->get('SearchType'), 'wgVariantArticlePath' => $conf->get('VariantArticlePath'), 'wgActionPaths' => (object) $conf->get('ActionPaths'), 'wgServer' => $conf->get('Server'), 'wgServerName' => $conf->get('ServerName'), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgTranslateNumerals' => $conf->get('TranslateNumerals'), 'wgVersion' => $conf->get('Version'), 'wgEnableAPI' => $conf->get('EnableAPI'), 'wgEnableWriteAPI' => $conf->get('EnableWriteAPI'), 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $conf->get('Sitename'), 'wgDBname' => $conf->get('DBname'), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $conf->get('ExtensionAssetsPath'), 'wgCookiePrefix' => $conf->get('CookiePrefix'), 'wgCookieDomain' => $conf->get('CookieDomain'), 'wgCookiePath' => $conf->get('CookiePath'), 'wgCookieExpiration' => $conf->get('CookieExpiration'), 'wgResourceLoaderMaxQueryLength' => $conf->get('ResourceLoaderMaxQueryLength'), 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $conf->get('ResourceLoaderStorageVersion'), 'wgResourceLoaderStorageEnabled' => $conf->get('ResourceLoaderStorageEnabled')); Hooks::run('ResourceLoaderGetConfigVars', array(&$vars)); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
public function getSkin() { if ($this->skin === self::INHERIT_VALUE) { return $this->context->getSkin(); } return $this->skin; }
/** * @param ResourceLoaderContext $context * @return array */ protected function getConfig($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength, $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion, $wgSearchType; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } // Build list of variables $vars = array('wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgSearchType' => $wgSearchType, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values(array_unique($wgFileExtensions)), 'wgDBname' => $wgDBname, 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $wgResourceLoaderStorageVersion, 'wgResourceLoaderStorageEnabled' => $wgResourceLoaderStorageEnabled); wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars)); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
/** * @param ResourceLoaderContext $context * @return array List of pages */ protected function getPages(ResourceLoaderContext $context) { $config = $this->getConfig(); $user = $context->getUserObj(); if ($user->isAnon()) { return []; } // Use localised/normalised variant to ensure $excludepage matches $userPage = $user->getUserPage()->getPrefixedDBkey(); $pages = []; if ($config->get('AllowUserCss')) { $pages["{$userPage}/common.css"] = ['type' => 'style']; $pages["{$userPage}/" . $context->getSkin() . '.css'] = ['type' => 'style']; } // User group pages are maintained site-wide and enabled with site JS/CSS. if ($config->get('UseSiteCss')) { foreach ($user->getEffectiveGroups() as $group) { if ($group == '*') { continue; } $pages["MediaWiki:Group-{$group}.css"] = ['type' => 'style']; } } // Hack for T28283: Allow excluding pages for preview on a CSS/JS page. // The excludepage parameter is set by OutputPage. $excludepage = $context->getRequest()->getVal('excludepage'); if (isset($pages[$excludepage])) { unset($pages[$excludepage]); } return $pages; }
public function getSkin() { if (!is_null($this->skin)) { return $this->skin; } else { return $this->context->getSkin(); } }
/** * Get list of pages used by this module * * @param ResourceLoaderContext $context * @return array List of pages */ protected function getPages(ResourceLoaderContext $context) { $config = $this->getConfig(); $user = $context->getUserObj(); if ($user->isAnon()) { return []; } // Use localised/normalised variant to ensure $excludepage matches $userPage = $user->getUserPage()->getPrefixedDBkey(); $pages = []; if ($config->get('AllowUserJs')) { $pages["{$userPage}/common.js"] = ['type' => 'script']; $pages["{$userPage}/" . $context->getSkin() . '.js'] = ['type' => 'script']; } if ($config->get('AllowUserCss')) { $pages["{$userPage}/common.css"] = ['type' => 'style']; $pages["{$userPage}/" . $context->getSkin() . '.css'] = ['type' => 'style']; } $useSiteJs = $config->get('UseSiteJs'); $useSiteCss = $config->get('UseSiteCss'); // User group pages are maintained site-wide and enabled with site JS/CSS. if ($useSiteJs || $useSiteCss) { foreach ($user->getEffectiveGroups() as $group) { if ($group == '*') { continue; } if ($useSiteJs) { $pages["MediaWiki:Group-{$group}.js"] = ['type' => 'script']; } if ($useSiteCss) { $pages["MediaWiki:Group-{$group}.css"] = ['type' => 'style']; } } } // Hack for bug 26283: if we're on a preview page for a CSS/JS page, // we need to exclude that page from this module. In that case, the excludepage // parameter will be set to the name of the page we need to exclude. $excludepage = $context->getRequest()->getVal('excludepage'); if (isset($pages[$excludepage])) { // This works because $excludepage is generated with getPrefixedDBkey(), // just like the keys in $pages[] above unset($pages[$excludepage]); } return $pages; }
/** * Get list of pages used by this module * * @param ResourceLoaderContext $context * @return array List of pages */ protected function getPages(ResourceLoaderContext $context) { $pages = []; if ($this->getConfig()->get('UseSiteJs')) { $pages['MediaWiki:Common.js'] = ['type' => 'script']; $pages['MediaWiki:' . ucfirst($context->getSkin()) . '.js'] = ['type' => 'script']; } return $pages; }
/** * Load information stored in the database about modules. * * This method grabs modules dependencies from the database and updates modules * objects. * * This is not inside the module code because it is much faster to * request all of the information at once than it is to have each module * requests its own information. This sacrifice of modularity yields a substantial * performance improvement. * * @param array $modules List of module names to preload information for * @param ResourceLoaderContext $context Context to load the information within */ public function preloadModuleInfo(array $modules, ResourceLoaderContext $context) { if (!count($modules)) { // Or else Database*::select() will explode, plus it's cheaper! return; } $dbr = wfGetDB(DB_SLAVE); $skin = $context->getSkin(); $lang = $context->getLanguage(); // Get file dependency information $res = $dbr->select('module_deps', array('md_module', 'md_deps'), array('md_module' => $modules, 'md_skin' => $skin), __METHOD__); // Set modules' dependencies $modulesWithDeps = array(); foreach ($res as $row) { $module = $this->getModule($row->md_module); if ($module) { $module->setFileDependencies($skin, FormatJson::decode($row->md_deps, true)); $modulesWithDeps[] = $row->md_module; } } // Register the absence of a dependency row too foreach (array_diff($modules, $modulesWithDeps) as $name) { $module = $this->getModule($name); if ($module) { $this->getModule($name)->setFileDependencies($skin, array()); } } // Get message blob mtimes. Only do this for modules with messages $modulesWithMessages = array(); foreach ($modules as $name) { $module = $this->getModule($name); if ($module && count($module->getMessages())) { $modulesWithMessages[] = $name; } } $modulesWithoutMessages = array_flip($modules); // Will be trimmed down by the loop below if (count($modulesWithMessages)) { $res = $dbr->select('msg_resource', array('mr_resource', 'mr_timestamp'), array('mr_resource' => $modulesWithMessages, 'mr_lang' => $lang), __METHOD__); foreach ($res as $row) { $module = $this->getModule($row->mr_resource); if ($module) { $module->setMsgBlobMtime($lang, wfTimestamp(TS_UNIX, $row->mr_timestamp)); unset($modulesWithoutMessages[$row->mr_resource]); } } } foreach (array_keys($modulesWithoutMessages) as $name) { $module = $this->getModule($name); if ($module) { $module->setMsgBlobMtime($lang, 0); } } }
public function testTypicalRequest() { $ctx = new ResourceLoaderContext($this->getResourceLoader(), new FauxRequest(['debug' => 'false', 'lang' => 'zh', 'modules' => 'foo|foo.quux,baz,bar|baz.quux', 'only' => 'styles', 'skin' => 'fallback'])); // Request parameters $this->assertEquals($ctx->getModules(), ['foo', 'foo.quux', 'foo.baz', 'foo.bar', 'baz.quux']); $this->assertEquals(false, $ctx->getDebug()); $this->assertEquals('zh', $ctx->getLanguage()); $this->assertEquals('styles', $ctx->getOnly()); $this->assertEquals('fallback', $ctx->getSkin()); $this->assertEquals(null, $ctx->getUser()); // Misc $this->assertEquals('ltr', $ctx->getDirection()); $this->assertEquals('zh|fallback|||styles|||||', $ctx->getHash()); }
/** * @param ResourceLoaderContext $context * @return array */ protected function getConfigSettings($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgContLang; $conf = $this->getConfig(); // We can't use Title::newMainPage() if 'mainpage' is in // $wgForceUIMsgAsContentMsg because that will try to use the session // user's language and we have no session user. This does the // equivalent but falling back to our ResourceLoaderContext language // instead. $mainPage = Title::newFromText($context->msg('mainpage')->inContentLanguage()->text()); if (!$mainPage) { $mainPage = Title::newFromText('Main Page'); } /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = []; foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } $illegalFileChars = $conf->get('IllegalFileChars'); // Build list of variables $vars = ['wgLoadScript' => wfScript('load'), 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $conf->get('StylePath'), 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $conf->get('ArticlePath'), 'wgScriptPath' => $conf->get('ScriptPath'), 'wgScriptExtension' => '.php', 'wgScript' => wfScript(), 'wgSearchType' => $conf->get('SearchType'), 'wgVariantArticlePath' => $conf->get('VariantArticlePath'), 'wgActionPaths' => (object) $conf->get('ActionPaths'), 'wgServer' => $conf->get('Server'), 'wgServerName' => $conf->get('ServerName'), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgTranslateNumerals' => $conf->get('TranslateNumerals'), 'wgVersion' => $conf->get('Version'), 'wgEnableAPI' => $conf->get('EnableAPI'), 'wgEnableWriteAPI' => $conf->get('EnableWriteAPI'), 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $conf->get('Sitename'), 'wgDBname' => $conf->get('DBname'), 'wgExtraSignatureNamespaces' => $conf->get('ExtraSignatureNamespaces'), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $conf->get('ExtensionAssetsPath'), 'wgCookiePrefix' => $conf->get('CookiePrefix'), 'wgCookieDomain' => $conf->get('CookieDomain'), 'wgCookiePath' => $conf->get('CookiePath'), 'wgCookieExpiration' => $conf->get('CookieExpiration'), 'wgResourceLoaderMaxQueryLength' => $conf->get('ResourceLoaderMaxQueryLength'), 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgIllegalFileChars' => Title::convertByteClassToUnicodeClass($illegalFileChars), 'wgResourceLoaderStorageVersion' => $conf->get('ResourceLoaderStorageVersion'), 'wgResourceLoaderStorageEnabled' => $conf->get('ResourceLoaderStorageEnabled'), 'wgResourceLoaderLegacyModules' => self::getLegacyModules(), 'wgForeignUploadTargets' => $conf->get('ForeignUploadTargets'), 'wgEnableUploads' => $conf->get('EnableUploads')]; Hooks::run('ResourceLoaderGetConfigVars', [&$vars]); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
/** * Get list of variants in this module that are 'global', i.e., available * for every image regardless of image options. * @param ResourceLoaderContext $context * @return string[] */ public function getGlobalVariants(ResourceLoaderContext $context) { $skin = $context->getSkin(); if (!isset($this->globalVariants)) { $this->loadFromDefinition(); $this->globalVariants = []; } if (!isset($this->globalVariants[$skin])) { $this->globalVariants[$skin] = []; if (!isset($this->variants[$skin])) { $this->variants[$skin] = isset($this->variants['default']) ? $this->variants['default'] : []; } foreach ($this->variants[$skin] as $name => $config) { if (isset($config['global']) && $config['global']) { $this->globalVariants[$skin][] = $name; } } } return $this->globalVariants[$skin]; }
/** * Gets a list of file paths for all styles in this module, in order of propper inclusion. * * @param $context ResourceLoaderContext: Context * @return Array: List of file paths */ protected function getStyleFiles(ResourceLoaderContext $context) { return array_merge_recursive(self::collateFilePathListByOption($this->styles, 'media', 'all'), self::collateFilePathListByOption(self::tryForKey($this->skinStyles, $context->getSkin(), 'default'), 'media', 'all')); }
/** * 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 $context ResourceLoaderContext: Context object * @return Array: array( mediaType => array( URL1, URL2, ... ), ... ) */ public function getStyleURLsForDebug(ResourceLoaderContext $context) { global $wgLoadScript; // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink() $query = array('modules' => $this->getName(), 'only' => 'styles', 'skin' => $context->getSkin(), 'user' => $context->getUser(), 'debug' => 'true', 'version' => $context->getVersion()); ksort($query); return array('all' => array(wfAppendQuery($wgLoadScript, $query) . '&*')); }
/** * 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(); $moduleNames = self::getStartupModules(); $query = ['modules' => ResourceLoader::makePackedModulesString($moduleNames), 'only' => 'scripts', 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', 'version' => $rl->getCombinedVersion($context, $moduleNames)]; // Ensure uniform query order ksort($query); return wfAppendQuery(wfScript('load'), $query); }
public function getScript(ResourceLoaderContext $context) { global $IP, $wgLoadScript; $out = file_get_contents("{$IP}/resources/startup.js"); if ($context->getOnly() === 'scripts') { // Build load query for jquery and mediawiki modules $query = array('modules' => implode('|', array('jquery', 'mediawiki')), 'only' => 'scripts', 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', 'version' => wfTimestamp(TS_ISO_8601_BASIC, round(max($context->getResourceLoader()->getModule('jquery')->getModifiedTime($context), $context->getResourceLoader()->getModule('mediawiki')->getModifiedTime($context)), -2))); // Ensure uniform query order ksort($query); // Startup function $configuration = $this->getConfig($context); $registrations = self::getModuleRegistrations($context); $out .= "var startUp = function() {\n" . "\t{$registrations}\n" . "\t" . Xml::encodeJsCall('mediaWiki.config.set', array($configuration)) . "};\n"; // Conditional script injection $scriptTag = Html::linkedScript($wgLoadScript . '?' . wfArrayToCGI($query)); $out .= "if ( isCompatible() ) {\n" . "\t" . Xml::encodeJsCall('document.write', array($scriptTag)) . "}\n" . "delete isCompatible;"; } return $out; }
/** * Set in-object cache for file dependencies. * * This is used to retrieve data in batches. See ResourceLoader::preloadModuleInfo(). * To save the data, use saveFileDependencies(). * * @param string $skin Skin name * @param array $deps Array of file names */ public function setFileDependencies(ResourceLoaderContext $context, $files) { $vary = $context->getSkin() . '|' . $context->getLanguage(); $this->fileDeps[$vary] = $files; }
/** * 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 $context ResourceLoaderContext: Context object * @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, 'styles', $context->getRequest()->getBool('printable'), $context->getRequest()->getBool('handheld')); return array('all' => array($url)); }
/** * @static * @param $module * @param ResourceLoaderContext $context * @param $userpage * @param $pages * @return bool */ public static function onResourceLoaderUserModuleGetPages($module, $context, $userpage, &$pages) { global $wgResourceLoaderAssetsSkinMapping; // handle skin name changes $skinName = $context->getSkin(); if (isset($wgResourceLoaderAssetsSkinMapping[$skinName])) { $mappedName = $wgResourceLoaderAssetsSkinMapping[$skinName]; $mapping = array("{$userpage}/" . $skinName . '.js' => "{$userpage}/" . $mappedName . '.js', "{$userpage}/" . $skinName . '.css' => "{$userpage}/" . $mappedName . '.css'); $pages = Wikia::renameArrayKeys($pages, $mapping); } // todo: add user-defined user scripts here return true; }
/** * Helper for createLoaderURL() * * @since 1.24 * @see makeLoaderQuery * @param ResourceLoaderContext $context * @param array $extraQuery * @return array */ public static function createLoaderQuery(ResourceLoaderContext $context, $extraQuery = array()) { return self::makeLoaderQuery($context->getModules(), $context->getLanguage(), $context->getSkin(), $context->getUser(), $context->getVersion(), $context->getDebug(), $context->getOnly(), $context->getRequest()->getBool('printable'), $context->getRequest()->getBool('handheld'), $extraQuery); }
/** * Get the last modified timestamp of this module. * * Last modified timestamps are calculated from the highest last modified * timestamp of this module's constituent files as well as the files it * depends on. This function is context-sensitive, only performing * calculations on files relevant to the given language, skin and debug * mode. * * @param $context ResourceLoaderContext: Context in which to calculate * the modified time * @return Integer: UNIX timestamp * @see ResourceLoaderModule::getFileDependencies */ public function getModifiedTime(ResourceLoaderContext $context) { if (isset($this->modifiedTime[$context->getHash()])) { return $this->modifiedTime[$context->getHash()]; } wfProfileIn(__METHOD__); $files = array(); // Flatten style files into $files $styles = self::collateFilePathListByOption($this->styles, 'media', 'all'); foreach ($styles as $styleFiles) { $files = array_merge($files, $styleFiles); } $skinFiles = self::tryForKey(self::collateFilePathListByOption($this->skinStyles, 'media', 'all'), $context->getSkin(), 'default'); foreach ($skinFiles as $styleFiles) { $files = array_merge($files, $styleFiles); } // Final merge, this should result in a master list of dependent files $files = array_merge($files, $this->scripts, $context->getDebug() ? $this->debugScripts : array(), self::tryForKey($this->languageScripts, $context->getLanguage()), self::tryForKey($this->skinScripts, $context->getSkin(), 'default'), $this->loaderScripts); $files = array_map(array($this, 'getLocalPath'), $files); // File deps need to be treated separately because they're already prefixed $files = array_merge($files, $this->getFileDependencies($context->getSkin())); // If a module is nothing but a list of dependencies, we need to avoid // giving max() an empty array if (count($files) === 0) { wfProfileOut(__METHOD__); return $this->modifiedTime[$context->getHash()] = 1; } wfProfileIn(__METHOD__ . '-filemtime'); $filesMtime = max(array_map('filemtime', $files)); wfProfileOut(__METHOD__ . '-filemtime'); $this->modifiedTime[$context->getHash()] = max($filesMtime, $this->getMsgBlobMtime($context->getLanguage())); wfProfileOut(__METHOD__); return $this->modifiedTime[$context->getHash()]; }