From b9fe0b2fbff7065571e3673e3d2628a76055fa15 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 28 Nov 2011 08:53:03 +0000 Subject: [PATCH] Restored r98710 but with a 'forRefresh' option (not used yet) --- includes/WikiFilePage.php | 4 ++-- includes/filerepo/file/File.php | 4 +++- includes/filerepo/file/ForeignAPIFile.php | 15 ++++++++++++--- includes/filerepo/file/LocalFile.php | 13 ++++++++++--- includes/media/Generic.php | 10 ++++++++++ 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/includes/WikiFilePage.php b/includes/WikiFilePage.php index 87b5487531..a7d6ccbbba 100644 --- a/includes/WikiFilePage.php +++ b/includes/WikiFilePage.php @@ -156,12 +156,12 @@ class WikiFilePage extends WikiPage { $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' ); $update->doUpdate(); $this->mFile->upgradeRow(); - $this->mFile->purgeCache(); + $this->mFile->purgeCache( array( 'forRefresh' => true ) ); } else { wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile->getName() . "; limiting purge to cache only\n" ); // even if the file supposedly doesn't exist, force any cached information // to be updated (in case the cached information is wrong) - $this->mFile->purgeCache(); + $this->mFile->purgeCache( array( 'forRefresh' => true ) ); } parent::doPurge(); } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 8d12ef895e..57e85684c1 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -863,8 +863,10 @@ abstract class File { * Purge shared caches such as thumbnails and DB data caching * STUB * Overridden by LocalFile + * @param $options Array Options, which include: + * 'forRefresh' : The purging is only to refresh thumbnails */ - function purgeCache() {} + function purgeCache( $options = array() ) {} /** * Purge the file description page, but don't go after diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index 9cd798da97..281687b1d1 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -214,8 +214,11 @@ class ForeignAPIFile extends File { return $files; } - function purgeCache() { - $this->purgeThumbnails(); + /** + * @see File::purgeCache() + */ + function purgeCache( $options = array() ) { + $this->purgeThumbnails( $options ); $this->purgeDescriptionPage(); } @@ -226,11 +229,17 @@ 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/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index d11030fdc6..9606119410 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/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() ) ); @@ -723,11 +723,18 @@ class LocalFile extends File { /** * Delete cached transformed files for the current version only. */ - function purgeThumbnails() { + function purgeThumbnails( $options ) { global $wgUseSquid; // Delete thumbnails $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..8684af552e 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