FileCache cleanuo:
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 28 Dec 2008 14:19:39 +0000 (14:19 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 28 Dec 2008 14:19:39 +0000 (14:19 +0000)
* Add a clearFileCache() function in the place of various unlink() calls. This also clears the raw page cache.
* Fix useFileCache() for loop
* Add mType field to file cache objects

includes/Article.php
includes/HTMLCacheUpdate.php
includes/HTMLFileCache.php
includes/RawPage.php
includes/Title.php

index 1b4bcce..b0bf080 100644 (file)
@@ -3164,7 +3164,7 @@ class Article {
        }
 
        public static function onArticleDelete( $title ) {
-               global $wgUseFileCache, $wgMessageCache;
+               global $wgMessageCache;
                # Update existence markers on article/talk tabs...
                if( $title->isTalkPage() ) {
                        $other = $title->getSubjectPage();
@@ -3178,10 +3178,7 @@ class Article {
                $title->purgeSquid();
 
                # File cache
-               if( $wgUseFileCache ) {
-                       $cm = new HTMLFileCache( $title );
-                       @unlink( $cm->fileCacheName() );
-               }
+               HTMLFileCache::clearFileCache( $title );
 
                # Messages
                if( $title->getNamespace() == NS_MEDIAWIKI ) {
@@ -3203,7 +3200,7 @@ class Article {
         * Purge caches on page update etc
         */
        public static function onArticleEdit( $title, $transclusions = 'transclusions' ) {
-               global $wgDeferredUpdateList, $wgUseFileCache;
+               global $wgDeferredUpdateList;
 
                // Invalidate caches of articles which include this page
                if( $transclusions !== 'skiptransclusions' )
@@ -3216,10 +3213,7 @@ class Article {
                $title->purgeSquid();
 
                # Clear file cache for this page only
-               if( $wgUseFileCache ) {
-                       $cm = new HTMLFileCache( $title );
-                       @unlink( $cm->fileCacheName() );
-               }
+               HTMLFileCache::clearFileCache( $title );
        }
 
        /**#@-*/
index 636d73f..402102e 100644 (file)
@@ -172,8 +172,7 @@ class HTMLCacheUpdate
                                # Update file cache
                                if  ( $wgUseFileCache ) {
                                        foreach ( $titles as $title ) {
-                                               $cm = new HTMLFileCache($title);
-                                               @unlink($cm->fileCacheName());
+                                               HTMLFileCache::clearFileCache( $title );
                                        }
                                }
                        }
index 15037cc..3f27d44 100644 (file)
  * @ingroup Cache
  */
 class HTMLFileCache {
-       var $mTitle, $mFileCache;
+       var $mTitle, $mFileCache, $mType;
 
-       public function __construct( &$title ) {
+       public function __construct( &$title, $type = 'view' ) {
                $this->mTitle = $title;
-               $this->mFileCache = $this->fileCacheName();
+               $this->mType = ($type == 'raw' || $type == 'view' ) ? $type : false;
+               $this->fileCacheName(); // init name
        }
 
        public function fileCacheName() {
                if( !$this->mFileCache ) {
                        global $wgFileCacheDirectory, $wgRequest;
+                       # Store raw pages (like CSS hits) elsewhere
+                       $subdir = ($this->mType === 'raw') ? 'raw/' : '';
                        $key = $this->mTitle->getPrefixedDbkey();
                        $hash = md5( $key );
                        # Avoid extension confusion
                        $key = str_replace( '.', '%2E', urlencode( $key ) );
-                       # Store raw pages (like CSS hits) elsewhere
-                       $subdir = $wgRequest->getVal('action') == 'raw' ? 'raw/' : '';
        
                        $hash1 = substr( $hash, 0, 1 );
                        $hash2 = substr( $hash, 0, 2 );
@@ -50,6 +51,7 @@ class HTMLFileCache {
        }
 
        public function isFileCached() {
+               if( $this->mType === false ) return false;
                return file_exists( $this->fileCacheName() );
        }
 
@@ -70,11 +72,13 @@ class HTMLFileCache {
                        if( $query == 'title' || $query == 'curid' ) continue;
                        // Normal page view in query form can have action=view.
                        // Raw hits for pages also stored, like .css pages for example.
-                       if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue;
-                       if( $query == 'usemsgcache' && $val == 'yes' ) continue;
+                       else if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue;
+                       else if( $query == 'usemsgcache' && $val == 'yes' ) continue;
                        // Below are header setting params
-                       if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' )
+                       else if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' )
                                continue;
+                       else
+                               return false;
                }
                // Check for non-standard user language; this covers uselang,
                // and extensions for auto-detecting user language.
@@ -193,4 +197,13 @@ class HTMLFileCache {
                return $text;
        }
 
+       public static function clearFileCache( $title ) {
+               global $wgUseFileCache;
+               if( !$wgUseFileCache ) return false;
+               $fc = new self( $title, '' );
+               @unlink( $fc->fileCacheName() );
+               $fc = new self( $title, 'raw' );
+               @unlink( $fc->fileCacheName() );
+               return true;
+       }
 }
index 9640cee..a7bc02c 100644 (file)
@@ -151,7 +151,7 @@ class RawPage {
                header( 'Cache-Control: '.$mode.', s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
                
                if( HTMLFileCache::useFileCache() ) {
-                       $cache = new HTMLFileCache( $this->mTitle );
+                       $cache = new HTMLFileCache( $this->mTitle, 'raw' );
                        if( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
                                /* Check incoming headers to see if client has this cached */
                                if( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) {
index abfae90..033d045 100644 (file)
@@ -1954,7 +1954,6 @@ class Title {
         * @return \type{\bool} true if the update succeded
         */
        public function invalidateCache() {
-               global $wgUseFileCache;
                if( wfReadOnly() ) {
                        return;
                }
@@ -1964,10 +1963,7 @@ class Title {
                        $this->pageCond(), 
                        __METHOD__
                );
-               if( $wgUseFileCache) {
-                       $cache = new HTMLFileCache( $this );
-                       @unlink( $cache->fileCacheName() );
-               }
+               HTMLFileCache::clearFileCache( $this );
                return $success;
        }