Index: trunk/phase3/includes/api/ApiQueryBase.php |
— | — | @@ -76,13 +76,10 @@ |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * This is a very simplistic utility function |
80 | | - * to convert a title string to a db key. |
81 | | - * It will replace all ' ' with '_', and make first letter uppercase |
| 80 | + * to convert a non-namespaced title string to a db key. |
| 81 | + * It will replace all ' ' with '_' |
82 | 82 | */ |
83 | 83 | public static function titleToKey($title) { |
84 | | - global $wgContLang, $wgCapitalLinks; |
85 | | - if ($wgCapitalLinks) |
86 | | - $title = $wgContLang->ucfirst( $title ); |
87 | 84 | return str_replace(' ', '_', $title); |
88 | 85 | } |
89 | 86 | |
Index: trunk/phase3/includes/api/ApiQueryRevisions.php |
— | — | @@ -142,7 +142,7 @@ |
143 | 143 | $where[] = 'rev_timestamp' . $before . $db->addQuotes($end); |
144 | 144 | |
145 | 145 | // must manually initialize unset limit |
146 | | - if (!!is_null($limit)) |
| 146 | + if (is_null($limit)) |
147 | 147 | $limit = 10; |
148 | 148 | |
149 | 149 | $this->validateLimit($this->encodeParamName('limit'), $limit, 1, $userMax, $botMax); |
Index: trunk/phase3/includes/api/ApiQueryAllpages.php |
— | — | @@ -59,7 +59,7 @@ |
60 | 60 | if (isset ($from)) { |
61 | 61 | $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($from)); |
62 | 62 | } |
63 | | - |
| 63 | + |
64 | 64 | if (isset ($prefix)) { |
65 | 65 | $where[] = "page_title LIKE '{$db->strencode(ApiQueryBase :: titleToKey($prefix))}%'"; |
66 | 66 | } |
— | — | @@ -108,8 +108,7 @@ |
109 | 109 | $id = intval($row->page_id); |
110 | 110 | $data[$id] = array ( |
111 | 111 | 'id' => $id, |
112 | | - 'ns' => $title->getNamespace(), |
113 | | - 'title' => $title->getPrefixedText()); |
| 112 | + 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText()); |
114 | 113 | } else { |
115 | 114 | $resultPageSet->processDbRow($row); |
116 | 115 | } |
— | — | @@ -125,27 +124,30 @@ |
126 | 125 | } |
127 | 126 | |
128 | 127 | protected function getAllowedParams() { |
129 | | - |
| 128 | + $namespaces = $this->getQuery()->getValidNamespaces(); |
130 | 129 | return array ( |
131 | 130 | 'from' => null, |
132 | 131 | 'prefix' => null, |
133 | 132 | 'namespace' => array ( |
134 | 133 | ApiBase :: PARAM_DFLT => 0, |
135 | | - ApiBase :: PARAM_TYPE => $this->getQuery()->getValidNamespaces()), |
| 134 | + ApiBase :: PARAM_TYPE => $namespaces |
| 135 | + ), |
136 | 136 | 'filterredir' => array ( |
137 | 137 | ApiBase :: PARAM_DFLT => 'all', |
138 | 138 | ApiBase :: PARAM_TYPE => array ( |
139 | 139 | 'all', |
140 | 140 | 'redirects', |
141 | 141 | 'nonredirects' |
142 | | - )), |
| 142 | + ) |
| 143 | + ), |
143 | 144 | 'limit' => array ( |
144 | 145 | ApiBase :: PARAM_DFLT => 10, |
145 | 146 | ApiBase :: PARAM_TYPE => 'limit', |
146 | 147 | ApiBase :: PARAM_MIN => 1, |
147 | 148 | ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1, |
148 | 149 | ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
149 | | - )); |
| 150 | + ) |
| 151 | + ); |
150 | 152 | } |
151 | 153 | |
152 | 154 | protected function getParamDescription() { |
Index: trunk/phase3/includes/api/ApiFeedWatchlist.php |
— | — | @@ -43,6 +43,9 @@ |
44 | 44 | $feedformat = null; |
45 | 45 | extract($this->extractRequestParams()); |
46 | 46 | |
| 47 | + // limit to 1 day |
| 48 | + $startTime = wfTimestamp(TS_MW, time() - intval(1 * 86400)); |
| 49 | + |
47 | 50 | // Prepare nested request |
48 | 51 | $params = new FauxRequest(array ( |
49 | 52 | 'action' => 'query', |
— | — | @@ -50,10 +53,10 @@ |
51 | 54 | 'siprop' => 'general', |
52 | 55 | 'list' => 'watchlist', |
53 | 56 | 'wlprop' => 'user|comment|timestamp', |
54 | | - 'wlstart' => wfTimestamp(TS_MW, time() - intval( 1 * 86400 )), // limit to 1 day |
| 57 | + 'wlstart' => $startTime, |
55 | 58 | 'wllimit' => 50 |
56 | 59 | )); |
57 | | - |
| 60 | + |
58 | 61 | // Execute |
59 | 62 | $module = new ApiMain($params); |
60 | 63 | $module->execute(); |
— | — | @@ -63,20 +66,34 @@ |
64 | 67 | |
65 | 68 | $feedItems = array (); |
66 | 69 | foreach ($data['query']['watchlist'] as $index => $info) { |
67 | | - $title = $info['title']; |
68 | | - $titleUrl = Title :: newFromText($title)->getFullUrl(); |
69 | | - $feedItems[] = new FeedItem($title, $info['comment'], $titleUrl, $info['timestamp'], $info['user']); |
| 70 | + $feedItems[] = $this->createFeedItem($info); |
70 | 71 | } |
71 | 72 | |
72 | 73 | global $wgFeedClasses, $wgSitename, $wgContLanguageCode; |
73 | 74 | $feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']'; |
74 | 75 | $feedUrl = Title :: makeTitle(NS_SPECIAL, 'Watchlist')->getFullUrl(); |
75 | | - $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist (TODO)!', $feedUrl); |
76 | 76 | |
| 77 | + $feed = new $wgFeedClasses[$feedformat] ($feedTitle, htmlspecialchars(wfMsgForContent('watchlist')), $feedUrl); |
| 78 | + |
77 | 79 | ApiFormatFeedWrapper :: setResult($this->getResult(), $feed, $feedItems); |
78 | 80 | } |
79 | 81 | |
80 | | - protected function GetAllowedParams() { |
| 82 | + private function createFeedItem($info) { |
| 83 | + global $wgUser; |
| 84 | + |
| 85 | + $titleStr = $info['title']; |
| 86 | + $title = Title :: newFromText($titleStr); |
| 87 | + $titleUrl = $title->getFullUrl(); |
| 88 | + $comment = $info['comment']; |
| 89 | + $timestamp = $info['timestamp']; |
| 90 | + $user = $info['user']; |
| 91 | + |
| 92 | + $completeText = "$comment ($user)"; |
| 93 | + |
| 94 | + return new FeedItem($titleStr, $completeText, $titleUrl, $timestamp, $user); |
| 95 | + } |
| 96 | + |
| 97 | + protected function getAllowedParams() { |
81 | 98 | global $wgFeedClasses; |
82 | 99 | $feedFormatNames = array_keys($wgFeedClasses); |
83 | 100 | return array ( |
— | — | @@ -87,17 +104,17 @@ |
88 | 105 | ); |
89 | 106 | } |
90 | 107 | |
91 | | - protected function GetParamDescription() { |
| 108 | + protected function getParamDescription() { |
92 | 109 | return array ( |
93 | 110 | 'feedformat' => 'The format of the feed' |
94 | 111 | ); |
95 | 112 | } |
96 | 113 | |
97 | | - protected function GetDescription() { |
| 114 | + protected function getDescription() { |
98 | 115 | return 'This module returns a watchlist feed'; |
99 | 116 | } |
100 | 117 | |
101 | | - protected function GetExamples() { |
| 118 | + protected function getExamples() { |
102 | 119 | return array ( |
103 | 120 | 'api.php?action=feedwatchlist' |
104 | 121 | ); |
Index: trunk/phase3/includes/api/ApiOpenSearch.php |
— | — | @@ -42,54 +42,58 @@ |
43 | 43 | public function execute() { |
44 | 44 | $search = null; |
45 | 45 | extract($this->ExtractRequestParams()); |
46 | | - |
| 46 | + |
| 47 | + $title = Title :: newFromText($search); |
| 48 | + if(!$title) |
| 49 | + return; // Return empty result |
| 50 | + |
47 | 51 | // Prepare nested request |
48 | 52 | $params = new FauxRequest(array ( |
49 | 53 | 'action' => 'query', |
50 | 54 | 'list' => 'allpages', |
51 | | - 'apnamespace' => 0, |
| 55 | + 'apnamespace' => $title->getNamespace(), |
52 | 56 | 'aplimit' => 10, |
53 | | - 'apprefix' => $search |
| 57 | + 'apprefix' => $title->getDBkey() |
54 | 58 | )); |
55 | | - |
| 59 | + |
56 | 60 | // Execute |
57 | 61 | $module = new ApiMain($params); |
58 | 62 | $module->execute(); |
59 | | - |
| 63 | + |
60 | 64 | // Get clean data |
61 | | - $data =& $module->getResultData(); |
62 | | - |
| 65 | + $data = & $module->getResultData(); |
| 66 | + |
63 | 67 | // Reformat useful data for future printing by JSON engine |
64 | | - $srchres = array(); |
65 | | - foreach ($data['query']['allpages'] as $pageid => &$pageinfo) { |
| 68 | + $srchres = array (); |
| 69 | + foreach ($data['query']['allpages'] as $pageid => & $pageinfo) { |
66 | 70 | // Note: this data will no be printable by the xml engine |
67 | 71 | // because it does not support lists of unnamed items |
68 | 72 | $srchres[] = $pageinfo['title']; |
69 | 73 | } |
70 | | - |
| 74 | + |
71 | 75 | // Set top level elements |
72 | 76 | $result = $this->getResult(); |
73 | 77 | $result->addValue(null, 0, $search); |
74 | 78 | $result->addValue(null, 1, $srchres); |
75 | 79 | } |
76 | | - |
77 | | - protected function GetAllowedParams() { |
| 80 | + |
| 81 | + protected function getAllowedParams() { |
78 | 82 | return array ( |
79 | 83 | 'search' => null |
80 | 84 | ); |
81 | 85 | } |
82 | 86 | |
83 | | - protected function GetParamDescription() { |
| 87 | + protected function getParamDescription() { |
84 | 88 | return array ( |
85 | 89 | 'search' => 'Search string' |
86 | 90 | ); |
87 | 91 | } |
88 | 92 | |
89 | | - protected function GetDescription() { |
| 93 | + protected function getDescription() { |
90 | 94 | return 'This module implements OpenSearch protocol'; |
91 | 95 | } |
92 | 96 | |
93 | | - protected function GetExamples() { |
| 97 | + protected function getExamples() { |
94 | 98 | return array ( |
95 | 99 | 'api.php?action=opensearch&search=Te' |
96 | 100 | ); |