46 parent::__construct( $query, $moduleName,
'cm' );
59 $this->
run( $resultPageSet );
66 private function validateHexSortkey( $hexSortkey ) {
68 return (
bool)preg_match(
'/^(?:[a-fA-F0-9]{2})*$/D', $hexSortkey );
75 private function run( $resultPageSet =
null ) {
79 if ( $categoryTitle->getNamespace() !==
NS_CATEGORY ) {
83 $prop = array_fill_keys(
$params[
'prop'],
true );
84 $fld_ids = isset( $prop[
'ids'] );
85 $fld_title = isset( $prop[
'title'] );
86 $fld_sortkey = isset( $prop[
'sortkey'] );
87 $fld_sortkeyprefix = isset( $prop[
'sortkeyprefix'] );
88 $fld_timestamp = isset( $prop[
'timestamp'] );
89 $fld_type = isset( $prop[
'type'] );
91 if ( $resultPageSet ===
null ) {
92 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type',
'page_namespace',
'page_title' ] );
94 $this->
addFieldsIf(
'cl_sortkey_prefix', $fld_sortkeyprefix );
96 $this->
addFields( $resultPageSet->getPageTableFields() );
97 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type' ] );
100 $this->
addFieldsIf(
'cl_timestamp', $fld_timestamp ||
$params[
'sort'] ==
'timestamp' );
102 $this->
addTables( [
'page',
'categorylinks' ] );
104 $this->
addWhereFld(
'cl_to', $categoryTitle->getDBkey() );
112 $miser_ns =
$params[
'namespace'] ?: [];
117 $dir = in_array(
$params[
'dir'], [
'asc',
'ascending',
'newer' ] ) ?
'newer' :
'older';
119 if (
$params[
'sort'] ==
'timestamp' ) {
127 if (
$params[
'continue'] !==
null ) {
129 $op = ( $dir ===
'newer' ?
'>=' :
'<=' );
130 $db = $this->
getDB();
131 $this->
addWhere( $db->buildComparison( $op, [
132 'cl_timestamp' => $db->timestamp( $cont[0] ),
133 'cl_from' => $cont[1],
137 $this->
addOption(
'USE INDEX', [
'categorylinks' =>
'cl_timestamp' ] );
143 $contTypeIndex = array_search( $cont[0], $queryTypes );
144 $queryTypes = array_slice( $queryTypes, $contTypeIndex );
148 $op = $dir ==
'newer' ?
'>=' :
'<=';
150 $contWhere = $this->
getDB()->buildComparison( $op, [
151 'cl_sortkey' => hex2bin( $cont[1] ),
152 'cl_from' => $cont[2],
158 if (
$params[
'startsortkeyprefix'] !==
null ) {
159 $startsortkey = $this->collation->getSortKey(
$params[
'startsortkeyprefix'] );
160 } elseif (
$params[
'starthexsortkey'] !==
null ) {
161 if ( !$this->validateHexSortkey(
$params[
'starthexsortkey'] ) ) {
163 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
165 $startsortkey = hex2bin(
$params[
'starthexsortkey'] );
167 $startsortkey =
$params[
'startsortkey'];
169 if (
$params[
'endsortkeyprefix'] !==
null ) {
170 $endsortkey = $this->collation->getSortKey(
$params[
'endsortkeyprefix'] );
171 } elseif (
$params[
'endhexsortkey'] !==
null ) {
172 if ( !$this->validateHexSortkey(
$params[
'endhexsortkey'] ) ) {
174 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
176 $endsortkey = hex2bin(
$params[
'endhexsortkey'] );
178 $endsortkey =
$params[
'endsortkey'];
188 $this->
addOption(
'USE INDEX', [
'categorylinks' =>
'cl_sortkey' ] );
191 $this->
addWhere(
'cl_from=page_id' );
196 if (
$params[
'sort'] ==
'sortkey' ) {
204 foreach ( $queryTypes as $type ) {
205 $extraConds = [
'cl_type' => $type ];
206 if ( $first && $contWhere ) {
209 $extraConds[] = $contWhere;
211 $res = $this->
select( __METHOD__, [
'where' => $extraConds ] );
212 if ( $type ===
'page' && $resultPageSet ===
null ) {
215 $rows = array_merge( $rows, iterator_to_array( $res ) );
216 if ( count( $rows ) >= $limit + 1 ) {
225 $res = $this->
select( __METHOD__ );
226 if ( $resultPageSet ===
null ) {
229 $rows = iterator_to_array( $res );
234 foreach ( $rows as $row ) {
235 if ( ++$count > $limit ) {
240 if (
$params[
'sort'] ==
'timestamp' ) {
243 $this->
getDB()->timestamp( $row->cl_timestamp ) .
"|$row->cl_from"
246 $sortkey = bin2hex( $row->cl_sortkey );
248 "{$row->cl_type}|$sortkey|{$row->cl_from}"
258 if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
262 if ( $resultPageSet ===
null ) {
267 $vals[
'pageid'] = (int)$row->page_id;
270 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
273 if ( $fld_sortkey ) {
274 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
276 if ( $fld_sortkeyprefix ) {
277 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
280 $vals[
'type'] = $row->cl_type;
282 if ( $fld_timestamp ) {
283 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
285 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
288 if (
$params[
'sort'] ==
'timestamp' ) {
291 $this->
getDB()->timestamp( $row->cl_timestamp ) .
"|$row->cl_from"
294 $sortkey = bin2hex( $row->cl_sortkey );
296 "{$row->cl_type}|$sortkey|{$row->cl_from}"
302 $resultPageSet->processDbRow( $row );
306 if ( $resultPageSet ===
null ) {
307 $result->addIndexedTagName(
315 ParamValidator::PARAM_TYPE =>
'string',
318 ParamValidator::PARAM_TYPE =>
'integer'
321 ParamValidator::PARAM_DEFAULT =>
'ids|title',
322 ParamValidator::PARAM_ISMULTI =>
true,
323 ParamValidator::PARAM_TYPE => [
334 ParamValidator::PARAM_ISMULTI =>
true,
335 ParamValidator::PARAM_TYPE =>
'namespace',
338 ParamValidator::PARAM_ISMULTI =>
true,
339 ParamValidator::PARAM_DEFAULT =>
'page|subcat|file',
340 ParamValidator::PARAM_TYPE => [
350 ParamValidator::PARAM_TYPE =>
'limit',
351 ParamValidator::PARAM_DEFAULT => 10,
352 IntegerDef::PARAM_MIN => 1,
357 ParamValidator::PARAM_DEFAULT =>
'sortkey',
358 ParamValidator::PARAM_TYPE => [
364 ParamValidator::PARAM_DEFAULT =>
'ascending',
365 ParamValidator::PARAM_TYPE => [
376 ParamValidator::PARAM_TYPE =>
'timestamp'
379 ParamValidator::PARAM_TYPE =>
'timestamp'
381 'starthexsortkey' =>
null,
382 'endhexsortkey' =>
null,
383 'startsortkeyprefix' =>
null,
384 'endsortkeyprefix' =>
null,
386 ParamValidator::PARAM_DEPRECATED =>
true,
389 ParamValidator::PARAM_DEPRECATED =>
true,
395 'api-help-param-limited-in-miser-mode',
404 'action=query&list=categorymembers&cmtitle=Category:Physics'
405 =>
'apihelp-query+categorymembers-example-simple',
406 'action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info'
407 =>
'apihelp-query+categorymembers-example-generator',
412 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categorymembers';
417class_alias( ApiQueryCategoryMembers::class,
'ApiQueryCategoryMembers' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.
A class containing constants representing the names of configuration variables.
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()