if (is_array($desc))
$desc = implode($paramPrefix, $desc);
- if (isset ($paramSettings[self :: PARAM_TYPE])) {
+ @ $type = $paramSettings[self :: PARAM_TYPE];
+ if (isset ($type)) {
if (isset ($paramSettings[self :: PARAM_ISMULTI]))
- $prompt = 'Multiple "|"-separated values: ';
+ $prompt = 'Values (separate with \'|\'): ';
else
- $prompt = 'Any one of these values: ';
- $type = $paramSettings[self :: PARAM_TYPE];
- if (is_array($type))
+ $prompt = 'One value: ';
+
+ if (is_array($type)) {
$desc .= $paramPrefix . $prompt . implode(', ', $type);
+ }
+ elseif ($type == 'namespace') {
+ // Special handling because namespaces are type-limited, yet they are not given
+ $desc .= $paramPrefix . $prompt . implode(', ', ApiBase :: getValidNamespaces());
+ }
}
$default = is_array($paramSettings) ? (isset ($paramSettings[self :: PARAM_DFLT]) ? $paramSettings[self :: PARAM_DFLT] : null) : $paramSettings;
return $this->getParameterFromSettings($paramName, $paramSettings);
}
+ public static function getValidNamespaces() {
+ static $mValidNamespaces = null;
+ if (is_null($mValidNamespaces)) {
+
+ global $wgContLang;
+ $mValidNamespaces = array ();
+ foreach (array_keys($wgContLang->getNamespaces()) as $ns) {
+ if ($ns >= 0)
+ $mValidNamespaces[] = $ns;
+ }
+ }
+ return $mValidNamespaces;
+ }
+
/**
* Using the settings determine the value for the given parameter
* @param $paramName String: parameter name
$value = $this->getMain()->getRequest()->getCheck($paramName);
} else {
$value = $this->getMain()->getRequest()->getVal($paramName, $default);
+
+ if (isset ($value) && $type == 'namespace')
+ $type = ApiBase :: getValidNamespaces();
}
if (isset ($value) && ($multi || is_array($type)))
return 'api.php?action=query&meta=siteinfo&siprop=namespaces&format=' . $this->getModuleName();
}
+ protected function getDescription() {
+ return $this->getIsHtml() ? ' (pretty-print in HTML)' : '';
+ }
+
public static function getBaseVersion() {
return __CLASS__ . ': $Id$';
}
wfHttpError(500, 'Internal Server Error', '');
}
}
-
+
public function getVersion() {
return __CLASS__ . ': $Id$';
}
class ApiFormatJson extends ApiFormatBase {
private $mIsRaw;
-
+
public function __construct($main, $format) {
parent :: __construct($main, $format);
- $this->mIsRaw = ($format === 'raw' || $format === 'rawfm');
+ $this->mIsRaw = ($format === 'rawfm');
}
public function getMimeType() {
return 'application/json';
}
-
+
public function getNeedsRawData() {
return $this->mIsRaw;
}
-
+
public function execute() {
if (!function_exists('json_encode') || $this->getIsHtml()) {
$json = new Services_JSON();
}
protected function getDescription() {
- return 'Output data in JSON format';
+ if ($this->mIsRaw)
+ return 'Output data with the debuging elements in JSON format' . parent :: getDescription();
+ else
+ return 'Output data in JSON format' . parent :: getDescription();
}
public function getVersion() {
}
protected function getDescription() {
- return 'Output data in serialized PHP format';
+ return 'Output data in serialized PHP format' . parent :: getDescription();
}
public function getVersion() {
}
protected function getDescription() {
- return 'Output data in WDDX format';
+ return 'Output data in WDDX format' . parent :: getDescription();
}
public function getVersion() {
}
public function execute() {
- $xmlindent = null;
- extract($this->extractRequestParams());
-
- if ($xmlindent || $this->getIsHtml())
- $xmlindent = -2;
- else
- $xmlindent = null;
-
$this->printText('<?xml version="1.0" encoding="utf-8"?>');
- $this->recXmlPrint($this->mRootElemName, $this->getResultData(), $xmlindent);
+ $this->recXmlPrint($this->mRootElemName, $this->getResultData(), $this->getIsHtml() ? -2 : null);
}
/**
}
}
protected function getDescription() {
- return 'Output data in XML format';
- }
-
- protected function getAllowedParams() {
- return array (
- 'xmlindent' => false
- );
- }
-
- protected function getParamDescription() {
- return array (
- 'xmlindent' => 'Enable XML indentation'
- );
+ return 'Output data in XML format' . parent :: getDescription();
}
public function getVersion() {
}
protected function getDescription() {
- return 'Output data in YAML format';
+ return 'Output data in YAML format' . parent :: getDescription();
}
public function getVersion() {
'xmlfm' => 'ApiFormatXml',
'yaml' => 'ApiFormatYaml',
'yamlfm' => 'ApiFormatYaml',
- 'raw' => 'ApiFormatJson',
'rawfm' => 'ApiFormatJson'
);
private $mPropModuleNames, $mListModuleNames, $mMetaModuleNames;
private $mPageSet;
- private $mValidNamespaces;
private $mQueryPropModules = array (
'info' => 'ApiQueryInfo',
$this->mPropModuleNames = array_keys($this->mQueryPropModules);
$this->mListModuleNames = array_keys($this->mQueryListModules);
$this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
- $this->mValidNamespaces = null;
// Allow the entire list of modules at first,
// but during module instantiation check if it can be used as a generator.
return $this->mPageSet;
}
- public function getValidNamespaces() {
- global $wgContLang;
-
- if (is_null($this->mValidNamespaces)) {
- $this->mValidNamespaces = array ();
- foreach (array_keys($wgContLang->getNamespaces()) as $ns) {
- if ($ns >= 0)
- $this->mValidNamespaces[] = $ns; // strval($ns);
- }
- }
- return $this->mValidNamespaces;
- }
-
/**
* Query execution happens in the following steps:
* #1 Create a PageSet object with any pages requested by the user
extract($this->extractRequestParams());
$this->addTables('page');
- if( !$this->addWhereIf('page_is_redirect = 1', $filterredir === 'redirects'))
+ if (!$this->addWhereIf('page_is_redirect = 1', $filterredir === 'redirects'))
$this->addWhereIf('page_is_redirect = 0', $filterredir === 'nonredirects');
$this->addWhereFld('page_namespace', $namespace);
if (isset ($from))
$this->addWhere("page_title LIKE '{$db->strencode(ApiQueryBase :: titleToKey($prefix))}%'");
if (is_null($resultPageSet)) {
- $this->addFields( array (
+ $this->addFields(array (
'page_id',
'page_namespace',
'page_title'
));
} else {
- $this->addFields( $resultPageSet->getPageTableFields());
+ $this->addFields($resultPageSet->getPageTableFields());
}
- $this->addOption( 'USE INDEX', 'name_title');
- $this->addOption( 'LIMIT', $limit +1);
- $this->addOption( 'ORDER BY', 'page_namespace, page_title');
+ $this->addOption('USE INDEX', 'name_title');
+ $this->addOption('LIMIT', $limit +1);
+ $this->addOption('ORDER BY', 'page_namespace, page_title');
wfProfileOut($this->getModuleProfileName() . '-parseParams');
if (is_null($resultPageSet)) {
$vals = $this->addRowInfo('page', $row);
- if($vals)
+ if ($vals)
$data[intval($row->page_id)] = $vals;
} else {
$resultPageSet->processDbRow($row);
$result->setIndexedTagName($data, 'p');
$result->addValue('query', $this->getModuleName(), $data);
}
-
+
wfProfileOut($this->getModuleProfileName() . '-saveResults');
}
protected function getAllowedParams() {
- $namespaces = $this->getQuery()->getValidNamespaces();
return array (
'from' => null,
'prefix' => null,
'namespace' => array (
ApiBase :: PARAM_DFLT => 0,
- ApiBase :: PARAM_TYPE => $namespaces
+ ApiBase :: PARAM_TYPE => 'namespace'
),
'filterredir' => array (
ApiBase :: PARAM_DFLT => 'all',
protected function getAllowedParams() {
- $namespaces = $this->getQuery()->getValidNamespaces();
return array (
'continue' => null,
'namespace' => array (
ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => $namespaces
+ ApiBase :: PARAM_TYPE => 'namespace'
),
'redirect' => false,
'limit' => array (
}
protected function getDescription() {
- return 'Find all pages that link to the given page';
+ switch ($this->getModuleName()) {
+ case 'backlinks' :
+ return 'Find all pages that link to the given page';
+ case 'embeddedin' :
+ return 'Find all pages that embed (transclude) the given title';
+ case 'imagelinks' :
+ return 'Find all pages that use the given image title.';
+ default :
+ ApiBase :: dieDebug(__METHOD__, 'Unknown module name');
+ }
}
protected function getExamples() {
$this->mQueryModule = $query;
$this->resetQueryParams();
}
-
+
protected function resetQueryParams() {
$this->tables = array ();
$this->where = array ();
- $this->fields = array();
+ $this->fields = array ();
$this->options = array ();
}
protected function addTables($value) {
- if(is_array($value))
+ if (is_array($value))
$this->tables = array_merge($this->tables, $value);
else
$this->tables[] = $value;
}
-
- protected function addFields($value) {
- if(is_array($value))
+
+ protected function addFields($value) {
+ if (is_array($value))
$this->fields = array_merge($this->fields, $value);
else
$this->fields[] = $value;
}
return false;
}
-
+
protected function addWhere($value) {
- if(is_array($value))
+ if (is_array($value))
$this->where = array_merge($this->where, $value);
else
$this->where[] = $value;
}
-
+
protected function addWhereIf($value, $condition) {
if ($condition) {
$this->addWhere($value);
}
protected function addWhereFld($field, $value) {
- if(!is_null($value))
+ if (!is_null($value))
$this->where[$field] = $value;
}
protected function addWhereRange($field, $dir, $start, $end) {
$isDirNewer = ($dir === 'newer');
- $after = ($isDirNewer ? '<=' : '>=');
- $before = ($isDirNewer ? '>=' : '<=');
+ $after = ($isDirNewer ? '>=' : '<=');
+ $before = ($isDirNewer ? '<=' : '>=');
$db = & $this->getDB();
if (!is_null($start))
if (!is_null($end))
$this->addWhere($field . $before . $db->addQuotes($end));
-
+
$this->addOption('ORDER BY', $field . ($isDirNewer ? '' : ' DESC'));
}
-
+
protected function addOption($name, $value = null) {
if (is_null($value))
$this->options[] = $name;
else
$this->options[$name] = $value;
}
-
+
protected function select($method) {
-
+
// getDB has its own profileDBIn/Out calls
- $db = & $this->getDB();
-
+ $db = & $this->getDB();
+
$this->profileDBIn();
$res = $db->select($this->tables, $this->fields, $this->where, $method, $this->options);
$this->profileDBOut();
-
+
return $res;
}
-
protected function addRowInfo($prefix, $row) {
- $vals = array();
-
+ $vals = array ();
+
// ID
- @$tmp = $row->{$prefix . '_id'};
- if(!is_null($tmp)) $vals[$prefix . 'id'] = intval($tmp);
+ @ $tmp = $row-> {
+ $prefix . '_id' };
+ if (!is_null($tmp))
+ $vals[$prefix . 'id'] = intval($tmp);
// Title
- $title = ApiQueryBase::addRowInfo_title($row, $prefix . '_namespace', $prefix . '_title');
+ $title = ApiQueryBase :: addRowInfo_title($row, $prefix . '_namespace', $prefix . '_title');
if ($title) {
if (!$title->userCanRead())
return false;
$vals['title'] = $title->getPrefixedText();
}
- switch($prefix) {
+ switch ($prefix) {
- case 'page':
+ case 'page' :
// page_is_redirect
- @$tmp = $row->page_is_redirect;
- if($tmp) $vals['redirect'] = '';
+ @ $tmp = $row->page_is_redirect;
+ if ($tmp)
+ $vals['redirect'] = '';
break;
- case 'rc':
+ case 'rc' :
// PageId
- @$tmp = $row->rc_cur_id;
- if(!is_null($tmp)) $vals['pageid'] = intval($tmp);
-
- @$tmp = $row->rc_this_oldid;
- if(!is_null($tmp)) $vals['revid'] = intval($tmp);
-
- @$tmp = $row->rc_last_oldid;
- if(!is_null($tmp)) $vals['old_revid'] = intval($tmp);
-
- $title = ApiQueryBase::addRowInfo_title($row, 'rc_moved_to_ns', 'rc_moved_to_title');
+ @ $tmp = $row->rc_cur_id;
+ if (!is_null($tmp))
+ $vals['pageid'] = intval($tmp);
+
+ @ $tmp = $row->rc_this_oldid;
+ if (!is_null($tmp))
+ $vals['revid'] = intval($tmp);
+
+ @ $tmp = $row->rc_last_oldid;
+ if (!is_null($tmp))
+ $vals['old_revid'] = intval($tmp);
+
+ $title = ApiQueryBase :: addRowInfo_title($row, 'rc_moved_to_ns', 'rc_moved_to_title');
if ($title) {
if (!$title->userCanRead())
return false;
$vals['new_ns'] = $title->getNamespace();
$vals['new_title'] = $title->getPrefixedText();
- }
-
- @$tmp = $row->rc_patrolled;
- if(!is_null($tmp)) $vals['patrolled'] = '';
+ }
+
+ @ $tmp = $row->rc_patrolled;
+ if (!is_null($tmp))
+ $vals['patrolled'] = '';
break;
- case 'log':
+ case 'log' :
// PageId
- @$tmp = $row->page_id;
- if(!is_null($tmp)) $vals['pageid'] = intval($tmp);
-
+ @ $tmp = $row->page_id;
+ if (!is_null($tmp))
+ $vals['pageid'] = intval($tmp);
+
if ($row->log_params !== '') {
$params = explode("\n", $row->log_params);
if ($row->log_type == 'move' && isset ($params[0])) {
$params = null;
}
}
-
+
if (!empty ($params)) {
$this->getResult()->setIndexedTagName($params, 'param');
$vals = array_merge($vals, $params);
break;
- case 'rev':
+ case 'rev' :
// PageID
- @$tmp = $row->rev_page;
- if (!is_null($tmp)) $vals['pageid'] = intval($tmp);
+ @ $tmp = $row->rev_page;
+ if (!is_null($tmp))
+ $vals['pageid'] = intval($tmp);
}
// Type
- @$tmp = $row->{$prefix . '_type'};
- if(!is_null($tmp)) $vals['type'] = $tmp;
+ @ $tmp = $row-> {
+ $prefix . '_type' };
+ if (!is_null($tmp))
+ $vals['type'] = $tmp;
// Action
- @$tmp = $row->{$prefix . '_action'};
- if(!is_null($tmp)) $vals['action'] = $tmp;
-
+ @ $tmp = $row-> {
+ $prefix . '_action' };
+ if (!is_null($tmp))
+ $vals['action'] = $tmp;
+
// Old ID
- @$tmp = $row->{$prefix . '_text_id'};
- if(!is_null($tmp)) $vals['oldid'] = intval($tmp);
+ @ $tmp = $row-> {
+ $prefix . '_text_id' };
+ if (!is_null($tmp))
+ $vals['oldid'] = intval($tmp);
// User Name / Anon IP
- @$tmp = $row->{$prefix . '_user_text'};
- if(is_null($tmp)) @$tmp = $row->user_name;
- if(!is_null($tmp)) {
+ @ $tmp = $row-> {
+ $prefix . '_user_text' };
+ if (is_null($tmp))
+ @ $tmp = $row->user_name;
+ if (!is_null($tmp)) {
$vals['user'] = $tmp;
- @$tmp = !$row->{$prefix . '_user'};
- if(!is_null($tmp) && $tmp)
+ @ $tmp = !$row-> {
+ $prefix . '_user' };
+ if (!is_null($tmp) && $tmp)
$vals['anon'] = '';
}
-
+
// Bot Edit
- @$tmp = $row->{$prefix . '_bot'};
- if(!is_null($tmp) && $tmp) $vals['bot'] = '';
-
+ @ $tmp = $row-> {
+ $prefix . '_bot' };
+ if (!is_null($tmp) && $tmp)
+ $vals['bot'] = '';
+
// New Edit
- @$tmp = $row->{$prefix . '_new'};
- if(is_null($tmp)) @$tmp = $row->{$prefix . '_is_new'};
- if(!is_null($tmp) && $tmp) $vals['new'] = '';
-
+ @ $tmp = $row-> {
+ $prefix . '_new' };
+ if (is_null($tmp))
+ @ $tmp = $row-> {
+ $prefix . '_is_new' };
+ if (!is_null($tmp) && $tmp)
+ $vals['new'] = '';
+
// Minor Edit
- @$tmp = $row->{$prefix . '_minor_edit'};
- if(is_null($tmp)) @$tmp = $row->{$prefix . '_minor'};
- if(!is_null($tmp) && $tmp) $vals['minor'] = '';
-
+ @ $tmp = $row-> {
+ $prefix . '_minor_edit' };
+ if (is_null($tmp))
+ @ $tmp = $row-> {
+ $prefix . '_minor' };
+ if (!is_null($tmp) && $tmp)
+ $vals['minor'] = '';
+
// Timestamp
- @$tmp = $row->{$prefix . '_timestamp'};
- if(!is_null($tmp))
+ @ $tmp = $row-> {
+ $prefix . '_timestamp' };
+ if (!is_null($tmp))
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $tmp);
// Comment
- @$tmp = $row->{$prefix . '_comment'};
- if(!empty($tmp)) // optimize bandwidth
+ @ $tmp = $row-> {
+ $prefix . '_comment' };
+ if (!empty ($tmp)) // optimize bandwidth
$vals['comment'] = $tmp;
-
+
return $vals;
- }
+ }
private static function addRowInfo_title($row, $nsfld, $titlefld) {
- @$ns = $row->$nsfld;
- if(!is_null($ns)) {
- @$title = $row->$titlefld;
- if(!empty($title))
+ @ $ns = $row-> $nsfld;
+ if (!is_null($ns)) {
+ @ $title = $row-> $titlefld;
+ if (!empty ($title))
return Title :: makeTitle($ns, $title);
}
return false;
//Get a database instance
$db = & $this->getDB();
+ if (is_null($user))
+ $this->dieUsage("User parameter may not be empty", 'param_user');
$userid = $db->selectField('user', 'user_id', array (
'user_name' => $user
));
protected function getExamples() {
return array (
- 'api.php?action=query&list=usercontribs&ucuser=Werdna'
+ 'api.php?action=query&list=usercontribs&ucuser=YurikBot'
);
}
protected function getAllowedParams() {
return array (
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
- ),
'type' => array (
ApiBase :: PARAM_ISMULTI => true,
ApiBase :: PARAM_TYPE => array (
)
),
'user' => null,
- 'title' => null
+ 'title' => null,
+ 'limit' => array (
+ ApiBase :: PARAM_DFLT => 10,
+ ApiBase :: PARAM_TYPE => 'limit',
+ ApiBase :: PARAM_MIN => 1,
+ ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ )
);
}
protected function getParamDescription() {
return array (
- 'limit' => '',
- 'type' => '',
- 'start' => '',
- 'end' => '',
- 'dir' => '',
- 'user' => '',
- 'title' => ''
+ 'type' => 'Filter log entries to only this type(s)',
+ 'start' => 'The timestamp to start enumerating from.',
+ 'end' => 'The timestamp to end enumerating.',
+ 'dir' => 'In which direction to enumerate.',
+ 'user' => 'Filter entries to those made by the given user.',
+ 'title' => 'Filter entries to those related to a page.',
+ 'limit' => 'How many total event entries to return.'
);
}
}
protected function getAllowedParams() {
- $namespaces = $this->getQuery()->getValidNamespaces();
return array (
+ 'start' => array (
+ ApiBase :: PARAM_TYPE => 'timestamp'
+ ),
+ 'end' => array (
+ ApiBase :: PARAM_TYPE => 'timestamp'
+ ),
'dir' => array (
ApiBase :: PARAM_DFLT => 'older',
ApiBase :: PARAM_TYPE => array (
'older'
)
),
- 'start' => array (
- ApiBase :: PARAM_TYPE => 'timestamp'
- ),
- 'end' => array (
- ApiBase :: PARAM_TYPE => 'timestamp'
- ),
'namespace' => array (
- ApiBase :: PARAM_DFLT => 0,
- ApiBase :: PARAM_TYPE => $namespaces
+ ApiBase :: PARAM_ISMULTI => true,
+ ApiBase :: PARAM_TYPE => 'namespace'
),
'prop' => array (
ApiBase :: PARAM_ISMULTI => true,
return array (
'start' => 'The timestamp to start enumerating from.',
'end' => 'The timestamp to end enumerating.',
+ 'dir' => 'In which direction to enumerate.',
+ 'namespace' => 'Filter log entries to only this namespace(s)',
+ 'prop' => 'Include additional pieces of information',
+ 'hide' => 'Hide certain changes (minor edits, bots, anonymous, logged-in-users)',
'limit' => 'How many total pages to return.'
);
}
// The order needs to be the same as start parameter to avoid SQL filesort.
if (is_null($startid))
- $this->addWhereRange('rev_id', $dir, $startid, $endid);
- else
$this->addWhereRange('rev_timestamp', $dir, $start, $end);
+ else
+ $this->addWhereRange('rev_id', $dir, $startid, $endid);
// must manually initialize unset limit
if (is_null($limit))
while ($row = $db->fetchObject($res)) {
if (++ $count > $limit) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
- $this->setContinueEnumParameter('from', $row->rc_timestamp);
+ $this->setContinueEnumParameter('start', $row->rc_timestamp);
break;
}
}
protected function getAllowedParams() {
- $namespaces = $this->getQuery()->getValidNamespaces();
return array (
'allrev' => false,
'start' => array (
),
'namespace' => array (
ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => $namespaces
+ ApiBase :: PARAM_TYPE => 'namespace'
),
'dir' => array (
ApiBase :: PARAM_DFLT => 'older',