17use Wikimedia\Timestamp\TimestampFormat as TS;
36 parent::__construct( $query, $moduleName,
'qp' );
37 $this->queryPages = array_values( array_diff(
49 $this->
run( $resultPageSet );
56 private function getSpecialPage( $name ):
QueryPage {
57 $qp = $this->specialPageFactory->getPage( $name );
61 'SpecialPageFactory failed to create special page ' . $name
64 if ( !( $qp instanceof QueryPage ) ) {
67 'Special page ' . $name .
' is not a QueryPage'
76 public function run( $resultPageSet =
null ) {
77 $params = $this->extractRequestParams();
78 $result = $this->getResult();
80 $qp = $this->getSpecialPage( $params[
'page'] );
81 if ( !$qp->userCanExecute( $this->getUser() ) ) {
82 $this->dieWithError(
'apierror-specialpage-cantexecute' );
85 if ( $resultPageSet ===
null ) {
86 $r = [
'name' => $params[
'page'] ];
87 if ( $qp->isCached() ) {
88 if ( !$qp->isCacheable() ) {
89 $r[
'disabled'] =
true;
92 $ts = $qp->getCachedTimestamp();
94 $r[
'cachedtimestamp'] =
wfTimestamp( TS::ISO_8601, $ts );
99 $result->addValue( [
'query' ], $this->getModuleName(), $r );
102 if ( $qp->isCached() && !$qp->isCacheable() ) {
107 $res = $qp->doQuery( $params[
'offset'], $params[
'limit'] + 1 );
110 foreach ( $res as $row ) {
111 if ( ++$count > $params[
'limit'] ) {
113 $this->setContinueEnumParameter(
'offset', $params[
'offset'] + $params[
'limit'] );
118 if ( $resultPageSet ===
null ) {
120 if ( isset( $row->value ) ) {
121 $data[
'value'] = $row->value;
122 if ( $qp->usesTimestamps() ) {
123 $data[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->value );
126 self::addTitleInfo( $data, $title );
128 foreach ( $row as $field => $value ) {
129 if ( !in_array( $field, [
'namespace',
'title',
'value',
'qc_type' ] ) ) {
130 $data[
'databaseResult'][$field] = $value;
134 $fit = $result->addValue( [
'query', $this->getModuleName(),
'results' ],
null, $data );
136 $this->setContinueEnumParameter(
'offset', $params[
'offset'] + $count - 1 );
143 if ( $resultPageSet ===
null ) {
144 $result->addIndexedTagName(
145 [
'query', $this->getModuleName(),
'results' ],
149 $resultPageSet->populateFromTitles( $titles );
155 $qp = $this->getSpecialPage( $params[
'page'] );
156 if ( $qp->getRestriction() !=
'' ) {
167 ParamValidator::PARAM_TYPE => $this->queryPages,
168 ParamValidator::PARAM_REQUIRED => true
171 ParamValidator::PARAM_DEFAULT => 0,
175 ParamValidator::PARAM_DEFAULT => 10,
176 ParamValidator::PARAM_TYPE =>
'limit',
177 IntegerDef::PARAM_MIN => 1,
187 'action=query&list=querypage&qppage=Ancientpages'
188 =>
'apihelp-query+querypage-example-ancientpages',
194 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Querypage';
199class_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...
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.
__construct(ApiQuery $query, string $moduleName, private readonly SpecialPageFactory $specialPageFactory,)
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.