MediaWiki REL1_33
ApiQueryQueryPage.php
Go to the documentation of this file.
1<?php
25
32
36 private $queryPages;
37
42
43 public function __construct( ApiQuery $query, $moduleName ) {
44 parent::__construct( $query, $moduleName, 'qp' );
45 $this->queryPages = array_values( array_diff(
46 array_column( QueryPage::getPages(), 1 ), // [ class, name ]
47 $this->getConfig()->get( 'APIUselessQueryPages' )
48 ) );
49 $this->specialPageFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
50 }
51
52 public function execute() {
53 $this->run();
54 }
55
56 public function executeGenerator( $resultPageSet ) {
57 $this->run( $resultPageSet );
58 }
59
64 private function getSpecialPage( $name ) {
65 $qp = $this->specialPageFactory->getPage( $name );
66 if ( !$qp ) {
68 __METHOD__,
69 'SpecialPageFactory failed to create special page ' . $name
70 );
71 }
72 if ( !( $qp instanceof QueryPage ) ) {
74 __METHOD__,
75 'Special page ' . $name . ' is not a QueryPage'
76 );
77 }
78 return $qp;
79 }
80
84 public function run( $resultPageSet = null ) {
86 $result = $this->getResult();
87
88 $qp = $this->getSpecialPage( $params['page'] );
89 if ( !$qp->userCanExecute( $this->getUser() ) ) {
90 $this->dieWithError( 'apierror-specialpage-cantexecute' );
91 }
92
93 $r = [ 'name' => $params['page'] ];
94 if ( $qp->isCached() ) {
95 if ( !$qp->isCacheable() ) {
96 $r['disabled'] = true;
97 } else {
98 $r['cached'] = true;
99 $ts = $qp->getCachedTimestamp();
100 if ( $ts ) {
101 $r['cachedtimestamp'] = wfTimestamp( TS_ISO_8601, $ts );
102 }
103 $r['maxresults'] = $this->getConfig()->get( 'QueryCacheLimit' );
104 }
105 }
106 $result->addValue( [ 'query' ], $this->getModuleName(), $r );
107
108 if ( $qp->isCached() && !$qp->isCacheable() ) {
109 // Disabled query page, don't run the query
110 return;
111 }
112
113 $res = $qp->doQuery( $params['offset'], $params['limit'] + 1 );
114 $count = 0;
115 $titles = [];
116 foreach ( $res as $row ) {
117 if ( ++$count > $params['limit'] ) {
118 // We've had enough
119 $this->setContinueEnumParameter( 'offset', $params['offset'] + $params['limit'] );
120 break;
121 }
122
123 $title = Title::makeTitle( $row->namespace, $row->title );
124 if ( is_null( $resultPageSet ) ) {
125 $data = [ 'value' => $row->value ];
126 if ( $qp->usesTimestamps() ) {
127 $data['timestamp'] = wfTimestamp( TS_ISO_8601, $row->value );
128 }
129 self::addTitleInfo( $data, $title );
130
131 foreach ( $row as $field => $value ) {
132 if ( !in_array( $field, [ 'namespace', 'title', 'value', 'qc_type' ] ) ) {
133 $data['databaseResult'][$field] = $value;
134 }
135 }
136
137 $fit = $result->addValue( [ 'query', $this->getModuleName(), 'results' ], null, $data );
138 if ( !$fit ) {
139 $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 );
140 break;
141 }
142 } else {
143 $titles[] = $title;
144 }
145 }
146 if ( is_null( $resultPageSet ) ) {
147 $result->addIndexedTagName(
148 [ 'query', $this->getModuleName(), 'results' ],
149 'page'
150 );
151 } else {
152 $resultPageSet->populateFromTitles( $titles );
153 }
154 }
155
156 public function getCacheMode( $params ) {
157 $qp = $this->getSpecialPage( $params['page'] );
158 if ( $qp->getRestriction() != '' ) {
159 return 'private';
160 }
161
162 return 'public';
163 }
164
165 public function getAllowedParams() {
166 return [
167 'page' => [
170 ],
171 'offset' => [
173 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
174 ],
175 'limit' => [
177 ApiBase::PARAM_TYPE => 'limit',
181 ],
182 ];
183 }
184
185 protected function getExamplesMessages() {
186 return [
187 'action=query&list=querypage&qppage=Ancientpages'
188 => 'apihelp-query+querypage-example-ancientpages',
189 ];
190 }
191
192 public function getHelpUrls() {
193 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Querypage';
194 }
195}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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:1990
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:2188
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
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:252
getResult()
Get the result object.
Definition ApiBase.php:632
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:743
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:254
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:512
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.
SpecialPageFactory $specialPageFactory
__construct(ApiQuery $query, $moduleName)
string[] $queryPages
list of special page names
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
MediaWikiServices is the service locator for the application scope of MediaWiki.
Factory for handling the special page list and generating SpecialPage objects.
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition QueryPage.php:35
static getPages()
Get a list of query page classes and their associated special pages, for periodic updates.
Definition QueryPage.php:73
$res
Definition database.txt:21
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
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:2004
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:1617
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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