r69376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69375‎ | r69376 | r69377 >
Date:02:05, 15 July 2010
Author:mah
Status:reverted
Tags:
Comment:
MFT r69339
Modified paths:
  • /branches/REL1_15/extensions/GlobalBlocking/ApiQueryGlobalBlocks.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiLogout.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiMain.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiParse.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiPatrol.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiPurge.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryAllmessages.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryBlocks.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryInfo.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryUserInfo.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiQueryWatchlistRaw.php (modified) (history)
  • /branches/REL1_15/phase3/includes/api/ApiWatch.php (modified) (history)

Diff [purge]

Index: branches/REL1_15/extensions/GlobalBlocking/ApiQueryGlobalBlocks.php
@@ -36,7 +36,6 @@
3737 }
3838
3939 public function execute() {
40 - global $wgUser;
4140 $params = $this->extractRequestParams();
4241
4342 $prop = array_flip($params['prop']);
Index: branches/REL1_15/phase3/includes/api/ApiQueryRecentChanges.php
@@ -116,8 +116,12 @@
117117
118118 // Check permissions
119119 global $wgUser;
120 - if((isset($show['patrolled']) || isset($show['!patrolled'])) && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol())
121 - $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
 120+ if(isset($show['patrolled']) || isset($show['!patrolled'])) {
 121+ $this->getMain()->setVaryCookie();
 122+ if(!$wgUser->useRCPatrol() && !$wgUser->useNPPatrol()) {
 123+ $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
 124+ }
 125+ }
122126
123127 /* Add additional conditions to query depending upon parameters. */
124128 $this->addWhereIf('rc_minor = 0', isset ($show['!minor']));
@@ -321,6 +325,9 @@
322326
323327 if(!is_null($this->token))
324328 {
 329+ // Don't cache tokens
 330+ $this->getMain()->setCachePrivate();
 331+
325332 $tokenFunctions = $this->getTokenFunctions();
326333 foreach($this->token as $t)
327334 {
Index: branches/REL1_15/phase3/includes/api/ApiWatch.php
@@ -41,6 +41,7 @@
4242
4343 public function execute() {
4444 global $wgUser;
 45+ $this->getMain()->setCachePrivate();
4546 if(!$wgUser->isLoggedIn())
4647 $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
4748 $params = $this->extractRequestParams();
Index: branches/REL1_15/phase3/includes/api/ApiLogout.php
@@ -42,6 +42,7 @@
4343
4444 public function execute() {
4545 global $wgUser;
 46+ $this->getMain()->setCachePrivate();
4647 $oldName = $wgUser->getName();
4748 $wgUser->logout();
4849
Index: branches/REL1_15/phase3/includes/api/ApiParse.php
@@ -115,8 +115,10 @@
116116 if(!$titleObj)
117117 $titleObj = Title::newFromText("API");
118118 $wgTitle = $titleObj;
119 - if($params['pst'] || $params['onlypst'])
 119+ if($params['pst'] || $params['onlypst']) {
120120 $text = $wgParser->preSaveTransform($text, $titleObj, $wgUser, $popts);
 121+ $this->getMain()->setVaryCookie();
 122+ }
121123 if($params['onlypst'])
122124 {
123125 // Build a result and bail out
Index: branches/REL1_15/phase3/includes/api/ApiPurge.php
@@ -42,6 +42,7 @@
4343 */
4444 public function execute() {
4545 global $wgUser;
 46+ $this->getMain()->setCachePrivate();
4647 $params = $this->extractRequestParams();
4748 if(!$wgUser->isAllowed('purge'))
4849 $this->dieUsageMsg(array('cantpurge'));
Index: branches/REL1_15/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -42,6 +42,7 @@
4343 public function execute() {
4444
4545 global $wgUser;
 46+ $this->getMain()->setVaryCookie();
4647 // Before doing anything at all, let's check permissions
4748 if(!$wgUser->isAllowed('deletedhistory'))
4849 $this->dieUsage('You don\'t have permission to view deleted revision information', 'permissiondenied');
Index: branches/REL1_15/phase3/includes/api/ApiQueryBlocks.php
@@ -115,6 +115,8 @@
116116 "ipb_range_end >= '$upper'"
117117 ));
118118 }
 119+ // Make sure private data (deleted blocks) isn't cached
 120+ $this->getMain()->setVaryCookie();
119121 if(!$wgUser->isAllowed('hideuser'))
120122 $this->addWhereFld('ipb_deleted', 0);
121123
Index: branches/REL1_15/phase3/includes/api/ApiQueryAllmessages.php
@@ -47,9 +47,11 @@
4848 {
4949 global $wgLang;
5050 $wgLang = Language::factory($params['lang']);
 51+ } else if ( is_null( $params['lang'] ) ) {
 52+ // Language not determined by URL but by user preferences, so don't cache
 53+ $this->getMain()->setVaryCookie();
5154 }
5255
53 -
5456 //Determine which messages should we print
5557 $messages_target = array();
5658 if( $params['messages'] == '*' ) {
Index: branches/REL1_15/phase3/includes/api/ApiQueryWatchlistRaw.php
@@ -53,6 +53,7 @@
5454
5555 $this->selectNamedDB('watchlist', DB_SLAVE, 'watchlist');
5656
 57+ $this->getMain()->setVaryCookie();
5758 if (!$wgUser->isLoggedIn())
5859 $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
5960 $params = $this->extractRequestParams();
@@ -178,4 +179,4 @@
179180 public function getVersion() {
180181 return __CLASS__ . ': $Id$';
181182 }
182 -}
\ No newline at end of file
 183+}
Index: branches/REL1_15/phase3/includes/api/ApiQueryUserInfo.php
@@ -40,6 +40,7 @@
4141 }
4242
4343 public function execute() {
 44+ $this->getMain()->setCachePrivate();
4445 $params = $this->extractRequestParams();
4546 $result = $this->getResult();
4647 $r = array();
Index: branches/REL1_15/phase3/includes/api/ApiMain.php
@@ -121,7 +121,7 @@
122122
123123
124124 private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
125 - private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage;
 125+ private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage, $mVaryCookie;
126126
127127 /**
128128 * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
@@ -166,6 +166,7 @@
167167
168168 $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
169169 $this->mCommit = false;
 170+ $this->mVaryCookie = false;
170171 }
171172
172173 /**
@@ -203,6 +204,35 @@
204205 }
205206
206207 /**
 208+ * Make sure Vary: Cookie and friends are set. Use this when the output of a request
 209+ * may be cached for anons but may not be cached for logged-in users.
 210+ *
 211+ * WARNING: This function must be called CONSISTENTLY for a given URL. This means that a
 212+ * given URL must either always or never call this function; if it sometimes does and
 213+ * sometimes doesn't, stuff will break.
 214+ */
 215+ public function setVaryCookie() {
 216+ $this->mVaryCookie = true;
 217+ }
 218+
 219+ /**
 220+ * Actually output the Vary: Cookie header and its friends, if flagged with setVaryCookie().
 221+ * Outputs the appropriate X-Vary-Options header and Cache-Control: private if needed.
 222+ */
 223+ private function outputVaryCookieHeader() {
 224+ global $wgUseXVO, $wgOut;
 225+ if ( $this->mVaryCookie ) {
 226+ header( 'Vary: Cookie' );
 227+ if ( $wgUseXVO ) {
 228+ header( $wgOut->getXVO() );
 229+ if ( $wgOut->haveCacheVaryCookies() ) {
 230+ $this->setCacheControl( array( 'private' => true ) );
 231+ }
 232+ }
 233+ }
 234+ }
 235+
 236+ /**
207237 * Create an instance of an output formatter by its name
208238 */
209239 public function createPrinterByName($format) {
@@ -212,6 +242,14 @@
213243 }
214244
215245 /**
 246+ * Make sure Cache-Control: private is set. Use this when the output of a request
 247+ * is for the current recipient only and should not be cached in any shared cache.
 248+ */
 249+ public function setCachePrivate() {
 250+ $this->setCacheControl( array( 'private' => true ) );
 251+ }
 252+
 253+ /**
216254 * Execute api request. Any errors will be handled if the API was called by the remote client.
217255 */
218256 public function execute() {
@@ -252,6 +290,7 @@
253291
254292 // Error results should not be cached
255293 $this->setCacheMaxAge(0);
 294+ $this->setCachePrivate();
256295
257296 $headerStr = 'MediaWiki-API-Error: ' . $errCode;
258297 if ($e->getCode() === 0)
@@ -266,6 +305,11 @@
267306 $this->mPrinter->safeProfileOut();
268307 $this->printResult(true);
269308 }
 309+
 310+ // If this wiki is private, don't cache anything ever
 311+ if ( in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) {
 312+ $this->setCachePrivate();
 313+ }
270314
271315 if($this->mSquidMaxage == -1)
272316 {
@@ -282,6 +326,7 @@
283327 $expires = ($exp == 0 ? 1 : time() + $exp);
284328 header('Expires: ' . wfTimestamp(TS_RFC2822, $expires));
285329 header('Cache-Control: s-maxage=' . $smaxage . ', must-revalidate, max-age=' . $maxage);
 330+ $this->outputVaryCookieHeader();
286331
287332 if($this->mPrinter->getIsHtml())
288333 echo wfReportTime();
@@ -388,7 +433,9 @@
389434 }
390435
391436 global $wgUser;
392 - if ($module->isReadMode() && !$wgUser->isAllowed('read'))
 437+ if ( $module->isReadMode() &&
 438+ !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) &&
 439+ !$wgUser->isAllowed('read'))
393440 $this->dieUsageMsg(array('readrequired'));
394441 if ($module->isWriteMode()) {
395442 if (!$this->mEnableWrite)
Index: branches/REL1_15/phase3/includes/api/ApiQueryWatchlist.php
@@ -56,6 +56,7 @@
5757
5858 $this->selectNamedDB('watchlist', DB_SLAVE, 'watchlist');
5959
 60+ $this->getMain()->setVaryCookie();
6061 if (!$wgUser->isLoggedIn())
6162 $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
6263
@@ -148,7 +149,9 @@
149150 }
150151
151152 // Check permissions
152 - global $wgUser;
 153+ global $wgUser
 154+ $this->getMain()->setVaryCookie();
 155+
153156 if((isset($show['patrolled']) || isset($show['!patrolled'])) && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol())
154157 $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
155158
Index: branches/REL1_15/phase3/includes/api/ApiPatrol.php
@@ -42,6 +42,7 @@
4343 */
4444 public function execute() {
4545 global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
 46+ $this->getMain()->setCachePrivate();
4647 $params = $this->extractRequestParams();
4748
4849 if(!isset($params['token']))
Index: branches/REL1_15/phase3/includes/api/ApiQueryRevisions.php
@@ -352,6 +352,9 @@
353353
354354 if(!is_null($this->token))
355355 {
 356+ // Don't cache tokens
 357+ $this->getMain()->setCachePrivate();
 358+
356359 $tokenFunctions = $this->getTokenFunctions();
357360 foreach($this->token as $t)
358361 {
Index: branches/REL1_15/phase3/includes/api/ApiQueryInfo.php
@@ -282,6 +282,9 @@
283283 }
284284
285285 if (!is_null($this->params['token'])) {
 286+ // Don't cache tokens
 287+ $this->getMain()->setCachePrivate();
 288+
286289 $tokenFunctions = $this->getTokenFunctions();
287290 $pageInfo['starttimestamp'] = wfTimestamp(TS_ISO_8601, time());
288291 foreach($this->params['token'] as $t)
Index: branches/REL1_15/phase3/includes/api/ApiQueryUserContributions.php
@@ -203,6 +203,8 @@
204204 $this->fld_patrolled)
205205 {
206206 global $wgUser;
 207+ // Don't cache private data
 208+ $this->getMain()->setVaryCookie();
207209 if(!$wgUser->useRCPatrol() && !$wgUser->useNPPatrol())
208210 $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
209211 // Use a redundant join condition on both

Follow-up revisions

RevisionCommit summaryAuthorDate
r69579Revert backport (r69376) of broken API cache header bug fix r69339.tstarling02:49, 20 July 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r69339API: Make output containing private or user-specific data uncacheable for log...catrope19:00, 14 July 2010

Status & tagging log