MediaWiki REL1_31
ApiQueryQueryPage.php
Go to the documentation of this file.
1<?php
29 private $qpMap;
30
31 public function __construct( ApiQuery $query, $moduleName ) {
32 parent::__construct( $query, $moduleName, 'qp' );
33 // Build mapping from special page names to QueryPage classes
34 $uselessQueryPages = $this->getConfig()->get( 'APIUselessQueryPages' );
35 $this->qpMap = [];
36 foreach ( QueryPage::getPages() as $page ) {
37 if ( !in_array( $page[1], $uselessQueryPages ) ) {
38 $this->qpMap[$page[1]] = $page[0];
39 }
40 }
41 }
42
43 public function execute() {
44 $this->run();
45 }
46
47 public function executeGenerator( $resultPageSet ) {
48 $this->run( $resultPageSet );
49 }
50
54 public function run( $resultPageSet = null ) {
56 $result = $this->getResult();
57
59 $qp = new $this->qpMap[$params['page']]();
60 if ( !$qp->userCanExecute( $this->getUser() ) ) {
61 $this->dieWithError( 'apierror-specialpage-cantexecute' );
62 }
63
64 $r = [ 'name' => $params['page'] ];
65 if ( $qp->isCached() ) {
66 if ( !$qp->isCacheable() ) {
67 $r['disabled'] = true;
68 } else {
69 $r['cached'] = true;
70 $ts = $qp->getCachedTimestamp();
71 if ( $ts ) {
72 $r['cachedtimestamp'] = wfTimestamp( TS_ISO_8601, $ts );
73 }
74 $r['maxresults'] = $this->getConfig()->get( 'QueryCacheLimit' );
75 }
76 }
77 $result->addValue( [ 'query' ], $this->getModuleName(), $r );
78
79 if ( $qp->isCached() && !$qp->isCacheable() ) {
80 // Disabled query page, don't run the query
81 return;
82 }
83
84 $res = $qp->doQuery( $params['offset'], $params['limit'] + 1 );
85 $count = 0;
86 $titles = [];
87 foreach ( $res as $row ) {
88 if ( ++$count > $params['limit'] ) {
89 // We've had enough
90 $this->setContinueEnumParameter( 'offset', $params['offset'] + $params['limit'] );
91 break;
92 }
93
94 $title = Title::makeTitle( $row->namespace, $row->title );
95 if ( is_null( $resultPageSet ) ) {
96 $data = [ 'value' => $row->value ];
97 if ( $qp->usesTimestamps() ) {
98 $data['timestamp'] = wfTimestamp( TS_ISO_8601, $row->value );
99 }
100 self::addTitleInfo( $data, $title );
101
102 foreach ( $row as $field => $value ) {
103 if ( !in_array( $field, [ 'namespace', 'title', 'value', 'qc_type' ] ) ) {
104 $data['databaseResult'][$field] = $value;
105 }
106 }
107
108 $fit = $result->addValue( [ 'query', $this->getModuleName(), 'results' ], null, $data );
109 if ( !$fit ) {
110 $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 );
111 break;
112 }
113 } else {
114 $titles[] = $title;
115 }
116 }
117 if ( is_null( $resultPageSet ) ) {
118 $result->addIndexedTagName(
119 [ 'query', $this->getModuleName(), 'results' ],
120 'page'
121 );
122 } else {
123 $resultPageSet->populateFromTitles( $titles );
124 }
125 }
126
127 public function getCacheMode( $params ) {
129 $qp = new $this->qpMap[$params['page']]();
130 if ( $qp->getRestriction() != '' ) {
131 return 'private';
132 }
133
134 return 'public';
135 }
136
137 public function getAllowedParams() {
138 return [
139 'page' => [
140 ApiBase::PARAM_TYPE => array_keys( $this->qpMap ),
142 ],
143 'offset' => [
145 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
146 ],
147 'limit' => [
149 ApiBase::PARAM_TYPE => 'limit',
153 ],
154 ];
155 }
156
157 protected function getExamplesMessages() {
158 return [
159 'action=query&list=querypage&qppage=Ancientpages'
160 => 'apihelp-query+querypage-example-ancientpages',
161 ];
162 }
163
164 public function getHelpUrls() {
165 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Querypage';
166 }
167}
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when run
Definition COPYING.txt:104
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_REQUIRED
(boolean) Is the parameter required?
Definition ApiBase.php:111
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition ApiBase.php:96
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:90
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1895
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:749
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:99
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:234
getResult()
Get the result object.
Definition ApiBase.php:641
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:236
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:521
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
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...
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.
__construct(ApiQuery $query, $moduleName)
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.
Definition ApiQuery.php:36
static getPages()
Get a list of query page classes and their associated special pages, for periodic updates.
Definition QueryPage.php:66
$res
Definition database.txt:21
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2006
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1620
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition linkcache.txt:17
$params