Split LocalFile.php to have one class in one file
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index cc39b94..7d4f4df 100644 (file)
@@ -29,6 +29,7 @@ use MediaWiki\MediaWikiServices;
  * @ingroup FileAbstraction
  */
 
+// @phan-file-suppress PhanTypeMissingReturn false positives
 /**
  * Implements some public methods and some protected utility functions which
  * are required by multiple child classes. Contains stub functionality for
@@ -207,7 +208,7 @@ abstract class File implements IDBAccessObject {
                if ( !is_callable( $function ) ) {
                        return null;
                } else {
-                       $this->$name = call_user_func( $function );
+                       $this->$name = $function();
 
                        return $this->$name;
                }
@@ -633,20 +634,15 @@ abstract class File implements IDBAccessObject {
                        // one would not expect it to be animated
                        // so true.
                        return true;
-               } else {
-                       if ( $this->allowInlineDisplay()
-                               && $handler->isAnimatedImage( $this )
-                               && !$handler->canAnimateThumbnail( $this )
-                       ) {
-                               // Image is animated, but thumbnail isn't.
-                               // This is unexpected to the user.
-                               return false;
-                       } else {
-                               // Image is not animated, so one would
-                               // not expect thumb to be
-                               return true;
-                       }
                }
+
+               return !$this->allowInlineDisplay()
+                       // Image is not animated, so one would
+                       // not expect thumb to be
+                       || !$handler->isAnimatedImage( $this )
+                       // Image is animated, but thumbnail isn't.
+                       // This is unexpected to the user.
+                       || $handler->canAnimateThumbnail( $this );
        }
 
        /**
@@ -1543,7 +1539,7 @@ abstract class File implements IDBAccessObject {
        function getArchiveRel( $suffix = false ) {
                $path = 'archive/' . $this->getHashPath();
                if ( $suffix === false ) {
-                       $path = substr( $path, 0, -1 );
+                       $path = rtrim( $path, '/' );
                } else {
                        $path .= $suffix;
                }
@@ -1586,11 +1582,9 @@ abstract class File implements IDBAccessObject {
         * @return string
         */
        function getArchiveThumbRel( $archiveName, $suffix = false ) {
-               $path = $this->getArchiveRel( $archiveName ) . "/";
-               if ( $suffix === false ) {
-                       $path = substr( $path, 0, -1 );
-               } else {
-                       $path .= $suffix;
+               $path = $this->getArchiveRel( $archiveName );
+               if ( $suffix !== false ) {
+                       $path .= '/' . $suffix;
                }
 
                return $path;
@@ -1657,7 +1651,7 @@ abstract class File implements IDBAccessObject {
                $ext = $this->getExtension();
                $path = $this->repo->getZoneUrl( 'public', $ext ) . '/archive/' . $this->getHashPath();
                if ( $suffix === false ) {
-                       $path = substr( $path, 0, -1 );
+                       $path = rtrim( $path, '/' );
                } else {
                        $path .= rawurlencode( $suffix );
                }
@@ -1676,11 +1670,9 @@ abstract class File implements IDBAccessObject {
                $this->assertRepoDefined();
                $ext = $this->getExtension();
                $path = $this->repo->getZoneUrl( 'thumb', $ext ) . '/archive/' .
-                       $this->getHashPath() . rawurlencode( $archiveName ) . "/";
-               if ( $suffix === false ) {
-                       $path = substr( $path, 0, -1 );
-               } else {
-                       $path .= rawurlencode( $suffix );
+                       $this->getHashPath() . rawurlencode( $archiveName );
+               if ( $suffix !== false ) {
+                       $path .= '/' . rawurlencode( $suffix );
                }
 
                return $path;
@@ -1750,7 +1742,7 @@ abstract class File implements IDBAccessObject {
                $this->assertRepoDefined();
                $path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
                if ( $suffix === false ) {
-                       $path = substr( $path, 0, -1 );
+                       $path = rtrim( $path, '/' );
                } else {
                        $path .= rawurlencode( $suffix );
                }