From 43993f1fd6ce18bb086728b72e30b6da184f863f Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sun, 20 Mar 2011 16:38:08 +0000 Subject: [PATCH] (bug 27641) purgeThumbnails should support exclusion of expensive files. Add $wgExcludeFromThumbnailPurge and don't purge thumbnails whose extension is in that array when the files they belong to are purged with action=purge. Committing patch by Michael Dale with small coding style tweaks --- includes/DefaultSettings.php | 6 ++++++ includes/filerepo/LocalFile.php | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e25bed0a50..e1c18060fa 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4645,6 +4645,12 @@ $wgJobClasses = array( 'uploadFromUrl' => 'UploadFromUrlJob', ); +/** + * Extensions of "thumbnails" that are very expensive to regenerate and should be + * excluded from normal action=purge thumbnail removal. + */ +$wgExcludeFromThumbnailPurge = array(); + /** * Additional functions to be performed with updateSpecialPages. * Expensive Querypages are already updated. diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 6e57ca08bf..d495c00c05 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -659,7 +659,7 @@ class LocalFile extends File { * Delete cached transformed files */ function purgeThumbnails() { - global $wgUseSquid; + global $wgUseSquid, $wgExcludeFromThumbnailPurge; // Delete thumbnails $files = $this->getThumbnails(); @@ -667,6 +667,12 @@ class LocalFile extends File { $urls = array(); foreach ( $files as $file ) { + // Only remove files not in the $wgExcludeFromThumbnailPurge configuration variable + $ext = pathinfo( "$dir/$file", PATHINFO_EXTENSION ); + if ( in_array( $ext, $wgExcludeFromThumbnailPurge ) ) { + continue; + } + # Check that the base file name is part of the thumb name # This is a basic sanity check to avoid erasing unrelated directories if ( strpos( $file, $this->getName() ) !== false ) { -- 2.20.1