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 saveOrder($xmlsd) { global $reporterOrderTable, $readerOrderTable, $editorOrderTable; $response = new AjaxResponse(); $response->setContentType('text/plain'); $xmlstr = '' . html_entity_decode($xmlsd); $dbr =& wfGetDB(DB_WRITE); $xml = new SimpleXMLElement($xmlstr); //delete all in table $result = $dbr->delete($editorOrderTable, "*"); $result = $dbr->delete($readerOrderTable, "*"); $result = $dbr->delete($reporterOrderTable, "*"); foreach ($xml->children() as $child) { if ($child->getName() == 'Editor') { $sql = 'INSERT INTO ' . $editorOrderTable . ' (id, rank) VALUES (' . $child['id'] . ',' . $child['rank'] . ')'; $result = $dbr->query($sql); } elseif ($child->getName() == 'Reader') { $sql = 'INSERT INTO ' . $readerOrderTable . ' (id, rank) VALUES (' . $child['id'] . ',' . $child['rank'] . ')'; $result = $dbr->query($sql); } elseif ($child->getName() == 'Reporter') { $sql = 'INSERT INTO ' . $reporterOrderTable . ' (id, rank) VALUES (' . $child['id'] . ',' . $child['rank'] . ')'; $result = $dbr->query($sql); } } $response->addtext("Changes Saved"); return $response; }
/** * Returns an AjaxResponse containing the combo ajax login/register code. */ function GetComboAjaxLogin() { $tmpl = AjaxLoginForm::getTemplateForCombinedForms(); $response = new AjaxResponse($tmpl->render('ComboAjaxLogin')); $response->setContentType('text/html; charset=utf-8'); return $response; }
function smwf_ws_callEQIXML($query) { global $IP; require_once $IP . '/extensions/SMWHalo/includes/webservices/SMW_EQI.php'; $result = new AjaxResponse(query($query, "xml")); $result->setContentType("application/xml"); return $result; }
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; }
function RecipesTemplateAjax() { global $wgRequest; $method = $wgRequest->getVal('method', false); if (method_exists('RecipesTemplateAjax', $method)) { $data = RecipesTemplateAjax::$method(); $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); return $response; } }
function VET() { global $wgRequest; $method = $wgRequest->getVal('method'); $vet = new VideoEmbedTool(); $html = $vet->{$method}(); $domain = $wgRequest->getVal('domain', null); if (!empty($domain)) { $html .= '<script type="text/javascript">document.domain = "' . $domain . '"</script>'; } $resp = new AjaxResponse($html); $resp->setContentType('text/html'); return $resp; }
function MyHomeAjax() { global $wgRequest; $method = $wgRequest->getVal('method', false); if (method_exists('MyHomeAjax', $method)) { wfProfileIn(__METHOD__); $data = MyHomeAjax::$method(); $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); wfProfileOut(__METHOD__); return $response; } }
function WMU() { global $wgRequest, $wgGroupPermissions, $wgAllowCopyUploads; // Overwrite configuration settings needed by image import functionality $wgAllowCopyUploads = true; $wgGroupPermissions['user']['upload_by_url'] = true; $dir = dirname(__FILE__) . '/'; require_once $dir . 'WikiaMiniUpload_body.php'; $method = $wgRequest->getVal('method'); $wmu = new WikiaMiniUpload(); $html = $wmu->{$method}(); $ar = new AjaxResponse($html); $ar->setContentType('text/html; charset=utf-8'); return $ar; }
function HomePageListAjax() { global $wgRequest; $method = $wgRequest->getVal("method", false); if (method_exists("HomePageList", $method)) { $data = HomePageList::$method(true); if (is_array($data)) { $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType("application/json; charset=utf-8"); } else { $response = new AjaxResponse($data); $response->setContentType("text/html; charset=utf-8"); } return $response; } }
function smwf_qc_updateQuery($paramAsJSON) { global $smwgQRCEnabled; if (!$smwgQRCEnabled) { $response['success'] = true; } else { $paramObj = json_decode($paramAsJSON); @($queryId = $paramObj->queryId); @($debug = $paramObj->debug); $qrc = new SMWQRCQueryResultsCache(); $response['success'] = $qrc->updateQueryResult($queryId); } $response = json_encode($response); if (!$debug) { $response = new AjaxResponse($response); $response->setContentType("application/json"); } return $response; }
function get_assigned($sitting_id) { global $reportersTable, $sitting_reporter; $dbr =& wfGetDB(DB_SLAVE); //$sql = 'SELECT * FROM '.$reportersTable.' WHERE id IN ( SELECT reporter_id FROM '.$sitting_reporter.' WHERE sitting_id='.$sitting_id.')'; $sql = 'SELECT ug_user FROM user_groups WHERE ug_user IN (SELECT user_id FROM sitting_assignment WHERE sitting_id=' . $sitting_id . ') and ug_group="reporter"'; $reporters = $dbr->query($sql); $xml = new AjaxResponse(); $xml->setContentType('text/xml'); $xml->addtext('<' . '?xml version="1.0" encoding="utf-8" ?' . ">"); $xml->addtext('<Response>' . ""); while ($rowReporters = $dbr->fetchobject($reporters)) { $user = User::newFromId($rowReporters->ug_user); $name = $user->getRealName(); $xml->addtext('<Reporter id="' . $rowReporters->ug_user . '" name="' . $name . '">'); $xml->addtext('</Reporter>'); } $xml->addtext('</Response>'); return $xml; }
function save($xmlstr) { global $reportersAssignmentTable; $response = new AjaxResponse(); $response->setContentType('text/plain'); $xmlsd = "" . html_entity_decode($xmlstr); $dbr =& wfGetDB(DB_WRITE); $xml = new SimpleXMLElement($xmlsd); $result = $dbr->delete($reportersAssignmentTable, "*"); foreach ($xml->children() as $reader) { $reader_id = $reader['id']; foreach ($ed->children() as $reporter) { $reporter_id = $reporter['id']; $sql2 = 'INSERT INTO ' . $reportersAssignmentTable . ' (reader_id, reporter_id) VALUES (' . $reader_id . ',' . $reporter_id . ')'; $result = $dbr->query($sql2); } } $response->addtext("Changes Saved"); return $response; }
function RTEAjax() { wfProfileIn(__METHOD__); global $wgRequest; $ret = false; $method = $wgRequest->getVal('method', false); if ($method && method_exists('RTEAjax', $method)) { $data = RTEAjax::$method(); if (is_array($data)) { $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); $ret = $response; } else { $ret = $data; } } wfProfileOut(__METHOD__); return $ret; }
function CrunchyrollAjax() { global $wgRequest; wfProfileIn(__METHOD__); $method = $wgRequest->getVal('method', false); if (method_exists('CrunchyrollAjax', $method)) { $data = CrunchyrollAjax::$method(); if (is_array($data)) { // send array as JSON $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); } else { // send text as text/html $response = new AjaxResponse($data); $response->setContentType('text/html; charset=utf-8'); } } wfProfileOut(__METHOD__); return $response; }
function PhalanxAjax() { global $wgUser, $wgRequest; wfProfileIn(__METHOD__); $method = $wgRequest->getVal('method', false); // check permissions if (!$wgUser->isAllowed('phalanx')) { $data = array('error' => 1, 'text' => 'Permission error.'); } else { if (method_exists('PhalanxAjax', $method)) { $data = PhalanxAjax::$method(); } else { $data = false; } } // return as JSON $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); wfProfileOut(__METHOD__); return $response; }
function save_staff($xmldata, $sitting_id) { global $sitting_reader, $sitting_editor, $sitting_reporter; $response = new AjaxResponse(); $response->setContentType('text/plain'); $xmlsd = "" . html_entity_decode($xmldata); $dbr =& wfGetDB(DB_WRITE); $xml = new SimpleXMLElement($xmlsd); $result = $dbr->delete($dbr->tableName(sitting_assignment), array('sitting_id' => $sitting_id)); foreach ($xml->children() as $child) { $name = $child->getName(); if ($name == 'AssignedEditors') { foreach ($child->children() as $editor) { $editor_id = $editor['id']; $sql2 = 'INSERT INTO sitting_assignment (user_id, sitting_id) VALUES (' . $editor_id . ',' . $sitting_id . ')'; $result = $dbr->query($sql2); } } else { if ($name == 'AssignedReaders') { foreach ($child->children() as $reader) { $reader_id = $reader['id']; $sql2 = 'INSERT INTO sitting_assignment (user_id, sitting_id) VALUES (' . $reader_id . ',' . $sitting_id . ')'; $result = $dbr->query($sql2); } } else { if ($name == 'AssignedReporters') { foreach ($child->children() as $reporter) { $reporter_id = $reporter['id']; $sql2 = 'INSERT INTO sitting_assignment (user_id, sitting_id) VALUES (' . $reporter_id . ',' . $sitting_id . ')'; $result = $dbr->query($sql2); } } } } } $response->addtext("Changes Saved"); return $response; }
function WMU() { global $wgRequest, $wgGroupPermissions, $wgAllowCopyUploads; // Overwrite configuration settings needed by image import functionality $wgAllowCopyUploads = true; $wgGroupPermissions['user']['upload_by_url'] = true; $dir = dirname(__FILE__) . '/'; require_once $dir . 'WikiaMiniUpload_body.php'; $method = $wgRequest->getVal('method'); $wmu = new WikiaMiniUpload(); if (method_exists($wmu, $method)) { $html = $wmu->{$method}(); $ar = new AjaxResponse($html); $ar->setContentType('text/html; charset=utf-8'); } else { $errorMessage = 'WMU::' . $method . ' does not exist'; \Wikia\Logger\WikiaLogger::instance()->error($errorMessage); $payload = json_encode(['message' => $errorMessage]); $ar = new AjaxResponse($payload); $ar->setResponseCode('501 Not implemented'); $ar->setContentType('application/json; charset=utf-8'); } return $ar; }
/** * 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; }
/** * @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; }
/** * Returns the JSON message */ protected static function returnMsg($code, $state) { $msgId = self::NAME . '-' . ($state ? 'unprotect' : 'protect'); $response = array('code' => $code, 'msg' => self::translateCode($code), 'state' => $state, 'text' => wfMsg($msgId)); $result = self::SimpleJsonEncode($response); $ajaxResponse = new AjaxResponse($result); $ajaxResponse->setContentType('application/json'); $ajaxResponse->setResponseCode(self::$codeHttpMap[$code]); return $ajaxResponse; }
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; }
/** * 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; }
/** * @static * @return AjaxResponse * * @var */ public static function addItem() { global $wgRequest, $wgUser; $result = array('result' => false); $errors = array(); $listText = $wgRequest->getVal('list'); $itemText = trim($wgRequest->getVal('text')); if (!empty($listText) && !empty($itemText)) { $list = TopList::newFromText($listText); if ($wgUser->isAllowed('toplists-create-item')) { if (!empty($list) && $list->exists()) { //check for duplicated foreach ($list->getItems() as $item) { if (strtolower($item->getArticle()->getContent()) == strtolower($itemText)) { $errors[] = wfMsg('toplists-error-duplicated-entry'); break; } } if (empty($errors)) { $newItem = $list->createItem(); $newItem->setNewContent($itemText); $saveResult = $newItem->save(TOPLISTS_SAVE_CREATE); if ($saveResult !== true) { foreach ($saveResult as $errorTuple) { $errors[] = wfMsg($errorTuple['msg'], $errorTuple['params']); } } else { //invalidate caches and trigger save event for the list article $newItem->getTitle()->invalidateCache(); $list->save(TOPLISTS_SAVE_UPDATE); $list->invalidateCache(); $result['result'] = true; $result['listBody'] = TopListParser::parse($list); } } } else { $errors[] = wfMsg('toplists-error-add-item-list-not-exists', $listText); } } else { if ($wgUser->isAnon()) { $loginURL = SpecialPage::getTitleFor('Signup')->getLocalURL() . '?returnto=' . $list->getTitle()->getPrefixedDBkey(); $errors[] = wfMsg('toplists-error-add-item-anon', array("{$loginURL}&type=login", "{$loginURL}&type=signup")); } else { $errors[] = wfMsg('toplists-error-add-item-permission'); } } } else { $errors[] = wfMsg('toplists-error-empty-item-name'); } if (!empty($errors)) { $result['errors'] = $errors; } $json = json_encode($result); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); return $response; }
function get_workload($id) { global $sitting_editor, $mvSittingsTable; $dbr =& wfGetDB(DB_SLAVE); $sittings = $dbr->select($dbr->tablename(sitting_assignment), '*', array('user_id' => $id)); $xml = new AjaxResponse(); $xml->setContentType('text/xml'); $xml->addtext('<' . '?xml version="1.0" encoding="utf-8" ?' . ">"); $xml->addtext('<Response>' . ""); while ($row = $dbr->fetchobject($sittings)) { $sit = $dbr->select($mvSittingsTable, '*', array('id' => $row->sitting_id)); $row2 = $dbr->fetchobject($sit); $xml->addtext('<Sitting id="' . $row2->id . '" name="' . $row2->name . '">'); $xml->addtext('</Sitting>'); } $xml->addtext('</Response>'); return $xml; }
function AchAjax() { global $wgRequest; $method = $wgRequest->getVal('method'); if ($method && method_exists('AchAjaxService', $method)) { $response = new AjaxResponse(AchAjaxService::$method()); $response->setContentType('text/html; charset=utf-8'); return $response; } /*elseif ($method == 'takeRankingSnapshot') { ob_start(); Ach_TakeRankingSnapshot($wgRequest->getVal('force')); $result = ob_get_clean(); $response = new AjaxResponse($result); $response->setContentType('text/html; charset=utf-8'); return $response; }*/ }
/** Pass the request to our internal function. * BEWARE! Data are passed as they have been supplied by the user, * they should be carefully handled in the function processing the * request. */ function performAction() { global $wgAjaxExportList; if (empty($this->mode)) { return; } if (!in_array($this->func_name, $wgAjaxExportList)) { header("HTTP/1.0 400 Bad Request"); header("Status: 400 Bad Request"); header('Content-type: text/html; charset=utf-8'); print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">" . "<html><head><title>" . htmlspecialchars("Bad Request") . "</title></head><body><h1>" . htmlspecialchars("Bad Request") . "</h1><p>" . nl2br(htmlspecialchars("unknown function " . (string) $this->func_name)) . "</p></body></html>\n"; } else { if (strpos($this->func_name, '::') !== false) { $func = explode('::', $this->func_name, 2); } else { $func = $this->func_name; } try { $result = call_user_func_array($func, $this->args); if ($result === false || $result === NULL) { } else { if (is_string($result)) { $result = new AjaxResponse($result); } if ($this->contentType) { $result->setContentType($this->contentType); } $result->sendHeaders($this->expire, $this->contentType); $result->printText(); } } catch (Exception $e) { wfDebug(__METHOD__ . ' ERROR while dispatching ' . $this->func_name . "(" . var_export($this->args, true) . "): " . get_class($e) . ": " . $e->getMessage() . "\n"); if (!headers_sent()) { wfHttpError(500, 'Internal Error', $e->getMessage()); } else { print $e->getMessage(); } } } }
/** * axWFactoryDomainQuery * * used in autocompletion * * @return string JSON encoded array */ function axWFactoryDomainQuery() { global $wgRequest; $query = $wgRequest->getVal("query", false); $return = array("query" => $query, "suggestions" => array(), "data" => array()); $exact = array("suggestions" => array(), "data" => array()); $match = array("suggestions" => array(), "data" => array()); // query terms: wik, wiki, wikia take too much memory // and end up with fatal errors if (substr("wikia", 0, strlen((string) $query)) === $query) { $query = false; } if ($query) { /** * maybe not very effective but used only by staff anyway */ $query = strtolower($query); $dbr = WikiFactory::db(DB_SLAVE); $cityDomainLike = $dbr->buildLike($dbr->anyString(), $query, $dbr->anyString()); $sth = $dbr->select(["city_domains"], ["city_id", "city_domain"], ["city_domain not like 'www.%'", "city_domain not like '%.wikicities.com'", "city_domain {$cityDomainLike}"], __METHOD__, ['LIMIT' => 15]); while ($domain = $dbr->fetchObject($sth)) { $domain->city_domain = strtolower($domain->city_domain); if (preg_match("/^{$query}/", $domain->city_domain)) { $exact["suggestions"][] = $domain->city_domain; $exact["data"][] = $domain->city_id; } elseif (preg_match("/{$query}/", $domain->city_domain)) { $match["suggestions"][] = $domain->city_domain; $match["data"][] = $domain->city_id; } } $return["suggestions"] = array_merge($exact["suggestions"], $match["suggestions"]); $return["data"] = array_merge($exact["data"], $match["suggestions"]); } $resp = new AjaxResponse(json_encode($return)); $resp->setContentType('application/json; charset=utf-8'); return $resp; }
/** * @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; }
/** * @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; }