Followup 1cf5a6e: use $wgResourceBasePath to refer to resources/assets, not $wgScriptPath
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index c6da1f1..b574c5e 100644 (file)
@@ -679,7 +679,7 @@ abstract class File {
        }
 
        /**
-        * Returns the mime type of the file.
+        * Returns the MIME type of the file.
         * Overridden by LocalFile, UnregisteredLocalFile
         * STUB
         *
@@ -714,7 +714,7 @@ abstract class File {
         */
        function canRender() {
                if ( !isset( $this->canRender ) ) {
-                       $this->canRender = $this->getHandler() && $this->handler->canRender( $this );
+                       $this->canRender = $this->getHandler() && $this->handler->canRender( $this ) && $this->exists();
                }
 
                return $this->canRender;
@@ -1231,9 +1231,25 @@ abstract class File {
                        }
                }
 
+               // Thumbnailing a very large file could result in network saturation if
+               // everyone does it at once.
+               if ( $this->getSize() >= 1e7 ) { // 10MB
+                       $that = $this;
+                       $work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ),
+                               array(
+                                       'doWork' => function() use ( $that ) {
+                                               return $that->getLocalRefPath();
+                                       }
+                               )
+                       );
+                       $srcPath = $work->execute();
+               } else {
+                       $srcPath = $this->getLocalRefPath();
+               }
+
                // Original file
                return array(
-                       'path' => $this->getLocalRefPath(),
+                       'path' => $srcPath,
                        'width' => $this->getWidth(),
                        'height' => $this->getHeight()
                );
@@ -1261,7 +1277,7 @@ abstract class File {
        /**
         * Creates a temp FS file with the same extension and the thumbnail
         * @param string $thumbPath Thumbnail path
-        * @returns TempFSFile
+        * @return TempFSFile
         */
        protected function makeTransformTmpFile( $thumbPath ) {
                $thumbExt = FileBackend::extensionFromPath( $thumbPath );
@@ -1287,6 +1303,7 @@ abstract class File {
         * Hook into transform() to allow migration of thumbnail files
         * STUB
         * Overridden by LocalFile
+        * @param string $thumbName
         */
        function migrateThumbFile( $thumbName ) {
        }
@@ -1311,16 +1328,16 @@ abstract class File {
         * @return ThumbnailImage
         */
        function iconThumb() {
-               global $wgStylePath, $wgStyleDirectory;
+               global $wgResourceBasePath, $IP;
+               $assetsPath = "$wgResourceBasePath/resources/assets/file-type-icons/";
+               $assetsDirectory = "$IP/resources/assets/file-type-icons/";
 
                $try = array( 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' );
                foreach ( $try as $icon ) {
-                       $path = '/common/images/icons/' . $icon;
-                       $filepath = $wgStyleDirectory . $path;
-                       if ( file_exists( $filepath ) ) { // always FS
+                       if ( file_exists( $assetsDirectory . $icon ) ) { // always FS
                                $params = array( 'width' => 120, 'height' => 120 );
 
-                               return new ThumbnailImage( $this, $wgStylePath . $path, false, $params );
+                               return new ThumbnailImage( $this, $assetsPath . $icon, false, $params );
                        }
                }
 
@@ -1330,6 +1347,7 @@ abstract class File {
        /**
         * Get last thumbnailing error.
         * Largely obsolete.
+        * @return string
         */
        function getLastError() {
                return $this->lastError;
@@ -1937,7 +1955,7 @@ abstract class File {
         * @note Use getWidth()/getHeight() instead of this method unless you have a
         *  a good reason. This method skips all caches.
         *
-        * @param string $fileName The path to the file (e.g. From getLocalPathRef() )
+        * @param string $filePath The path to the file (e.g. From getLocalPathRef() )
         * @return array The width, followed by height, with optionally more things after
         */
        function getImageSize( $filePath ) {