51 parent::__construct( $query, $moduleName,
'qp' );
52 $this->queryPages = array_values( array_diff(
56 $this->specialPageFactory = $specialPageFactory;
64 $this->
run( $resultPageSet );
71 private function getSpecialPage( $name ):
QueryPage {
72 $qp = $this->specialPageFactory->getPage( $name );
76 'SpecialPageFactory failed to create special page ' . $name
79 if ( !( $qp instanceof QueryPage ) ) {
82 'Special page ' . $name .
' is not a QueryPage'
92 public function run( $resultPageSet =
null ) {
93 $params = $this->extractRequestParams();
94 $result = $this->getResult();
96 $qp = $this->getSpecialPage(
$params[
'page'] );
97 if ( !$qp->userCanExecute( $this->getUser() ) ) {
98 $this->dieWithError(
'apierror-specialpage-cantexecute' );
101 if ( $resultPageSet ===
null ) {
102 $r = [
'name' =>
$params[
'page'] ];
103 if ( $qp->isCached() ) {
104 if ( !$qp->isCacheable() ) {
105 $r[
'disabled'] =
true;
108 $ts = $qp->getCachedTimestamp();
110 $r[
'cachedtimestamp'] =
wfTimestamp( TS_ISO_8601, $ts );
115 $result->addValue( [
'query' ], $this->getModuleName(), $r );
118 if ( $qp->isCached() && !$qp->isCacheable() ) {
126 foreach ( $res as $row ) {
127 if ( ++$count >
$params[
'limit'] ) {
129 $this->setContinueEnumParameter(
'offset',
$params[
'offset'] +
$params[
'limit'] );
133 $title = Title::makeTitle( $row->namespace, $row->title );
134 if ( $resultPageSet ===
null ) {
136 if ( isset( $row->value ) ) {
137 $data[
'value'] = $row->value;
138 if ( $qp->usesTimestamps() ) {
139 $data[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->value );
142 self::addTitleInfo( $data, $title );
144 foreach ( $row as $field => $value ) {
145 if ( !in_array( $field, [
'namespace',
'title',
'value',
'qc_type' ] ) ) {
146 $data[
'databaseResult'][$field] = $value;
150 $fit = $result->addValue( [
'query', $this->getModuleName(),
'results' ],
null, $data );
152 $this->setContinueEnumParameter(
'offset',
$params[
'offset'] + $count - 1 );
159 if ( $resultPageSet ===
null ) {
160 $result->addIndexedTagName(
161 [
'query', $this->getModuleName(),
'results' ],
165 $resultPageSet->populateFromTitles( $titles );
170 $qp = $this->getSpecialPage(
$params[
'page'] );
171 if ( $qp->getRestriction() !=
'' ) {
181 ParamValidator::PARAM_TYPE => $this->queryPages,
182 ParamValidator::PARAM_REQUIRED => true
185 ParamValidator::PARAM_DEFAULT => 0,
189 ParamValidator::PARAM_DEFAULT => 10,
190 ParamValidator::PARAM_TYPE =>
'limit',
191 IntegerDef::PARAM_MIN => 1,
200 'action=query&list=querypage&qppage=Ancientpages'
201 =>
'apihelp-query+querypage-example-ancientpages',
206 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Querypage';
211class_alias( ApiQueryQueryPage::class,
'ApiQueryQueryPage' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.
Query module to get the results of a QueryPage-based special page.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
__construct(ApiQuery $query, string $moduleName, SpecialPageFactory $specialPageFactory)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getExamplesMessages()
Returns usage examples for this module.
run( $resultPageSet=null)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
executeGenerator( $resultPageSet)
Execute this module as a generator.
A class containing constants representing the names of configuration variables.
const QueryCacheLimit
Name constant for the QueryCacheLimit setting, for use with Config::get()
const APIUselessQueryPages
Name constant for the APIUselessQueryPages setting, for use with Config::get()
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
static getPages()
Get a list of query page classes and their associated special pages, for periodic updates.
Factory for handling the special page list and generating SpecialPage objects.