function wfTalkHereAjaxEditor( $page, $section, $returnto ) { global $wgRequest, $wgTitle, $wgOut; $title = Title::newFromText( $page ); if ( !$title ) { return false; } //fake editor environment $args = array( 'wpTalkHere' => '1', 'wpReturnTo' => $returnto, 'action' => 'edit', 'section' => $section ); $wgRequest = new FauxRequest( $args ); $wgTitle = $title; $article = Article::newFromTitle( $title, RequestContext::getMain() ); $editor = new TalkHereEditPage( $article ); //generate form $editor->importFormData( $wgRequest ); $editor->showEditForm(); $response = new AjaxResponse(); $response->addText( $wgOut->getHTML() ); $response->setCacheDuration( false ); //don't cache, because of tokens etc return $response; }
static function setHubsFeedsVariable() { global $wgRequest, $wgCityId, $wgMemc, $wgUser; wfProfileIn(__METHOD__); if (!$wgUser->isAllowed('corporatepagemanager')) { $result['response'] = 'error'; } else { $result = array('response' => 'ok'); $tagname = $wgRequest->getVal('tag'); $feedname = strtolower($wgRequest->getVal('feed')); $key = wfMemcKey('autohubs', $tagname, 'feeds_displayed'); $oldtags = self::getHubsFeedsVariable($tagname); $oldtags[$tagname][$feedname] = !$oldtags[$tagname][$feedname]; $result['disabled'] = $oldtags[$tagname][$feedname]; if (!WikiFactory::setVarByName('wgWikiaAutoHubsFeedsDisplayed', $wgCityId, $oldtags)) { $result['response'] = 'error'; } else { $wgMemc->delete($key); } } $json = json_encode($result); $response = new AjaxResponse($json); $response->setCacheDuration(0); $response->setContentType('text/plain; charset=utf-8'); wfProfileOut(__METHOD__); return $response; }
function getLinkSuggestImage() { global $wgRequest; wfProfileIn(__METHOD__); $res = LinkSuggest::getLinkSuggestImage($wgRequest->getText('imageName')); $ar = new AjaxResponse($res); $ar->setCacheDuration(60 * 60); $ar->setContentType('text/plain; charset=utf-8'); wfProfileOut(__METHOD__); return $ar; }
/** * Entry point for Ajax, registered in $wgAjaxExportList. * This loads CategoryTreeFunctions.php and calls CategoryTree::ajax() */ function efAjaxTest($text, $usestring, $httpcache, $lastmod, $error) { $text = htmlspecialchars($text) . "(" . wfTimestampNow() . ")"; if ($usestring) { return $text; } else { $response = new AjaxResponse($text); if ($error) { throw new Exception($text); } if ($httpcache) { $response->setCacheDuration(24 * 60 * 60); } # cache for a day if ($lastmod) { $response->checkLastModified('19700101000001'); # never modified } return $response; } }
/** * axWFactoryGetVariable * * Method for getting variable form via AJAX request. * * @author Krzysztof Krzyżaniak <*****@*****.**> * @access public * * @return HTML code with variable data */ function axWFactoryGetVariable() { global $wgRequest, $wgUser, $wgOut, $wgPreWikiFactoryValues; if (!$wgUser->isAllowed('wikifactory')) { $wgOut->readOnlyPage(); #--- FIXME: later change to something reasonable return; } $cv_id = $wgRequest->getVal("varid"); $city_id = $wgRequest->getVal("wiki"); $variable = WikiFactory::getVarById($cv_id, $city_id); // BugId:3054 if (empty($variable)) { return json_encode(array('error' => true, 'message' => 'No such variable.')); } $related = array(); $r_pages = array(); if (preg_match("/Related variables:(.*)\$/", $variable->cv_description, $matches)) { $names = preg_split("/[\\s,;.()]+/", $matches[1], null, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $rel_var = WikiFactory::getVarByName($name, $city_id); if (!empty($rel_var)) { $related[] = $rel_var; } else { if (preg_match("/^MediaWiki:.*\$/", $name, $matches2)) { $r_pages[] = array("url" => GlobalTitle::newFromText($name, 0, $city_id)->getFullURL()); } } } } $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/"); $oTmpl->set_vars(array("cityid" => $city_id, "variable" => $variable, "groups" => WikiFactory::getGroups(), "accesslevels" => WikiFactory::$levels, "related" => $related, "related_pages" => $r_pages, "preWFValues" => $wgPreWikiFactoryValues, 'wikiFactoryUrl' => Title::makeTitle(NS_SPECIAL, 'WikiFactory')->getFullUrl())); $response = new AjaxResponse(json_encode(array("div-body" => $oTmpl->render("variable"), "div-name" => "wk-variable-form"))); $response->setCacheDuration(0); $response->setContentType('application/json; charset=utf-8'); return $response; }
/** * Validates user names. * * @Author CorfiX (corfix@wikia.com) * @Author Maciej Błaszkowski <marooned at wikia-inc.com> * * @Param String $uName * * @Return String */ function cxValidateUserName() { global $wgRequest; wfProfileIn(__METHOD__); $uName = $wgRequest->getVal('uName'); $result = wfValidateUserName($uName); if ($result === true) { $message = ''; if (!wfRunHooks("cxValidateUserName", array($uName, &$message))) { $result = $message; } } if ($result === true) { $data = array('result' => 'OK'); } else { $data = array('result' => 'INVALID', 'msg' => wfMsg($result), 'msgname' => $result); } $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); $response->setCacheDuration(60); wfProfileOut(__METHOD__); return $response; }
/** * This is used when an author wants to CLONE a title from outside the Documentation namespace into a * title within it. We must be passed the title of the original/source topic and then the destination * title which should be a full form PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':<manual>:<topicName>:<version>' * which it will then tag with the supplied version and strip out any other Category tags (since they are * invalid in the Documentation namespace unless a DEFINED version). * * This will return an AjaxResponse object which MAY contain an error in the case the version is not * valid or the topic already exists (destination). * * @FIXME: Should validate version is defined. * * @param string $topic Title of topic to clone. * @param string $destTitle Title of destination topic. * @return AjaxResponse */ function efPonyDocsAjaxCloneExternalTopic($topic, $destTitle) { $response = new AjaxResponse(); $response->setCacheDuration(false); $pieces = split(':', $destTitle); if (sizeof($pieces) < 4 || strcasecmp($pieces[0], PONYDOCS_DOCUMENTATION_NAMESPACE_NAME) != 0) { $response->addText('Destination title is not valid.'); return $response; } if (!PonyDocsManual::IsManual($pieces[1])) { $response->addText('Destination title references an invalid manual.'); return $response; } if (!PonyDocsVersion::IsVersion($pieces[3])) { $response->addText('Destination title references an undefined version.'); return $response; } $destArticle = new Article(Title::newFromText($destTitle)); if ($destArticle->exists()) { $response->addText('Destination title already exists.'); return $response; } $article = new Article(Title::newFromText($topic)); if (!$article->exists()) { $response->addText('Source article could not be found.'); return $response; } $content = $article->getContent(); //$content = preg_replace( '/\[\[ return $response; }
function axWStats() { wfProfileIn(__METHOD__); $return = WikiStatsAjax::fromRequest()->getResult(); $ar = new AjaxResponse($return); $ar->setCacheDuration(60 * 30); // cache results for one hour wfProfileOut(__METHOD__); return $ar; }
function wfCreatePageAjaxCheckTitle() { global $wgRequest, $wgUser; $result = array('result' => 'ok'); $sTitle = $wgRequest->getVal('title'); $nameSpace = $wgRequest->getInt('namespace'); // perform title validation if (empty($sTitle)) { $result['result'] = 'error'; $result['msg'] = wfMsg('createpage-error-empty-title'); } else { $oTitle = Title::newFromText($sTitle, $nameSpace); if (!$oTitle instanceof Title) { $result['result'] = 'error'; $result['msg'] = wfMsg('createpage-error-invalid-title'); } else { if ($oTitle->exists()) { $result['result'] = 'error'; $result['msg'] = wfMsg('createpage-error-article-exists', array($oTitle->getFullUrl(), $oTitle->getText())); } else { // title not exists // macbre: use dedicated hook for this check (change related to release of Phalanx) if (!wfRunHooks('CreatePageTitleCheck', array($oTitle))) { $result['result'] = 'error'; $result['msg'] = wfMsg('createpage-error-article-spam'); } if ($oTitle->getNamespace() == NS_SPECIAL) { $result['result'] = 'error'; $result['msg'] = wfMsg('createpage-error-invalid-title'); } if ($wgUser->isBlockedFrom($oTitle, false)) { $result['result'] = 'error'; $result['msg'] = wfMsg('createpage-error-article-blocked'); } } } } $json = json_encode($result); $response = new AjaxResponse($json); $response->setCacheDuration(3600); $response->setContentType('application/json; charset=utf-8'); return $response; }
function ChatAjax() { error_log(var_export($_REQUEST, true)); global $wgRequest, $wgUser, $wgMemc; $method = $wgRequest->getVal('method', false); if (method_exists('ChatAjax', $method)) { wfProfileIn(__METHOD__); // Don't let Varnish cache this. header("X-Pass-Cache-Control: max-age=0"); $key = $wgRequest->getVal('key'); // macbre: check to protect against BugId:27916 if (!is_null($key)) { $data = $wgMemc->get($key, false); if (!empty($data)) { $wgUser = User::newFromId($data['user_id']); } } $data = ChatAjax::$method(); // send array as JSON $json = json_encode($data); $response = new AjaxResponse($json); $response->setCacheDuration(0); // don't cache any of these requests $response->setContentType('application/json; charset=utf-8'); wfProfileOut(__METHOD__); return $response; } }
/** * Get localisation */ public static function i18n() { // code of requested language global $wgLang; $lang = $wgLang->getCode(); // get CK messages array $messages = RTELang::getMessages($lang); $js = "CKEDITOR.lang['{$lang}'] = " . json_encode($messages) . ';'; $ret = new AjaxResponse($js); $ret->setContentType('application/x-javascript'); $ret->setCacheDuration(86400 * 365 * 10); // 10 years return $ret; }
function createUserLogin() { global $wgRequest, $wgUser, $wgExternalSharedDB, $wgWikiaEnableConfirmEditExt, $wgEnableCOPPA, $wgDefaultSkin; // Init session if necessary if (session_id() == '') { wfSetupSession(); } $response = new AjaxResponse(); $response->setCacheDuration(3600 * 24 * 365); if (!(($wgRequest->getCheck("wpCreateaccountMail") || $wgRequest->getCheck("wpCreateaccount")) && $wgRequest->wasPosted())) { $response->addText(json_encode(array('status' => "ERROR", 'msg' => wfMsgExt('comboajaxlogin-post-not-understood', array('parseinline')), 'type' => 'error'))); return $response; } if ($wgRequest->getVal('type', '') == '') { $wgRequest->setVal('type', 'signup'); } $form = new AjaxLoginForm($wgRequest); $form->load(); if ($wgEnableCOPPA && !$form->checkDate()) { // If the users is too young to legally register. $response->addText(json_encode(array('status' => "ERROR", 'msg' => wfMsg('userlogin-unable-info'), 'type' => 'error'))); return $response; } $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $dbl = wfGetDB(DB_MASTER); $dbw->begin(); $dbl->begin(); $form->execute('signup'); $dbw->commit(); $dbl->commit(); if ($form->msgtype == "error") { if (!$wgWikiaEnableConfirmEditExt) { /*theoretically impossible because the only possible error is captcha error*/ $response->addText(json_encode(array('status' => "ERROR", 'msg' => $form->msg, 'type' => $form->msgtype, 'captchaUrl' => '', 'captcha' => ''))); return $response; } $captchaObj = new FancyCaptcha(); $captcha = $captchaObj->pickImage(); $captchaIndex = $captchaObj->storeCaptcha($captcha); $titleObj = SpecialPage::getTitleFor('Captcha/image'); $captchaUrl = $titleObj->getLocalUrl('wpCaptchaId=' . urlencode($captchaIndex)); $response->addText(json_encode(array('status' => "ERROR", 'msg' => $form->msg, 'type' => $form->msgtype, 'captchaUrl' => $captchaUrl, 'captcha' => $captchaIndex))); return $response; } $response->addText(json_encode(array('status' => "OK"))); return $response; }
function linkSuggestAjaxResponse($out) { global $wgRequest; if ($wgRequest->getText('format') == 'json') { $ar = new AjaxResponse($out); $ar->setCacheDuration(60 * 60); // cache results for one hour $ar->setContentType('application/json; charset=utf-8'); } else { $ar = new AjaxResponse($out); $ar->setCacheDuration(60 * 60); $ar->setContentType('text/plain; charset=utf-8'); } return $ar; }
/** * AJAX callback function * * @return $ar Array of link suggestions */ function getLinkSuggest() { global $wgRequest, $wgContLang, $wgContentNamespaces; // trim passed query and replace spaces by underscores // - this is how MediaWiki stores article titles in database $query = urldecode(trim($wgRequest->getText('query'))); $query = str_replace(' ', '_', $query); // explode passed query by ':' to get namespace and article title $queryParts = explode(':', $query, 2); if (count($queryParts) == 2) { $query = $queryParts[1]; $namespaceName = $queryParts[0]; // try to get the index by canonical name first $namespace = MWNamespace::getCanonicalIndex(strtolower($namespaceName)); if ($namespace == null) { // if we failed, try looking through localized namespace names $namespace = array_search(ucfirst($namespaceName), $wgContLang->getNamespaces()); if (empty($namespace)) { // getting here means our "namespace" is not real and can only // be a part of the title $query = $namespaceName . ':' . $query; } } } // list of namespaces to search in if (empty($namespace)) { // search only within content namespaces - default behaviour $namespaces = $wgContentNamespaces; } else { // search only within a namespace from query $namespaces = $namespace; } $results = array(); $dbr = wfGetDB(DB_SLAVE); $query = $dbr->strencode(mb_strtolower($query)); $res = $dbr->select(array('querycache', 'page'), array('qc_namespace', 'qc_title'), array('qc_title = page_title', 'qc_namespace = page_namespace', 'page_is_redirect = 0', 'qc_type' => 'Mostlinked', "LOWER(qc_title) LIKE '{$query}%'", 'qc_namespace' => $namespaces), __METHOD__, array('ORDER BY' => 'qc_value DESC', 'LIMIT' => 10)); foreach ($res as $row) { $results[] = wfLinkSuggestFormatTitle($row->qc_namespace, $row->qc_title); } $res = $dbr->select('page', array('page_namespace', 'page_title'), array("LOWER(page_title) LIKE '{$query}%'", 'page_is_redirect' => 0, 'page_namespace' => $namespaces), __METHOD__, array('ORDER BY' => 'page_title ASC', 'LIMIT' => 15 - count($results))); foreach ($res as $row) { $results[] = wfLinkSuggestFormatTitle($row->page_namespace, $row->page_title); } $results = array_unique($results); $format = $wgRequest->getText('format'); if ($format == 'json') { $out = json_encode(array('query' => $wgRequest->getText('query'), 'suggestions' => array_values($results))); } else { $out = implode("\n", $results); } $ar = new AjaxResponse($out); $ar->setCacheDuration(60 * 60); // cache results for one hour // set proper content type to ease development if ($format == 'json') { $ar->setContentType('application/json; charset=utf-8'); } else { $ar->setContentType('text/plain; charset=utf-8'); } return $ar; }
function wfSajaxSearch($term) { global $wgContLang, $wgOut; $limit = 16; $l = new Linker(); $term = str_replace(' ', '_', $wgContLang->ucfirst($wgContLang->checkTitleEncoding($wgContLang->recodeInput(js_unescape($term))))); if (strlen(str_replace('_', '', $term)) < 3) { return; } $db =& wfGetDB(DB_SLAVE); $res = $db->select('page', 'page_title', array('page_namespace' => 0, "page_title LIKE '" . $db->strencode($term) . "%'"), "wfSajaxSearch", array('LIMIT' => $limit + 1)); $r = ""; $i = 0; while (($row = $db->fetchObject($res)) && ++$i <= $limit) { $nt = Title::newFromDBkey($row->page_title); $r .= '<li>' . $l->makeKnownLinkObj($nt) . "</li>\n"; } if ($i > $limit) { $more = '<i>' . $l->makeKnownLink($wgContLang->specialPage("Allpages"), wfMsg('moredotdotdot'), "namespace=0&from=" . wfUrlEncode($term)) . '</i>'; } else { $more = ''; } $subtitlemsg = Title::newFromText($term) ? 'searchsubtitle' : 'searchsubtitleinvalid'; $subtitle = $wgOut->parse(wfMsg($subtitlemsg, wfEscapeWikiText($term))); #FIXME: parser is missing mTitle ! $term = htmlspecialchars($term); $html = '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">' . wfMsg('hideresults') . '</a></div>' . '<h1 class="firstHeading">' . wfMsg('search') . '</h1><div id="contentSub">' . $subtitle . '</div><ul><li>' . $l->makeKnownLink($wgContLang->specialPage('Search'), wfMsg('searchcontaining', $term), "search={$term}&fulltext=Search") . '</li><li>' . $l->makeKnownLink($wgContLang->specialPage('Search'), wfMsg('searchnamed', $term), "search={$term}&go=Go") . "</li></ul><h2>" . wfMsg('articletitles', $term) . "</h2>" . '<ul>' . $r . '</ul>' . $more; $response = new AjaxResponse($html); $response->setCacheDuration(30 * 60); return $response; }
/** * check status of the list (vote/edit permissions) */ public static function checkListStatus() { global $wgRequest; $result = array('result' => true, 'canVote' => false); $titleText = $wgRequest->getVal('title'); if (!empty($titleText)) { $list = TopList::newFromText($titleText); if ($list instanceof TopList) { $result['canVote'] = $list->userCanVote(); //$result['canEdit'] = false; // TODO: implement, dropped for the moment } } $json = json_encode($result); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); $response->setCacheDuration(0); return $response; }
function wfSajaxSearch($term) { global $wgContLang, $wgOut, $wgUser, $wgCapitalLinks, $wgMemc; $limit = 16; $sk = $wgUser->getSkin(); $output = ''; $term = trim($term); $term = $wgContLang->checkTitleEncoding($wgContLang->recodeInput(js_unescape($term))); if ($wgCapitalLinks) { $term = $wgContLang->ucfirst($term); } $term_title = Title::newFromText($term); $memckey = $term_title ? wfMemcKey('ajaxsearch', md5($term_title->getFullText())) : wfMemcKey('ajaxsearch', md5($term)); $cached = $wgMemc->get($memckey); if (is_array($cached) && $cached['version'] == AJAX_SEARCH_VERSION) { $response = new AjaxResponse($cached['html']); $response->setCacheDuration(30 * 60); return $response; } $r = $more = ''; $canSearch = true; $results = PrefixSearch::titleSearch($term, $limit + 1); foreach (array_slice($results, 0, $limit) as $titleText) { $r .= '<li>' . $sk->makeKnownLink($titleText) . "</li>\n"; } // Hack to check for specials if ($results) { $t = Title::newFromText($results[0]); if ($t && $t->getNamespace() == NS_SPECIAL) { $canSearch = false; if (count($results) > $limit) { $more = '<i>' . $sk->makeKnownLinkObj(SpecialPage::getTitleFor('Specialpages'), wfMsgHtml('moredotdotdot')) . '</i>'; } } else { if (count($results) > $limit) { $more = '<i>' . $sk->makeKnownLinkObj(SpecialPage::getTitleFor("Allpages", $term), wfMsgHtml('moredotdotdot')) . '</i>'; } } } $valid = (bool) $term_title; $term_url = urlencode($term); $term_diplay = htmlspecialchars($valid ? $term_title->getFullText() : $term); $subtitlemsg = $valid ? 'searchsubtitle' : 'searchsubtitleinvalid'; $subtitle = wfMsgWikiHtml($subtitlemsg, $term_diplay); $html = '<div id="searchTargetHide"><a onclick="Searching_Hide_Results();">' . wfMsgHtml('hideresults') . '</a></div>' . '<h1 class="firstHeading">' . wfMsgHtml('search') . '</h1><div id="contentSub">' . $subtitle . '</div>'; if ($canSearch) { $html .= '<ul><li>' . $sk->makeKnownLink($wgContLang->specialPage('Search'), wfMsgHtml('searchcontaining', $term_diplay), "search={$term_url}&fulltext=Search") . '</li><li>' . $sk->makeKnownLink($wgContLang->specialPage('Search'), wfMsgHtml('searchnamed', $term_diplay), "search={$term_url}&go=Go") . "</li></ul>"; } if ($r) { $html .= "<h2>" . wfMsgHtml('articletitles', $term_diplay) . "</h2>" . '<ul>' . $r . '</ul>' . $more; } $wgMemc->set($memckey, array('version' => AJAX_SEARCH_VERSION, 'html' => $html), 30 * 60); $response = new AjaxResponse($html); $response->setCacheDuration(30 * 60); return $response; }
/** * Add required HTML and JS variables [for 'view article' mode] * * @author Maciej Błaszkowski <marooned at wikia-inc.com>> * @author macbre */ function CategorySelectGenerateHTMLforView() { $html = '<div id="csMainContainer" class="csViewMode"> <div id="csSuggestContainer"> <div id="csHintContainer">' . wfMsg('categoryselect-suggest-hint') . '</div> </div> <div id="csItemsContainer" class="clearfix"> <input id="csCategoryInput" type="text" style="display: none; outline: none;" /> </div> <div id="csButtonsContainer" class="color1"> <input type="button" id="csSave" onclick="csSave()" value="' . wfMsg('categoryselect-button-save') . '" /> <input type="button" id="csCancel" onclick="csCancel()" value="' . wfMsg('categoryselect-button-cancel') . '" ' . (F::app()->checkSkin('oasis') ? 'class="secondary" ' : '') . '/> </div> </div>'; // lazy load global JS variables $vars = array(); CategorySelectSetupVars($vars); $data = json_encode(array('html' => $html, 'vars' => $vars)); $ar = new AjaxResponse($data); $ar->setCacheDuration(60 * 60); $ar->setContentType('application/json; charset=utf-8'); return $ar; }
/** * @author Maciej Błaszkowski <marooned at wikia-inc.com> */ function CommunityWidgetAjax() { global $wgRequest, $wgLang, $wgLanguageCode, $wgContentNamespaces; wfProfileIn(__METHOD__); //this should be the same as in /extensions/wikia/WidgetFramework/Widgets/WidgetCommunity/WidgetCommunity.php $parameters = array('type' => 'widget', 'maxElements' => 5, 'flags' => array('shortlist'), 'includeNamespaces' => implode('|', $wgContentNamespaces)); $uselang = $wgRequest->getVal('uselang'); $langCode = $wgLang->getCode(); if (!empty($uselang) && $langCode != $uselang) { $wgLang = Language::factory($uselang); } else { $uselang = $langCode; } $parameters['uselang'] = $uselang; $userLangEqContent = $uselang == $wgLanguageCode && $uselang == 'en'; //since we are using jQuery `timeago` plugin which works only for en, let's cache longer only this language $feedHTML = ActivityFeedHelper::getListForWidget($parameters, $userLangEqContent); $data = array('data' => $feedHTML, 'timestamp' => wfTimestampNow()); $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); $response->setCacheDuration($userLangEqContent ? 60 * 60 * 24 : 60 * 5); wfProfileOut(__METHOD__); return $response; }
/** * @author Maciej Błaszkowski <marooned at wikia-inc.com> */ function wfAnswersGetEditPointsAjax() { global $wgRequest, $wgSquidMaxage; $userId = intval($wgRequest->getVal('userId')); $points = AttributionCache::getInstance()->getUserEditPoints($userId); $timestamp = AttributionCache::getInstance()->getUserLastModifiedFromCache($userId); $timestamp = !empty($timestamp) ? $timestamp : wfTimestampNow(); $data = array('points' => $points, 'timestamp' => wfTimestampNow()); $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); $response->checkLastModified(strtotime($timestamp)); $response->setCacheDuration($wgSquidMaxage); return $response; }
/** * @deprecated * Get localisation entry point */ public static function i18n() { $js = self::getMessagesScript(); $ret = new AjaxResponse($js); $ret->setContentType('application/x-javascript'); $ret->setCacheDuration(86400 * 365 * 10); // 10 years return $ret; }
function ChatAjax() { global $wgChatDebugEnabled; if (!empty($wgChatDebugEnabled)) { Wikia::log(__METHOD__, "", "Chat debug:" . json_encode($_REQUEST)); } global $wgRequest, $wgUser, $wgMemc; $method = $wgRequest->getVal('method', false); if (method_exists('ChatAjax', $method)) { wfProfileIn(__METHOD__); $key = $wgRequest->getVal('key'); // macbre: check to protect against BugId:27916 if (!is_null($key)) { $data = $wgMemc->get($key, false); if (!empty($data)) { $wgUser = User::newFromId($data['user_id']); } } $data = ChatAjax::$method(); // send array as JSON $json = json_encode($data); $response = new AjaxResponse($json); $response->setCacheDuration(0); // don't cache any of these requests $response->setContentType('application/json; charset=utf-8'); wfProfileOut(__METHOD__); return $response; } }