From ab9446c9118dfbea55830838ffba9f7af8ef4a0f Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Mon, 14 Sep 2015 19:03:04 +0200 Subject: [PATCH] Add option to expose original sha1 in thumb url Bug: T112546 Change-Id: I545586ff8d0020d00d9faa1dff2d0d9721134452 --- includes/filerepo/FileRepo.php | 13 +++++++++++++ includes/filerepo/LocalRepo.php | 3 --- includes/filerepo/file/File.php | 13 ++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 7370c5cd4a..0bb814dea8 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -52,6 +52,9 @@ class FileRepo { /** @var bool */ protected $hasSha1Storage = false; + /** @var bool */ + protected $supportsSha1URLs = false; + /** @var FileBackend */ protected $backend; @@ -200,6 +203,8 @@ class FileRepo { $this->zones[$zone]['urlsByExt'] = array(); } } + + $this->supportsSha1URLs = !empty( $info['supportsSha1URLs'] ); } /** @@ -1896,6 +1901,14 @@ class FileRepo { public function hasSha1Storage() { return $this->hasSha1Storage; } + + /** + * Returns whether or not repo supports having originals SHA-1s in the thumb URLs + * @return boolean + */ + public function supportsSha1URLs() { + return $this->supportsSha1URLs; + } } /** diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 6a2c0640be..f702a222d7 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -29,9 +29,6 @@ * @ingroup FileRepo */ class LocalRepo extends FileRepo { - /** @var bool */ - protected $hasSha1Storage = false; - /** @var array */ protected $fileFactory = array( 'LocalFile', 'newFromTitle' ); diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index f40d216c58..912e919b45 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -946,9 +946,16 @@ abstract class File implements IDBAccessObject { $extension = $this->getExtension(); list( $thumbExt, ) = $this->getHandler()->getThumbType( $extension, $this->getMimeType(), $params ); - $thumbName = $this->getHandler()->makeParamString( $params ) . '-' . $name; - if ( $thumbExt != $extension ) { - $thumbName .= ".$thumbExt"; + $thumbName = $this->getHandler()->makeParamString( $params ); + + if ( $this->repo->supportsSha1URLs() ) { + $thumbName .= '-' . $this->getSha1() . '.' . $thumbExt; + } else { + $thumbName .= '-' . $name; + + if ( $thumbExt != $extension ) { + $thumbName .= ".$thumbExt"; + } } return $thumbName; -- 2.20.1