Merge "Add option to expose original sha1 in thumb url"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 30 Sep 2015 01:43:52 +0000 (01:43 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 30 Sep 2015 01:43:52 +0000 (01:43 +0000)
includes/filerepo/FileRepo.php
includes/filerepo/LocalRepo.php
includes/filerepo/file/File.php

index 25e46d8..c0ae3b6 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'] );
        }
 
        /**
@@ -1894,6 +1899,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 6e3fb51..6361463 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 ec5af85..cde5e6a 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;