r22268 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22267‎ | r22268 | r22269 >
Date:20:26, 19 May 2007
Author:yurik
Status:old
Tags:
Comment:
API:
* breaking change: Converted a map of revisions into a list of revisions to allow easier json processing (no need to know map keys)
* html formatting now properly links urls ending with a '\n' string (jsonfm)
* regression: fixed allpages to return int instead of string for pageid and ns
* Added: info now returns page length, counter, and a new flag
Modified paths:
  • /trunk/phase3/includes/api/ApiFormatBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllpages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiResult.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllpages.php
@@ -92,9 +92,9 @@
9393 if (is_null($resultPageSet)) {
9494 $title = Title :: makeTitle($row->page_namespace, $row->page_title);
9595 if ($title->userCanRead()) {
96 - $data[intval($row->page_id)] = array(
97 - 'pageid' => $row->page_id,
98 - 'ns' => $title->getNamespace(),
 96+ $data[] = array(
 97+ 'pageid' => intval($row->page_id),
 98+ 'ns' => intval($title->getNamespace()),
9999 'title' => $title->getPrefixedText());
100100 }
101101 } else {
Index: trunk/phase3/includes/api/ApiMain.php
@@ -29,7 +29,16 @@
3030 }
3131
3232 /**
33 - * This is the main API class, used for both external and internal processing.
 33+ * This is the main API class, used for both external and internal processing.
 34+ * When executed, it will create the requested formatter object,
 35+ * instantiate and execute an object associated with the needed action,
 36+ * and use formatter to print results.
 37+ * In case of an exception, an error message will be printed using the same formatter.
 38+ *
 39+ * To use API from another application, run it using FauxRequest object, in which
 40+ * case any internal exceptions will not be handled but passed up to the caller.
 41+ * After successful execution, use getResult() for the resulting data.
 42+ *
3443 * @addtogroup API
3544 */
3645 class ApiMain extends ApiBase {
@@ -43,11 +52,11 @@
4453 * List of available modules: action name => module class
4554 */
4655 private static $Modules = array (
47 - 'help' => 'ApiHelp',
4856 // 'login' => 'ApiLogin', // LOGIN is temporarily disabled until it becomes more secure
4957 'query' => 'ApiQuery',
5058 'opensearch' => 'ApiOpenSearch',
51 - 'feedwatchlist' => 'ApiFeedWatchlist'
 59+ 'feedwatchlist' => 'ApiFeedWatchlist',
 60+ 'help' => 'ApiHelp',
5261 );
5362
5463 /**
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -176,11 +176,13 @@
177177 if ($showContent)
178178 ApiResult :: setContent($vals, Revision :: getRevisionText($row));
179179
180 - $this->getResult()->addValue(array (
181 - 'query',
182 - 'pages',
183 - intval($row->rev_page
184 - ), 'revisions'), intval($row->rev_id), $vals);
 180+ $this->getResult()->addValue(
 181+ array (
 182+ 'query',
 183+ 'pages',
 184+ intval($row->rev_page),
 185+ 'revisions'),
 186+ null, $vals);
185187 }
186188 }
187189 $db->freeResult($res);
Index: trunk/phase3/includes/api/ApiResult.php
@@ -125,7 +125,8 @@
126126 /**
127127 * Add value to the output data at the given path.
128128 * Path is an indexed array, each element specifing the branch at which to add the new value
129 - * Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value
 129+ * Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value
 130+ * If $name is empty, the $value is added as a next list element data[] = $value
130131 */
131132 public function addValue($path, $name, $value) {
132133
@@ -145,7 +146,10 @@
146147 }
147148 }
148149
149 - ApiResult :: setElement($data, $name, $value);
 150+ if (empty($name))
 151+ $data[] = $value; // Add list element
 152+ else
 153+ ApiResult :: setElement($data, $name, $value); // Add named element
150154 }
151155
152156 public function execute() {
Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -40,8 +40,11 @@
4141 public function requestExtraData() {
4242 $pageSet = $this->getPageSet();
4343 $pageSet->requestField('page_is_redirect');
 44+ $pageSet->requestField('page_is_new');
 45+ $pageSet->requestField('page_counter');
4446 $pageSet->requestField('page_touched');
4547 $pageSet->requestField('page_latest');
 48+ $pageSet->requestField('page_len');
4649 }
4750
4851 public function execute() {
@@ -51,18 +54,26 @@
5255 $result = $this->getResult();
5356
5457 $pageIsRedir = $pageSet->getCustomField('page_is_redirect');
 58+ $pageIsNew = $pageSet->getCustomField('page_is_new');
 59+ $pageCounter = $pageSet->getCustomField('page_counter');
5560 $pageTouched = $pageSet->getCustomField('page_touched');
5661 $pageLatest = $pageSet->getCustomField('page_latest');
 62+ $pageLength = $pageSet->getCustomField('page_len');
5763
5864 foreach ( $titles as $pageid => $unused ) {
5965 $pageInfo = array (
6066 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
61 - 'lastrevid' => intval($pageLatest[$pageid])
 67+ 'lastrevid' => intval($pageLatest[$pageid]),
 68+ 'counter' => $pageCounter[$pageid],
 69+ 'length' => $pageLength[$pageid],
6270 );
6371
6472 if ($pageIsRedir[$pageid])
6573 $pageInfo['redirect'] = '';
6674
 75+ if ($pageIsNew[$pageid])
 76+ $pageInfo['new'] = '';
 77+
6778 $result->addValue(array (
6879 'query',
6980 'pages'
Index: trunk/phase3/includes/api/ApiFormatBase.php
@@ -149,9 +149,9 @@
150150 $text = ereg_replace('\<([^>]+)\>', '<span style="color:blue;">&lt;\1&gt;</span>', $text);
151151 // identify URLs
152152 $protos = "http|https|ftp|gopher";
153 - $text = ereg_replace("($protos)://[^ '\"()<\n]+", '<a href="\\0">\\0</a>', $text);
 153+ $text = ereg_replace("($protos)://[^ \\'\"()<\n]+", '<a href="\\0">\\0</a>', $text);
154154 // identify requests to api.php
155 - $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text);
 155+ $text = ereg_replace("api\\.php\\?[^ \\()<\n\t]+", '<a href="\\0">\\0</a>', $text);
156156 // make strings inside * bold
157157 $text = ereg_replace("\\*[^<>\n]+\\*", '<b>\\0</b>', $text);
158158 // make strings inside $ italic