18use Wikimedia\Timestamp\TimestampFormat as TS;
34 parent::__construct( $query, $moduleName,
'cm' );
49 $this->run( $resultPageSet );
56 private function validateHexSortkey( $hexSortkey ) {
58 return (
bool)preg_match(
'/^(?:[a-fA-F0-9]{2})*$/D', $hexSortkey );
65 private function run( $resultPageSet =
null ) {
69 if ( $categoryTitle->getNamespace() !==
NS_CATEGORY ) {
73 $prop = array_fill_keys( $params[
'prop'],
true );
74 $fld_ids = isset( $prop[
'ids'] );
75 $fld_title = isset( $prop[
'title'] );
76 $fld_sortkey = isset( $prop[
'sortkey'] );
77 $fld_sortkeyprefix = isset( $prop[
'sortkeyprefix'] );
78 $fld_timestamp = isset( $prop[
'timestamp'] );
79 $fld_type = isset( $prop[
'type'] );
84 if ( $resultPageSet ===
null ) {
85 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type',
'page_namespace',
'page_title' ] );
87 $this->
addFieldsIf(
'cl_sortkey_prefix', $fld_sortkeyprefix );
89 $this->
addFields( $resultPageSet->getPageTableFields() );
90 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type' ] );
93 $this->
addFieldsIf(
'cl_timestamp', $fld_timestamp || $params[
'sort'] ==
'timestamp' );
95 $this->
addTables( [
'page',
'categorylinks',
'linktarget' ] );
96 $this->
addJoinConds( [
'categorylinks' => [
'JOIN',
'cl_from=page_id' ] ] );
97 $this->
addJoinConds( [
'linktarget' => [
'JOIN',
'cl_target_id = lt_id ' ] ] );
100 'lt_title' => $categoryTitle->getDBkey(),
110 $miser_ns =
$params[
'namespace'] ?: [];
112 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
115 $dir = in_array( $params[
'dir'], [
'asc',
'ascending',
'newer' ] ) ?
'newer' :
'older';
117 if ( $params[
'sort'] ==
'timestamp' ) {
125 if ( $params[
'continue'] !==
null ) {
127 $op = ( $dir ===
'newer' ?
'>=' :
'<=' );
128 $this->
addWhere( $db->buildComparison( $op, [
129 'cl_timestamp' => $db->timestamp( $cont[0] ),
130 'cl_from' => $cont[1],
134 if ( $params[
'continue'] ) {
138 $contTypeIndex = array_search( $cont[0], $queryTypes );
139 $queryTypes = array_slice( $queryTypes, $contTypeIndex );
143 $op = $dir ==
'newer' ?
'>=' :
'<=';
145 $contWhere = $db->buildComparison( $op, [
146 'cl_sortkey' => hex2bin( $cont[1] ),
147 'cl_from' => $cont[2],
153 if ( $params[
'startsortkeyprefix'] !==
null ) {
154 $startsortkey = $this->collation->getSortKey( $params[
'startsortkeyprefix'] );
155 } elseif ( $params[
'starthexsortkey'] !==
null ) {
156 if ( !$this->validateHexSortkey( $params[
'starthexsortkey'] ) ) {
158 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
160 $startsortkey = hex2bin( $params[
'starthexsortkey'] );
162 $startsortkey =
$params[
'startsortkey'];
164 if ( $params[
'endsortkeyprefix'] !==
null ) {
165 $endsortkey = $this->collation->getSortKey( $params[
'endsortkeyprefix'] );
166 } elseif ( $params[
'endhexsortkey'] !==
null ) {
167 if ( !$this->validateHexSortkey( $params[
'endhexsortkey'] ) ) {
169 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
171 $endsortkey = hex2bin( $params[
'endhexsortkey'] );
173 $endsortkey =
$params[
'endsortkey'];
183 $this->
addOption(
'USE INDEX', [
'categorylinks' =>
'cl_sortkey_id' ] );
189 if ( $params[
'sort'] ==
'sortkey' ) {
197 foreach ( $queryTypes as $type ) {
198 $extraConds = [
'cl_type' => $type ];
199 if ( $first && $contWhere ) {
202 $extraConds[] = $contWhere;
204 $res = $this->
select( __METHOD__, [
'where' => $extraConds ] );
205 if ( $type ===
'page' && $resultPageSet ===
null ) {
208 $rows = array_merge( $rows, iterator_to_array( $res ) );
209 if ( count( $rows ) >= $limit + 1 ) {
218 $res = $this->
select( __METHOD__ );
219 if ( $resultPageSet ===
null ) {
222 $rows = iterator_to_array( $res );
227 foreach ( $rows as $row ) {
228 if ( ++$count > $limit ) {
233 if ( $params[
'sort'] ==
'timestamp' ) {
236 $db->timestamp( $row->cl_timestamp ) .
"|$row->cl_from"
239 $sortkey = bin2hex( $row->cl_sortkey );
241 "{$row->cl_type}|$sortkey|{$row->cl_from}"
251 if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
255 if ( $resultPageSet ===
null ) {
260 $vals[
'pageid'] = (int)$row->page_id;
266 if ( $fld_sortkey ) {
267 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
269 if ( $fld_sortkeyprefix ) {
270 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
273 $vals[
'type'] = $row->cl_type;
275 if ( $fld_timestamp ) {
276 $vals[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->cl_timestamp );
278 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
281 if ( $params[
'sort'] ==
'timestamp' ) {
284 $db->timestamp( $row->cl_timestamp ) .
"|$row->cl_from"
287 $sortkey = bin2hex( $row->cl_sortkey );
289 "{$row->cl_type}|$sortkey|{$row->cl_from}"
295 $resultPageSet->processDbRow( $row );
299 if ( $resultPageSet ===
null ) {
300 $result->addIndexedTagName(
309 ParamValidator::PARAM_TYPE =>
'string',
312 ParamValidator::PARAM_TYPE =>
'integer'
315 ParamValidator::PARAM_DEFAULT =>
'ids|title',
316 ParamValidator::PARAM_ISMULTI =>
true,
317 ParamValidator::PARAM_TYPE => [
328 ParamValidator::PARAM_ISMULTI =>
true,
329 ParamValidator::PARAM_TYPE =>
'namespace',
332 ParamValidator::PARAM_ISMULTI =>
true,
333 ParamValidator::PARAM_DEFAULT =>
'page|subcat|file',
334 ParamValidator::PARAM_TYPE => [
344 ParamValidator::PARAM_TYPE =>
'limit',
345 ParamValidator::PARAM_DEFAULT => 10,
346 IntegerDef::PARAM_MIN => 1,
351 ParamValidator::PARAM_DEFAULT =>
'sortkey',
352 ParamValidator::PARAM_TYPE => [
358 ParamValidator::PARAM_DEFAULT =>
'ascending',
359 ParamValidator::PARAM_TYPE => [
370 ParamValidator::PARAM_TYPE =>
'timestamp'
373 ParamValidator::PARAM_TYPE =>
'timestamp'
375 'starthexsortkey' =>
null,
376 'endhexsortkey' =>
null,
377 'startsortkeyprefix' =>
null,
378 'endsortkeyprefix' =>
null,
380 ParamValidator::PARAM_DEPRECATED =>
true,
383 ParamValidator::PARAM_DEPRECATED =>
true,
389 'api-help-param-limited-in-miser-mode',
399 'action=query&list=categorymembers&cmtitle=Category:Physics'
400 =>
'apihelp-query+categorymembers-example-simple',
401 'action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info'
402 =>
'apihelp-query+categorymembers-example-generator',
408 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categorymembers';
413class_alias( ApiQueryCategoryMembers::class,
'ApiQueryCategoryMembers' );
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
A class containing constants representing the names of configuration variables.
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()