Index: branches/wmf/1.16wmf4/includes/api/ApiQueryExternalLinks.php |
— | — | @@ -83,6 +83,10 @@ |
84 | 84 | $db->freeResult( $res ); |
85 | 85 | } |
86 | 86 | |
| 87 | + public function getCacheMode( $params ) { |
| 88 | + return 'public'; |
| 89 | + } |
| 90 | + |
87 | 91 | public function getAllowedParams() { |
88 | 92 | return array( |
89 | 93 | 'limit' => array( |
— | — | @@ -117,4 +121,4 @@ |
118 | 122 | public function getVersion() { |
119 | 123 | return __CLASS__ . ': $Id$'; |
120 | 124 | } |
121 | | -} |
\ No newline at end of file |
| 125 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryCategoryInfo.php |
— | — | @@ -99,6 +99,10 @@ |
100 | 100 | $db->freeResult( $res ); |
101 | 101 | } |
102 | 102 | |
| 103 | + public function getCacheMode( $params ) { |
| 104 | + return 'public'; |
| 105 | + } |
| 106 | + |
103 | 107 | public function getAllowedParams() { |
104 | 108 | return array ( |
105 | 109 | 'continue' => null, |
— | — | @@ -122,4 +126,4 @@ |
123 | 127 | public function getVersion() { |
124 | 128 | return __CLASS__ . ': $Id$'; |
125 | 129 | } |
126 | | -} |
\ No newline at end of file |
| 130 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryUsers.php |
— | — | @@ -156,9 +156,6 @@ |
157 | 157 | |
158 | 158 | if ( !is_null( $params['token'] ) ) |
159 | 159 | { |
160 | | - // Don't cache tokens |
161 | | - $this->getMain()->setCachePrivate(); |
162 | | - |
163 | 160 | $tokenFunctions = $this->getTokenFunctions(); |
164 | 161 | foreach ( $params['token'] as $t ) |
165 | 162 | { |
— | — | @@ -210,6 +207,14 @@ |
211 | 208 | return $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'user' ); |
212 | 209 | } |
213 | 210 | |
| 211 | + public function getCacheMode( $params ) { |
| 212 | + if ( isset( $params['token'] ) ) { |
| 213 | + return 'private'; |
| 214 | + } else { |
| 215 | + return 'public'; |
| 216 | + } |
| 217 | + } |
| 218 | + |
214 | 219 | public function getAllowedParams() { |
215 | 220 | return array ( |
216 | 221 | 'prop' => array ( |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryUserContributions.php |
— | — | @@ -164,8 +164,6 @@ |
165 | 165 | "rev_timestamp $op= '$encTS')" ); |
166 | 166 | } |
167 | 167 | |
168 | | - // Make sure private data (deleted revisions) isn't cached |
169 | | - $this->getMain()->setVaryCookie(); |
170 | 168 | if ( !$wgUser->isAllowed( 'hideuser' ) ) |
171 | 169 | $this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ); |
172 | 170 | // We only want pages by the specified users. |
— | — | @@ -212,12 +210,8 @@ |
213 | 211 | $this->fld_patrolled ) |
214 | 212 | { |
215 | 213 | global $wgUser; |
216 | | - // Don't cache private data |
217 | | - $this->getMain()->setVaryCookie(); |
218 | | - if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) { |
219 | | - $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' ); |
220 | | - } |
221 | | - |
| 214 | + if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) |
| 215 | + $this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' ); |
222 | 216 | // Use a redundant join condition on both |
223 | 217 | // timestamp and ID so we can use the timestamp |
224 | 218 | // index |
— | — | @@ -314,7 +308,6 @@ |
315 | 309 | |
316 | 310 | if ( $this->fld_parsedcomment ) { |
317 | 311 | global $wgUser; |
318 | | - $this->getMain()->setVaryCookie(); |
319 | 312 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rev_comment, $title ); |
320 | 313 | } |
321 | 314 | } |
— | — | @@ -345,6 +338,12 @@ |
346 | 339 | wfTimestamp( TS_ISO_8601, $row->rev_timestamp ); |
347 | 340 | } |
348 | 341 | |
| 342 | + public function getCacheMode( $params ) { |
| 343 | + // This module provides access to deleted revisions and patrol flags if |
| 344 | + // the requester is logged in |
| 345 | + return 'anon-public-user-private'; |
| 346 | + } |
| 347 | + |
349 | 348 | public function getAllowedParams() { |
350 | 349 | return array ( |
351 | 350 | 'limit' => array ( |
Index: branches/wmf/1.16wmf4/includes/api/ApiQuerySearch.php |
— | — | @@ -155,6 +155,10 @@ |
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
| 159 | + public function getCacheMode( $params ) { |
| 160 | + return 'public'; |
| 161 | + } |
| 162 | + |
159 | 163 | public function getAllowedParams() { |
160 | 164 | return array ( |
161 | 165 | 'search' => null, |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryRecentChanges.php |
— | — | @@ -137,12 +137,8 @@ |
138 | 138 | |
139 | 139 | // Check permissions |
140 | 140 | global $wgUser; |
141 | | - if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) { |
142 | | - $this->getMain()->setVaryCookie(); |
143 | | - if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) { |
144 | | - $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' ); |
145 | | - } |
146 | | - } |
| 141 | + if ( ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) |
| 142 | + $this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' ); |
147 | 143 | |
148 | 144 | /* Add additional conditions to query depending upon parameters. */ |
149 | 145 | $this->addWhereIf( 'rc_minor = 0', isset ( $show['!minor'] ) ); |
— | — | @@ -362,7 +358,6 @@ |
363 | 359 | |
364 | 360 | if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) { |
365 | 361 | global $wgUser; |
366 | | - $this->getMain()->setVaryCookie(); |
367 | 362 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title ); |
368 | 363 | } |
369 | 364 | |
— | — | @@ -395,9 +390,6 @@ |
396 | 391 | |
397 | 392 | if ( !is_null( $this->token ) ) |
398 | 393 | { |
399 | | - // Don't cache tokens |
400 | | - $this->getMain()->setCachePrivate(); |
401 | | - |
402 | 394 | $tokenFunctions = $this->getTokenFunctions(); |
403 | 395 | foreach ( $this->token as $t ) |
404 | 396 | { |
— | — | @@ -430,6 +422,24 @@ |
431 | 423 | } |
432 | 424 | } |
433 | 425 | |
| 426 | + public function getCacheMode( $params ) { |
| 427 | + if ( isset( $params['show'] ) ) { |
| 428 | + foreach ( $params['show'] as $show ) { |
| 429 | + if ( $show === 'patrolled' || $show === '!patrolled' ) { |
| 430 | + return 'private'; |
| 431 | + } |
| 432 | + } |
| 433 | + } |
| 434 | + if ( isset( $params['token'] ) ) { |
| 435 | + return 'private'; |
| 436 | + } |
| 437 | + if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { |
| 438 | + // formatComment() calls wfMsg() among other things |
| 439 | + return 'anon-public-user-private'; |
| 440 | + } |
| 441 | + return 'public'; |
| 442 | + } |
| 443 | + |
434 | 444 | public function getAllowedParams() { |
435 | 445 | return array ( |
436 | 446 | 'start' => array ( |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryWatchlistRaw.php |
— | — | @@ -65,7 +65,6 @@ |
66 | 66 | $this->addFields( array( 'wl_namespace', 'wl_title' ) ); |
67 | 67 | $this->addFieldsIf( 'wl_notificationtimestamp', isset( $prop['changed'] ) ); |
68 | 68 | $this->addWhereFld( 'wl_user', $wgUser->getId() ); |
69 | | - $this->getMain()->setVaryCookie(); // Temp live hack until new code using getWatchlistUser() is merged |
70 | 69 | $this->addWhereFld( 'wl_namespace', $params['namespace'] ); |
71 | 70 | $this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['changed'] ) ); |
72 | 71 | $this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!changed'] ) ); |
— | — | @@ -189,4 +188,4 @@ |
190 | 189 | public function getVersion() { |
191 | 190 | return __CLASS__ . ': $Id$'; |
192 | 191 | } |
193 | | -} |
| 192 | +} |
\ No newline at end of file |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryAllCategories.php |
— | — | @@ -44,6 +44,10 @@ |
45 | 45 | $this->run(); |
46 | 46 | } |
47 | 47 | |
| 48 | + public function getCacheMode( $params ) { |
| 49 | + return 'public'; |
| 50 | + } |
| 51 | + |
48 | 52 | public function executeGenerator( $resultPageSet ) { |
49 | 53 | $this->run( $resultPageSet ); |
50 | 54 | } |
— | — | @@ -177,4 +181,4 @@ |
178 | 182 | public function getVersion() { |
179 | 183 | return __CLASS__ . ': $Id$'; |
180 | 184 | } |
181 | | -} |
\ No newline at end of file |
| 185 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiQuery.php |
— | — | @@ -206,9 +206,15 @@ |
207 | 207 | $this->InstantiateModules( $modules, 'list', $this->mQueryListModules ); |
208 | 208 | $this->InstantiateModules( $modules, 'meta', $this->mQueryMetaModules ); |
209 | 209 | |
| 210 | + $cacheMode = 'public'; |
| 211 | + |
210 | 212 | // If given, execute generator to substitute user supplied data with generated data. |
211 | 213 | if ( isset ( $this->params['generator'] ) ) { |
212 | | - $this->executeGeneratorModule( $this->params['generator'], $modules ); |
| 214 | + $generator = $this->newGenerator( $this->params['generator'] ); |
| 215 | + $params = $generator->extractRequestParams(); |
| 216 | + $cacheMode = $this->mergeCacheMode( $cacheMode, |
| 217 | + $generator->getCacheMode( $params ) ); |
| 218 | + $this->executeGeneratorModule( $generator, $modules ); |
213 | 219 | } else { |
214 | 220 | // Append custom fields and populate page/revision information |
215 | 221 | $this->addCustomFldsToPageSet( $modules, $this->mPageSet ); |
— | — | @@ -220,14 +226,38 @@ |
221 | 227 | |
222 | 228 | // Execute all requested modules. |
223 | 229 | foreach ( $modules as $module ) { |
| 230 | + $params = $module->extractRequestParams(); |
| 231 | + $cacheMode = $this->mergeCacheMode( |
| 232 | + $cacheMode, $module->getCacheMode( $params ) ); |
224 | 233 | $module->profileIn(); |
225 | 234 | $module->execute(); |
226 | 235 | wfRunHooks( 'APIQueryAfterExecute', array( &$module ) ); |
227 | 236 | $module->profileOut(); |
228 | 237 | } |
| 238 | + |
| 239 | + // Set the cache mode |
| 240 | + $this->getMain()->setCacheMode( $cacheMode ); |
229 | 241 | } |
230 | 242 | |
231 | 243 | /** |
| 244 | + * Update a cache mode string, applying the cache mode of a new module to it. |
| 245 | + * The cache mode may increase in the level of privacy, but public modules |
| 246 | + * added to private data do not decrease the level of privacy. |
| 247 | + */ |
| 248 | + protected function mergeCacheMode( $cacheMode, $modCacheMode ) { |
| 249 | + if ( $modCacheMode === 'anon-public-user-private' ) { |
| 250 | + if ( $cacheMode !== 'private' ) { |
| 251 | + $cacheMode = 'anon-public-user-private'; |
| 252 | + } |
| 253 | + } elseif ( $modCacheMode === 'public' ) { |
| 254 | + // do nothing, if it's public already it will stay public |
| 255 | + } else { // private |
| 256 | + $cacheMode = 'private'; |
| 257 | + } |
| 258 | + return $cacheMode; |
| 259 | + } |
| 260 | + |
| 261 | + /** |
232 | 262 | * Query modules may optimize data requests through the $this->getPageSet() object |
233 | 263 | * by adding extra fields from the page table. |
234 | 264 | * This function will gather all the extra request fields from the modules. |
— | — | @@ -401,12 +431,9 @@ |
402 | 432 | } |
403 | 433 | |
404 | 434 | /** |
405 | | - * For generator mode, execute generator, and use its output as new |
406 | | - * ApiPageSet |
407 | | - * @param $generatorName string Module name |
408 | | - * @param $modules array of module objects |
| 435 | + * Create a generator object of the given type and return it |
409 | 436 | */ |
410 | | - protected function executeGeneratorModule( $generatorName, $modules ) { |
| 437 | + public function newGenerator( $generatorName ) { |
411 | 438 | |
412 | 439 | // Find class that implements requested generator |
413 | 440 | if ( isset ( $this->mQueryListModules[$generatorName] ) ) { |
— | — | @@ -424,9 +451,20 @@ |
425 | 452 | $generator = new $className ( $this, $generatorName ); |
426 | 453 | if ( !$generator instanceof ApiQueryGeneratorBase ) |
427 | 454 | $this->dieUsage( "Module $generatorName cannot be used as a generator", "badgenerator" ); |
428 | | - |
429 | 455 | $generator->setGeneratorMode(); |
| 456 | + return $generator; |
| 457 | + } |
430 | 458 | |
| 459 | + /** |
| 460 | + * For generator mode, execute generator, and use its output as new |
| 461 | + * ApiPageSet |
| 462 | + * @param $generatorName string Module name |
| 463 | + * @param $modules array of module objects |
| 464 | + */ |
| 465 | + protected function executeGeneratorModule( $generator, $modules ) { |
| 466 | + // Generator results |
| 467 | + $resultPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles ); |
| 468 | + |
431 | 469 | // Add any additional fields modules may need |
432 | 470 | $generator->requestExtraData( $this->mPageSet ); |
433 | 471 | $this->addCustomFldsToPageSet( $modules, $resultPageSet ); |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryLinks.php |
— | — | @@ -64,6 +64,10 @@ |
65 | 65 | $this->run(); |
66 | 66 | } |
67 | 67 | |
| 68 | + public function getCacheMode( $params ) { |
| 69 | + return 'public'; |
| 70 | + } |
| 71 | + |
68 | 72 | public function executeGenerator( $resultPageSet ) { |
69 | 73 | $this->run( $resultPageSet ); |
70 | 74 | } |
— | — | @@ -206,4 +210,4 @@ |
207 | 211 | public function getVersion() { |
208 | 212 | return __CLASS__ . ': $Id$'; |
209 | 213 | } |
210 | | -} |
\ No newline at end of file |
| 214 | +} |
Property changes on: branches/wmf/1.16wmf4/includes/api/ApiLogin.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
211 | 215 | Merged /branches/REL1_16/phase3/includes/api/ApiLogin.php:r69932 |
Index: branches/wmf/1.16wmf4/includes/api/ApiLogout.php |
— | — | @@ -42,7 +42,6 @@ |
43 | 43 | |
44 | 44 | public function execute() { |
45 | 45 | global $wgUser; |
46 | | - $this->getMain()->setCachePrivate(); |
47 | 46 | $oldName = $wgUser->getName(); |
48 | 47 | $wgUser->logout(); |
49 | 48 | |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryExtLinksUsage.php |
— | — | @@ -41,6 +41,10 @@ |
42 | 42 | $this->run(); |
43 | 43 | } |
44 | 44 | |
| 45 | + public function getCacheMode( $params ) { |
| 46 | + return 'public'; |
| 47 | + } |
| 48 | + |
45 | 49 | public function executeGenerator( $resultPageSet ) { |
46 | 50 | $this->run( $resultPageSet ); |
47 | 51 | } |
— | — | @@ -218,4 +222,4 @@ |
219 | 223 | public function getVersion() { |
220 | 224 | return __CLASS__ . ': $Id$'; |
221 | 225 | } |
222 | | -} |
\ No newline at end of file |
| 226 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryUserInfo.php |
— | — | @@ -40,7 +40,6 @@ |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function execute() { |
44 | | - $this->getMain()->setCachePrivate(); |
45 | 44 | $params = $this->extractRequestParams(); |
46 | 45 | $result = $this->getResult(); |
47 | 46 | $r = array(); |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryBacklinks.php |
— | — | @@ -92,6 +92,10 @@ |
93 | 93 | $this->run(); |
94 | 94 | } |
95 | 95 | |
| 96 | + public function getCacheMode( $params ) { |
| 97 | + return 'public'; |
| 98 | + } |
| 99 | + |
96 | 100 | public function executeGenerator( $resultPageSet ) { |
97 | 101 | $this->run( $resultPageSet ); |
98 | 102 | } |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryDeletedrevs.php |
— | — | @@ -42,7 +42,6 @@ |
43 | 43 | public function execute() { |
44 | 44 | |
45 | 45 | global $wgUser; |
46 | | - $this->getMain()->setVaryCookie(); |
47 | 46 | // Before doing anything at all, let's check permissions |
48 | 47 | if ( !$wgUser->isAllowed( 'deletedhistory' ) ) |
49 | 48 | $this->dieUsage( 'You don\'t have permission to view deleted revision information', 'permissiondenied' ); |
— | — | @@ -200,7 +199,6 @@ |
201 | 200 | |
202 | 201 | if ( $fld_parsedcomment ) { |
203 | 202 | global $wgUser; |
204 | | - $this->getMain()->setVaryCookie(); |
205 | 203 | $rev['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->ar_comment, $title ); |
206 | 204 | } |
207 | 205 | if ( $fld_minor && $row->ar_minor_edit == 1 ) |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryCategories.php |
— | — | @@ -43,6 +43,10 @@ |
44 | 44 | $this->run(); |
45 | 45 | } |
46 | 46 | |
| 47 | + public function getCacheMode( $params ) { |
| 48 | + return 'public'; |
| 49 | + } |
| 50 | + |
47 | 51 | public function executeGenerator( $resultPageSet ) { |
48 | 52 | $this->run( $resultPageSet ); |
49 | 53 | } |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryCategoryMembers.php |
— | — | @@ -43,6 +43,10 @@ |
44 | 44 | $this->run(); |
45 | 45 | } |
46 | 46 | |
| 47 | + public function getCacheMode( $params ) { |
| 48 | + return 'public'; |
| 49 | + } |
| 50 | + |
47 | 51 | public function executeGenerator( $resultPageSet ) { |
48 | 52 | $this->run( $resultPageSet ); |
49 | 53 | } |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryAllUsers.php |
— | — | @@ -189,6 +189,10 @@ |
190 | 190 | $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'u' ); |
191 | 191 | } |
192 | 192 | |
| 193 | + public function getCacheMode( $params ) { |
| 194 | + return 'public'; |
| 195 | + } |
| 196 | + |
193 | 197 | public function getAllowedParams() { |
194 | 198 | return array ( |
195 | 199 | 'from' => null, |
— | — | @@ -242,4 +246,4 @@ |
243 | 247 | public function getVersion() { |
244 | 248 | return __CLASS__ . ': $Id$'; |
245 | 249 | } |
246 | | -} |
\ No newline at end of file |
| 250 | +} |
Property changes on: branches/wmf/1.16wmf4/includes/api/ApiQueryAllUsers.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
247 | 251 | Merged /trunk/phase3/includes/api/ApiQueryAllUsers.php:r69339,69347,69350,69369,69379,69776,69931 |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryInfo.php |
— | — | @@ -244,7 +244,6 @@ |
245 | 245 | $this->getProtectionInfo(); |
246 | 246 | |
247 | 247 | if ( $this->fld_watched ) |
248 | | - $this->getMain()->setVaryCookie(); |
249 | 248 | $this->getWatchedInfo(); |
250 | 249 | |
251 | 250 | // Run the talkid/subjectid query if requested |
— | — | @@ -289,9 +288,6 @@ |
290 | 289 | } |
291 | 290 | |
292 | 291 | if ( !is_null( $this->params['token'] ) ) { |
293 | | - // Don't cache tokens |
294 | | - $this->getMain()->setCachePrivate(); |
295 | | - |
296 | 292 | $tokenFunctions = $this->getTokenFunctions(); |
297 | 293 | $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601, time() ); |
298 | 294 | foreach ( $this->params['token'] as $t ) |
— | — | @@ -557,6 +553,27 @@ |
558 | 554 | } |
559 | 555 | } |
560 | 556 | |
| 557 | + public function getCacheMode( $params ) { |
| 558 | + $publicProps = array( |
| 559 | + 'protection', |
| 560 | + 'talkid', |
| 561 | + 'subjectid', |
| 562 | + 'url', |
| 563 | + 'preload', |
| 564 | + ); |
| 565 | + if ( !is_null( $params['prop'] ) ) { |
| 566 | + foreach ( $params['prop'] as $prop ) { |
| 567 | + if ( !in_array( $prop, $publicProps ) ) { |
| 568 | + return 'private'; |
| 569 | + } |
| 570 | + } |
| 571 | + } |
| 572 | + if ( !is_null( $params['token'] ) ) { |
| 573 | + return 'private'; |
| 574 | + } |
| 575 | + return 'public'; |
| 576 | + } |
| 577 | + |
561 | 578 | public function getAllowedParams() { |
562 | 579 | return array ( |
563 | 580 | 'prop' => array ( |
— | — | @@ -565,11 +582,13 @@ |
566 | 583 | ApiBase :: PARAM_TYPE => array ( |
567 | 584 | 'protection', |
568 | 585 | 'talkid', |
569 | | - 'watched', |
| 586 | + 'watched', # private |
570 | 587 | 'subjectid', |
571 | 588 | 'url', |
572 | | - 'readable', |
| 589 | + 'readable', # private |
573 | 590 | 'preload' |
| 591 | + // If you add more properties here, please consider whether they |
| 592 | + // need to be added to getCacheMode() |
574 | 593 | ) ), |
575 | 594 | 'token' => array ( |
576 | 595 | ApiBase :: PARAM_DFLT => null, |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryDuplicateFiles.php |
— | — | @@ -43,6 +43,10 @@ |
44 | 44 | $this->run(); |
45 | 45 | } |
46 | 46 | |
| 47 | + public function getCacheMode( $params ) { |
| 48 | + return 'public'; |
| 49 | + } |
| 50 | + |
47 | 51 | public function executeGenerator( $resultPageSet ) { |
48 | 52 | $this->run( $resultPageSet ); |
49 | 53 | } |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryAllimages.php |
— | — | @@ -55,6 +55,10 @@ |
56 | 56 | $this->run(); |
57 | 57 | } |
58 | 58 | |
| 59 | + public function getCacheMode( $params ) { |
| 60 | + return 'public'; |
| 61 | + } |
| 62 | + |
59 | 63 | public function executeGenerator( $resultPageSet ) { |
60 | 64 | if ( $resultPageSet->isResolvingRedirects() ) |
61 | 65 | $this->dieUsage( 'Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator', 'params' ); |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryTags.php |
— | — | @@ -129,6 +129,10 @@ |
130 | 130 | return true; |
131 | 131 | } |
132 | 132 | |
| 133 | + public function getCacheMode( $params ) { |
| 134 | + return 'public'; |
| 135 | + } |
| 136 | + |
133 | 137 | public function getAllowedParams() { |
134 | 138 | return array ( |
135 | 139 | 'continue' => array( |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryAllmessages.php |
— | — | @@ -46,9 +46,6 @@ |
47 | 47 | { |
48 | 48 | global $wgLang; |
49 | 49 | $wgLang = Language::factory( $params['lang'] ); |
50 | | - } else if ( is_null( $params['lang'] ) ) { |
51 | | - // Language not determined by URL but by user preferences, so don't cache |
52 | | - $this->getMain()->setVaryCookie(); |
53 | 50 | } |
54 | 51 | |
55 | 52 | $prop = array_flip( (array)$params['prop'] ); |
— | — | @@ -123,6 +120,19 @@ |
124 | 121 | $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' ); |
125 | 122 | } |
126 | 123 | |
| 124 | + public function getCacheMode( $params ) { |
| 125 | + if ( is_null( $params['lang'] ) ) { |
| 126 | + // Language not specified, will be fetched from preferences |
| 127 | + return 'anon-public-user-private'; |
| 128 | + } elseif ( $params['enableparser'] ) { |
| 129 | + // User-specific parser options will be used |
| 130 | + return 'anon-public-user-private'; |
| 131 | + } else { |
| 132 | + // OK to cache |
| 133 | + return 'public'; |
| 134 | + } |
| 135 | + } |
| 136 | + |
127 | 137 | public function getAllowedParams() { |
128 | 138 | return array ( |
129 | 139 | 'messages' => array ( |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryImages.php |
— | — | @@ -122,6 +122,10 @@ |
123 | 123 | $db->freeResult( $res ); |
124 | 124 | } |
125 | 125 | |
| 126 | + public function getCacheMode( $params ) { |
| 127 | + return 'public'; |
| 128 | + } |
| 129 | + |
126 | 130 | public function getAllowedParams() { |
127 | 131 | return array( |
128 | 132 | 'limit' => array( |
— | — | @@ -164,4 +168,4 @@ |
165 | 169 | public function getVersion() { |
166 | 170 | return __CLASS__ . ': $Id$'; |
167 | 171 | } |
168 | | -} |
\ No newline at end of file |
| 172 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryLogEvents.php |
— | — | @@ -267,7 +267,6 @@ |
268 | 268 | |
269 | 269 | if ( $this->fld_parsedcomment ) { |
270 | 270 | global $wgUser; |
271 | | - $this->getMain()->setVaryCookie(); |
272 | 271 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->log_comment, $title ); |
273 | 272 | } |
274 | 273 | } |
— | — | @@ -286,6 +285,15 @@ |
287 | 286 | return $vals; |
288 | 287 | } |
289 | 288 | |
| 289 | + public function getCacheMode( $params ) { |
| 290 | + if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { |
| 291 | + // formatComment() calls wfMsg() among other things |
| 292 | + return 'anon-public-user-private'; |
| 293 | + } else { |
| 294 | + return 'public'; |
| 295 | + } |
| 296 | + } |
| 297 | + |
290 | 298 | public function getAllowedParams() { |
291 | 299 | global $wgLogTypes; |
292 | 300 | return array ( |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryAllLinks.php |
— | — | @@ -43,6 +43,10 @@ |
44 | 44 | $this->run(); |
45 | 45 | } |
46 | 46 | |
| 47 | + public function getCacheMode( $params ) { |
| 48 | + return 'public'; |
| 49 | + } |
| 50 | + |
47 | 51 | public function executeGenerator( $resultPageSet ) { |
48 | 52 | $this->run( $resultPageSet ); |
49 | 53 | } |
— | — | @@ -207,4 +211,4 @@ |
208 | 212 | public function getVersion() { |
209 | 213 | return __CLASS__ . ': $Id$'; |
210 | 214 | } |
211 | | -} |
\ No newline at end of file |
| 215 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryProtectedTitles.php |
— | — | @@ -100,7 +100,6 @@ |
101 | 101 | |
102 | 102 | if ( isset( $prop['parsedcomment'] ) ) { |
103 | 103 | global $wgUser; |
104 | | - $this->getMain()->setVaryCookie(); |
105 | 104 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->pt_reason, $title ); |
106 | 105 | } |
107 | 106 | |
— | — | @@ -127,6 +126,15 @@ |
128 | 127 | $resultPageSet->populateFromTitles( $titles ); |
129 | 128 | } |
130 | 129 | |
| 130 | + public function getCacheMode( $params ) { |
| 131 | + if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { |
| 132 | + // formatComment() calls wfMsg() among other things |
| 133 | + return 'anon-public-user-private'; |
| 134 | + } else { |
| 135 | + return 'public'; |
| 136 | + } |
| 137 | + } |
| 138 | + |
131 | 139 | public function getAllowedParams() { |
132 | 140 | global $wgRestrictionLevels; |
133 | 141 | return array ( |
— | — | @@ -198,4 +206,4 @@ |
199 | 207 | public function getVersion() { |
200 | 208 | return __CLASS__ . ': $Id$'; |
201 | 209 | } |
202 | | -} |
\ No newline at end of file |
| 210 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiWatch.php |
— | — | @@ -41,7 +41,6 @@ |
42 | 42 | |
43 | 43 | public function execute() { |
44 | 44 | global $wgUser; |
45 | | - $this->getMain()->setCachePrivate(); |
46 | 45 | if ( !$wgUser->isLoggedIn() ) |
47 | 46 | $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); |
48 | 47 | |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryRandom.php |
— | — | @@ -121,6 +121,10 @@ |
122 | 122 | return $vals; |
123 | 123 | } |
124 | 124 | |
| 125 | + public function getCacheMode( $params ) { |
| 126 | + return 'public'; |
| 127 | + } |
| 128 | + |
125 | 129 | public function getAllowedParams() { |
126 | 130 | return array ( |
127 | 131 | 'namespace' => array( |
— | — | @@ -161,4 +165,4 @@ |
162 | 166 | public function getVersion() { |
163 | 167 | return __CLASS__ . ': $Id: ApiQueryRandom.php overlordq$'; |
164 | 168 | } |
165 | | -} |
\ No newline at end of file |
| 169 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -421,6 +421,9 @@ |
422 | 422 | return $this->getResult()->addValue( 'query', $property, $data ); |
423 | 423 | } |
424 | 424 | |
| 425 | + public function getCacheMode( $params ) { |
| 426 | + return 'public'; |
| 427 | + } |
425 | 428 | |
426 | 429 | public function getAllowedParams() { |
427 | 430 | return array( |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryLangLinks.php |
— | — | @@ -93,6 +93,10 @@ |
94 | 94 | $db->freeResult( $res ); |
95 | 95 | } |
96 | 96 | |
| 97 | + public function getCacheMode( $params ) { |
| 98 | + return 'public'; |
| 99 | + } |
| 100 | + |
97 | 101 | public function getAllowedParams() { |
98 | 102 | return array( |
99 | 103 | 'limit' => array( |
— | — | @@ -133,4 +137,4 @@ |
134 | 138 | public function getVersion() { |
135 | 139 | return __CLASS__ . ': $Id$'; |
136 | 140 | } |
137 | | -} |
\ No newline at end of file |
| 141 | +} |
Index: branches/wmf/1.16wmf4/includes/api/ApiParse.php |
— | — | @@ -38,6 +38,9 @@ |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function execute() { |
| 42 | + // The data is hot but user-dependent, like page views, so we set vary cookies |
| 43 | + $this->getMain()->setCacheMode( 'anon-public-user-private' ); |
| 44 | + |
42 | 45 | // Get parameters |
43 | 46 | $params = $this->extractRequestParams(); |
44 | 47 | $text = $params['text']; |
— | — | @@ -118,11 +121,10 @@ |
119 | 122 | if ( !$titleObj ) |
120 | 123 | $titleObj = Title::newFromText( "API" ); |
121 | 124 | $wgTitle = $titleObj; |
122 | | - if ( $params['pst'] || $params['onlypst'] ) { |
| 125 | + if ( $params['pst'] || $params['onlypst'] ) |
123 | 126 | $text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts ); |
124 | | - $this->getMain()->setVaryCookie(); |
125 | | - } |
126 | | - if ( $params['onlypst'] ) { |
| 127 | + if ( $params['onlypst'] ) |
| 128 | + { |
127 | 129 | // Build a result and bail out |
128 | 130 | $result_array['text'] = array(); |
129 | 131 | $this->getResult()->setContent( $result_array['text'], $text ); |
— | — | @@ -145,7 +147,6 @@ |
146 | 148 | |
147 | 149 | if ( !is_null( $params['summary'] ) ) { |
148 | 150 | $result_array['parsedsummary'] = array(); |
149 | | - $this->getMain()->setVaryCookie(); |
150 | 151 | $result->setContent( $result_array['parsedsummary'], $wgUser->getSkin()->formatComment( $params['summary'], $titleObj ) ); |
151 | 152 | } |
152 | 153 | |
— | — | @@ -174,7 +175,6 @@ |
175 | 176 | if ( isset( $prop['headhtml'] ) ) { |
176 | 177 | $out = new OutputPage; |
177 | 178 | $out->addParserOutputNoText( $p_result ); |
178 | | - $this->getMain()->setVaryCookie(); |
179 | 179 | $result_array['headhtml'] = array(); |
180 | 180 | $result->setContent( $result_array['headhtml'], $out->headElement( $wgUser->getSkin() ) ); |
181 | 181 | } |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryAllpages.php |
— | — | @@ -43,6 +43,10 @@ |
44 | 44 | $this->run(); |
45 | 45 | } |
46 | 46 | |
| 47 | + public function getCacheMode( $params ) { |
| 48 | + return 'public'; |
| 49 | + } |
| 50 | + |
47 | 51 | public function executeGenerator( $resultPageSet ) { |
48 | 52 | if ( $resultPageSet->isResolvingRedirects() ) |
49 | 53 | $this->dieUsage( 'Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params' ); |
Index: branches/wmf/1.16wmf4/includes/api/ApiPurge.php |
— | — | @@ -42,7 +42,6 @@ |
43 | 43 | */ |
44 | 44 | public function execute() { |
45 | 45 | global $wgUser; |
46 | | - $this->getMain()->setCachePrivate(); |
47 | 46 | $params = $this->extractRequestParams(); |
48 | 47 | if ( !$wgUser->isAllowed( 'purge' ) ) |
49 | 48 | $this->dieUsageMsg( array( 'cantpurge' ) ); |
Index: branches/wmf/1.16wmf4/includes/api/ApiMain.php |
— | — | @@ -124,9 +124,10 @@ |
125 | 125 | |
126 | 126 | private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames; |
127 | 127 | private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest; |
128 | | - private $mInternalMode, $mSquidMaxage, $mModule, $mVaryCookie; |
| 128 | + private $mInternalMode, $mSquidMaxage, $mModule; |
129 | 129 | |
130 | | - private $mCacheControl = array( 'must-revalidate' => true ); |
| 130 | + private $mCacheMode = 'private'; |
| 131 | + private $mCacheControl = array(); |
131 | 132 | |
132 | 133 | /** |
133 | 134 | * Constructs an instance of ApiMain that utilizes the module and format specified by $request. |
— | — | @@ -171,7 +172,6 @@ |
172 | 173 | |
173 | 174 | $this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling() |
174 | 175 | $this->mCommit = false; |
175 | | - $this->mVaryCookie = false; |
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
— | — | @@ -222,19 +222,67 @@ |
223 | 223 | 's-maxage' => $maxage |
224 | 224 | ) ); |
225 | 225 | } |
| 226 | + |
| 227 | + /** |
| 228 | + * Set the type of caching headers which will be sent. |
| 229 | + * |
| 230 | + * @param $mode One of: |
| 231 | + * - 'public': Cache this object in public caches, if the maxage or smaxage |
| 232 | + * parameter is set, or if setCacheMaxAge() was called. If a maximum age is |
| 233 | + * not provided by any of these means, the object will be private. |
| 234 | + * - 'private': Cache this object only in private client-side caches. |
| 235 | + * - 'anon-public-user-private': Make this object cacheable for logged-out |
| 236 | + * users, but private for logged-in users. IMPORTANT: If this is set, it must be |
| 237 | + * set consistently for a given URL, it cannot be set differently depending on |
| 238 | + * things like the contents of the database, or whether the user is logged in. |
| 239 | + * |
| 240 | + * If the wiki does not allow anonymous users to read it, the mode set here |
| 241 | + * will be ignored, and private caching headers will always be sent. In other words, |
| 242 | + * the "public" mode is equivalent to saying that the data sent is as public as a page |
| 243 | + * view. |
| 244 | + * |
| 245 | + * For user-dependent data, the private mode should generally be used. The |
| 246 | + * anon-public-user-private mode should only be used where there is a particularly |
| 247 | + * good performance reason for caching the anonymous response, but where the |
| 248 | + * response to logged-in users may differ, or may contain private data. |
| 249 | + * |
| 250 | + * If this function is never called, then the default will be the private mode. |
| 251 | + */ |
| 252 | + public function setCacheMode( $mode ) { |
| 253 | + if ( !in_array( $mode, array( 'private', 'public', 'anon-public-user-private' ) ) ) { |
| 254 | + wfDebug( __METHOD__.": unrecognised cache mode \"$mode\"\n" ); |
| 255 | + // Ignore for forwards-compatibility |
| 256 | + return; |
| 257 | + } |
| 258 | + |
| 259 | + if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) { |
| 260 | + // Private wiki, only private headers |
| 261 | + if ( $mode !== 'private' ) { |
| 262 | + wfDebug( __METHOD__.": ignoring request for $mode cache mode, private wiki\n" ); |
| 263 | + return; |
| 264 | + } |
| 265 | + } |
| 266 | + |
| 267 | + wfDebug( __METHOD__.": setting cache mode $mode\n" ); |
| 268 | + $this->mCacheMode = $mode; |
| 269 | + } |
226 | 270 | |
227 | 271 | /** |
228 | | - * Make sure Cache-Control: private is set. Use this when the output of a request |
229 | | - * is for the current recipient only and should not be cached in any shared cache. |
| 272 | + * @deprecated Private caching is now the default, so there is usually no |
| 273 | + * need to call this function. If there is a need, you can use |
| 274 | + * $this->setCacheMode('private') |
230 | 275 | */ |
231 | 276 | public function setCachePrivate() { |
232 | | - $this->setCacheControl( array( 'private' => true ) ); |
| 277 | + $this->setCacheMode( 'private' ); |
233 | 278 | } |
234 | 279 | |
235 | 280 | /** |
236 | 281 | * Set directives (key/value pairs) for the Cache-Control header. |
237 | 282 | * Boolean values will be formatted as such, by including or omitting |
238 | 283 | * without an equals sign. |
| 284 | + * |
| 285 | + * Cache control values set here will only be used if the cache mode is not |
| 286 | + * private, see setCacheMode(). |
239 | 287 | */ |
240 | 288 | public function setCacheControl( $directives ) { |
241 | 289 | $this->mCacheControl = $directives + $this->mCacheControl; |
— | — | @@ -247,27 +295,12 @@ |
248 | 296 | * WARNING: This function must be called CONSISTENTLY for a given URL. This means that a |
249 | 297 | * given URL must either always or never call this function; if it sometimes does and |
250 | 298 | * sometimes doesn't, stuff will break. |
| 299 | + * |
| 300 | + * @deprecated Use setCacheMode( 'anon-public-user-private' ) |
251 | 301 | */ |
252 | 302 | public function setVaryCookie() { |
253 | | - $this->mVaryCookie = true; |
| 303 | + $this->setCacheMode( 'anon-public-user-private' ); |
254 | 304 | } |
255 | | - |
256 | | - /** |
257 | | - * Actually output the Vary: Cookie header and its friends, if flagged with setVaryCookie(). |
258 | | - * Outputs the appropriate X-Vary-Options header and Cache-Control: private if needed. |
259 | | - */ |
260 | | - private function outputVaryCookieHeader() { |
261 | | - global $wgUseXVO, $wgOut; |
262 | | - if ( $this->mVaryCookie ) { |
263 | | - header( 'Vary: Cookie' ); |
264 | | - if ( $wgUseXVO ) { |
265 | | - header( $wgOut->getXVO() ); |
266 | | - if ( $wgOut->haveCacheVaryCookies() ) { |
267 | | - $this->setCacheControl( array( 'private' => true ) ); |
268 | | - } |
269 | | - } |
270 | | - } |
271 | | - } |
272 | 305 | |
273 | 306 | /** |
274 | 307 | * Create an instance of an output formatter by its name |
— | — | @@ -318,8 +351,7 @@ |
319 | 352 | $errCode = $this->substituteResultWithError( $e ); |
320 | 353 | |
321 | 354 | // Error results should not be cached |
322 | | - $this->setCacheMaxAge( 0 ); |
323 | | - $this->setCachePrivate(); |
| 355 | + $this->setCacheMode( 'private' ); |
324 | 356 | |
325 | 357 | $headerStr = 'MediaWiki-API-Error: ' . $errCode; |
326 | 358 | if ( $e->getCode() === 0 ) |
— | — | @@ -334,12 +366,49 @@ |
335 | 367 | $this->mPrinter->safeProfileOut(); |
336 | 368 | $this->printResult( true ); |
337 | 369 | } |
338 | | - |
339 | | - // If this wiki is private, don't cache anything ever |
340 | | - if ( ! in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) { |
341 | | - $this->setCachePrivate(); |
| 370 | + |
| 371 | + // Send cache headers after any code which might generate an error, to |
| 372 | + // avoid sending public cache headers for errors. |
| 373 | + $this->sendCacheHeaders(); |
| 374 | + |
| 375 | + if ( $this->mPrinter->getIsHtml() && !$this->mPrinter->isDisabled() ) { |
| 376 | + echo wfReportTime(); |
342 | 377 | } |
343 | 378 | |
| 379 | + ob_end_flush(); |
| 380 | + } |
| 381 | + |
| 382 | + protected function sendCacheHeaders() { |
| 383 | + if ( $this->mCacheMode == 'private' ) { |
| 384 | + header( 'Cache-Control: private' ); |
| 385 | + return; |
| 386 | + } |
| 387 | + |
| 388 | + if ( $this->mCacheMode == 'anon-public-user-private' ) { |
| 389 | + global $wgUseXVO, $wgOut; |
| 390 | + header( 'Vary: Accept-Encoding, Cookie' ); |
| 391 | + if ( $wgUseXVO ) { |
| 392 | + header( $wgOut->getXVO() ); |
| 393 | + if ( $wgOut->haveCacheVaryCookies() ) { |
| 394 | + // Logged in, mark this request private |
| 395 | + header( 'Cache-Control: private' ); |
| 396 | + return; |
| 397 | + } |
| 398 | + // Logged out, send normal public headers below |
| 399 | + } elseif ( session_id() != '' ) { |
| 400 | + // Logged in or otherwise has session (e.g. anonymous users who have edited) |
| 401 | + // Mark request private |
| 402 | + header( 'Cache-Control: private' ); |
| 403 | + return; |
| 404 | + } // else no XVO and anonymous, send public headers below |
| 405 | + } else /* if public */ { |
| 406 | + // Give a debugging message if the user object is unstubbed on a public request |
| 407 | + global $wgUser; |
| 408 | + if ( !( $wgUser instanceof StubUser ) ) { |
| 409 | + wfDebug( __METHOD__." \$wgUser is unstubbed on a public request!\n" ); |
| 410 | + } |
| 411 | + } |
| 412 | + |
344 | 413 | // If nobody called setCacheMaxAge(), use the (s)maxage parameters |
345 | 414 | if ( !isset( $this->mCacheControl['s-maxage'] ) ) { |
346 | 415 | $this->mCacheControl['s-maxage'] = $this->getParameter( 'smaxage' ); |
— | — | @@ -348,12 +417,21 @@ |
349 | 418 | $this->mCacheControl['max-age'] = $this->getParameter( 'maxage' ); |
350 | 419 | } |
351 | 420 | |
352 | | - // Set the cache expiration at the last moment, as any errors may change the expiration. |
353 | | - // if $this->mSquidMaxage == 0, the expiry time is set to the first second of unix epoch |
354 | | - $exp = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] ); |
355 | | - $expires = ( $exp == 0 ? 1 : time() + $exp ); |
356 | | - header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expires ) ); |
| 421 | + if ( !$this->mCacheControl['s-maxage'] && !$this->mCacheControl['max-age'] ) { |
| 422 | + // Public cache not requested |
| 423 | + // Sending a Vary header in this case is harmless, and protects us |
| 424 | + // against conditional calls of setCacheMaxAge(). |
| 425 | + header( 'Cache-Control: private' ); |
| 426 | + return; |
| 427 | + } |
357 | 428 | |
| 429 | + $this->mCacheControl['public'] = true; |
| 430 | + |
| 431 | + // Send an Expires header |
| 432 | + $maxAge = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] ); |
| 433 | + $expiryUnixTime = ( $maxAge == 0 ? 1 : time() + $maxAge ); |
| 434 | + header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) ); |
| 435 | + |
358 | 436 | // Construct the Cache-Control header |
359 | 437 | $ccHeader = ''; |
360 | 438 | $separator = ''; |
— | — | @@ -370,12 +448,6 @@ |
371 | 449 | } |
372 | 450 | |
373 | 451 | header( "Cache-Control: $ccHeader" ); |
374 | | - $this->outputVaryCookieHeader(); |
375 | | - |
376 | | - if ( $this->mPrinter->getIsHtml() ) |
377 | | - echo wfReportTime(); |
378 | | - |
379 | | - ob_end_flush(); |
380 | 452 | } |
381 | 453 | |
382 | 454 | /** |
— | — | @@ -491,8 +563,7 @@ |
492 | 564 | } |
493 | 565 | |
494 | 566 | global $wgUser, $wgGroupPermissions; |
495 | | - if ( $module->isReadMode() && !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) && |
496 | | - !$wgUser->isAllowed( 'read' ) ) |
| 567 | + if ( $module->isReadMode() && !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) && !$wgUser->isAllowed( 'read' ) ) |
497 | 568 | $this->dieUsageMsg( array( 'readrequired' ) ); |
498 | 569 | if ( $module->isWriteMode() ) { |
499 | 570 | if ( !$this->mEnableWrite ) |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryImageInfo.php |
— | — | @@ -244,6 +244,10 @@ |
245 | 245 | return $retval; |
246 | 246 | } |
247 | 247 | |
| 248 | + public function getCacheMode( $params ) { |
| 249 | + return 'public'; |
| 250 | + } |
| 251 | + |
248 | 252 | private function getContinueStr( $img ) |
249 | 253 | { |
250 | 254 | return $img->getOriginalTitle()->getText() . |
Index: branches/wmf/1.16wmf4/includes/api/ApiOpenSearch.php |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | // Open search results may be stored for a very long |
58 | 58 | // time |
59 | 59 | $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry ); |
60 | | - $this->getMain()->setCacheControl( array( 'must-revalidate' => false ) ); |
| 60 | + $this->getMain()->setCacheMode( 'public' ); |
61 | 61 | |
62 | 62 | $srchres = PrefixSearch::titleSearch( $search, $limit, |
63 | 63 | $namespaces ); |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryWatchlist.php |
— | — | @@ -68,14 +68,9 @@ |
69 | 69 | if ( $token == '' || $token != $params['token'] ) { |
70 | 70 | $this->dieUsage( 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences', 'bad_wltoken' ); |
71 | 71 | } |
| 72 | + } elseif ( !$wgUser->isLoggedIn() ) { |
| 73 | + $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); |
72 | 74 | } else { |
73 | | - // Temp live hack until new code using getWatchlistUser() is deployed |
74 | | - |
75 | | - // User not determined by URL, so don't cache |
76 | | - $this->getMain()->setVaryCookie(); |
77 | | - if ( !$wgUser->isLoggedIn() ) { |
78 | | - $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); |
79 | | - } |
80 | 75 | $user = $wgUser; |
81 | 76 | } |
82 | 77 | |
— | — | @@ -95,7 +90,6 @@ |
96 | 91 | $this->fld_notificationtimestamp = isset( $prop['notificationtimestamp'] ); |
97 | 92 | |
98 | 93 | if ( $this->fld_patrol ) { |
99 | | - $this->getMain()->setVaryCookie(); |
100 | 94 | if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) |
101 | 95 | $this->dieUsage( 'patrol property is not available', 'patrol' ); |
102 | 96 | } |
— | — | @@ -160,13 +154,9 @@ |
161 | 155 | $this->dieUsageMsg( array( 'show' ) ); |
162 | 156 | } |
163 | 157 | |
164 | | - // Check permissions. FIXME: should this check $user instead of $wgUser? |
165 | | - if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) { |
166 | | - $this->getMain()->setVaryCookie(); |
167 | | - if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) { |
168 | | - $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' ); |
169 | | - } |
170 | | - } |
| 158 | + // Check permissions. |
| 159 | + if ( ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) |
| 160 | + $this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' ); |
171 | 161 | |
172 | 162 | /* Add additional conditions to query depending upon parameters. */ |
173 | 163 | $this->addWhereIf( 'rc_minor = 0', isset ( $show['!minor'] ) ); |
— | — | @@ -282,7 +272,6 @@ |
283 | 273 | |
284 | 274 | if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) { |
285 | 275 | global $wgUser; |
286 | | - $this->getMain()->setVaryCookie(); |
287 | 276 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title ); |
288 | 277 | } |
289 | 278 | |
Index: branches/wmf/1.16wmf4/includes/api/ApiExpandTemplates.php |
— | — | @@ -42,6 +42,9 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function execute() { |
| 46 | + // Cache may vary on $wgUser because ParserOptions gets data from it |
| 47 | + $this->getMain()->setCacheMode( 'anon-public-user-private' ); |
| 48 | + |
46 | 49 | // Get parameters |
47 | 50 | $params = $this->extractRequestParams(); |
48 | 51 | |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryBase.php |
— | — | @@ -47,6 +47,17 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
| 51 | + * Get the cache mode for the data generated by this module. Override this |
| 52 | + * in the module subclass. |
| 53 | + * |
| 54 | + * Public caching will only be allowed if *all* the modules that supply |
| 55 | + * data for a given request return a cache mode of public. |
| 56 | + */ |
| 57 | + public function getCacheMode( $params ) { |
| 58 | + return 'private'; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
51 | 62 | * Blank the internal arrays with query parameters |
52 | 63 | */ |
53 | 64 | protected function resetQueryParams() { |
Index: branches/wmf/1.16wmf4/includes/api/ApiPatrol.php |
— | — | @@ -41,7 +41,6 @@ |
42 | 42 | * Patrols the article or provides the reason the patrol failed. |
43 | 43 | */ |
44 | 44 | public function execute() { |
45 | | - $this->getMain()->setCachePrivate(); |
46 | 45 | $params = $this->extractRequestParams(); |
47 | 46 | |
48 | 47 | if ( !isset( $params['rcid'] ) ) |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryBlocks.php |
— | — | @@ -121,9 +121,6 @@ |
122 | 122 | 'ipb_auto' => 0 |
123 | 123 | ) ); |
124 | 124 | } |
125 | | - |
126 | | - // Make sure private data (deleted blocks) isn't cached |
127 | | - $this->getMain()->setVaryCookie(); |
128 | 125 | if ( !$wgUser->isAllowed( 'hideuser' ) ) |
129 | 126 | $this->addWhereFld( 'ipb_deleted', 0 ); |
130 | 127 | |
— | — | @@ -283,4 +280,4 @@ |
284 | 281 | public function getVersion() { |
285 | 282 | return __CLASS__ . ': $Id$'; |
286 | 283 | } |
287 | | -} |
| 284 | +} |
\ No newline at end of file |
Index: branches/wmf/1.16wmf4/includes/api/ApiQueryRevisions.php |
— | — | @@ -378,7 +378,6 @@ |
379 | 379 | |
380 | 380 | if ( $this->fld_parsedcomment ) { |
381 | 381 | global $wgUser; |
382 | | - $this->getMain()->setVaryCookie(); |
383 | 382 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $comment, $title ); |
384 | 383 | } |
385 | 384 | } |
— | — | @@ -397,9 +396,6 @@ |
398 | 397 | |
399 | 398 | if ( !is_null( $this->token ) ) |
400 | 399 | { |
401 | | - // Don't cache tokens |
402 | | - $this->getMain()->setCachePrivate(); |
403 | | - |
404 | 400 | $tokenFunctions = $this->getTokenFunctions(); |
405 | 401 | foreach ( $this->token as $t ) |
406 | 402 | { |
— | — | @@ -468,6 +464,17 @@ |
469 | 465 | return $vals; |
470 | 466 | } |
471 | 467 | |
| 468 | + public function getCacheMode( $params ) { |
| 469 | + if ( isset( $params['token'] ) ) { |
| 470 | + return 'private'; |
| 471 | + } |
| 472 | + if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { |
| 473 | + // formatComment() calls wfMsg() among other things |
| 474 | + return 'anon-public-user-private'; |
| 475 | + } |
| 476 | + return 'public'; |
| 477 | + } |
| 478 | + |
472 | 479 | public function getAllowedParams() { |
473 | 480 | return array ( |
474 | 481 | 'prop' => array ( |
Property changes on: branches/wmf/1.16wmf4/includes/api |
___________________________________________________________________ |
Modified: svn:mergeinfo |
475 | 482 | Merged /branches/REL1_16/phase3/includes/api:r69932 |
476 | 483 | Merged /trunk/phase3/includes/api:r69339,69347,69350,69369,69379,69776,69931 |