Daniel Kinzler has uploaded a new change for review.

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


Change subject: Config setting for cache duration of entity data.
......................................................................

Config setting for cache duration of entity data.

This introduces $wgWBRepoSettings['dataSquidMaxage'] instead
of using $wgSquidMaxage to determine the cache duration for
the output of Special:EntityData. $wgWBRepoSettings['dataSquidMaxage']
defaults to $wgSquidMaxage, but should be overwritten when and where
$wgSquidMaxage is larger than a few hours, since entity data isn't
automatically purged from HTTP caches.

Change-Id: I1dabe792619c5ebd690bfe3e7bf5cd28eb5f19c9
---
M repo/config/Wikibase.default.php
M repo/includes/specials/SpecialEntityData.php
2 files changed, 19 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/81/64281/1

diff --git a/repo/config/Wikibase.default.php b/repo/config/Wikibase.default.php
index da4768c..6e8d04b 100644
--- a/repo/config/Wikibase.default.php
+++ b/repo/config/Wikibase.default.php
@@ -30,6 +30,7 @@
  */
 
 return call_user_func( function() {
+       global $wgSquidMaxage;
 
        $defaults = array(
 
@@ -72,6 +73,10 @@
 
                // Should the page names (titles) be normalized against the 
external site
                'normalizeItemByTitlePageNames' => false,
+
+               // Number of seconds for which data output shall be cached.
+               // Note: keep that low, because such caches can not always be 
purged easily.
+               'dataSquidMaxAge' => $wgSquidMaxage,
        );
 
        return $defaults;
diff --git a/repo/includes/specials/SpecialEntityData.php 
b/repo/includes/specials/SpecialEntityData.php
index fa0a084..a181649 100755
--- a/repo/includes/specials/SpecialEntityData.php
+++ b/repo/includes/specials/SpecialEntityData.php
@@ -68,6 +68,11 @@
        protected $idFormatter = null;
 
        /**
+        * @var int Cache dureation in seconds
+        */
+       protected $maxAge = 0;
+
+       /**
         * Constructor.
         *
         * @since 0.4
@@ -113,11 +118,13 @@
                        return;
                }
 
+               //TODO: move this, so we can inject alternative values
                $repo = \Wikibase\Repo\WikibaseRepo::getDefaultInstance();
                $this->rdfBaseURI = $repo->getRdfBaseURI();
                $this->entityLookup = 
\Wikibase\StoreFactory::getStore()->getEntityLookup();
                $this->dataTypeFactory = $repo->getDataTypeFactory();
                $this->idFormatter = $repo->getIdFormatter();
+               $this->maxAge = \Wikibase\Settings::get( 'dataSquidMaxAge' );
 
                $this->showData( $format, $id, $revision );
        }
@@ -413,25 +420,24 @@
         * @param Revision $revision
         */
        public function outputData( $data, $contentType, Revision $revision = 
null ) {
-               global $wgSquidMaxage;
-
                // NOTE: similar code as in RawAction::onView, keep in sync.
 
                $request = $this->getRequest();
                $response = $request->response();
 
-               $maxage = $request->getInt( 'maxage', $wgSquidMaxage );
-               $smaxage = $request->getInt( 'smaxage', $wgSquidMaxage );
+               $maxage = $request->getInt( 'maxage', $this->maxAge );
+               $smaxage = $request->getInt( 'smaxage', $this->maxAge );
 
-               // Sanity: 0 to 30 days. // todo: Hard maximum could be 
configurable somehow.
-               $maxage  = max( 0, min( 60 * 60 * 24 * 30, $maxage ) );
-               $smaxage = max( 0, min( 60 * 60 * 24 * 30, $smaxage ) );
+               // XXX: do we want public caching even for data from old 
revisions?
+               // Sanity: 0 to 31 days. // todo: Hard maximum could be 
configurable somehow.
+               $maxage  = max( 0, min( 60 * 60 * 24 * 31, $maxage ) );
+               $smaxage = max( 0, min( 60 * 60 * 24 * 31, $smaxage ) );
 
                $response->header( 'Content-Type: ' . $contentType . '; 
charset=UTF-8' );
                $response->header( 'Content-Length: ' . strlen( $data ) );
 
                if ( $revision ) {
-                       $response->header( 'Last-Modified: ' . wfTimestamp( 
TS_ISO_8601, $revision->getTimestamp() ) );
+                       $response->header( 'Last-Modified: ' . wfTimestamp( 
TS_RFC2822, $revision->getTimestamp() ) );
                }
 
                //Set X-Frame-Options API results (bug 39180)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1dabe792619c5ebd690bfe3e7bf5cd28eb5f19c9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to