Add option to expose original sha1 in thumb url
authorGilles Dubuc <gdubuc@wikimedia.org>
Mon, 14 Sep 2015 17:03:04 +0000 (19:03 +0200)
committerGilles Dubuc <gdubuc@wikimedia.org>
Tue, 29 Sep 2015 21:37:23 +0000 (23:37 +0200)
Bug: T112546
Change-Id: I545586ff8d0020d00d9faa1dff2d0d9721134452

includes/filerepo/FileRepo.php
includes/filerepo/LocalRepo.php
includes/filerepo/file/File.php

index 7370c5c..0bb814d 100644 (file)
@@ -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;
+       }
 }
 
 /**
index 6a2c064..f702a22 100644 (file)
@@ -29,9 +29,6 @@
  * @ingroup FileRepo
  */
 class LocalRepo extends FileRepo {
-       /** @var bool */
-       protected $hasSha1Storage = false;
-
        /** @var array */
        protected $fileFactory = array( 'LocalFile', 'newFromTitle' );
 
index f40d216..912e919 100644 (file)
@@ -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;