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; }
/** * Returns a string that contains minified javascript of a small function stub which will * spool any calls to WikiaTracker.trackEvent until the code is actually loaded for doing the tracking (at * which point the calls will be replayed). */ public static function getTrackerSpoolingJs() { global $wgCacheBuster, $wgMemc, $wgDevelEnvironment; wfProfileIn(__METHOD__); // This code will spool all of the calls (in the order they were called) and different code will replay them later. // The wikiatracker implememtation will be replaced directly as soon as the correct file will load. ob_start(); ?> window.WikiaTracker = window.WikiaTracker || { trackEvent: function(eventName, params, method){ wikiaTrackingSpool.push([eventName, params, method]); } }; <?php $jsString = ob_get_clean(); // We're embedding this in every page, so minify it. Minifying takes a while, so cache it in memcache (BugzId 43421). if (!empty($wgDevelEnvironment)) { $memcKey = wfMemcKey('tracker_spooling_js'); // cachebuster changes on every pageview in dev... this will cache on devboxes anyway. } else { $memcKey = wfMemcKey('tracker_spooling_js', $wgCacheBuster); } $cachedValue = $wgMemc->get($memcKey); if (!$cachedValue) { $jsString = AssetsManagerBaseBuilder::minifyJs($jsString); // This code doesn't look like it should change almost at all, so we give it a long duration (cachebuster also purges it because that's in the key). // Warning: Memcached expirations work strangely around the one-month boundary (if the duration is too long, it interprets it as a timestamp instead of a duration). $TWO_WEEKS = 60 * 60 * 24 * 14; // in seconds. $wgMemc->set($memcKey, $jsString, $TWO_WEEKS); } else { $jsString = $cachedValue; } wfProfileOut(__METHOD__); return $jsString; }