*/
/**
- * @todo Document - e.g. Provide top-level description of this class.
+ * This abstract class implements many basic API functions, and is the base of all API classes.
+ * The class functions are divided into several areas of functionality:
+ *
+ * Module parameters: Derived classes can define getAllowedParams() to specify which parameters to expect,
+ * how to parse and validate them.
+ *
+ * Profiling: various methods to allow keeping tabs on various tasks and their time costs
+ *
+ * Self-documentation: code to allow api to document its own state.
+ *
* @addtogroup API
*/
abstract class ApiBase {
private function run($resultPageSet = null) {
- wfProfileIn($this->getModuleProfileName() . '-getDB');
$db = $this->getDB();
- wfProfileOut($this->getModuleProfileName() . '-getDB');
- wfProfileIn($this->getModuleProfileName() . '-parseParams');
$limit = $from = $namespace = $filterredir = $prefix = null;
extract($this->extractRequestParams());
$this->addOption('LIMIT', $limit +1);
$this->addOption('ORDER BY', 'page_namespace, page_title');
- wfProfileOut($this->getModuleProfileName() . '-parseParams');
-
$res = $this->select(__METHOD__);
- wfProfileIn($this->getModuleProfileName() . '-saveResults');
-
$data = array ();
$count = 0;
while ($row = $db->fetchObject($res)) {
}
if (is_null($resultPageSet)) {
- $vals = $this->addRowInfo('page', $row);
- if ($vals)
- $data[intval($row->page_id)] = $vals;
+ $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(),
+ 'title' => $title->getPrefixedText());
+ }
} else {
$resultPageSet->processDbRow($row);
}
$result->setIndexedTagName($data, 'p');
$result->addValue('query', $this->getModuleName(), $data);
}
-
- wfProfileOut($this->getModuleProfileName() . '-saveResults');
}
protected function getAllowedParams() {
if ($title) {
if (!$title->userCanRead())
return false;
- $vals['new_ns'] = $title->getNamespace();
- $vals['new_title'] = $title->getPrefixedText();
+ ApiQueryBase :: addTitleInfo($vals, $title, 'new_');
}
if ( isset( $row->rc_patrolled ) )
if ($row->log_type == 'move' && isset ($params[0])) {
$newTitle = Title :: newFromText($params[0]);
if ($newTitle) {
- $vals['new_ns'] = $newTitle->getNamespace();
- $vals['new_title'] = $newTitle->getPrefixedText();
+ ApiQueryBase :: addTitleInfo($vals, $newTitle, 'new_');
$params = null;
}
}
}
// Type
- @ $tmp = $row-> {
- $prefix . '_type' };
+ @ $tmp = $row-> { $prefix . '_type' };
if (!is_null($tmp))
$vals['type'] = $tmp;
// Action
- @ $tmp = $row-> {
- $prefix . '_action' };
+ @ $tmp = $row-> { $prefix . '_action' };
if (!is_null($tmp))
$vals['action'] = $tmp;
// Old ID
- @ $tmp = $row-> {
- $prefix . '_text_id' };
+ @ $tmp = $row-> { $prefix . '_text_id' };
if (!is_null($tmp))
$vals['oldid'] = intval($tmp);
// User Name / Anon IP
- @ $tmp = $row-> {
- $prefix . '_user_text' };
+ @ $tmp = $row-> { $prefix . '_user_text' };
if (is_null($tmp))
@ $tmp = $row->user_name;
if (!is_null($tmp)) {
$vals['user'] = $tmp;
- @ $tmp = !$row-> {
- $prefix . '_user' };
+ @ $tmp = !$row-> { $prefix . '_user' };
if (!is_null($tmp) && $tmp)
$vals['anon'] = '';
}
// Bot Edit
- @ $tmp = $row-> {
- $prefix . '_bot' };
+ @ $tmp = $row-> { $prefix . '_bot' };
if (!is_null($tmp) && $tmp)
$vals['bot'] = '';
// New Edit
- @ $tmp = $row-> {
- $prefix . '_new' };
+ @ $tmp = $row-> { $prefix . '_new' };
if (is_null($tmp))
- @ $tmp = $row-> {
- $prefix . '_is_new' };
+ @ $tmp = $row-> { $prefix . '_is_new' };
if (!is_null($tmp) && $tmp)
$vals['new'] = '';
// Minor Edit
- @ $tmp = $row-> {
- $prefix . '_minor_edit' };
+ @ $tmp = $row-> { $prefix . '_minor_edit' };
if (is_null($tmp))
- @ $tmp = $row-> {
- $prefix . '_minor' };
+ @ $tmp = $row-> { $prefix . '_minor' };
if (!is_null($tmp) && $tmp)
$vals['minor'] = '';
// Timestamp
- @ $tmp = $row-> {
- $prefix . '_timestamp' };
+ @ $tmp = $row-> { $prefix . '_timestamp' };
if (!is_null($tmp))
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $tmp);
// Comment
- @ $tmp = $row-> {
- $prefix . '_comment' };
+ @ $tmp = $row-> { $prefix . '_comment' };
if (!empty ($tmp)) // optimize bandwidth
$vals['comment'] = $tmp;
return $vals;
}
- protected static function addTitleInfo(&$arr, $title) {
- $arr['ns'] = $title->getNamespace();
- $arr['title'] = $title->getPrefixedText();
+ protected static function addTitleInfo(&$arr, $title, $prefix='') {
+ $arr[$prefix . 'ns'] = $title->getNamespace();
+ $arr[$prefix . 'title'] = $title->getPrefixedText();
+ if (!$title->userCanRead())
+ $arr[$prefix . 'inaccessible'] = "";
}
private static function addRowInfo_title($row, $nsfld, $titlefld) {