41 parent::__construct( $query, $moduleName,
'cl' );
53 $this->
run( $resultPageSet );
59 private function run( $resultPageSet =
null ) {
61 if ( $pages === [] ) {
66 $prop = array_fill_keys( (array)
$params[
'prop'],
true );
67 $show = array_fill_keys( (array)
$params[
'show'],
true );
74 $this->
addFieldsIf( [
'cl_sortkey',
'cl_sortkey_prefix' ], isset( $prop[
'sortkey'] ) );
75 $this->
addFieldsIf(
'cl_timestamp', isset( $prop[
'timestamp'] ) );
78 $this->
addWhereFld(
'cl_from', array_keys( $pages ) );
81 foreach (
$params[
'categories'] as $cat ) {
82 $title = Title::newFromText( $cat );
83 if ( !$title || $title->getNamespace() !==
NS_CATEGORY ) {
86 $cats[] = $title->getDBkey();
96 if (
$params[
'continue'] !==
null ) {
99 $op =
$params[
'dir'] ==
'descending' ?
'<=' :
'>=';
100 $this->
addWhere( $db->buildComparison( $op, [
101 'cl_from' => $cont[0],
106 if ( isset( $show[
'hidden'] ) && isset( $show[
'!hidden'] ) ) {
109 if ( isset( $show[
'hidden'] ) || isset( $show[
'!hidden'] ) || isset( $prop[
'hidden'] ) ) {
111 $this->
addTables( [
'page',
'page_props' ] );
112 $this->
addFieldsIf(
'pp_propname', isset( $prop[
'hidden'] ) );
114 'page' => [
'LEFT JOIN', [
116 'page_title = cl_to' ] ],
117 'page_props' => [
'LEFT JOIN', [
119 'pp_propname' =>
'hiddencat' ] ]
121 if ( isset( $show[
'hidden'] ) ) {
122 $this->
addWhere( $this->
getDB()->expr(
'pp_propname',
'!=',
null ) );
123 } elseif ( isset( $show[
'!hidden'] ) ) {
124 $this->
addWhere( [
'pp_propname' =>
null ] );
128 $sort = (
$params[
'dir'] ==
'descending' ?
' DESC' :
'' );
130 if ( count( $pages ) === 1 ) {
131 $this->
addOption(
'ORDER BY',
'cl_to' . $sort );
140 $res = $this->
select( __METHOD__ );
143 if ( $resultPageSet ===
null ) {
144 foreach ( $res as $row ) {
145 if ( ++$count >
$params[
'limit'] ) {
152 $title = Title::makeTitle(
NS_CATEGORY, $row->cl_to );
155 if ( isset( $prop[
'sortkey'] ) ) {
156 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
157 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
159 if ( isset( $prop[
'timestamp'] ) ) {
160 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
162 if ( isset( $prop[
'hidden'] ) ) {
163 $vals[
'hidden'] = $row->pp_propname !==
null;
174 foreach ( $res as $row ) {
175 if ( ++$count >
$params[
'limit'] ) {
182 $titles[] = Title::makeTitle(
NS_CATEGORY, $row->cl_to );
184 $resultPageSet->populateFromTitles( $titles );
191 ParamValidator::PARAM_ISMULTI =>
true,
192 ParamValidator::PARAM_TYPE => [
200 ParamValidator::PARAM_ISMULTI =>
true,
201 ParamValidator::PARAM_TYPE => [
207 ParamValidator::PARAM_DEFAULT => 10,
208 ParamValidator::PARAM_TYPE =>
'limit',
209 IntegerDef::PARAM_MIN => 1,
217 ParamValidator::PARAM_ISMULTI =>
true,
220 ParamValidator::PARAM_DEFAULT =>
'ascending',
221 ParamValidator::PARAM_TYPE => [
231 'action=query&prop=categories&titles=Albert%20Einstein'
232 =>
'apihelp-query+categories-example-simple',
233 'action=query&generator=categories&titles=Albert%20Einstein&prop=info'
234 =>
'apihelp-query+categories-example-generator',
239 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categories';
244class_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.