From: Yuri Astrakhan Date: Wed, 18 Oct 2006 23:49:09 +0000 (+0000) Subject: API * X-Git-Tag: 1.31.0-rc.0~55438 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=398160f15e748e1b09388b20d43029c940877a30;p=lhc%2Fweb%2Fwiklou.git API * * OpenSearch support for namespaces * Minor watchlist feed cleanup --- diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index 6dd5f9879f..b26948f3f0 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -43,6 +43,9 @@ class ApiFeedWatchlist extends ApiBase { $feedformat = null; extract($this->extractRequestParams()); + // limit to 1 day + $startTime = wfTimestamp(TS_MW, time() - intval(1 * 86400)); + // Prepare nested request $params = new FauxRequest(array ( 'action' => 'query', @@ -50,10 +53,10 @@ class ApiFeedWatchlist extends ApiBase { 'siprop' => 'general', 'list' => 'watchlist', 'wlprop' => 'user|comment|timestamp', - 'wlstart' => wfTimestamp(TS_MW, time() - intval( 1 * 86400 )), // limit to 1 day + 'wlstart' => $startTime, 'wllimit' => 50 )); - + // Execute $module = new ApiMain($params); $module->execute(); @@ -63,20 +66,34 @@ class ApiFeedWatchlist extends ApiBase { $feedItems = array (); foreach ($data['query']['watchlist'] as $index => $info) { - $title = $info['title']; - $titleUrl = Title :: newFromText($title)->getFullUrl(); - $feedItems[] = new FeedItem($title, $info['comment'], $titleUrl, $info['timestamp'], $info['user']); + $feedItems[] = $this->createFeedItem($info); } global $wgFeedClasses, $wgSitename, $wgContLanguageCode; $feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']'; $feedUrl = Title :: makeTitle(NS_SPECIAL, 'Watchlist')->getFullUrl(); - $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist (TODO)!', $feedUrl); + + $feed = new $wgFeedClasses[$feedformat] ($feedTitle, htmlspecialchars(wfMsgForContent('watchlist')), $feedUrl); ApiFormatFeedWrapper :: setResult($this->getResult(), $feed, $feedItems); } - protected function GetAllowedParams() { + private function createFeedItem($info) { + global $wgUser; + + $titleStr = $info['title']; + $title = Title :: newFromText($titleStr); + $titleUrl = $title->getFullUrl(); + $comment = $info['comment']; + $timestamp = $info['timestamp']; + $user = $info['user']; + + $completeText = "$comment ($user)"; + + return new FeedItem($titleStr, $completeText, $titleUrl, $timestamp, $user); + } + + protected function getAllowedParams() { global $wgFeedClasses; $feedFormatNames = array_keys($wgFeedClasses); return array ( @@ -87,17 +104,17 @@ class ApiFeedWatchlist extends ApiBase { ); } - protected function GetParamDescription() { + protected function getParamDescription() { return array ( 'feedformat' => 'The format of the feed' ); } - protected function GetDescription() { + protected function getDescription() { return 'This module returns a watchlist feed'; } - protected function GetExamples() { + protected function getExamples() { return array ( 'api.php?action=feedwatchlist' ); diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 77481d2cbd..8b24af91f9 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -42,54 +42,58 @@ class ApiOpenSearch extends ApiBase { public function execute() { $search = null; extract($this->ExtractRequestParams()); - + + $title = Title :: newFromText($search); + if(!$title) + return; // Return empty result + // Prepare nested request $params = new FauxRequest(array ( 'action' => 'query', 'list' => 'allpages', - 'apnamespace' => 0, + 'apnamespace' => $title->getNamespace(), 'aplimit' => 10, - 'apprefix' => $search + 'apprefix' => $title->getDBkey() )); - + // Execute $module = new ApiMain($params); $module->execute(); - + // Get clean data - $data =& $module->getResultData(); - + $data = & $module->getResultData(); + // Reformat useful data for future printing by JSON engine - $srchres = array(); - foreach ($data['query']['allpages'] as $pageid => &$pageinfo) { + $srchres = array (); + foreach ($data['query']['allpages'] as $pageid => & $pageinfo) { // Note: this data will no be printable by the xml engine // because it does not support lists of unnamed items $srchres[] = $pageinfo['title']; } - + // Set top level elements $result = $this->getResult(); $result->addValue(null, 0, $search); $result->addValue(null, 1, $srchres); } - - protected function GetAllowedParams() { + + protected function getAllowedParams() { return array ( 'search' => null ); } - protected function GetParamDescription() { + protected function getParamDescription() { return array ( 'search' => 'Search string' ); } - protected function GetDescription() { + protected function getDescription() { return 'This module implements OpenSearch protocol'; } - protected function GetExamples() { + protected function getExamples() { return array ( 'api.php?action=opensearch&search=Te' ); diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index e1bc280f20..117cfa7c78 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -59,7 +59,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { if (isset ($from)) { $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($from)); } - + if (isset ($prefix)) { $where[] = "page_title LIKE '{$db->strencode(ApiQueryBase :: titleToKey($prefix))}%'"; } @@ -108,8 +108,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $id = intval($row->page_id); $data[$id] = array ( 'id' => $id, - 'ns' => $title->getNamespace(), - 'title' => $title->getPrefixedText()); + 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText()); } else { $resultPageSet->processDbRow($row); } @@ -125,27 +124,30 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } protected function getAllowedParams() { - + $namespaces = $this->getQuery()->getValidNamespaces(); return array ( 'from' => null, 'prefix' => null, 'namespace' => array ( ApiBase :: PARAM_DFLT => 0, - ApiBase :: PARAM_TYPE => $this->getQuery()->getValidNamespaces()), + ApiBase :: PARAM_TYPE => $namespaces + ), 'filterredir' => array ( ApiBase :: PARAM_DFLT => 'all', ApiBase :: PARAM_TYPE => array ( 'all', 'redirects', 'nonredirects' - )), + ) + ), 'limit' => array ( ApiBase :: PARAM_DFLT => 10, ApiBase :: PARAM_TYPE => 'limit', ApiBase :: PARAM_MIN => 1, ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1, ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 - )); + ) + ); } protected function getParamDescription() { diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index c5655f19e7..4963927358 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -76,13 +76,10 @@ abstract class ApiQueryBase extends ApiBase { /** * This is a very simplistic utility function - * to convert a title string to a db key. - * It will replace all ' ' with '_', and make first letter uppercase + * to convert a non-namespaced title string to a db key. + * It will replace all ' ' with '_' */ public static function titleToKey($title) { - global $wgContLang, $wgCapitalLinks; - if ($wgCapitalLinks) - $title = $wgContLang->ucfirst( $title ); return str_replace(' ', '_', $title); } diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 8e075bf557..6b51c482d7 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -142,7 +142,7 @@ class ApiQueryRevisions extends ApiQueryBase { $where[] = 'rev_timestamp' . $before . $db->addQuotes($end); // must manually initialize unset limit - if (!!is_null($limit)) + if (is_null($limit)) $limit = 10; $this->validateLimit($this->encodeParamName('limit'), $limit, 1, $userMax, $botMax);