14use Wikimedia\Timestamp\TimestampFormat as TS;
24 parent::__construct( $query, $moduleName,
'cl' );
38 $this->run( $resultPageSet );
44 private function run( $resultPageSet =
null ) {
46 if ( $pages === [] ) {
51 $prop = array_fill_keys( (array)$params[
'prop'],
true );
52 $show = array_fill_keys( (array)$params[
'show'],
true );
54 $this->
addFields( [
'cl_from',
'lt_title' ] );
55 $this->
addFieldsIf( [
'cl_sortkey',
'cl_sortkey_prefix' ], isset( $prop[
'sortkey'] ) );
56 $this->
addFieldsIf(
'cl_timestamp', isset( $prop[
'timestamp'] ) );
60 $this->
addJoinConds( [
'linktarget' => [
'JOIN',
'cl_target_id = lt_id ' ] ] );
62 $this->
addWhereFld(
'cl_from', array_keys( $pages ) );
64 if ( $params[
'categories'] ) {
66 foreach ( $params[
'categories'] as $cat ) {
67 $title = Title::newFromText( $cat );
68 if ( !$title || $title->getNamespace() !==
NS_CATEGORY ) {
71 $cats[] = $title->getDBkey();
81 if ( $params[
'continue'] !==
null ) {
84 $op =
$params[
'dir'] ==
'descending' ?
'<=' :
'>=';
85 $this->
addWhere( $db->buildComparison( $op, [
86 'cl_from' => $cont[0],
87 'lt_title' => $cont[1],
91 if ( isset( $show[
'hidden'] ) && isset( $show[
'!hidden'] ) ) {
94 if ( isset( $show[
'hidden'] ) || isset( $show[
'!hidden'] ) || isset( $prop[
'hidden'] ) ) {
96 $this->
addTables( [
'page',
'page_props' ] );
97 $this->
addFieldsIf(
'pp_propname', isset( $prop[
'hidden'] ) );
99 'page' => [
'LEFT JOIN', [
101 'page_title = lt_title' ] ],
102 'page_props' => [
'LEFT JOIN', [
104 'pp_propname' =>
'hiddencat' ] ]
106 if ( isset( $show[
'hidden'] ) ) {
107 $this->
addWhere( $this->
getDB()->expr(
'pp_propname',
'!=',
null ) );
108 } elseif ( isset( $show[
'!hidden'] ) ) {
109 $this->
addWhere( [
'pp_propname' =>
null ] );
113 $sort = (
$params[
'dir'] ==
'descending' ?
' DESC' :
'' );
115 if ( count( $pages ) === 1 ) {
116 $this->
addOption(
'ORDER BY',
'lt_title' . $sort );
123 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
125 $res = $this->
select( __METHOD__ );
128 if ( $resultPageSet ===
null ) {
129 foreach ( $res as $row ) {
130 if ( ++$count > $params[
'limit'] ) {
140 if ( isset( $prop[
'sortkey'] ) ) {
141 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
142 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
144 if ( isset( $prop[
'timestamp'] ) ) {
145 $vals[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->cl_timestamp );
147 if ( isset( $prop[
'hidden'] ) ) {
148 $vals[
'hidden'] = $row->pp_propname !==
null;
159 foreach ( $res as $row ) {
160 if ( ++$count > $params[
'limit'] ) {
169 $resultPageSet->populateFromTitles( $titles );
177 ParamValidator::PARAM_ISMULTI =>
true,
178 ParamValidator::PARAM_TYPE => [
186 ParamValidator::PARAM_ISMULTI =>
true,
187 ParamValidator::PARAM_TYPE => [
193 ParamValidator::PARAM_DEFAULT => 10,
194 ParamValidator::PARAM_TYPE =>
'limit',
195 IntegerDef::PARAM_MIN => 1,
203 ParamValidator::PARAM_ISMULTI =>
true,
206 ParamValidator::PARAM_DEFAULT =>
'ascending',
207 ParamValidator::PARAM_TYPE => [
218 'action=query&prop=categories&titles=Albert%20Einstein'
219 =>
'apihelp-query+categories-example-simple',
220 'action=query&generator=categories&titles=Albert%20Einstein&prop=info'
221 =>
'apihelp-query+categories-example-generator',
227 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categories';
232class_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.