From 6b75e88a79d502c182f3a1a822365df10cd4e5c6 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sun, 2 Oct 2011 20:08:05 +0000 Subject: [PATCH] Follow-up r84395: Give MediaHandlers the option to remove items from the thumbnail purge list. Is needed for TMH because thumbnail rendering may be very expensive for media files. Haven't thought yet of a way to integrate this with the UI, but the current framework should be flexible enough to implement that later. Added array $options to File::purgeCache(), LocalFile::purgeCache(), LocalFile::purgeThumbnails(), ForeignAPIFile::purgeCache() and ForeignAPIFile::purgeThumbnails() which is currently empty, but can be used later to indicate a full or partial purge. Added MediaHandler::filterThumbnailPurgeList(), which can remove items from the purge list and also gets passed this $options array --- includes/filerepo/File.php | 3 ++- includes/filerepo/ForeignAPIFile.php | 16 +++++++++++++--- includes/filerepo/LocalFile.php | 16 ++++++++++++---- includes/media/Generic.php | 10 ++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 93ca6c4f7f..30717f678c 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -823,8 +823,9 @@ abstract class File { * Purge shared caches such as thumbnails and DB data caching * STUB * Overridden by LocalFile + * @param array $options Array with options, currently undefined */ - function purgeCache() {} + function purgeCache( $options = array() ) {} /** * Purge the file description page, but don't go after diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php index ba699beec0..e027dddc6d 100644 --- a/includes/filerepo/ForeignAPIFile.php +++ b/includes/filerepo/ForeignAPIFile.php @@ -209,8 +209,11 @@ class ForeignAPIFile extends File { return $files; } - function purgeCache() { - $this->purgeThumbnails(); + /** + * @see File::purgeCache() + */ + function purgeCache( $options = array() ) { + $this->purgeThumbnails( $options ); $this->purgeDescriptionPage(); } @@ -221,11 +224,18 @@ class ForeignAPIFile extends File { $wgMemc->delete( $key ); } - function purgeThumbnails() { + function purgeThumbnails( $options = array() ) { global $wgMemc; $key = $this->repo->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $this->getName() ); $wgMemc->delete( $key ); + $files = $this->getThumbnails(); + // Give media handler a chance to filter the purge list + $handler = $this->getHandler(); + if ( $handler ) { + $handler->filterThumbnailPurgeList( $files, $options ); + } + $dir = $this->getThumbPath( $this->getName() ); foreach ( $files as $file ) { unlink( $dir . $file ); diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 767e76273e..17f7bd604b 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -675,12 +675,12 @@ class LocalFile extends File { /** * Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid */ - function purgeCache() { + function purgeCache( $options = array() ) { // Refresh metadata cache $this->purgeMetadataCache(); // Delete thumbnails - $this->purgeThumbnails(); + $this->purgeThumbnails( $options ); // Purge squid cache for this file SquidUpdate::purge( array( $this->getURL() ) ); @@ -720,10 +720,18 @@ class LocalFile extends File { /** * Delete cached transformed files for the current version only. */ - function purgeThumbnails() { + function purgeThumbnails( $options = array() ) { global $wgUseSquid; - // get a list of thumbnails and URLs + + // Get a list of thumbnails and URLs $files = $this->getThumbnails(); + + // Give media handler a chance to filter the purge list + $handler = $this->getHandler(); + if ( $handler ) { + $handler->filterThumbnailPurgeList( $files, $options ); + } + $dir = array_shift( $files ); $this->purgeThumbList( $dir, $files ); diff --git a/includes/media/Generic.php b/includes/media/Generic.php index 5cd5a20bde..12f35db5d4 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -504,6 +504,16 @@ abstract class MediaHandler { } return false; } + + /** + * Remove files from the purge list + * + * @param array $files + * @param array $options + */ + public function filterThumbnailPurgeList( &$files, $options ) { + // Do nothing + } } /** -- 2.20.1