From: Roan Kattouw Date: Sun, 20 Mar 2011 16:38:08 +0000 (+0000) Subject: (bug 27641) purgeThumbnails should support exclusion of expensive files. Add $wgExclu... X-Git-Tag: 1.31.0-rc.0~31296 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=43993f1fd6ce18bb086728b72e30b6da184f863f;p=lhc%2Fweb%2Fwiklou.git (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 --- 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 ) {