Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/222526

Change subject: RawAction: Clean up max-age/s-maxage computation
......................................................................

RawAction: Clean up max-age/s-maxage computation

No behavioural change, but makes the code easier to understand.
It was somewhat all scattered.

* Remove outdated comment about 24 hours.
  - ForcedRawSMaxage defaults to 5 minutes.
  - SquidMaxage defaults to 5 hours (wmf-config: 31 days).

Change-Id: I7f3b67780ba9e8c024dcbd68772495b91abb2d01
---
M includes/DefaultSettings.php
M includes/actions/RawAction.php
2 files changed, 23 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/26/222526/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 7dbe35a..f233ad7 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -2541,13 +2541,16 @@
 /**
  * Cache timeout for the squid, will be sent as s-maxage (without ESI) or
  * Surrogate-Control (with ESI). Without ESI, you should strip out s-maxage in
- * the Squid config. 18000 seconds = 5 hours, more cache hits with 2678400 = 31
- * days
+ * the Squid config.
+ *
+* 18000 seconds = 5 hours, more cache hits with 2678400 = 31 days.
  */
 $wgSquidMaxage = 18000;
 
 /**
  * Default maximum age for raw CSS/JS accesses
+ *
+ * 300 seconds = 5 minutes.
  */
 $wgForcedRawSMaxage = 300;
 
diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php
index b04ffbe..b71b0e9 100644
--- a/includes/actions/RawAction.php
+++ b/includes/actions/RawAction.php
@@ -34,10 +34,10 @@
  */
 class RawAction extends FormlessAction {
        /**
-        * @var bool Does the request include a gen=css|javascript parameter
-        * @deprecated This used to be a string for "css" or "javascript" but
-        * it is no longer used. Setting this parameter results in empty content
-        * being served
+        * Whether the request includes a 'gen' parameter
+        * @var bool
+        * @deprecated since 1.17 This used to be a string for "css" or 
"javascript" but
+        * it is no longer used. Setting this parameter results in an empty 
response.
         */
        private $gen = false;
 
@@ -56,6 +56,7 @@
        function onView() {
                $this->getOutput()->disable();
                $request = $this->getRequest();
+               $response = $request->response();
                $config = $this->context->getConfig();
 
                if ( !$request->checkUrlExtension() ) {
@@ -66,42 +67,35 @@
                        return; // Client cache fresh and headers sent, nothing 
more to do.
                }
 
-               # special case for 'generated' raw things: user css/js
-               # This is deprecated and will only return empty content
                $gen = $request->getVal( 'gen' );
-               $smaxage = $request->getIntOrNull( 'smaxage' );
-
                if ( $gen == 'css' || $gen == 'js' ) {
                        $this->gen = true;
-                       if ( $smaxage === null ) {
-                               $smaxage = $config->get( 'SquidMaxage' );
-                       }
                }
 
                $contentType = $this->getContentType();
 
-               # Force caching for CSS and JS raw content, default: 5 minutes.
-               # Note: If using a canonical url for userpage css/js, we send 
an HTCP purge.
+               $maxage = $request->getInt( 'maxage', $config->get( 
'SquidMaxage' ) );
+               $smaxage = $request->getIntOrNull( 'smaxage' );
                if ( $smaxage === null ) {
-                       if ( $contentType == 'text/css' || $contentType == 
'text/javascript' ) {
+                       if ( $this->gen ) {
+                               $smaxage = $config->get( 'SquidMaxage' );
+                       } elseif ( $contentType == 'text/css' || $contentType 
== 'text/javascript' ) {
+                               // CSS/JS raw content has its own squid max age 
configuration.
+                               // Note: Title::getSquidURLs() includes 
action=raw for css/js pages,
+                               // so if using the canonical url, this will get 
HTCP purges.
                                $smaxage = intval( $config->get( 
'ForcedRawSMaxage' ) );
                        } else {
+                               // No squid cache for anything else
                                $smaxage = 0;
                        }
                }
 
-               $maxage = $request->getInt( 'maxage', $config->get( 
'SquidMaxage' ) );
-
-               $response = $request->response();
-
                $response->header( 'Content-type: ' . $contentType . '; 
charset=UTF-8' );
-               # Output may contain user-specific data;
-               # vary generated content for open sessions on private wikis
+               // Output may contain user-specific data;
+               // vary generated content for open sessions on private wikis
                $privateCache = !User::isEveryoneAllowed( 'read' ) && ( 
$smaxage == 0 || session_id() != '' );
-               // Bug 53032 - make this private if user is logged in,
-               // so we don't accidentally cache cookies
-               $privateCache = $privateCache ?: $this->getUser()->isLoggedIn();
-               # allow the client to cache this for 24 hours
+               // Don't accidentally cache cookies if user is logged in 
(T55032)
+               $privateCache = $privateCache || $this->getUser()->isLoggedIn();
                $mode = $privateCache ? 'private' : 'public';
                $response->header(
                        'Cache-Control: ' . $mode . ', s-maxage=' . $smaxage . 
', max-age=' . $maxage

-- 
To view, visit https://gerrit.wikimedia.org/r/222526
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f3b67780ba9e8c024dcbd68772495b91abb2d01
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to