Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -167,6 +167,7 @@ |
168 | 168 | private function outputGeneralPageInfo() { |
169 | 169 | |
170 | 170 | $pageSet = $this->getPageSet(); |
| 171 | + $result = $this->getResult(); |
171 | 172 | |
172 | 173 | // Title normalizations |
173 | 174 | $normValues = array (); |
— | — | @@ -178,8 +179,8 @@ |
179 | 180 | } |
180 | 181 | |
181 | 182 | if (!empty ($normValues)) { |
182 | | - ApiResult :: setIndexedTagName($normValues, 'n'); |
183 | | - $this->getResult()->addValue('query', 'normalized', $normValues); |
| 183 | + $result->setIndexedTagName($normValues, 'n'); |
| 184 | + $result->addValue('query', 'normalized', $normValues); |
184 | 185 | } |
185 | 186 | |
186 | 187 | // Show redirect information |
— | — | @@ -192,8 +193,8 @@ |
193 | 194 | } |
194 | 195 | |
195 | 196 | if (!empty ($redirValues)) { |
196 | | - ApiResult :: setIndexedTagName($redirValues, 'r'); |
197 | | - $this->getResult()->addValue('query', 'redirects', $redirValues); |
| 197 | + $result->setIndexedTagName($redirValues, 'r'); |
| 198 | + $result->addValue('query', 'redirects', $redirValues); |
198 | 199 | } |
199 | 200 | |
200 | 201 | |
— | — | @@ -208,8 +209,8 @@ |
209 | 210 | 'revid' => $revid |
210 | 211 | ); |
211 | 212 | } |
212 | | - ApiResult :: setIndexedTagName($revids, 'rev'); |
213 | | - $this->getResult()->addValue('query', 'badrevids', $revids); |
| 213 | + $result->setIndexedTagName($revids, 'rev'); |
| 214 | + $result->addValue('query', 'badrevids', $revids); |
214 | 215 | } |
215 | 216 | |
216 | 217 | // |
— | — | @@ -239,8 +240,8 @@ |
240 | 241 | } |
241 | 242 | |
242 | 243 | if (!empty ($pages)) { |
243 | | - ApiResult :: setIndexedTagName($pages, 'page'); |
244 | | - $this->getResult()->addValue('query', 'pages', $pages); |
| 244 | + $result->setIndexedTagName($pages, 'page'); |
| 245 | + $result->addValue('query', 'pages', $pages); |
245 | 246 | } |
246 | 247 | } |
247 | 248 | |
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | ); |
67 | 67 | ApiResult :: setContent($data[$ns], $title); |
68 | 68 | } |
69 | | - ApiResult :: setIndexedTagName($data, 'ns'); |
| 69 | + $this->getResult()->setIndexedTagName($data, 'ns'); |
70 | 70 | $this->getResult()->addValue('query', $p, $data); |
71 | 71 | break; |
72 | 72 | |
Index: trunk/phase3/includes/api/ApiQueryRevisions.php |
— | — | @@ -225,10 +225,11 @@ |
226 | 226 | $db->freeResult($res); |
227 | 227 | |
228 | 228 | // Ensure that all revisions are shown as '<r>' elements |
229 | | - $data = & $this->getResultData(); |
| 229 | + $result = $this->getResult(); |
| 230 | + $data = & $result->getData(); |
230 | 231 | foreach ($data['query']['pages'] as & $page) { |
231 | 232 | if (is_array($page) && array_key_exists('revisions', $page)) { |
232 | | - ApiResult :: setIndexedTagName($page['revisions'], 'rev'); |
| 233 | + $result->setIndexedTagName($page['revisions'], 'rev'); |
233 | 234 | } |
234 | 235 | } |
235 | 236 | } |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -166,7 +166,7 @@ |
167 | 167 | $paramsDescription = $this->getParamDescription(); |
168 | 168 | $msg = ''; |
169 | 169 | $paramPrefix = "\n" . str_repeat(' ', 19); |
170 | | - foreach ($params as $paramName => & $paramSettings) { |
| 170 | + foreach ($params as $paramName => $paramSettings) { |
171 | 171 | $desc = isset ($paramsDescription[$paramName]) ? $paramsDescription[$paramName] : ''; |
172 | 172 | if (is_array($desc)) |
173 | 173 | $desc = implode($paramPrefix, $desc); |
Index: trunk/phase3/includes/api/ApiResult.php |
— | — | @@ -31,19 +31,28 @@ |
32 | 32 | |
33 | 33 | class ApiResult extends ApiBase { |
34 | 34 | |
35 | | - private $mData; |
| 35 | + private $mData, $mNeedsRaw; |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Constructor |
39 | 39 | */ |
40 | 40 | public function __construct($main) { |
41 | 41 | parent :: __construct($main, 'result'); |
42 | | - $this->Reset(); |
| 42 | + $this->mNeedsRaw = false; |
| 43 | + $this->reset(); |
43 | 44 | } |
44 | 45 | |
45 | | - public function Reset() { |
| 46 | + public function reset() { |
46 | 47 | $this->mData = array (); |
47 | 48 | } |
| 49 | + |
| 50 | + /** |
| 51 | + * Call this function when special elements such as '_element' |
| 52 | + * are needed by the formatter, for example in XML printing. |
| 53 | + */ |
| 54 | + public function setRawMode() { |
| 55 | + $this->mNeedsRaw = true; |
| 56 | + } |
48 | 57 | |
49 | 58 | function & getData() { |
50 | 59 | return $this->mData; |
— | — | @@ -97,10 +106,13 @@ |
98 | 107 | * In case the array contains indexed values (in addition to named), |
99 | 108 | * all indexed values will have the given tag name. |
100 | 109 | */ |
101 | | - public static function setIndexedTagName(& $arr, $tag) { |
102 | | - // Do not use setElement() as it is ok to call this more than once |
| 110 | + public function setIndexedTagName(& $arr, $tag) { |
| 111 | + // In raw mode, add the '_element', otherwise just ignore |
| 112 | + if (!$this->mNeedsRaw) |
| 113 | + return; |
103 | 114 | if ($arr === null || $tag === null || !is_array($arr) || is_array($tag)) |
104 | 115 | ApiBase :: dieDebug(__METHOD__, 'Bad parameter'); |
| 116 | + // Do not use setElement() as it is ok to call this more than once |
105 | 117 | $arr['_element'] = $tag; |
106 | 118 | } |
107 | 119 | |
— | — | @@ -130,26 +142,6 @@ |
131 | 143 | ApiResult :: setElement($data, $name, $value); |
132 | 144 | } |
133 | 145 | |
134 | | - /** |
135 | | - * Recursivelly removes any elements from the array that begin with an '_'. |
136 | | - * The content element '*' is the only special element that is left. |
137 | | - * Use this method when the entire data object gets sent to the user. |
138 | | - */ |
139 | | - public function SanitizeData() { |
140 | | - ApiResult :: SanitizeDataInt($this->mData); |
141 | | - } |
142 | | - |
143 | | - private static function SanitizeDataInt(& $data) { |
144 | | - foreach ($data as $key => & $value) { |
145 | | - if ($key[0] === '_') { |
146 | | - unset ($data[$key]); |
147 | | - } |
148 | | - elseif (is_array($value)) { |
149 | | - ApiResult :: SanitizeDataInt($value); |
150 | | - } |
151 | | - } |
152 | | - } |
153 | | - |
154 | 146 | public function execute() { |
155 | 147 | ApiBase :: dieDebug(__METHOD__, 'execute() is not supported on Result object'); |
156 | 148 | } |
Index: trunk/phase3/includes/api/ApiQueryAllpages.php |
— | — | @@ -118,8 +118,9 @@ |
119 | 119 | $db->freeResult($res); |
120 | 120 | |
121 | 121 | if (is_null($resultPageSet)) { |
122 | | - ApiResult :: setIndexedTagName($data, 'p'); |
123 | | - $this->getResult()->addValue('query', $this->getModuleName(), $data); |
| 122 | + $result = $this->getResult(); |
| 123 | + $result->setIndexedTagName($data, 'p'); |
| 124 | + $result->addValue('query', $this->getModuleName(), $data); |
124 | 125 | } |
125 | 126 | } |
126 | 127 | |
Index: trunk/phase3/includes/api/ApiFormatBase.php |
— | — | @@ -98,9 +98,10 @@ |
99 | 99 | ?> |
100 | 100 | <br/> |
101 | 101 | <small> |
102 | | - This result is being shown in <?=$this->mFormat?> format, |
103 | | - which might not be suitable for your application.<br/> |
104 | | - See <a href='api.php'>API help</a> for more information.<br/> |
| 102 | + You are looking at the HTML representation of the <?=$this->mFormat?> format.<br/> |
| 103 | + HTML is good for debugging, but probably not suitable for your application.<br/> |
| 104 | + Please see "format" parameter documentation at the <a href='api.php'>API help</a> |
| 105 | + for more information.<br/> |
105 | 106 | </small> |
106 | 107 | <?php |
107 | 108 | |
— | — | @@ -143,7 +144,7 @@ |
144 | 145 | // encode all tags as safe blue strings |
145 | 146 | $text = ereg_replace('\<([^>]+)\>', '<font color=blue><\1></font>', $text); |
146 | 147 | // identify URLs |
147 | | - $text = ereg_replace("[a-zA-Z]+://[^ '()<\n]+", '<a href="\\0">\\0</a>', $text); |
| 148 | + $text = ereg_replace("[a-zA-Z]+://[^ '\"()<\n]+", '<a href="\\0">\\0</a>', $text); |
148 | 149 | // identify requests to api.php |
149 | 150 | $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text); |
150 | 151 | // make strings inside * bold |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -136,6 +136,8 @@ |
137 | 137 | // Printer may not be initialized if the extractRequestParams() fails for the main module |
138 | 138 | if (!isset ($this->mPrinter)) { |
139 | 139 | $this->mPrinter = $this->createPrinterByName(self :: API_DEFAULT_FORMAT); |
| 140 | + if ($this->mPrinter->getNeedsRawData()) |
| 141 | + $this->getResult()->setRawMode(); |
140 | 142 | } |
141 | 143 | |
142 | 144 | if ($e instanceof UsageException) { |
— | — | @@ -167,8 +169,8 @@ |
168 | 170 | |
169 | 171 | // Reset and print just the error message |
170 | 172 | ob_clean(); |
171 | | - $this->mResult->Reset(); |
172 | | - $this->mResult->addValue(null, 'error', $errMessage); |
| 173 | + $this->getResult()->reset(); |
| 174 | + $this->getResult()->addValue(null, 'error', $errMessage); |
173 | 175 | |
174 | 176 | // If the error occured during printing, do a printer->profileOut() |
175 | 177 | $this->mPrinter->safeProfileOut(); |
— | — | @@ -193,11 +195,13 @@ |
194 | 196 | |
195 | 197 | // See if custom printer is used |
196 | 198 | $this->mPrinter = $module->getCustomPrinter(); |
197 | | - |
198 | 199 | if (is_null($this->mPrinter)) { |
199 | 200 | // Create an appropriate printer |
200 | 201 | $this->mPrinter = $this->createPrinterByName($format); |
201 | 202 | } |
| 203 | + |
| 204 | + if ($this->mPrinter->getNeedsRawData()) |
| 205 | + $this->getResult()->setRawMode(); |
202 | 206 | } |
203 | 207 | |
204 | 208 | // Execute |
— | — | @@ -218,8 +222,6 @@ |
219 | 223 | $printer = $this->mPrinter; |
220 | 224 | $printer->profileIn(); |
221 | 225 | $printer->initPrinter($isError); |
222 | | - if (!$printer->getNeedsRawData()) |
223 | | - $this->getResult()->SanitizeData(); |
224 | 226 | $printer->execute(); |
225 | 227 | $printer->closePrinter(); |
226 | 228 | $printer->profileOut(); |
Index: trunk/phase3/includes/api/ApiFeedWatchlist.php |
— | — | @@ -49,7 +49,8 @@ |
50 | 50 | 'meta' => 'siteinfo', |
51 | 51 | 'siprop' => 'general', |
52 | 52 | 'list' => 'watchlist', |
53 | | - 'wlstart' => wfTimestamp(TS_MW, time() - intval( 3 * 86400 )), // limit to 3 days |
| 53 | + 'wlprop' => 'user|comment|timestamp', |
| 54 | + 'wlstart' => wfTimestamp(TS_MW, time() - intval( 1 * 86400 )), // limit to 1 day |
54 | 55 | 'wllimit' => 50 |
55 | 56 | )); |
56 | 57 | |
— | — | @@ -57,22 +58,20 @@ |
58 | 59 | $module = new ApiMain($params); |
59 | 60 | $module->execute(); |
60 | 61 | |
61 | | - // Get clean data |
62 | | - $result = & $module->getResult(); |
63 | | - $result->SanitizeData(); |
64 | | - $data = & $result->GetData(); |
| 62 | + // Get data array |
| 63 | + $data = & $module->getResultData(); |
65 | 64 | |
66 | 65 | $feedItems = array (); |
67 | 66 | foreach ($data['query']['watchlist'] as $index => $info) { |
68 | 67 | $title = $info['title']; |
69 | 68 | $titleUrl = Title :: newFromText($title)->getFullUrl(); |
70 | | - $feedItems[] = new FeedItem($title, '', $titleUrl, $info['timestamp'], $info['user']); |
| 69 | + $feedItems[] = new FeedItem($title, $info['comment'], $titleUrl, $info['timestamp'], $info['user']); |
71 | 70 | } |
72 | 71 | |
73 | 72 | global $wgFeedClasses, $wgSitename, $wgContLanguageCode; |
74 | 73 | $feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']'; |
75 | 74 | $feedUrl = Title :: makeTitle(NS_SPECIAL, 'Watchlist')->getFullUrl(); |
76 | | - $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist!', $feedUrl); |
| 75 | + $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist (TODO)!', $feedUrl); |
77 | 76 | |
78 | 77 | ApiFormatFeedWrapper :: setResult($this->getResult(), $feed, $feedItems); |
79 | 78 | } |
Index: trunk/phase3/includes/api/ApiOpenSearch.php |
— | — | @@ -57,9 +57,7 @@ |
58 | 58 | $module->execute(); |
59 | 59 | |
60 | 60 | // Get clean data |
61 | | - $result =& $module->getResult(); |
62 | | - $result->SanitizeData(); |
63 | | - $data =& $result->GetData(); |
| 61 | + $data =& $module->getResultData(); |
64 | 62 | |
65 | 63 | // Reformat useful data for future printing by JSON engine |
66 | 64 | $srchres = array(); |
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php |
— | — | @@ -195,7 +195,7 @@ |
196 | 196 | $db->freeResult($res); |
197 | 197 | |
198 | 198 | if (is_null($resultPageSet)) { |
199 | | - ApiResult :: setIndexedTagName($data, 'item'); |
| 199 | + $this->getResult()->setIndexedTagName($data, 'item'); |
200 | 200 | $this->getResult()->addValue('query', $this->getModuleName(), $data); |
201 | 201 | } |
202 | 202 | elseif ($allrev) { |
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php |
— | — | @@ -130,7 +130,7 @@ |
131 | 131 | } |
132 | 132 | |
133 | 133 | if(!empty($params)) { |
134 | | - ApiResult :: setIndexedTagName($params, 'param'); |
| 134 | + $this->getResult()->setIndexedTagName($params, 'param'); |
135 | 135 | $vals = array_merge($vals, $params); |
136 | 136 | } |
137 | 137 | } |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | } |
145 | 145 | $db->freeResult($res); |
146 | 146 | |
147 | | - ApiResult :: setIndexedTagName($data, 'item'); |
| 147 | + $this->getResult()->setIndexedTagName($data, 'item'); |
148 | 148 | $this->getResult()->addValue('query', $this->getModuleName(), $data); |
149 | 149 | } |
150 | 150 | |