45 parent::__construct( $query, $moduleName,
'cm' );
58 $this->
run( $resultPageSet );
67 return (
bool)preg_match(
'/^(?:[a-fA-F0-9]{2})*$/D', $hexSortkey );
74 private function run( $resultPageSet =
null ) {
78 if ( $categoryTitle->getNamespace() !==
NS_CATEGORY ) {
82 $prop = array_fill_keys( $params[
'prop'],
true );
83 $fld_ids = isset( $prop[
'ids'] );
84 $fld_title = isset( $prop[
'title'] );
85 $fld_sortkey = isset( $prop[
'sortkey'] );
86 $fld_sortkeyprefix = isset( $prop[
'sortkeyprefix'] );
87 $fld_timestamp = isset( $prop[
'timestamp'] );
88 $fld_type = isset( $prop[
'type'] );
90 if ( $resultPageSet ===
null ) {
91 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type',
'page_namespace',
'page_title' ] );
93 $this->
addFieldsIf(
'cl_sortkey_prefix', $fld_sortkeyprefix );
95 $this->
addFields( $resultPageSet->getPageTableFields() );
96 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type' ] );
99 $this->
addFieldsIf(
'cl_timestamp', $fld_timestamp || $params[
'sort'] ==
'timestamp' );
101 $this->
addTables( [
'page',
'categorylinks' ] );
103 $this->
addWhereFld(
'cl_to', $categoryTitle->getDBkey() );
104 $queryTypes = $params[
'type'];
110 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
111 $miser_ns = $params[
'namespace'] ?: [];
113 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
116 $dir = in_array( $params[
'dir'], [
'asc',
'ascending',
'newer' ] ) ?
'newer' :
'older';
118 if ( $params[
'sort'] ==
'timestamp' ) {
126 if ( $params[
'continue'] !==
null ) {
127 $cont = explode(
'|', $params[
'continue'] );
129 $op = ( $dir ===
'newer' ?
'>' :
'<' );
130 $db = $this->
getDB();
131 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
132 $continueFrom = (int)$cont[1];
134 $this->
addWhere(
"cl_timestamp $op $continueTimestamp OR " .
135 "(cl_timestamp = $continueTimestamp AND " .
136 "cl_from $op= $continueFrom)"
140 $this->
addOption(
'USE INDEX',
'cl_timestamp' );
142 if ( $params[
'continue'] ) {
143 $cont = explode(
'|', $params[
'continue'], 3 );
147 $contTypeIndex = array_search( $cont[0], $queryTypes );
148 $queryTypes = array_slice( $queryTypes, $contTypeIndex );
152 $escSortkey = $this->
getDB()->addQuotes( hex2bin( $cont[1] ) );
153 $from = (int)$cont[2];
154 $op = $dir ==
'newer' ?
'>' :
'<';
156 $contWhere =
"cl_sortkey $op $escSortkey OR " .
157 "(cl_sortkey = $escSortkey AND " .
158 "cl_from $op= $from)";
163 if ( $params[
'startsortkeyprefix'] !==
null ) {
164 $startsortkey = $this->collation->getSortKey( $params[
'startsortkeyprefix'] );
165 } elseif ( $params[
'starthexsortkey'] !==
null ) {
168 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
170 $startsortkey = hex2bin( $params[
'starthexsortkey'] );
172 $startsortkey = $params[
'startsortkey'];
174 if ( $params[
'endsortkeyprefix'] !==
null ) {
175 $endsortkey = $this->collation->getSortKey( $params[
'endsortkeyprefix'] );
176 } elseif ( $params[
'endhexsortkey'] !==
null ) {
179 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
181 $endsortkey = hex2bin( $params[
'endhexsortkey'] );
183 $endsortkey = $params[
'endsortkey'];
193 $this->
addOption(
'USE INDEX',
'cl_sortkey' );
196 $this->
addWhere(
'cl_from=page_id' );
198 $limit = $params[
'limit'];
201 if ( $params[
'sort'] ==
'sortkey' ) {
209 foreach ( $queryTypes as
$type ) {
210 $extraConds = [
'cl_type' =>
$type ];
211 if ( $first && $contWhere ) {
214 $extraConds[] = $contWhere;
216 $res = $this->
select( __METHOD__, [
'where' => $extraConds ] );
217 if (
$type ===
'page' && $resultPageSet ===
null ) {
220 $rows = array_merge( $rows, iterator_to_array(
$res ) );
221 if ( count( $rows ) >= $limit + 1 ) {
231 if ( $resultPageSet ===
null ) {
234 $rows = iterator_to_array(
$res );
239 foreach ( $rows as $row ) {
240 if ( ++$count > $limit ) {
245 if ( $params[
'sort'] ==
'timestamp' ) {
248 $sortkey = bin2hex( $row->cl_sortkey );
250 "{$row->cl_type}|$sortkey|{$row->cl_from}"
260 if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
264 if ( $resultPageSet ===
null ) {
266 ApiResult::META_TYPE =>
'assoc',
269 $vals[
'pageid'] = (int)$row->page_id;
272 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
275 if ( $fld_sortkey ) {
276 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
278 if ( $fld_sortkeyprefix ) {
279 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
282 $vals[
'type'] = $row->cl_type;
284 if ( $fld_timestamp ) {
285 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
287 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
290 if ( $params[
'sort'] ==
'timestamp' ) {
293 $sortkey = bin2hex( $row->cl_sortkey );
295 "{$row->cl_type}|$sortkey|{$row->cl_from}"
301 $resultPageSet->processDbRow( $row );
305 if ( $resultPageSet ===
null ) {
306 $result->addIndexedTagName(
380 'starthexsortkey' =>
null,
381 'endhexsortkey' =>
null,
382 'startsortkeyprefix' =>
null,
383 'endsortkeyprefix' =>
null,
392 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
394 'api-help-param-limited-in-miser-mode',
403 'action=query&list=categorymembers&cmtitle=Category:Physics'
404 =>
'apihelp-query+categorymembers-example-simple',
405 'action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info'
406 =>
'apihelp-query+categorymembers-example-generator',
411 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categorymembers';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const LIMIT_BIG1
Fast query, standard limit.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
A query module to enumerate pages that belong to a category.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, CollationFactory $collationFactory)
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
validateHexSortkey( $hexSortkey)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
encodeParamName( $paramName)
Overrides ApiBase to prepend 'g' to every generator parameter.
This is the main query class.