From e5752b2372672a5b8e014902ebc2aa68fcd3c906 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 16 Oct 2006 05:53:07 +0000 Subject: [PATCH] * API: added prop parameter to watchlist, added partrolled flag --- includes/api/ApiFeedWatchlist.php | 2 +- includes/api/ApiFormatBase.php | 2 +- includes/api/ApiFormatJson.php | 1 - includes/api/ApiQueryWatchlist.php | 87 +++++++++++++++++++++++------- 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index c5af3029b8..ac0bc352db 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -105,7 +105,7 @@ class ApiFeedWatchlist extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id:$'; + return __CLASS__ . ': $Id$'; } } ?> \ No newline at end of file diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index e185158a4b..aba3109d8a 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -218,7 +218,7 @@ class ApiFormatFeedWrapper extends ApiFormatBase { } public function getVersion() { - return __CLASS__ . ': $Id:$'; + return __CLASS__ . ': $Id$'; } } ?> \ No newline at end of file diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 62c03f22ed..48de5af59a 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -46,7 +46,6 @@ class ApiFormatJson extends ApiFormatBase { } else { $this->printText(json_encode($this->getResultData())); } - } protected function getDescription() { diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index ab4a240886..c7ccc8bf48 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -49,7 +49,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { if (!$wgUser->isLoggedIn()) $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin'); - $allrev = $start = $end = $namespace = $dir = $limit = null; + $allrev = $start = $end = $namespace = $dir = $limit = $prop = null; extract($this->extractRequestParams()); $db = $this->getDB(); @@ -69,23 +69,42 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { 'ORDER BY' => 'rc_timestamp' . ($dirNewer ? '' : ' DESC' )); + $patrol = $timestamp = $user = $comment = false; + if (!is_null($prop)) { + if (!is_null($resultPageSet)) + $this->dieUsage('prop parameter may not be used in a generator', 'params'); + + $user = (false !== array_search('user', $prop)); + $comment = (false !== array_search('comment', $prop)); + $timestamp = (false !== array_search('timestamp', $prop)); + $patrol = (false !== array_search('patrol', $prop)); + + if ($patrol) { + global $wgUseRCPatrol, $wgUser; + if (!$wgUseRCPatrol || !$wgUser->isAllowed('patrol')) + $this->dieUsage('patrol property is not available', 'patrol'); + } + } + if (is_null($resultPageSet)) { $fields = array ( - 'rc_namespace AS page_namespace', - 'rc_title AS page_title', - 'rc_comment AS rev_comment', 'rc_cur_id AS page_id', - 'rc_user AS rev_user', - 'rc_user_text AS rev_user_text', - 'rc_timestamp AS rev_timestamp', - 'rc_minor AS rev_minor_edit', 'rc_this_oldid AS rev_id', - 'rc_last_oldid', - 'rc_id', - 'rc_new AS page_is_new' - // 'rc_patrolled' - + 'rc_namespace AS page_namespace', + 'rc_title AS page_title', + 'rc_new AS page_is_new', + 'rc_minor AS rev_minor_edit' ); + if ($user) { + $fields[] = 'rc_user AS rev_user'; + $fields[] = 'rc_user_text AS rev_user_text'; + } + if ($comment) + $fields[] = 'rc_comment AS rev_comment'; + if ($timestamp) + $fields[] = 'rc_timestamp AS rev_timestamp'; + if ($patrol) + $fields[] = 'rc_patrolled'; } elseif ($allrev) { $fields = array ( @@ -143,10 +162,30 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { if (is_null($resultPageSet)) { $id = intval($row->page_id); - $data[] = array ( - 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText(), 'id' => intval($row->page_id), 'comment' => $row->rev_comment, 'isuser' => $row->rev_user, 'user' => $row->rev_user_text, 'timestamp' => $row->rev_timestamp, 'minor' => $row->rev_minor_edit, 'rev_id' => $row->rev_id, 'rc_last_oldid' => $row->rc_last_oldid, 'rc_id' => $row->rc_id, - // 'rc_patrolled' => $row->rc_patrolled, - 'isnew' => $row->page_is_new); + $vals = array (); + $vals['pageid'] = intval($row->page_id); + $vals['revid'] = intval($row->rev_id); + $vals['ns'] = $title->getNamespace(); + $vals['title'] = $title->getPrefixedText(); + + if ($row->page_is_new) + $vals['new'] = ''; + if ($row->rev_minor_edit) + $vals['minor'] = ''; + + if ($user) { + if (!$row->rev_user) + $vals['anon'] = ''; + $vals['user'] = $row->rev_user_text; + } + if ($comment) + $vals['comment'] = $row->rev_comment; + if ($timestamp) + $vals['timestamp'] = $row->rev_timestamp; + if ($patrol && $row->rc_patrolled) + $vals['patrolled'] = ''; + + $data[] = $vals; } elseif ($allrev) { $data[] = intval($row->rev_id); @@ -158,7 +197,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $db->freeResult($res); if (is_null($resultPageSet)) { - ApiResult :: setIndexedTagName($data, 'p'); + ApiResult :: setIndexedTagName($data, 'item'); $this->getResult()->addValue('query', 'watchlist', $data); } elseif ($allrev) { @@ -195,6 +234,15 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { ApiBase :: PARAM_MIN => 1, ApiBase :: PARAM_MAX1 => 500, ApiBase :: PARAM_MAX2 => 5000 + ), + 'prop' => array ( + APIBase :: PARAM_ISMULTI => true, + APIBase :: PARAM_TYPE => array ( + 'user', + 'comment', + 'timestamp', + 'patrol' + ) ) ); } @@ -206,7 +254,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { 'end' => 'The timestamp to end enumerating.', 'namespace' => 'Filter changes to only the given namespace(s).', 'dir' => 'In which direction to enumerate pages.', - 'limit' => 'How many total pages to return per request.' + 'limit' => 'How many total pages to return per request.', + 'prop' => 'Which additional items to get (non-generator mode only).' ); } -- 2.20.1