/** * Business-logic for determining if the javascript should be at the bottom of the page (it usually should be * at the bottom for performance reasons, but there are some exceptions for engineering reasons). * * TODO: make sure JavaScripts can be always loaded on bottom * * Note: NS_FILE pages need JS at top because AnyClips relies on jQuery. */ public static function JsAtBottom() { global $wgTitle; // decide where JS should be placed (only add JS at the top for non-search Special and edit pages) if (WikiaPageType::isSearch() || WikiaPageType::isForum()) { // Remove this whole condition when AdDriver2.js is fully implemented and deployed $jsAtBottom = true; // Liftium.js (part of AssetsManager) must be loaded after LiftiumOptions variable is set in page source } elseif ($wgTitle->getNamespace() == NS_SPECIAL || BodyController::isEditPage()) { $jsAtBottom = false; } else { $jsAtBottom = true; } return $jsAtBottom; }
public function onBeforePageDisplay(OutputPage $out, $skin) { wfProfileIn(__METHOD__); // don't load it on edit pages (perf improvement) if (F::app()->checkSkin('oasis', $skin) && !BodyController::isEditPage()) { $assetsManager = F::build('AssetsManager', array(), 'getInstance'); $scssPackage = 'relatedvideos_scss'; $jsPackage = 'relatedvideos_js'; foreach ($assetsManager->getURL($scssPackage) as $url) { $out->addStyle($url); } foreach ($assetsManager->getURL($jsPackage) as $url) { $out->addScript("<script src=\"{$url}\"></script>"); } } wfProfileOut(__METHOD__); return true; }
public static function getLiftiumOptionsScript() { wfProfileIn(__METHOD__); global $wgDBname, $wgTitle, $wgLang; // See Liftium.js for documentation on options $options = array(); $options['pubid'] = 999; $options['baseUrl'] = '/__varnish_liftium/'; $options['kv_wgDBname'] = $wgDBname; if (is_object($wgTitle)) { $options['kv_article_id'] = $wgTitle->getArticleID(); $options['kv_wpage'] = $wgTitle->getPartialURL(); } $cat = AdEngine::getCachedCategory(); $options['kv_Hub'] = $cat['name']; $options['kv_skin'] = RequestContext::getMain()->getSkin()->getSkinName(); $options['kv_user_lang'] = $wgLang->getCode(); $options['kv_cont_lang'] = $GLOBALS['wgLanguageCode']; $options['kv_isMainPage'] = WikiaPageType::isMainPage(); $options['kv_page_type'] = WikiaPageType::getPageType(); $options['geoUrl'] = "http://geoiplookup.wikia.com/"; if (!empty($wgDartCustomKeyValues)) { $options['kv_dart'] = $wgDartCustomKeyValues; } $options['kv_domain'] = $_SERVER['HTTP_HOST']; $js = "LiftiumOptions = " . json_encode($options) . ";\n"; if (WikiaPageType::isSearch() || !$wgTitle->getNamespace() == NS_SPECIAL && !BodyController::isEditPage()) { $js .= <<<EOT \t\t\t\tif ( !window.wgLoadAdDriverOnLiftiumInit && ( !window.Wikia.AbTest || !Wikia.AbTest.inTreatmentGroup( "AD_LOAD_TIMING", "ONLOAD" ) ) ) { \t\t\t\t\tLiftiumOptions['hasMoreCalls'] = true; \t\t\t\t\tLiftiumOptions['isCalledAfterOnload'] = true; \t\t\t\t\tLiftiumOptions['maxLoadDelay'] = 6000; \t\t\t\t} \t\t\t\telse { \t\t\t\t\tLiftiumOptions['autoInit'] = false; \t\t\t\t} EOT; } else { $js .= <<<EOT \t\t\t\tLiftiumOptions['hasMoreCalls'] = true; \t\t\t\tLiftiumOptions['isCalledAfterOnload'] = true; \t\t\t\tLiftiumOptions['maxLoadDelay'] = 6000; EOT; } $js = AssetsManagerBaseBuilder::minifyJs($js); $out = "\n<!-- Liftium options -->\n"; $out .= Html::inlineScript($js) . "\n"; wfProfileOut(__METHOD__); return $out; }
public function getRailModuleList() { wfProfileIn(__METHOD__); global $wgTitle, $wgUser, $wgEnableAchievementsExt, $wgContentNamespaces, $wgExtraNamespaces, $wgExtraNamespacesLocal, $wgEnableWikiAnswers, $wgEnableHuluVideoPanel, $wgEnableWallEngine, $wgRequest, $wgEnableForumExt; $namespace = $wgTitle->getNamespace(); $subjectNamespace = MWNamespace::getSubject($namespace); $railModuleList = array(); $latestActivityKey = $wgUser->isAnon() ? 1250 : 1300; $huluVideoPanelKey = $wgUser->isAnon() ? 1390 : 1280; // Forum Extension if ($wgEnableForumExt && ForumHelper::isForum()) { $railModuleList = array(1202 => array('Forum', 'forumRelatedThreads', null), 1201 => array('Forum', 'forumActivityModule', null), 1490 => array('Ad', 'Index', ['slotName' => 'TOP_RIGHT_BOXAD'])); // Include additional modules from other extensions (like chat) wfRunHooks('GetRailModuleList', array(&$railModuleList)); wfProfileOut(__METHOD__); return $railModuleList; } if ($namespace == NS_SPECIAL) { if (WikiaPageType::isSearch()) { if (empty($this->wg->EnableWikiaHomePageExt)) { $railModuleList = array($latestActivityKey => array('LatestActivity', 'Index', null)); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); if (empty($wgEnableWikiAnswers)) { if ($wgEnableHuluVideoPanel) { $railModuleList[$huluVideoPanelKey] = array('HuluVideoPanel', 'Index', null); } } } } else { if ($wgTitle->isSpecial('Leaderboard')) { $railModuleList = array($latestActivityKey => array('LatestActivity', 'Index', null), 1290 => array('LatestEarnedBadges', 'Index', null)); } else { if ($wgTitle->isSpecial('WikiActivity')) { $railModuleList = array(1102 => array('HotSpots', 'Index', null), 1101 => array('CommunityCorner', 'Index', null)); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); } else { if ($wgTitle->isSpecial('Following') || $wgTitle->isSpecial('Contributions')) { // intentional nothing here } else { if ($wgTitle->isSpecial('ThemeDesignerPreview')) { $railModuleList = array($latestActivityKey => array('LatestActivity', 'Index', null)); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); if (empty($wgEnableWikiAnswers)) { if ($wgEnableHuluVideoPanel) { $railModuleList[$huluVideoPanelKey] = array('HuluVideoPanel', 'Index', null); } } } else { // don't show any module for MW core special pages $railModuleList = array(); wfRunHooks('GetRailModuleSpecialPageList', array(&$railModuleList)); wfProfileOut(__METHOD__); return $railModuleList; } } } } } } // Content, category and forum namespaces. FB:1280 Added file,video,mw,template if ($wgTitle->isSubpage() && $wgTitle->getNamespace() == NS_USER || in_array($subjectNamespace, array(NS_CATEGORY, NS_CATEGORY_TALK, NS_FORUM, NS_PROJECT, NS_FILE, NS_MEDIAWIKI, NS_TEMPLATE, NS_HELP)) || in_array($subjectNamespace, $wgContentNamespaces) || array_key_exists($subjectNamespace, $wgExtraNamespaces)) { // add any content page related rail modules here $railModuleList[$latestActivityKey] = array('LatestActivity', 'Index', null); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); if (empty($wgEnableWikiAnswers)) { if ($wgEnableHuluVideoPanel) { $railModuleList[$huluVideoPanelKey] = array('HuluVideoPanel', 'Index', null); } } } // User page namespaces if (in_array($wgTitle->getNamespace(), self::getUserPagesNamespaces())) { $page_owner = User::newFromName($wgTitle->getText()); if ($page_owner) { if (!$page_owner->getGlobalPreference('hidefollowedpages')) { $railModuleList[1101] = array('FollowedPages', 'Index', null); } if ($wgEnableAchievementsExt) { $railModuleList[1102] = array('Achievements', 'Index', null); } } } if (self::isBlogPost() || self::isBlogListing()) { $railModuleList[1250] = array('PopularBlogPosts', 'Index', null); } // No rail on main page or edit page for oasis skin // except &action=history of wall if (!empty($wgEnableWallEngine)) { $isEditPage = !WallHelper::isWallNamespace($namespace) && BodyController::isEditPage() || $wgRequest->getVal('diff'); } else { $isEditPage = BodyController::isEditPage(); } if ($isEditPage || WikiaPageType::isMainPage()) { $modules = array(); wfRunHooks('GetEditPageRailModuleList', array(&$modules)); wfProfileOut(__METHOD__); return $modules; } // No modules on Custom namespaces, unless they are in the ContentNamespaces list, those get the content rail if (is_array($wgExtraNamespacesLocal) && array_key_exists($subjectNamespace, $wgExtraNamespacesLocal) && !in_array($subjectNamespace, $wgContentNamespaces)) { wfProfileOut(__METHOD__); return array(); } // If the entire page is non readable due to permissions, don't display the rail either RT#75600 if (!$wgTitle->userCan('read')) { wfProfileOut(__METHOD__); return array(); } $railModuleList[1440] = array('Ad', 'Index', ['slotName' => 'TOP_RIGHT_BOXAD']); $railModuleList[1100] = array('Ad', 'Index', ['slotName' => 'LEFT_SKYSCRAPER_2']); unset($railModuleList[1450]); wfRunHooks('GetRailModuleList', array(&$railModuleList)); wfProfileOut(__METHOD__); return $railModuleList; }
/** * add resources needed by chat * as chat entry points or links can appear on any page, * we really need them everywhere */ public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { global $wgExtensionsPath, $wgTitle, $wgResourceBasePath; wfProfileIn(__METHOD__); $sp = array('Contributions', 'Log', 'Recentchanges'); foreach ($sp as $value) { if ($wgTitle->isSpecial($value)) { // For Chat2 (doesn't exist in Chat(1)) $srcs = F::build('AssetsManager', array(), 'getInstance')->getGroupCommonURL('chat_ban_js', array()); foreach ($srcs as $val) { $out->addScript('<script src="' . $val . '"></script>'); } F::build('JSMessages')->enqueuePackage('ChatBanModal', JSMessages::EXTERNAL); $out->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/Chat2/css/ChatModal.scss')); break; } } // don't load ChatEntryPoint on edit pages (perf optimization) if (F::app()->checkSkin('oasis') && !BodyController::isEditPage()) { // TODO: move these to asset manager when we release chat globally $out->addScriptFile($wgResourceBasePath . '/resources/wikia/libraries/bootstrap/popover.js'); $out->addScriptFile($wgExtensionsPath . '/wikia/Chat2/js/ChatEntryPoint.js'); $out->addStyle(AssetsManager::getInstance()->getSassCommonURL('resources/wikia/libraries/bootstrap/popover.scss')); $out->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/Chat2/css/ChatEntryPoint.scss')); } wfProfileOut(__METHOD__); return true; }
public function getRailModuleList() { wfProfileIn(__METHOD__); global $wgTitle, $wgUser, $wgEnableAchievementsExt, $wgContentNamespaces, $wgExtraNamespaces, $wgExtraNamespacesLocal, $wgEnableCorporatePageExt, $wgEnableWikiAnswers, $wgSalesTitles, $wgEnableHuluVideoPanel, $wgEnableGamingCalendarExt, $wgEnableWallEngine, $wgRequest; $namespace = $wgTitle->getNamespace(); $subjectNamespace = MWNamespace::getSubject($namespace); $railModuleList = array(); $latestPhotosKey = $wgUser->isAnon() ? 1300 : 1250; $latestActivityKey = $wgUser->isAnon() ? 1250 : 1300; $huluVideoPanelKey = $wgUser->isAnon() ? 1390 : 1280; // Forum Extension if (WikiaPageType::isForum()) { $railModuleList = array ( 1500 => array('Search', 'Index', null), 1002 => array('Forum', 'forumRelatedThreads', null), 1001 => array('Forum', 'forumActivityModule', null), 1000 => array('Forum', 'forumParticipationModule', null), 1490 => array('Ad', 'Index', array('slotname' => 'TOP_RIGHT_BOXAD')), ); return $railModuleList; } if($namespace == NS_SPECIAL) { if (WikiaPageType::isSearch()) { if (empty($this->wg->EnableWikiaHomePageExt)) { $railModuleList = array( $latestActivityKey => array('LatestActivity', 'Index', null), ); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); if( empty( $wgEnableWikiAnswers ) ) { $railModuleList[$latestPhotosKey] = array('LatestPhotos', 'Index', null); if ($wgEnableHuluVideoPanel) { $railModuleList[$huluVideoPanelKey] = array('HuluVideoPanel', 'Index', null); } } } elseif ($wgEnableCorporatePageExt) { $railModuleList = array( 1490 => array('Ad', 'Index', array('slotname' => 'TOP_RIGHT_BOXAD')) ); wfProfileOut(__METHOD__); return $railModuleList; } } else if ($wgTitle->isSpecial('Leaderboard')) { $railModuleList = array ( 1500 => array('Search', 'Index', null), $latestActivityKey => array('LatestActivity', 'Index', null), 1290 => array('LatestEarnedBadges', 'Index', null) ); } else if ($wgTitle->isSpecial('WikiActivity')) { $railModuleList = array ( 1500 => array('Search', 'Index', null), 1102 => array('HotSpots', 'Index', null), 1101 => array('CommunityCorner', 'Index', null), ); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); } else if ($wgTitle->isSpecial('Following') || $wgTitle->isSpecial('Contributions') ) { // intentional nothing here } else if ($wgTitle->isSpecial('ThemeDesignerPreview') ) { $railModuleList = array ( 1500 => array('Search', 'Index', null), $latestActivityKey => array('LatestActivity', 'Index', null), ); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); if( empty( $wgEnableWikiAnswers ) ) { $railModuleList[$latestPhotosKey] = array('LatestPhotos', 'Index', null); if ($wgEnableHuluVideoPanel) { $railModuleList[$huluVideoPanelKey] = array('HuluVideoPanel', 'Index', null); } } } else if( $wgTitle->isSpecial('PageLayoutBuilderForm') ) { $railModuleList = array ( 1501 => array('Search', 'Index', null), 1500 => array('PageLayoutBuilderForm', 'Index', null) ); } else { // don't show any module for MW core special pages $railModuleList = array(); wfRunHooks( 'GetRailModuleSpecialPageList', array( &$railModuleList ) ); wfProfileOut(__METHOD__); return $railModuleList; } } else if ( !self::showUserPagesHeader() ) { // ProfilePagesV3 renders its own search box. // If this page is not a page with the UserPagesHeader on version 3, show search (majority case) $railModuleList = array ( 1500 => array('Search', 'Index', null), ); } // Content, category and forum namespaces. FB:1280 Added file,video,mw,template if( $wgTitle->isSubpage() && $wgTitle->getNamespace() == NS_USER || in_array($subjectNamespace, array (NS_CATEGORY, NS_CATEGORY_TALK, NS_FORUM, NS_PROJECT, NS_FILE, NS_VIDEO, NS_MEDIAWIKI, NS_TEMPLATE, NS_HELP)) || in_array($subjectNamespace, $wgContentNamespaces) || array_key_exists( $subjectNamespace, $wgExtraNamespaces ) ) { // add any content page related rail modules here $railModuleList[$latestActivityKey] = array('LatestActivity', 'Index', null); $railModuleList[1450] = array('PagesOnWiki', 'Index', null); if( empty( $wgEnableWikiAnswers ) ) { $railModuleList[$latestPhotosKey] = array('LatestPhotos', 'Index', null); if ($wgEnableHuluVideoPanel) { $railModuleList[$huluVideoPanelKey] = array('HuluVideoPanel', 'Index', null); } } } // User page namespaces if( in_array($wgTitle->getNamespace(), self::getUserPagesNamespaces() ) ) { $page_owner = User::newFromName($wgTitle->getText()); if($page_owner) { if( !$page_owner->getOption('hidefollowedpages') ) { $railModuleList[1101] = array('FollowedPages', 'Index', null); } if($wgEnableAchievementsExt && !(($wgUser->getId() == $page_owner->getId()) && $page_owner->getOption('hidepersonalachievements'))){ $railModuleList[1102] = array('Achievements', 'Index', null); } } } if (self::isBlogPost() || self::isBlogListing()) { $railModuleList[1500] = array('Search', 'Index', null); $railModuleList[1250] = array('PopularBlogPosts', 'Index', null); } // A/B testing leftovers, leave for now because we will do another one $useTestBoxad = false; // Special case rail modules for Corporate Skin if ($wgEnableCorporatePageExt) { $railModuleList = array ( 1500 => array('Search', 'Index', null), ); // No rail on main page or edit page for corporate skin if ( BodyController::isEditPage() || WikiaPageType::isMainPage() ) { $railModuleList = array(); } else if (self::isHubPage()) { if ($useTestBoxad) { $railModuleList[1490] = array('Ad', 'Index', array('slotname' => 'TEST_TOP_RIGHT_BOXAD')); } else { $railModuleList[1490] = array('Ad', 'Index', array('slotname' => 'CORP_TOP_RIGHT_BOXAD')); } $railModuleList[1480] = array('CorporateSite', 'HotSpots', null); // $railModuleList[1470] = array('CorporateSite', 'PopularHubPosts', null); // temp disabled - data not updating $railModuleList[1460] = array('CorporateSite', 'TopHubUsers', null); } else if ( is_array( $wgSalesTitles ) && in_array( $wgTitle->getText(), $wgSalesTitles ) ){ $railModuleList[1470] = array('CorporateSite', 'SalesSupport', null); } else { // content pages $railModuleList[1470] = array('CorporateSite', 'PopularStaffPosts', null); } wfProfileOut(__METHOD__); return $railModuleList; } // No rail on main page or edit page for oasis skin // except &action=history of wall if( !empty($wgEnableWallEngine) ) { $isEditPage = !WallHelper::isWallNamespace($namespace) && BodyController::isEditPage() || $wgRequest->getVal('diff'); } else { $isEditPage = BodyController::isEditPage(); } if ( $isEditPage || WikiaPageType::isMainPage() ) { $modules = array(); wfRunHooks( 'GetEditPageRailModuleList', array( &$modules ) ); wfProfileOut(__METHOD__); return $modules; } // No modules on Custom namespaces, unless they are in the ContentNamespaces list, those get the content rail if (is_array($wgExtraNamespacesLocal) && array_key_exists($subjectNamespace, $wgExtraNamespacesLocal) && !in_array($subjectNamespace, $wgContentNamespaces)) { wfProfileOut(__METHOD__); return array(); } // If the entire page is non readable due to permissions, don't display the rail either RT#75600 if (!$wgTitle->userCan( 'read' )) { wfProfileOut(__METHOD__); return array(); } if ($useTestBoxad) { $railModuleList[1440] = array('Ad', 'Index', array('slotname' => 'TEST_TOP_RIGHT_BOXAD')); } else { $railModuleList[1440] = array('Ad', 'Index', array('slotname' => 'TOP_RIGHT_BOXAD')); } $railModuleList[1291] = array('Ad', 'Index', array('slotname' => 'MIDDLE_RIGHT_BOXAD')); $railModuleList[1100] = array('Ad', 'Index', array('slotname' => 'LEFT_SKYSCRAPER_2')); /** * Michał Roszka <*****@*****.**> * * SSW Gaming Calendar * * This is most likely going to be replaced with something similar to: * * $railModuleList[1260] = array( 'Ad', 'Index', array( 'slotname' => 'GAMING_CALENDAR_RAIL' ) ); */ if ( !empty( $wgEnableGamingCalendarExt ) ) { $railModuleList[1430] = array( 'GamingCalendarRail', 'Index', array( ) ); } else { $railModuleList[1430] = array('Ad', 'Index', array('slotname' => 'TOP_RIGHT_BUTTON')); } // WikiNav v2 - begin // TODO: remove once it's enabled sitewide global $wgOasisNavV2; if (!empty($wgOasisNavV2)) { // remove PagesOnWiki module unset($railModuleList[1450]); } // WikiNav v2 - end wfRunHooks( 'GetRailModuleList', array( &$railModuleList ) ); wfProfileOut(__METHOD__); return $railModuleList; }
private function loadJs() { global $wgTitle, $wgOut, $wgJsMimeType, $wgUser; wfProfileIn(__METHOD__); // decide where JS should be placed (only add JS at the top for special and edit pages) if ($wgTitle->getNamespace() == NS_SPECIAL || BodyController::isEditPage()) { $this->jsAtBottom = false; } else { $this->jsAtBottom = true; } //store AssetsManager output and reset jsFiles $jsAssets = $this->jsFiles; $this->jsFiles = ''; // load WikiaScriptLoader $this->wikiaScriptLoader = ''; $wslFiles = AssetsManager::getInstance()->getGroupCommonURL( 'wsl' ); foreach($wslFiles as $wslFile) { $this->wikiaScriptLoader .= "<script type=\"$wgJsMimeType\" src=\"$wslFile\"></script>"; } // get JS files from <script> tags returned by AssetsManager // TODO: get AssetsManager package (and other JS files to be loaded) here preg_match_all("/src=\"([^\"]+)/", $jsAssets, $matches, PREG_SET_ORDER); foreach($matches as $scriptSrc) { $jsReferences[] = str_replace('&', '&', $scriptSrc[1]);; } // move JS files added to OutputPage to list of files to be loaded using WSL $scripts = $wgUser->getSkin()->getScripts(); foreach ( $scripts as $s ) { //add inline scripts to jsFiles and move non-inline to WSL queue if ( !empty( $s['url'] ) ) { $jsReferences[] = $s['url']; } else { $this->jsFiles .= $s['tag']; } } // add user JS (if User:XXX/wikia.js page exists) // copied from Skin::getHeadScripts if($wgUser->isLoggedIn()){ wfProfileIn(__METHOD__ . '::checkForEmptyUserJS'); $userJS = $wgUser->getUserPage()->getPrefixedText() . '/wikia.js'; $userJStitle = Title::newFromText( $userJS ); if ( $userJStitle->exists() ) { global $wgSquidMaxage; $siteargs = array( 'action' => 'raw', 'maxage' => $wgSquidMaxage, ); $userJS = Skin::makeUrl( $userJS, wfArrayToCGI( $siteargs ) ); $jsReferences[] = Skin::makeUrl( $userJS, wfArrayToCGI( $siteargs ) );; } wfProfileOut(__METHOD__ . '::checkForEmptyUserJS'); } // generate code to load JS files $jsReferences = json_encode($jsReferences); $jsLoader = "<script type=\"text/javascript\">/*<![CDATA[*/ (function(){ wsl.loadScript({$jsReferences}); })(); /*]]>*/</script>"; // use loader script instead of separate JS files $this->jsFiles = $jsLoader . $this->jsFiles; wfProfileOut(__METHOD__); }