37 private int $migrationStage;
40 parent::__construct( $query, $moduleName,
'cl' );
41 $this->migrationStage = $query->
getConfig()->get(
55 $this->run( $resultPageSet );
61 private function run( $resultPageSet =
null ) {
63 if ( $pages === [] ) {
68 $prop = array_fill_keys( (array)$params[
'prop'],
true );
69 $show = array_fill_keys( (array)$params[
'show'],
true );
71 $this->
addFieldsIf( [
'cl_sortkey',
'cl_sortkey_prefix' ], isset( $prop[
'sortkey'] ) );
72 $this->
addFieldsIf(
'cl_timestamp', isset( $prop[
'timestamp'] ) );
76 $titleField =
'cl_to';
79 $this->
addJoinConds( [
'linktarget' => [
'JOIN',
'cl_target_id = lt_id ' ] ] );
81 $titleField =
'lt_title';
87 $this->
addWhereFld(
'cl_from', array_keys( $pages ) );
88 if ( $params[
'categories'] ) {
90 foreach ( $params[
'categories'] as $cat ) {
91 $title = Title::newFromText( $cat );
92 if ( !$title || $title->getNamespace() !==
NS_CATEGORY ) {
95 $cats[] = $title->getDBkey();
105 if ( $params[
'continue'] !==
null ) {
106 $db = $this->
getDB();
108 $op =
$params[
'dir'] ==
'descending' ?
'<=' :
'>=';
109 $this->
addWhere( $db->buildComparison( $op, [
110 'cl_from' => $cont[0],
111 $titleField => $cont[1],
115 if ( isset( $show[
'hidden'] ) && isset( $show[
'!hidden'] ) ) {
118 if ( isset( $show[
'hidden'] ) || isset( $show[
'!hidden'] ) || isset( $prop[
'hidden'] ) ) {
120 $this->
addTables( [
'page',
'page_props' ] );
121 $this->
addFieldsIf(
'pp_propname', isset( $prop[
'hidden'] ) );
123 'page' => [
'LEFT JOIN', [
125 'page_title = ' . $titleField ] ],
126 'page_props' => [
'LEFT JOIN', [
128 'pp_propname' =>
'hiddencat' ] ]
130 if ( isset( $show[
'hidden'] ) ) {
131 $this->
addWhere( $this->
getDB()->expr(
'pp_propname',
'!=',
null ) );
132 } elseif ( isset( $show[
'!hidden'] ) ) {
133 $this->
addWhere( [
'pp_propname' =>
null ] );
137 $sort = (
$params[
'dir'] ==
'descending' ?
' DESC' :
'' );
139 if ( count( $pages ) === 1 ) {
140 $this->
addOption(
'ORDER BY', $titleField . $sort );
147 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
149 $res = $this->
select( __METHOD__ );
152 if ( $resultPageSet ===
null ) {
153 foreach ( $res as $row ) {
154 if ( ++$count > $params[
'limit'] ) {
161 $title = Title::makeTitle(
NS_CATEGORY, $row->$titleField );
164 if ( isset( $prop[
'sortkey'] ) ) {
165 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
166 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
168 if ( isset( $prop[
'timestamp'] ) ) {
169 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
171 if ( isset( $prop[
'hidden'] ) ) {
172 $vals[
'hidden'] = $row->pp_propname !==
null;
183 foreach ( $res as $row ) {
184 if ( ++$count > $params[
'limit'] ) {
191 $titles[] = Title::makeTitle(
NS_CATEGORY, $row->$titleField );
193 $resultPageSet->populateFromTitles( $titles );
200 ParamValidator::PARAM_ISMULTI =>
true,
201 ParamValidator::PARAM_TYPE => [
209 ParamValidator::PARAM_ISMULTI =>
true,
210 ParamValidator::PARAM_TYPE => [
216 ParamValidator::PARAM_DEFAULT => 10,
217 ParamValidator::PARAM_TYPE =>
'limit',
218 IntegerDef::PARAM_MIN => 1,
226 ParamValidator::PARAM_ISMULTI =>
true,
229 ParamValidator::PARAM_DEFAULT =>
'ascending',
230 ParamValidator::PARAM_TYPE => [
240 'action=query&prop=categories&titles=Albert%20Einstein'
241 =>
'apihelp-query+categories-example-simple',
242 'action=query&generator=categories&titles=Albert%20Einstein&prop=info'
243 =>
'apihelp-query+categories-example-generator',
248 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categories';
253class_alias( ApiQueryCategories::class,
'ApiQueryCategories' );
const SCHEMA_COMPAT_READ_OLD
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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()