54 parent::__construct( $query, $moduleName,
'qp' );
55 $this->queryPages = array_values( array_diff(
56 array_column( QueryPage::getPages(), 1 ),
57 $this->
getConfig()->
get( MainConfigNames::APIUselessQueryPages )
59 $this->specialPageFactory = $specialPageFactory;
67 $this->
run( $resultPageSet );
74 private function getSpecialPage( $name ):
QueryPage {
75 $qp = $this->specialPageFactory->getPage( $name );
79 'SpecialPageFactory failed to create special page ' . $name
85 'Special page ' . $name .
' is not a QueryPage'
95 public function run( $resultPageSet =
null ) {
96 $params = $this->extractRequestParams();
97 $result = $this->getResult();
99 $qp = $this->getSpecialPage( $params[
'page'] );
100 if ( !$qp->userCanExecute( $this->getUser() ) ) {
101 $this->dieWithError(
'apierror-specialpage-cantexecute' );
104 if ( $resultPageSet ===
null ) {
105 $r = [
'name' => $params[
'page'] ];
106 if ( $qp->isCached() ) {
107 if ( !$qp->isCacheable() ) {
108 $r[
'disabled'] =
true;
111 $ts = $qp->getCachedTimestamp();
113 $r[
'cachedtimestamp'] =
wfTimestamp( TS_ISO_8601, $ts );
115 $r[
'maxresults'] = $this->getConfig()->get( MainConfigNames::QueryCacheLimit );
118 $result->addValue( [
'query' ], $this->getModuleName(), $r );
121 if ( $qp->isCached() && !$qp->isCacheable() ) {
126 $res = $qp->doQuery( $params[
'offset'], $params[
'limit'] + 1 );
129 foreach ( $res as $row ) {
130 if ( ++$count > $params[
'limit'] ) {
132 $this->setContinueEnumParameter(
'offset', $params[
'offset'] + $params[
'limit'] );
136 $title = Title::makeTitle( $row->namespace, $row->title );
137 if ( $resultPageSet ===
null ) {
139 if ( isset( $row->value ) ) {
140 $data[
'value'] = $row->value;
141 if ( $qp->usesTimestamps() ) {
142 $data[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->value );
145 self::addTitleInfo( $data, $title );
147 foreach ( $row as $field => $value ) {
148 if ( !in_array( $field, [
'namespace',
'title',
'value',
'qc_type' ] ) ) {
149 $data[
'databaseResult'][$field] = $value;
153 $fit = $result->addValue( [
'query', $this->getModuleName(),
'results' ],
null, $data );
155 $this->setContinueEnumParameter(
'offset', $params[
'offset'] + $count - 1 );
162 if ( $resultPageSet ===
null ) {
163 $result->addIndexedTagName(
164 [
'query', $this->getModuleName(),
'results' ],
168 $resultPageSet->populateFromTitles( $titles );
173 $qp = $this->getSpecialPage( $params[
'page'] );
174 if ( $qp->getRestriction() !=
'' ) {
184 ParamValidator::PARAM_TYPE => $this->queryPages,
185 ParamValidator::PARAM_REQUIRED =>
true
188 ParamValidator::PARAM_DEFAULT => 0,
192 ParamValidator::PARAM_DEFAULT => 10,
193 ParamValidator::PARAM_TYPE =>
'limit',
194 IntegerDef::PARAM_MIN => 1,
203 'action=query&list=querypage&qppage=Ancientpages'
204 =>
'apihelp-query+querypage-example-ancientpages',
209 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Querypage';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
const LIMIT_BIG1
Fast query, standard limit.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
Query module to get the results of a QueryPage-based special page.
__construct(ApiQuery $query, $moduleName, SpecialPageFactory $specialPageFactory)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
executeGenerator( $resultPageSet)
Execute this module as a generator.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getExamplesMessages()
Returns usage examples for this module.
run( $resultPageSet=null)
This is the main query class.
A class containing constants representing the names of configuration variables.
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Factory for handling the special page list and generating SpecialPage objects.