本文整理汇总了PHP中AjaxResponse::setCacheDuration方法的典型用法代码示例。如果您正苦于以下问题:PHP AjaxResponse::setCacheDuration方法的具体用法?PHP AjaxResponse::setCacheDuration怎么用?PHP AjaxResponse::setCacheDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AjaxResponse
的用法示例。
在下文中一共展示了AjaxResponse::setCacheDuration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wfTalkHereAjaxEditor
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;
}
示例2: setHubsFeedsVariable
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;
}
示例3: getLinkSuggestImage
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;
}
示例4: efAjaxTest
/**
* 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;
}
}
示例5: axWFactoryGetVariable
/**
* axWFactoryGetVariable
*
* Method for getting variable form via AJAX request.
*
* @author Krzysztof Krzyżaniak <eloy@wikia.com>
* @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;
}
示例6: cxValidateUserName
/**
* 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;
}
示例7: efPonyDocsAjaxCloneExternalTopic
/**
* 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;
}
示例8: axWStats
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;
}
示例9: wfCreatePageAjaxCheckTitle
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;
}
示例10: ChatAjax
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;
}
}
示例11: i18n
/**
* 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;
}
示例12: createUserLogin
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;
}
示例13: linkSuggestAjaxResponse
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;
}
示例14: getLinkSuggest
/**
* 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;
}
示例15: wfSajaxSearch
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;
}