Add small HtmlCacheUpdater service class to normalize purging code
[lhc/web/wiklou.git] / includes / cache / HTMLFileCache.php
index a0d61b2..6d0b87e 100644 (file)
@@ -219,21 +219,33 @@ class HTMLFileCache extends FileCacheBase {
                return $text;
        }
 
+       /**
+        * @param string[] $prefixedDbKeys List of prefixed DB keys for pages to purge
+        * @since 1.34
+        */
+       public static function purge( array $prefixedDbKeys ) {
+               foreach ( $prefixedDbKeys as $prefixedDbKey ) {
+                       foreach ( self::cacheablePageActions() as $type ) {
+                               $fc = new self( $prefixedDbKey, $type );
+                               $fc->clearCache();
+                       }
+               }
+       }
+
        /**
         * Clear the file caches for a page for all actions
-        * @param Title $title
+        * @param Traversable|Title[]|Title $titles
         * @return bool Whether $wgUseFileCache is enabled
         */
-       public static function clearFileCache( Title $title ) {
+       public static function clearFileCache( $titles ) {
                $config = MediaWikiServices::getInstance()->getMainConfig();
-
                if ( !$config->get( 'UseFileCache' ) ) {
                        return false;
                }
 
-               foreach ( self::cacheablePageActions() as $type ) {
-                       $fc = new self( $title, $type );
-                       $fc->clearCache();
+               $titleIterator = ( $titles instanceof Title ) ? [ $titles ] : $titles;
+               foreach ( $titleIterator as $title ) {
+                       self::purge( [ $title->getPrefixedDBkey() ] );
                }
 
                return true;