Exemple #1
0
/**
 * @param array $vars JS variables to be added at the top of the page
 * @param array $scripts JS scripts to add to the top of the page
 * @return bool return true - it's a hook
 */
function wfJSVariablesTopScripts(array &$vars, &$scripts)
{
    $wg = F::app()->wg;
    $title = $wg->Title;
    $out = $wg->Out;
    // ads need it
    $vars['wgAfterContentAndJS'] = array();
    if (is_array($wg->WikiFactoryTags)) {
        $vars['wgWikiFactoryTagIds'] = array_keys($wg->WikiFactoryTags);
        $vars['wgWikiFactoryTagNames'] = array_values($wg->WikiFactoryTags);
    }
    $vars['wgCdnRootUrl'] = $wg->CdnRootUrl;
    $vars['wgCdnApiUrl'] = $wg->CdnApiUrl;
    // analytics needs it (from here till the end of the function)
    $vars['wgDBname'] = $wg->DBname;
    $vars['wgCityId'] = $wg->CityId;
    // c&p from OutputPage::getJSVars with an old 1.16 name
    $vars['wgContentLanguage'] = $title->getPageLanguage()->getCode();
    // c&p from OutputPage::getJSVars, it's needed earlier
    $user = $wg->User;
    /** @var $user User */
    if ($user->isAnon()) {
        $vars['wgUserName'] = null;
    } else {
        $vars['wgUserName'] = $user->getName();
        /*
         * Remove when SOC-217 ABTest is finished
         */
        $vars['wgNotConfirmedEmail'] = $user->getGlobalAttribute(UserLoginSpecialController::NOT_CONFIRMED_LOGIN_OPTION_NAME);
        /*
         * End remove
         */
    }
    if ($out->isArticle()) {
        $vars['wgArticleId'] = $out->getWikiPage()->getId();
    }
    $vars['wgCategories'] = $out->getCategories();
    $vars['wgPageName'] = $title->getPrefixedDBKey();
    $vars['wikiaPageType'] = WikiaPageType::getPageType();
    $vars['wikiaPageIsCorporate'] = WikiaPageType::isCorporatePage();
    $vars['wgArticleType'] = WikiaPageType::getArticleType();
    // missing in 1.19
    $skin = RequestContext::getMain()->getSkin();
    $vars['skin'] = $skin->getSkinName();
    // for Google Analytics
    $vars['_gaq'] = array();
    $vars['wgIsGASpecialWiki'] = $wg->IsGASpecialWiki;
    // PER-58: moved wgStyleVersion to <head>
    $vars['wgStyleVersion'] = (string) $wg->StyleVersion;
    $wg->NoExternals = $wg->Request->getBool('noexternals', $wg->NoExternals);
    if (!empty($wg->NoExternals)) {
        $vars["wgNoExternals"] = $wg->NoExternals;
    }
    $vars['wgTransactionContext'] = Transaction::getAttributes();
    $scripts .= Html::inlineScript("var wgNow = new Date();") . "\n";
    return true;
}
 /**
  * Sends all events via Scribe
  */
 public static function onShutdown()
 {
     // Check dependencies (perform autoload if required)
     if (!is_callable('Transaction::getAttributes') || !is_callable('WScribeClient::singleton')) {
         return;
     }
     // send events with full context data
     self::send(Transaction::getEvents(), Transaction::getAttributes());
     // send raw events with the minimal context
     self::send(Transaction::getRawEvents(), [Transaction::PSEUDO_PARAM_TYPE => Transaction::getType(), Transaction::PARAM_ENVIRONMENT => Transaction::getAttribute(Transaction::PARAM_ENVIRONMENT)]);
 }
 /**
  * Send data via Scribe
  *
  * @param ProfilerData $data
  */
 public function send(ProfilerData $data)
 {
     if (!$this->checkDependencies()) {
         return;
     }
     $scribeKey = $this->getScribeKey($data->getEngine());
     $data = array('time' => microtime(true), 'engine' => $data->getEngine(), 'profile' => $data->getProfile(), 'context' => Transaction::getAttributes(), 'request' => $data->getRequest(), 'entries' => $data->getEntries());
     $data = json_encode($data);
     try {
         WScribeClient::singleton($scribeKey)->send($data);
     } catch (TException $e) {
         Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage());
     }
 }