/** * @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; }
/** * @desc returns an article in simplified json structure * * @param int $articleId * @return array */ private function getArticleJson($articleId, Title $title) { $redirect = $this->request->getVal('redirect'); $articleAsJson = $this->sendRequest('ArticlesApi', 'getAsJson', ['id' => $articleId, 'redirect' => $redirect])->getData(); $articleType = WikiaPageType::getArticleType($title); if (!empty($articleType)) { $articleAsJson['type'] = $articleType; } return $articleAsJson; }