* 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
$text = ereg_replace('\<([^>]+)\>', '<span style="color:blue;"><\1></span>', $text);
// identify URLs
$protos = "http|https|ftp|gopher";
- $text = ereg_replace("($protos)://[^ '\"()<\n]+", '<a href="\\0">\\0</a>', $text);
+ $text = ereg_replace("($protos)://[^ \\'\"()<\n]+", '<a href="\\0">\\0</a>', $text);
// identify requests to api.php
- $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text);
+ $text = ereg_replace("api\\.php\\?[^ \\()<\n\t]+", '<a href="\\0">\\0</a>', $text);
// make strings inside * bold
$text = ereg_replace("\\*[^<>\n]+\\*", '<b>\\0</b>', $text);
// make strings inside $ italic
}
/**
- * This is the main API class, used for both external and internal processing.
+ * This is the main API class, used for both external and internal processing.
+ * When executed, it will create the requested formatter object,
+ * instantiate and execute an object associated with the needed action,
+ * and use formatter to print results.
+ * In case of an exception, an error message will be printed using the same formatter.
+ *
+ * To use API from another application, run it using FauxRequest object, in which
+ * case any internal exceptions will not be handled but passed up to the caller.
+ * After successful execution, use getResult() for the resulting data.
+ *
* @addtogroup API
*/
class ApiMain extends ApiBase {
* List of available modules: action name => module class
*/
private static $Modules = array (
- 'help' => 'ApiHelp',
// 'login' => 'ApiLogin', // LOGIN is temporarily disabled until it becomes more secure
'query' => 'ApiQuery',
'opensearch' => 'ApiOpenSearch',
- 'feedwatchlist' => 'ApiFeedWatchlist'
+ 'feedwatchlist' => 'ApiFeedWatchlist',
+ 'help' => 'ApiHelp',
);
/**
if (is_null($resultPageSet)) {
$title = Title :: makeTitle($row->page_namespace, $row->page_title);
if ($title->userCanRead()) {
- $data[intval($row->page_id)] = array(
- 'pageid' => $row->page_id,
- 'ns' => $title->getNamespace(),
+ $data[] = array(
+ 'pageid' => intval($row->page_id),
+ 'ns' => intval($title->getNamespace()),
'title' => $title->getPrefixedText());
}
} else {
public function requestExtraData() {
$pageSet = $this->getPageSet();
$pageSet->requestField('page_is_redirect');
+ $pageSet->requestField('page_is_new');
+ $pageSet->requestField('page_counter');
$pageSet->requestField('page_touched');
$pageSet->requestField('page_latest');
+ $pageSet->requestField('page_len');
}
public function execute() {
$result = $this->getResult();
$pageIsRedir = $pageSet->getCustomField('page_is_redirect');
+ $pageIsNew = $pageSet->getCustomField('page_is_new');
+ $pageCounter = $pageSet->getCustomField('page_counter');
$pageTouched = $pageSet->getCustomField('page_touched');
$pageLatest = $pageSet->getCustomField('page_latest');
+ $pageLength = $pageSet->getCustomField('page_len');
foreach ( $titles as $pageid => $unused ) {
$pageInfo = array (
'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
- 'lastrevid' => intval($pageLatest[$pageid])
+ 'lastrevid' => intval($pageLatest[$pageid]),
+ 'counter' => $pageCounter[$pageid],
+ 'length' => $pageLength[$pageid],
);
if ($pageIsRedir[$pageid])
$pageInfo['redirect'] = '';
+ if ($pageIsNew[$pageid])
+ $pageInfo['new'] = '';
+
$result->addValue(array (
'query',
'pages'
if ($showContent)
ApiResult :: setContent($vals, Revision :: getRevisionText($row));
- $this->getResult()->addValue(array (
- 'query',
- 'pages',
- intval($row->rev_page
- ), 'revisions'), intval($row->rev_id), $vals);
+ $this->getResult()->addValue(
+ array (
+ 'query',
+ 'pages',
+ intval($row->rev_page),
+ 'revisions'),
+ null, $vals);
}
}
$db->freeResult($res);
/**
* Add value to the output data at the given path.
* Path is an indexed array, each element specifing the branch at which to add the new value
- * Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value
+ * Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value
+ * If $name is empty, the $value is added as a next list element data[] = $value
*/
public function addValue($path, $name, $value) {
}
}
- ApiResult :: setElement($data, $name, $value);
+ if (empty($name))
+ $data[] = $value; // Add list element
+ else
+ ApiResult :: setElement($data, $name, $value); // Add named element
}
public function execute() {