Add maxage too
authorRoan Kattouw <catrope@users.mediawiki.org>
Mon, 16 Jun 2008 20:06:23 +0000 (20:06 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Mon, 16 Jun 2008 20:06:23 +0000 (20:06 +0000)
RELEASE-NOTES
includes/api/ApiMain.php

index 63d8805..f5d3b56 100644 (file)
@@ -450,7 +450,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 14526) Unescaped SQL in list=backlinks
 * Added 'hidden' flag to list=allcategories and prop=categoryinfo output
 * Added nocreate parameter to action=edit
-* (bug 14402) Added smaxage parameter to api.php
+* (bug 14402) Added maxage and smaxage parameters to api.php
 
 === Languages updated in 1.13 ===
 
index 0911482..b0096d0 100644 (file)
@@ -262,14 +262,20 @@ class ApiMain extends ApiBase {
 
                $params = $this->extractRequestParams(); 
                if($this->mSquidMaxage == -1)
-                       # Nobody called setCacheMaxAge(), use the smaxage parameter
-                       $this->mSquidMaxage = $params['smaxage'];
-                       
+               {
+                       # Nobody called setCacheMaxAge(), use the (s)maxage parameters
+                       $smaxage = $params['smaxage'];
+                       $maxage = $params['maxage'];
+               }
+               else
+                       $smaxage = $maxage = $this->mSquidMaxage;
+
                // Set the cache expiration at the last moment, as any errors may change the expiration.
                // if $this->mSquidMaxage == 0, the expiry time is set to the first second of unix epoch
-               $expires = $this->mSquidMaxage == 0 ? 1 : time() + $this->mSquidMaxage;
+               $exp = min($smaxage, $maxage);
+               $expires = $exp == 0 ? 1 : time() + $this->mSquidMaxage;
                header('Expires: ' . wfTimestamp(TS_RFC2822, $expires));
-               header('Cache-Control: s-maxage=' . $this->mSquidMaxage . ', must-revalidate, max-age=0');
+               header('Cache-Control: s-maxage=' . $smaxage . ', must-revalidate, max-age=' . $maxage);
 
                if($this->mPrinter->getIsHtml())
                        echo wfReportTime();
@@ -420,6 +426,10 @@ class ApiMain extends ApiBase {
                                ApiBase :: PARAM_TYPE => 'integer',
                                ApiBase :: PARAM_DFLT => 0
                        ),
+                       'maxage' => array (
+                               ApiBase :: PARAM_TYPE => 'integer',
+                               ApiBase :: PARAM_DFLT => 0
+                       ),
                );
        }
 
@@ -432,7 +442,8 @@ class ApiMain extends ApiBase {
                        'action' => 'What action you would like to perform',
                        'version' => 'When showing help, include version for each module',
                        'maxlag' => 'Maximum lag',
-                       'smaxage' => 'Cache the result for this many seconds. Errors are never cached',
+                       'smaxage' => 'Set the s-maxage header to this many seconds. Errors are never cached',
+                       'maxage' => 'Set the max-age header to this many seconds. Errors are never cached',
                );
        }