Merge "Fix various mistakes in PHPDoc comments"
[lhc/web/wiklou.git] / includes / cache / HTMLFileCache.php
index 91580f9..298f6e2 100644 (file)
@@ -35,21 +35,29 @@ class HTMLFileCache extends FileCacheBase {
         * @param string $action
         * @throws MWException
         * @return HTMLFileCache
+        *
+        * @deprecated Since 1.24, instantiate this class directly
         */
        public static function newFromTitle( $title, $action ) {
-               $cache = new self();
+               return new self( $title, $action );
+       }
 
+       /**
+        * @param Title|string $title Title object or prefixed DB key string
+        * @param string $action
+        * @throws MWException
+        */
+       public function __construct( $title, $action ) {
+               parent::__construct();
                $allowedTypes = self::cacheablePageActions();
                if ( !in_array( $action, $allowedTypes ) ) {
-                       throw new MWException( "Invalid filecache type given." );
+                       throw new MWException( 'Invalid file cache type given.' );
                }
-               $cache->mKey = ( $title instanceof Title )
+               $this->mKey = ( $title instanceof Title )
                        ? $title->getPrefixedDBkey()
                        : (string)$title;
-               $cache->mType = (string)$action;
-               $cache->mExt = 'html';
-
-               return $cache;
+               $this->mType = (string)$action;
+               $this->mExt = 'html';
        }
 
        /**
@@ -88,12 +96,12 @@ class HTMLFileCache extends FileCacheBase {
         * @return bool
         */
        public static function useFileCache( IContextSource $context ) {
-               global $wgUseFileCache, $wgShowIPinHeader, $wgDebugToolbar, $wgContLang;
+               global $wgUseFileCache, $wgDebugToolbar, $wgContLang;
                if ( !$wgUseFileCache ) {
                        return false;
                }
-               if ( $wgShowIPinHeader || $wgDebugToolbar ) {
-                       wfDebug( "HTML file cache skipped. Either \$wgShowIPinHeader and/or \$wgDebugToolbar on\n" );
+               if ( $wgDebugToolbar ) {
+                       wfDebug( "HTML file cache skipped. \$wgDebugToolbar on\n" );
 
                        return false;
                }
@@ -120,7 +128,11 @@ class HTMLFileCache extends FileCacheBase {
                $clang = $wgContLang->getCode();
 
                // Check that there are no other sources of variation
-               return !$user->getId() && !$user->getNewtalk() && $ulang == $clang;
+               if ( $user->getId() || $user->getNewtalk() || $ulang != $clang ) {
+                       return false;
+               }
+               // Allow extensions to disable caching
+               return Hooks::run( 'HTMLFileCache::useFileCache', array( $context ) );
        }
 
        /**
@@ -211,7 +223,7 @@ class HTMLFileCache extends FileCacheBase {
                }
 
                foreach ( self::cacheablePageActions() as $type ) {
-                       $fc = self::newFromTitle( $title, $type );
+                       $fc = new self( $title, $type );
                        $fc->clearCache();
                }