39 parent::__construct( $query, $moduleName,
'cl' );
51 $this->
run( $resultPageSet );
57 private function run( $resultPageSet =
null ) {
59 if ( $pages === [] ) {
64 $prop = array_fill_keys( (array)
$params[
'prop'],
true );
65 $show = array_fill_keys( (array)
$params[
'show'],
true );
72 $this->
addFieldsIf( [
'cl_sortkey',
'cl_sortkey_prefix' ], isset( $prop[
'sortkey'] ) );
73 $this->
addFieldsIf(
'cl_timestamp', isset( $prop[
'timestamp'] ) );
76 $this->
addWhereFld(
'cl_from', array_keys( $pages ) );
79 foreach (
$params[
'categories'] as $cat ) {
80 $title = Title::newFromText( $cat );
81 if ( !$title || $title->getNamespace() !==
NS_CATEGORY ) {
84 $cats[] = $title->getDBkey();
94 if (
$params[
'continue'] !==
null ) {
97 $op =
$params[
'dir'] ==
'descending' ?
'<=' :
'>=';
98 $this->
addWhere( $db->buildComparison( $op, [
99 'cl_from' => $cont[0],
104 if ( isset( $show[
'hidden'] ) && isset( $show[
'!hidden'] ) ) {
107 if ( isset( $show[
'hidden'] ) || isset( $show[
'!hidden'] ) || isset( $prop[
'hidden'] ) ) {
109 $this->
addTables( [
'page',
'page_props' ] );
110 $this->
addFieldsIf(
'pp_propname', isset( $prop[
'hidden'] ) );
112 'page' => [
'LEFT JOIN', [
114 'page_title = cl_to' ] ],
115 'page_props' => [
'LEFT JOIN', [
117 'pp_propname' =>
'hiddencat' ] ]
119 if ( isset( $show[
'hidden'] ) ) {
120 $this->
addWhere( [
'pp_propname IS NOT NULL' ] );
121 } elseif ( isset( $show[
'!hidden'] ) ) {
122 $this->
addWhere( [
'pp_propname' =>
null ] );
126 $sort = (
$params[
'dir'] ==
'descending' ?
' DESC' :
'' );
128 if ( count( $pages ) === 1 ) {
129 $this->
addOption(
'ORDER BY',
'cl_to' . $sort );
138 $res = $this->
select( __METHOD__ );
141 if ( $resultPageSet ===
null ) {
142 foreach ( $res as $row ) {
143 if ( ++$count >
$params[
'limit'] ) {
150 $title = Title::makeTitle(
NS_CATEGORY, $row->cl_to );
153 if ( isset( $prop[
'sortkey'] ) ) {
154 $vals[
'sortkey'] = bin2hex( $row->cl_sortkey );
155 $vals[
'sortkeyprefix'] = $row->cl_sortkey_prefix;
157 if ( isset( $prop[
'timestamp'] ) ) {
158 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
160 if ( isset( $prop[
'hidden'] ) ) {
161 $vals[
'hidden'] = $row->pp_propname !==
null;
172 foreach ( $res as $row ) {
173 if ( ++$count >
$params[
'limit'] ) {
180 $titles[] = Title::makeTitle(
NS_CATEGORY, $row->cl_to );
182 $resultPageSet->populateFromTitles( $titles );
189 ParamValidator::PARAM_ISMULTI =>
true,
190 ParamValidator::PARAM_TYPE => [
198 ParamValidator::PARAM_ISMULTI =>
true,
199 ParamValidator::PARAM_TYPE => [
205 ParamValidator::PARAM_DEFAULT => 10,
206 ParamValidator::PARAM_TYPE =>
'limit',
207 IntegerDef::PARAM_MIN => 1,
215 ParamValidator::PARAM_ISMULTI =>
true,
218 ParamValidator::PARAM_DEFAULT =>
'ascending',
219 ParamValidator::PARAM_TYPE => [
229 'action=query&prop=categories&titles=Albert%20Einstein'
230 =>
'apihelp-query+categories-example-simple',
231 'action=query&generator=categories&titles=Albert%20Einstein&prop=info'
232 =>
'apihelp-query+categories-example-generator',
237 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categories';
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.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
const LIMIT_BIG2
Fast query, apihighlimits limit.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
addFields( $value)
Add a set of fields to select to the internal array.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
A query module to enumerate categories the set of pages belong to.
executeGenerator( $resultPageSet)
Execute this module as a generator.
__construct(ApiQuery $query, $moduleName)
getHelpUrls()
Return links to more detailed help pages about the module.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
getPageSet()
Get the PageSet object to work on.
This is the main query class.