replace TYPE= with ENGINE=, (supported since 4.0, TYPE deprecated since 4.1)
[lhc/web/wiklou.git] / includes / ParserCache.php
index e283367..d9a7c84 100644 (file)
  * @package MediaWiki
  */
 class ParserCache {
+       /**
+        * Get an instance of this object
+        */
+       function &singleton() {
+               static $instance;
+               if ( !isset( $instance ) ) {
+                       global $parserMemc;
+                       $instance = new ParserCache( $parserMemc );
+               }
+               return $instance;
+       }
+
        /**
         * Setup a cache pathway with a given back-end storage mechanism.
         * May be a memcached client or a BagOStuff derivative.
@@ -19,15 +31,26 @@ class ParserCache {
        function ParserCache( &$memCached ) {
                $this->mMemc =& $memCached;
        }
-       
+
        function getKey( &$article, &$user ) {
-               global $wgDBname;
+               global $wgDBname, $action;
                $hash = $user->getPageRenderingHash();
+               if( !$article->mTitle->userCanEdit() ) {
+                       // section edit links are suppressed even if the user has them on
+                       $edit = '!edit=0';
+               } else {
+                       $edit = '';
+               }
                $pageid = intval( $article->getID() );
-               $key = "$wgDBname:pcache:idhash:$pageid-$hash";
+               $renderkey = (int)($action == 'render');
+               $key = "$wgDBname:pcache:idhash:$pageid-$renderkey!$hash$edit";
                return $key;
        }
-       
+
+       function getETag( &$article, &$user ) {
+               return 'W/"' . $this->getKey($article, $user) . "--" . $article->mTouched. '"';
+       }
+
        function get( &$article, &$user ) {
                global $wgCacheEpoch;
                $fname = 'ParserCache::get';
@@ -68,8 +91,9 @@ class ParserCache {
                wfProfileOut( $fname );
                return $value;
        }
-       
+
        function save( $parserOutput, &$article, &$user ){
+               global $wgParserCacheExpireTime;
                $key = $this->getKey( $article, $user );
                $now = wfTimestampNow();
                $parserOutput->setCacheTime( $now );
@@ -79,7 +103,7 @@ class ParserCache {
                if( $parserOutput->containsOldMagic() ){
                        $expire = 3600; # 1 hour
                } else {
-                       $expire = 86400; # 1 day
+                       $expire = $wgParserCacheExpireTime;
                }
                $this->mMemc->set( $key, $parserOutput, $expire );
        }