Deprecate HTMLFileCache::newFromTitle() in favor of constructor
authorMax Semenik <maxsem.wiki@gmail.com>
Mon, 15 Sep 2014 22:47:30 +0000 (15:47 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 19 Sep 2014 00:07:51 +0000 (00:07 +0000)
Change-Id: I903e68fc1f486501d790ca69146ecb835d90c9cc

includes/MediaWiki.php
includes/actions/HistoryAction.php
includes/cache/HTMLFileCache.php
includes/db/DatabaseError.php
includes/page/Article.php

index 9213c02..545a46f 100644 (file)
@@ -560,7 +560,7 @@ class MediaWiki {
                        wfProfileIn( 'main-try-filecache' );
                        if ( HTMLFileCache::useFileCache( $this->context ) ) {
                                // Try low-level file cache hit
-                               $cache = HTMLFileCache::newFromTitle( $title, $action );
+                               $cache = new HTMLFileCache( $title, $action );
                                if ( $cache->isCacheGood( /* Assume up to date */ ) ) {
                                        // Check incoming headers to see if client has this cached
                                        $timestamp = $cache->cacheTimestamp();
index 523da68..8522e56 100644 (file)
@@ -110,7 +110,7 @@ class HistoryAction extends FormlessAction {
                # Fill in the file cache if not set already
                $useFileCache = $config->get( 'UseFileCache' );
                if ( $useFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
-                       $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'history' );
+                       $cache = new HTMLFileCache( $this->getTitle(), 'history' );
                        if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
                                ob_start( array( &$cache, 'saveToFileCache' ) );
                        }
index 91580f9..033941f 100644 (file)
@@ -35,21 +35,28 @@ 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 ) {
                $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';
        }
 
        /**
@@ -211,7 +218,7 @@ class HTMLFileCache extends FileCacheBase {
                }
 
                foreach ( self::cacheablePageActions() as $type ) {
-                       $fc = self::newFromTitle( $title, $type );
+                       $fc = new self( $title, $type );
                        $fc->clearCache();
                }
 
index 8229c99..2dfec41 100644 (file)
@@ -306,7 +306,7 @@ EOT;
                        }
                }
 
-               $cache = HTMLFileCache::newFromTitle( $t, 'view' );
+               $cache = new HTMLFileCache( $t, 'view' );
                if ( $cache->isCached() ) {
                        return $cache->fetchText();
                } else {
index 9845316..daf3311 100644 (file)
@@ -1841,7 +1841,7 @@ class Article implements Page {
 
                $called = true;
                if ( $this->isFileCacheable() ) {
-                       $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'view' );
+                       $cache = new HTMLFileCache( $this->getTitle(), 'view' );
                        if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
                                wfDebug( "Article::tryFileCache(): about to load file\n" );
                                $cache->loadFromFileCache( $this->getContext() );