function __construct() { global $wgOut; parent::__construct('VenusTemplate', 'venus'); $wgOut->addModuleStyles('skins.venus'); $this->strictAssetUrlCheck = true; $this->pushRLModulesToBottom = true; }
function __construct() { parent::__construct( 'MonoBookTemplate', 'wikiaapp'); //non-strict checks of css/js/scss assets/packages $this->strictAssetUrlCheck = false; $this->mRenderColumnOne = false; $this->useHeadElement = true; }
private function setAssets($type = 'live') { global $wgOut; $jsHeadGroups = ['venus_head_js']; $jsHeadFiles = ''; $jsBodyGroups = ['venus_body_js']; $jsBodyFiles = ''; $cssGroups = ['venus_css']; $cssLinks = ''; if ($type == 'preview') { $cssGroups[] = 'article_scss'; $jsPreviewFiles = ''; foreach ($this->assetsManager->getURL(['venus_preview_js']) as $src) { $jsPreviewFiles .= "<script src='{$src}'></script>"; } $this->jsPreviewFiles = $jsPreviewFiles; } else { // let extensions manipulate the asset packages (e.g. ArticleComments, // this is done to cut down the number or requests) $this->app->runHook('VenusAssetsPackages', [&$jsHeadGroups, &$jsBodyGroups, &$cssGroups]); } // SASS files requested via VenusAssetsPackages hook $sassFiles = []; foreach ($this->assetsManager->getURL($cssGroups) as $src) { if ($this->assetsManager->checkAssetUrlForSkin($src, $this->skin)) { $sassFiles[] = $src; } } // try to fetch all SASS files using a single request (CON-1487) // "WikiaSkin::getStylesWithCombinedSASS: combined 9 SASS files" $cssLinks .= $this->skin->getStylesWithCombinedSASS($sassFiles); foreach ($this->assetsManager->getURL($jsHeadGroups) as $src) { if ($this->assetsManager->checkAssetUrlForSkin($src, $this->skin)) { $jsHeadFiles .= "<script src='{$src}'></script>"; } } // try to fetch all AM groups in a single JS request (CON-1772) // "WikiaSkin::getScriptsWithCombinedGroups: combined 8 JS groups" $jsBodyFiles = $this->skin->getScriptsWithCombinedGroups($jsBodyGroups); // global variables from ResourceLoaderStartUpModule $res = new ResourceVariablesGetter(); $vars = WikiaSkin::makeInlineVariablesScript($res->get()); // is it used anywhere? // set variables $this->cssLinks = $cssLinks; $this->jsBodyFiles = $jsBodyFiles; $this->jsHeadScripts = $wgOut->getHeadScripts() . $jsHeadFiles; }
function __construct() { parent::__construct( 'CampfireTemplate', 'campfire' ); //non-strict checks of css/js/scss assets/packages $this->strictAssetUrlCheck = false; global $IP, $wgAutoloadClasses, $wgExtensionMessagesFiles; $dir = dirname( __FILE__ ); $wgExtensionMessagesFiles['Campfire'] = $IP . '/extensions/wikia/Campfire/Campfire.i18n.php'; $wgAutoloadClasses['CampfireController'] = $dir . '/campfire/modules/CampfireController.class.php'; $wgAutoloadClasses['CampfireBodyController'] = $dir . '/campfire/modules/CampfireBodyController.class.php'; $wgAutoloadClasses['CampfireHeaderController'] = $dir . '/campfire/modules/CampfireHeaderController.class.php'; $wgAutoloadClasses['CampfireCategoriesController'] = $dir . '/campfire/modules/CampfireCategoriesController.class.php'; $wgAutoloadClasses['CampfireFooterController'] = $dir . '/campfire/modules/CampfireFooterController.class.php'; }
function getTopScripts($globalVariables = []) { $vars = []; $scripts = ''; $globalVariables['Wikia'] = new StdClass(); //this is run to grab all global variables wfRunHooks('WikiaSkinTopScripts', [&$vars, &$scripts, $this]); // load ResourceLoader modules that have a short caching time $scripts .= $this->renderTopShortTTLModules(); //send list of supported videos so we can treat not supported ones differently $globalVariables['supportedVideos'] = $this->wg->WikiaMobileSupportedVideos; //global variables //from Output class //and from ResourceLoaderStartUpModule $res = new ResourceVariablesGetter(); $vars = array_intersect_key($this->wg->Out->getJSVars() + $res->get() + $vars, array_flip($this->wg->WikiaMobileIncludeJSGlobals)); return WikiaSkin::makeInlineVariablesScript($vars + $globalVariables) . $scripts; }
/** * Oasis handles OutputPage::mScripts differently * so we don't want them to be duplicated * * @return string */ public function bottomScripts() { $bottomScripts = parent::bottomScripts(); $bottomScripts = str_replace($this->wg->out->getScriptsOnly(), '', $bottomScripts); return $bottomScripts; }
public function index() { $this->wf->profileIn(__METHOD__); $jsHeadPackages = array('wikiamobile_js_head'); $jsBodyPackages = array(); $scssPackages = array(); $cssLinks = ''; $jsBodyFiles = ''; $jsHeadFiles = ''; $styles = null; $scripts = null; $assetsManager = F::build('AssetsManager', array(), 'getInstance'); $advert = ''; F::build('JSMessages')->enqueuePackage('WkMbl', JSMessages::INLINE); $jsBodyPackages[] = 'wikiamobile_js_body_full'; $scssPackages[] = 'wikiamobile_scss'; $styles = $this->skin->getStyles(); $scripts = $this->skin->getScripts(); //show ads only for anon users if ($this->wg->user->isAnon()) { $jsBodyPackages[] = 'wikiamobile_js_ads'; $advert = $this->app->renderView('WikiaMobileAdService', 'index'); } $nav = $this->app->renderView('WikiaMobileNavigationService', 'index'); $pageContent = $this->app->renderView('WikiaMobileBodyService', 'index', array('bodyText' => $this->templateObject->get('bodytext'), 'categoryLinks' => $this->templateObject->get('catlinks'))); $footer = $this->app->renderView('WikiaMobileFooterService', 'index'); //let extensions manipulate the asset packages (e.g. ArticleComments, //this is done to cut down the number or requests) $this->app->runHook('WikiaMobileAssetsPackages', array(&$jsHeadPackages, &$jsBodyPackages, &$scssPackages)); if (is_array($scssPackages)) { //force main SCSS as first to make overriding it possible foreach ($assetsManager->getURL($scssPackages) as $s) { //packages/assets are enqueued via an hook, let's make sure we should actually let them through if ($assetsManager->checkAssetUrlForSkin($s, $this->skin)) { //W3C standard says type attribute and quotes (for single non-URI values) not needed, let's save on output size $cssLinks .= "<link rel=stylesheet href=\"" . $s . "\"/>"; } } } if (is_array($styles)) { foreach ($styles as $s) { //safe URL's as getStyles performs all the required checks //W3C standard says type attribute and quotes (for single non-URI values) not needed, let's save on output size $cssLinks .= "<link rel=stylesheet href=\"{$s['url']}\"/>"; //this is a strict skin, getStyles returns only elements with a set URL } } if (is_array($jsHeadPackages)) { //core JS in the head section, definitely safe foreach ($assetsManager->getURL($jsHeadPackages) as $src) { //HTML5 standard, no type attribute required == smaller output $jsHeadFiles .= "<script src=\"{$src}\"></script>"; } } if (is_array($jsBodyPackages)) { foreach ($assetsManager->getURL($jsBodyPackages) as $s) { //packages/assets are enqueued via an hook, let's make sure we should actually let them through if ($assetsManager->checkAssetUrlForSkin($s, $this->skin)) { //HTML5 standard, no type attribute required == smaller output $jsBodyFiles .= "<script src=\"{$s}\"></script>"; } } } if (is_array($scripts)) { foreach ($scripts as $s) { //safe URL's as getScripts performs all the required checks //HTML5 standard, no type attribute required == smaller output $jsBodyFiles .= "<script src=\"{$s['url']}\"></script>"; } } //Bottom Scripts //do not run this hook, all the functionalities hooking in this don't take into account the pecularity of the mobile skin //$this->wf->RunHooks( 'SkinAfterBottomScripts', array ( $this->wg->User->getSkin(), &$bottomscripts ) ); //AppCache will be disabled for the first several releases //$this->appCacheManifestPath = ( $this->wg->DevelEnvironment && !$this->wg->Request->getBool( 'appcache' ) ) ? null : self::CACHE_MANIFEST_PATH . "&{$this->wg->StyleVersion}"; $this->response->setVal('jsHeadFiles', $jsHeadFiles); $this->response->setVal('topScripts', $this->skin->getTopScripts()); $this->response->setVal('allowRobots', !$this->wg->DevelEnvironment); $this->response->setVal('cssLinks', $cssLinks); $this->response->setVal('mimeType', $this->templateObject->get('mimetype')); $this->response->setVal('charSet', $this->templateObject->get('charset')); $this->response->setVal('headItems', $this->skin->getHeadItems()); $this->response->setVal('languageCode', $this->templateObject->get('lang')); $this->response->setVal('languageDirection', $this->templateObject->get('dir')); $this->response->setVal('headLinks', $this->wg->Out->getHeadLinks()); $this->response->setVal('pageTitle', $this->wg->Out->getHTMLTitle()); $this->response->setVal('bodyClasses', array('wkMobile', $this->templateObject->get('pageclass'))); $this->response->setVal('jsBodyFiles', $jsBodyFiles); $this->response->setVal('advertisement', $advert); $this->response->setVal('wikiaNavigation', $nav); $this->response->setVal('pageContent', $pageContent); $this->response->setVal('wikiaFooter', $footer); //global variables //from Output class //and from ResourceLoaderStartUpModule $res = new ResourceVariablesGetter(); $vars = array_diff_key($this->wg->Out->getJSVars() + $res->get(), array_flip($this->wg->WikiaMobileExcludeJSGlobals)); $this->response->setVal('globalVariablesScript', WikiaSkin::makeInlineVariablesScript($vars)); //tracking $trackingCode = ''; if (!in_array($this->wg->Request->getVal('action'), array('edit', 'submit'))) { $trackingCode .= AnalyticsEngine::track('QuantServe', AnalyticsEngine::EVENT_PAGEVIEW, array(), array('extraLabels' => array('mobilebrowser'))) . AnalyticsEngine::track('Comscore', AnalyticsEngine::EVENT_PAGEVIEW); } //Stats for Gracenote reporting if ($this->wg->cityId == self::LYRICSWIKI_ID) { $trackingCode .= AnalyticsEngine::track('GA_Urchin', 'lyrics'); } $trackingCode .= AnalyticsEngine::track('GA_Urchin', AnalyticsEngine::EVENT_PAGEVIEW) . AnalyticsEngine::track('GA_Urchin', 'onewiki', array($this->wg->cityId)) . AnalyticsEngine::track('GA_Urchin', 'pagetime', array('wikiamobile')) . AnalyticsEngine::track('GA_Urchin', 'varnish-stat') . AnalyticsEngine::track('GAS', 'usertiming'); $this->response->setVal('trackingCode', $trackingCode); $this->wf->profileOut(__METHOD__); }
function __construct() { parent::__construct( 'WikiaMobileTemplate', 'wikiamobile' ); }
public function bottomScripts() { $analytics = $this->getAnalyticsCode(); $bottomScriptText = parent::bottomScripts(); $html = <<<HTML <!-- WikiaBottomScripts --> {$bottomScriptText} <!-- /WikiaBottomScripts --> {$analytics} <div id="positioned_elements"></div> HTML; return $html; }
/** * function returns globals needed for an Article */ public function getGlobals() { $wg = F::app()->wg; $skin = Skin::newFromKey('wikiamobile'); //global variables //from Output class //and from ResourceLoaderStartUpModule $res = new ResourceVariablesGetter(); $vars = array_intersect_key($wg->Out->getJSVars() + $res->get(), array_flip($wg->GameGuidesGlobalsWhiteList)); $this->setVal('globals', WikiaSkin::makeInlineVariablesScript($vars) . $skin->getTopScripts()); }
/** * Checks if an URL produced by any of the AssetsManager::getGroup*Url() methods is associated to a package registered for a specific skin * This method is used to filter our unwanted assets when outputting references in skin logic (e.g. in the WikiaMobile skin) * * @author Federico "Lox" Lucignano <federico(at)wikia-inc.com> * * @param string $url the url to get the package config for * @param WikiaSkin $skin the skin instance * * @throws WikiaException * * @return bool wether the package has been registered for the specified skin or not */ public function checkAssetUrlForSkin($url, WikiaSkin $skin) { wfProfileIn(__METHOD__); //lazy loading of AssetsConfig $this->loadConfig(); $group = null; $skinName = $skin->getSkinName(); $strict = $skin->isStrict(); if (is_string($url) && array_key_exists($url, $this->mGeneratedUrls)) { $group = $this->mGeneratedUrls[$url]; } else { /** * One of the following scenarios: * - the url passed in is not a string * - the package has not been processed by any of the getGroup*Url methods so far * - this is a URL of a single asset generated by one of the getOne*Url methods * - this is an hardcoded URL passed directly to e.g. OutputPage::addScript * * If we're in strict mode then return false, the asset should be registered for $skin in config.php and * it should have been generated by getGroup*Url if the developer knew what he was trying to do. * * If we're in non-strict mode then return true as assets not bound to a skin are allowed anyways */ wfProfileOut(__METHOD__); return !$strict; } $registeredSkin = $this->mAssetsConfig->getGroupSkin($group); $check = is_array($registeredSkin) ? in_array($skinName, $registeredSkin) : $skinName === $registeredSkin; //if not strict packages with no skin registered are positive if ($strict === false) { $check = $check || empty($registeredSkin); } wfProfileOut(__METHOD__); return $check; }
/** * Checks if an URL produced by any of the AssetsManager::getGroup*Url() methods is associated to a package registered for a specific skin * This method is used to filter our unwanted assets when outputting references in skin logic (e.g. in the WikiaMobile skin) * * @author Federico "Lox" Lucignano <federico(at)wikia-inc.com> * * @param string $url the url to get the package config for * @param WikiaSkin $skin the skin instance * * @throws WikiaException * * @return bool wether the package has been registered for the specified skin or not */ public function checkAssetUrlForSkin($url, WikiaSkin $skin) { wfProfileIn(__METHOD__); // ResourceLoader has its own skin filtering mechanism, skip the check for /__load/ URLs - CON-2113 if (strpos($url, '/__load/') !== false) { wfProfileOut(__METHOD__); return true; } //lazy loading of AssetsConfig $this->loadConfig(); $group = null; $strict = $skin->isStrict(); if (is_string($url) && array_key_exists($url, $this->mGeneratedUrls)) { $group = $this->mGeneratedUrls[$url]; } else { /** * One of the following scenarios: * - the url passed in is not a string * - the package has not been processed by any of the getGroup*Url methods so far * - this is a URL of a single asset generated by one of the getOne*Url methods * - this is an hardcoded URL passed directly to e.g. OutputPage::addScript * * If we're in strict mode then return false, the asset should be registered for $skin in config.php and * it should have been generated by getGroup*Url if the developer knew what he was trying to do. * * If we're in non-strict mode then return true as assets not bound to a skin are allowed anyways */ wfProfileOut(__METHOD__); return !$strict; } $check = $this->checkIfGroupForSkin($group, $skin); wfProfileOut(__METHOD__); return $check; }