/** * Finds search suggestions phrases for chosen query * * @requestParam string $query search term for suggestions * * @responseParam array $items The list of phrases matching the query * * @example &query=los */ public function getList() { wfProfileIn(__METHOD__); if (!empty($this->wg->EnableLinkSuggestExt)) { $query = trim($this->request->getVal(self::PARAMETER_QUERY, null)); if (empty($query)) { throw new MissingParameterApiException(self::PARAMETER_QUERY); } $request = new WebRequest(); $request->setVal('format', 'array'); $linkSuggestions = LinkSuggest::getLinkSuggest($request); if (!empty($linkSuggestions)) { foreach ($linkSuggestions as $suggestion) { $searchSuggestions[]['title'] = $suggestion; } $this->response->setVal('items', $searchSuggestions); } else { throw new NotFoundApiException(); } $this->response->setCacheValidity(WikiaResponse::CACHE_STANDARD); } else { throw new NotFoundApiException('Link Suggest extension not available'); } wfProfileOut(__METHOD__); }
function getLinkSuggest() { global $wgRequest; wfProfileIn(__METHOD__); $out = LinkSuggest::getLinkSuggest($wgRequest); $ar = new AjaxResponse($out); $ar->setCacheDuration(60 * 60); if ($wgRequest->getText('format') == 'json') { $ar->setContentType('application/json; charset=utf-8'); } else { $ar->setContentType('text/plain; charset=utf-8'); } wfProfileOut(__METHOD__); return $ar; }