17use Wikimedia\Timestamp\TimestampFormat as TS;
38 parent::__construct( $query, $moduleName,
'qp' );
39 $this->queryPages = array_values( array_diff(
43 $this->specialPageFactory = $specialPageFactory;
52 $this->
run( $resultPageSet );
59 private function getSpecialPage( $name ):
QueryPage {
60 $qp = $this->specialPageFactory->getPage( $name );
64 'SpecialPageFactory failed to create special page ' . $name
67 if ( !( $qp instanceof QueryPage ) ) {
70 'Special page ' . $name .
' is not a QueryPage'
80 public function run( $resultPageSet =
null ) {
81 $params = $this->extractRequestParams();
82 $result = $this->getResult();
84 $qp = $this->getSpecialPage( $params[
'page'] );
85 if ( !$qp->userCanExecute( $this->getUser() ) ) {
86 $this->dieWithError(
'apierror-specialpage-cantexecute' );
89 if ( $resultPageSet ===
null ) {
90 $r = [
'name' => $params[
'page'] ];
91 if ( $qp->isCached() ) {
92 if ( !$qp->isCacheable() ) {
93 $r[
'disabled'] =
true;
96 $ts = $qp->getCachedTimestamp();
98 $r[
'cachedtimestamp'] =
wfTimestamp( TS::ISO_8601, $ts );
103 $result->addValue( [
'query' ], $this->getModuleName(), $r );
106 if ( $qp->isCached() && !$qp->isCacheable() ) {
111 $res = $qp->doQuery( $params[
'offset'], $params[
'limit'] + 1 );
114 foreach ( $res as $row ) {
115 if ( ++$count > $params[
'limit'] ) {
117 $this->setContinueEnumParameter(
'offset', $params[
'offset'] + $params[
'limit'] );
122 if ( $resultPageSet ===
null ) {
124 if ( isset( $row->value ) ) {
125 $data[
'value'] = $row->value;
126 if ( $qp->usesTimestamps() ) {
127 $data[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->value );
130 self::addTitleInfo( $data, $title );
132 foreach ( $row as $field => $value ) {
133 if ( !in_array( $field, [
'namespace',
'title',
'value',
'qc_type' ] ) ) {
134 $data[
'databaseResult'][$field] = $value;
138 $fit = $result->addValue( [
'query', $this->getModuleName(),
'results' ],
null, $data );
140 $this->setContinueEnumParameter(
'offset', $params[
'offset'] + $count - 1 );
147 if ( $resultPageSet ===
null ) {
148 $result->addIndexedTagName(
149 [
'query', $this->getModuleName(),
'results' ],
153 $resultPageSet->populateFromTitles( $titles );
159 $qp = $this->getSpecialPage( $params[
'page'] );
160 if ( $qp->getRestriction() !=
'' ) {
171 ParamValidator::PARAM_TYPE => $this->queryPages,
172 ParamValidator::PARAM_REQUIRED => true
175 ParamValidator::PARAM_DEFAULT => 0,
179 ParamValidator::PARAM_DEFAULT => 10,
180 ParamValidator::PARAM_TYPE =>
'limit',
181 IntegerDef::PARAM_MIN => 1,
191 'action=query&list=querypage&qppage=Ancientpages'
192 =>
'apihelp-query+querypage-example-ancientpages',
198 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Querypage';
203class_alias( ApiQueryQueryPage::class,
'ApiQueryQueryPage' );
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
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.Return value has query strings as keys, with values being eith...
run( $resultPageSet=null)
getCacheMode( $params)
Get the cache mode for the data generated by this module.Override this in the module subclass....
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
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.