37 parent::__construct( $query, $moduleName,
'cl' );
49 $this->
run( $resultPageSet );
55 private function run( $resultPageSet =
null ) {
57 if ( $pages === [] ) {
62 $prop = array_fill_keys( (array)
$params[
'prop'],
true );
63 $show = array_fill_keys( (array)
$params[
'show'],
true );
70 $this->
addFieldsIf( [
'cl_sortkey',
'cl_sortkey_prefix' ], isset( $prop[
'sortkey'] ) );
71 $this->
addFieldsIf(
'cl_timestamp', isset( $prop[
'timestamp'] ) );
74 $this->
addWhereFld(
'cl_from', array_keys( $pages ) );
77 foreach (
$params[
'categories'] as $cat ) {
78 $title = Title::newFromText( $cat );
79 if ( !$title || $title->getNamespace() !==
NS_CATEGORY ) {
82 $cats[] = $title->getDBkey();
92 if (
$params[
'continue'] !==
null ) {
95 $op =
$params[
'dir'] ==
'descending' ?
'<=' :
'>=';
96 $this->
addWhere( $db->buildComparison( $op, [
97 'cl_from' => $cont[0],
102 if ( isset( $show[
'hidden'] ) && isset( $show[
'!hidden'] ) ) {
105 if ( isset( $show[
'hidden'] ) || isset( $show[
'!hidden'] ) || isset( $prop[
'hidden'] ) ) {
107 $this->
addTables( [
'page',
'page_props' ] );
108 $this->
addFieldsIf(
'pp_propname', isset( $prop[
'hidden'] ) );
110 'page' => [
'LEFT JOIN', [
112 'page_title = cl_to' ] ],
113 'page_props' => [
'LEFT JOIN', [
115 'pp_propname' =>
'hiddencat' ] ]
117 if ( isset( $show[
'hidden'] ) ) {
118 $this->
addWhere( $this->
getDB()->expr(
'pp_propname',
'!=',
null ) );
119 } elseif ( isset( $show[
'!hidden'] ) ) {
120 $this->
addWhere( [
'pp_propname' =>
null ] );
124 $sort = (
$params[
'dir'] ==
'descending' ?
' DESC' :
'' );
126 if ( count( $pages ) === 1 ) {
127 $this->
addOption(
'ORDER BY',
'cl_to' . $sort );
136 $res = $this->
select( __METHOD__ );
139 if ( $resultPageSet ===
null ) {
140 foreach ( $res as $row ) {
141 if ( ++$count >
$params[
'limit'] ) {
148 $title = Title::makeTitle(
NS_CATEGORY, $row->cl_to );
151 if ( isset( $prop[
'sortkey'] ) ) {
152 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
153 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
155 if ( isset( $prop[
'timestamp'] ) ) {
156 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
158 if ( isset( $prop[
'hidden'] ) ) {
159 $vals[
'hidden'] = $row->pp_propname !==
null;
170 foreach ( $res as $row ) {
171 if ( ++$count >
$params[
'limit'] ) {
178 $titles[] = Title::makeTitle(
NS_CATEGORY, $row->cl_to );
180 $resultPageSet->populateFromTitles( $titles );
187 ParamValidator::PARAM_ISMULTI =>
true,
188 ParamValidator::PARAM_TYPE => [
196 ParamValidator::PARAM_ISMULTI =>
true,
197 ParamValidator::PARAM_TYPE => [
203 ParamValidator::PARAM_DEFAULT => 10,
204 ParamValidator::PARAM_TYPE =>
'limit',
205 IntegerDef::PARAM_MIN => 1,
213 ParamValidator::PARAM_ISMULTI =>
true,
216 ParamValidator::PARAM_DEFAULT =>
'ascending',
217 ParamValidator::PARAM_TYPE => [
227 'action=query&prop=categories&titles=Albert%20Einstein'
228 =>
'apihelp-query+categories-example-simple',
229 'action=query&generator=categories&titles=Albert%20Einstein&prop=info'
230 =>
'apihelp-query+categories-example-generator',
235 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categories';
240class_alias( ApiQueryCategories::class,
'ApiQueryCategories' );
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.
array $params
The job parameters.