$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',
'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();
$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 (
);
}
- 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'
);
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'
);
if (isset ($from)) {
$where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($from));
}
-
+
if (isset ($prefix)) {
$where[] = "page_title LIKE '{$db->strencode(ApiQueryBase :: titleToKey($prefix))}%'";
}
$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);
}
}
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() {
/**
* 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);
}
$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);