40 private int $migrationStage;
47 parent::__construct( $query, $moduleName,
'cm' );
49 $this->migrationStage = $query->
getConfig()->get(
63 $this->run( $resultPageSet );
70 private function validateHexSortkey( $hexSortkey ) {
72 return (
bool)preg_match(
'/^(?:[a-fA-F0-9]{2})*$/D', $hexSortkey );
79 private function run( $resultPageSet =
null ) {
83 if ( $categoryTitle->getNamespace() !==
NS_CATEGORY ) {
87 $prop = array_fill_keys( $params[
'prop'],
true );
88 $fld_ids = isset( $prop[
'ids'] );
89 $fld_title = isset( $prop[
'title'] );
90 $fld_sortkey = isset( $prop[
'sortkey'] );
91 $fld_sortkeyprefix = isset( $prop[
'sortkeyprefix'] );
92 $fld_timestamp = isset( $prop[
'timestamp'] );
93 $fld_type = isset( $prop[
'type'] );
95 if ( $resultPageSet ===
null ) {
96 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type',
'page_namespace',
'page_title' ] );
98 $this->
addFieldsIf(
'cl_sortkey_prefix', $fld_sortkeyprefix );
100 $this->
addFields( $resultPageSet->getPageTableFields() );
101 $this->
addFields( [
'cl_from',
'cl_sortkey',
'cl_type' ] );
104 $this->
addFieldsIf(
'cl_timestamp', $fld_timestamp || $params[
'sort'] ==
'timestamp' );
106 $this->
addTables( [
'page',
'categorylinks' ] );
108 $this->
addWhereFld(
'cl_to', $categoryTitle->getDBkey() );
111 $this->
addJoinConds( [
'linktarget' => [
'JOIN',
'cl_target_id = lt_id ' ] ] );
114 'lt_title' => $categoryTitle->getDBkey(),
125 $miser_ns =
$params[
'namespace'] ?: [];
127 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
130 $dir = in_array( $params[
'dir'], [
'asc',
'ascending',
'newer' ] ) ?
'newer' :
'older';
132 if ( $params[
'sort'] ==
'timestamp' ) {
140 if ( $params[
'continue'] !==
null ) {
142 $op = ( $dir ===
'newer' ?
'>=' :
'<=' );
143 $db = $this->
getDB();
144 $this->
addWhere( $db->buildComparison( $op, [
145 'cl_timestamp' => $db->timestamp( $cont[0] ),
146 'cl_from' => $cont[1],
150 $this->
addOption(
'USE INDEX', [
'categorylinks' =>
'cl_timestamp' ] );
152 if ( $params[
'continue'] ) {
156 $contTypeIndex = array_search( $cont[0], $queryTypes );
157 $queryTypes = array_slice( $queryTypes, $contTypeIndex );
161 $op = $dir ==
'newer' ?
'>=' :
'<=';
163 $contWhere = $this->
getDB()->buildComparison( $op, [
164 'cl_sortkey' => hex2bin( $cont[1] ),
165 'cl_from' => $cont[2],
171 if ( $params[
'startsortkeyprefix'] !==
null ) {
172 $startsortkey = $this->collation->getSortKey( $params[
'startsortkeyprefix'] );
173 } elseif ( $params[
'starthexsortkey'] !==
null ) {
174 if ( !$this->validateHexSortkey( $params[
'starthexsortkey'] ) ) {
176 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
178 $startsortkey = hex2bin( $params[
'starthexsortkey'] );
180 $startsortkey =
$params[
'startsortkey'];
182 if ( $params[
'endsortkeyprefix'] !==
null ) {
183 $endsortkey = $this->collation->getSortKey( $params[
'endsortkeyprefix'] );
184 } elseif ( $params[
'endhexsortkey'] !==
null ) {
185 if ( !$this->validateHexSortkey( $params[
'endhexsortkey'] ) ) {
187 $this->
dieWithError( [
'apierror-badparameter', $encParamName ],
"badvalue_$encParamName" );
189 $endsortkey = hex2bin( $params[
'endhexsortkey'] );
191 $endsortkey =
$params[
'endsortkey'];
201 $this->
addOption(
'USE INDEX', [
'categorylinks' =>
'cl_sortkey' ] );
204 $this->
addWhere(
'cl_from=page_id' );
209 if ( $params[
'sort'] ==
'sortkey' ) {
217 foreach ( $queryTypes as $type ) {
218 $extraConds = [
'cl_type' => $type ];
219 if ( $first && $contWhere ) {
222 $extraConds[] = $contWhere;
224 $res = $this->
select( __METHOD__, [
'where' => $extraConds ] );
225 if ( $type ===
'page' && $resultPageSet ===
null ) {
228 $rows = array_merge( $rows, iterator_to_array( $res ) );
229 if ( count( $rows ) >= $limit + 1 ) {
238 $res = $this->
select( __METHOD__ );
239 if ( $resultPageSet ===
null ) {
242 $rows = iterator_to_array( $res );
247 foreach ( $rows as $row ) {
248 if ( ++$count > $limit ) {
253 if ( $params[
'sort'] ==
'timestamp' ) {
256 $this->
getDB()->timestamp( $row->cl_timestamp ) .
"|$row->cl_from"
259 $sortkey = bin2hex( $row->cl_sortkey );
261 "{$row->cl_type}|$sortkey|{$row->cl_from}"
271 if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
275 if ( $resultPageSet ===
null ) {
280 $vals[
'pageid'] = (int)$row->page_id;
283 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
286 if ( $fld_sortkey ) {
287 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
289 if ( $fld_sortkeyprefix ) {
290 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
293 $vals[
'type'] = $row->cl_type;
295 if ( $fld_timestamp ) {
296 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
298 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
301 if ( $params[
'sort'] ==
'timestamp' ) {
304 $this->
getDB()->timestamp( $row->cl_timestamp ) .
"|$row->cl_from"
307 $sortkey = bin2hex( $row->cl_sortkey );
309 "{$row->cl_type}|$sortkey|{$row->cl_from}"
315 $resultPageSet->processDbRow( $row );
319 if ( $resultPageSet ===
null ) {
320 $result->addIndexedTagName(
328 ParamValidator::PARAM_TYPE =>
'string',
331 ParamValidator::PARAM_TYPE =>
'integer'
334 ParamValidator::PARAM_DEFAULT =>
'ids|title',
335 ParamValidator::PARAM_ISMULTI =>
true,
336 ParamValidator::PARAM_TYPE => [
347 ParamValidator::PARAM_ISMULTI =>
true,
348 ParamValidator::PARAM_TYPE =>
'namespace',
351 ParamValidator::PARAM_ISMULTI =>
true,
352 ParamValidator::PARAM_DEFAULT =>
'page|subcat|file',
353 ParamValidator::PARAM_TYPE => [
363 ParamValidator::PARAM_TYPE =>
'limit',
364 ParamValidator::PARAM_DEFAULT => 10,
365 IntegerDef::PARAM_MIN => 1,
370 ParamValidator::PARAM_DEFAULT =>
'sortkey',
371 ParamValidator::PARAM_TYPE => [
377 ParamValidator::PARAM_DEFAULT =>
'ascending',
378 ParamValidator::PARAM_TYPE => [
389 ParamValidator::PARAM_TYPE =>
'timestamp'
392 ParamValidator::PARAM_TYPE =>
'timestamp'
394 'starthexsortkey' =>
null,
395 'endhexsortkey' =>
null,
396 'startsortkeyprefix' =>
null,
397 'endsortkeyprefix' =>
null,
399 ParamValidator::PARAM_DEPRECATED =>
true,
402 ParamValidator::PARAM_DEPRECATED =>
true,
408 'api-help-param-limited-in-miser-mode',
417 'action=query&list=categorymembers&cmtitle=Category:Physics'
418 =>
'apihelp-query+categorymembers-example-simple',
419 'action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info'
420 =>
'apihelp-query+categorymembers-example-generator',
425 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categorymembers';
430class_alias( ApiQueryCategoryMembers::class,
'ApiQueryCategoryMembers' );
const SCHEMA_COMPAT_READ_OLD
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 CategoryLinksSchemaMigrationStage
Name constant for the CategoryLinksSchemaMigrationStage setting, for use with Config::get()
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()