Add small HtmlCacheUpdater service class to normalize purging code
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index d7d6bf7..989d222 100644 (file)
@@ -25,6 +25,7 @@ use Wikimedia\AtEase\AtEase;
 use MediaWiki\Logger\LoggerFactory;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\IResultWrapper;
 use MediaWiki\MediaWikiServices;
 
 /**
@@ -99,7 +100,7 @@ class LocalFile extends File {
        /** @var int Number of line to return by nextHistoryLine() (constructor) */
        private $historyLine;
 
-       /** @var int Result of the query for the file's history (nextHistoryLine) */
+       /** @var IResultWrapper|null Result of the query for the file's history (nextHistoryLine) */
        private $historyRes;
 
        /** @var string Major MIME type */
@@ -1046,10 +1047,7 @@ class LocalFile extends File {
                $this->purgeThumbnails( $options );
 
                // Purge CDN cache for this file
-               DeferredUpdates::addUpdate(
-                       new CdnCacheUpdate( [ $this->getUrl() ] ),
-                       DeferredUpdates::PRESEND
-               );
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $this->getUrl() );
        }
 
        /**
@@ -1072,7 +1070,7 @@ class LocalFile extends File {
                foreach ( $files as $file ) {
                        $urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
                }
-               DeferredUpdates::addUpdate( new CdnCacheUpdate( $urls ), DeferredUpdates::PRESEND );
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $urls );
        }
 
        /**
@@ -1104,7 +1102,7 @@ class LocalFile extends File {
                $this->purgeThumbList( $dir, $files );
 
                // Purge the CDN
-               DeferredUpdates::addUpdate( new CdnCacheUpdate( $urls ), DeferredUpdates::PRESEND );
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $urls );
        }
 
        /**
@@ -1724,8 +1722,9 @@ class LocalFile extends File {
                                                }
                                        } else {
                                                # Existing file page: invalidate description page cache
-                                               $wikiPage->getTitle()->invalidateCache();
-                                               $wikiPage->getTitle()->purgeSquid();
+                                               $title = $wikiPage->getTitle();
+                                               $title->invalidateCache();
+                                               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $title );
                                                # Allow the new file version to be patrolled from the page footer
                                                Article::purgePatrolFooterCache( $descId );
                                        }
@@ -1773,10 +1772,8 @@ class LocalFile extends File {
                                                # Delete old thumbnails
                                                $this->purgeThumbnails();
                                                # Remove the old file from the CDN cache
-                                               DeferredUpdates::addUpdate(
-                                                       new CdnCacheUpdate( [ $this->getUrl() ] ),
-                                                       DeferredUpdates::PRESEND
-                                               );
+                                               MediaWikiServices::getInstance()
+                                                       ->getHtmlCacheUpdater()->purge( $this->getUrl() );
                                        } else {
                                                # Update backlink pages pointing to this title if created
                                                LinksUpdate::queueRecursiveJobsForTable(
@@ -1799,9 +1796,12 @@ class LocalFile extends File {
                }
 
                # Invalidate cache for all pages using this file
-               DeferredUpdates::addUpdate(
-                       new HTMLCacheUpdate( $this->getTitle(), 'imagelinks', 'file-upload' )
+               $job = HTMLCacheUpdateJob::newForBacklinks(
+                       $this->getTitle(),
+                       'imagelinks',
+                       [ 'causeAction' => 'file-upload', 'causeAgent' => $user->getName() ]
                );
+               JobQueueGroup::singleton()->lazyPush( $job );
 
                return Status::newGood();
        }
@@ -2003,7 +2003,7 @@ class LocalFile extends File {
                foreach ( $archiveNames as $archiveName ) {
                        $purgeUrls[] = $this->getArchiveUrl( $archiveName );
                }
-               DeferredUpdates::addUpdate( new CdnCacheUpdate( $purgeUrls ), DeferredUpdates::PRESEND );
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $purgeUrls );
 
                return $status;
        }
@@ -2040,10 +2040,8 @@ class LocalFile extends File {
                        $this->purgeDescription();
                }
 
-               DeferredUpdates::addUpdate(
-                       new CdnCacheUpdate( [ $this->getArchiveUrl( $archiveName ) ] ),
-                       DeferredUpdates::PRESEND
-               );
+               $url = $this->getArchiveUrl( $archiveName );
+               MediaWikiServices::getInstance()->getHtmlCacheUpdater()->purge( $url );
 
                return $status;
        }