Merge "Move IP::isConfigured/TrustedProxy() to ProxyLookup service"
[lhc/web/wiklou.git] / includes / filebackend / FSFile.php
index 8aa11b6..e7e2608 100644 (file)
@@ -85,15 +85,6 @@ class FSFile {
                return $timestamp;
        }
 
-       /**
-        * Guess the MIME type from the file contents alone
-        *
-        * @return string
-        */
-       public function getMimeType() {
-               return MimeMagic::singleton()->guessMimeType( $this->path, false );
-       }
-
        /**
         * Get an associative array containing information about
         * a file with the given storage path.
@@ -117,45 +108,34 @@ class FSFile {
         * @return array
         */
        public function getProps( $ext = true ) {
-               wfDebug( __METHOD__ . ": Getting file info for $this->path\n" );
-
                $info = self::placeholderProps();
                $info['fileExists'] = $this->exists();
 
                if ( $info['fileExists'] ) {
+                       $info['size'] = $this->getSize(); // bytes
+                       $info['sha1'] = $this->getSha1Base36();
+                       // @TODO: replace the code below with bare FileInfo use so this can go in /libs
                        $magic = MimeMagic::singleton();
 
-                       # get the file extension
-                       if ( $ext === true ) {
-                               $ext = self::extensionFromPath( $this->path );
-                       }
-
                        # MIME type according to file contents
-                       $info['file-mime'] = $this->getMimeType();
-                       # logical MIME type
+                       $info['file-mime'] = $magic->guessMimeType( $this->path, false );
+                       # Logical MIME type
+                       $ext = ( $ext === true ) ? FileBackend::extensionFromPath( $this->path ) : $ext;
                        $info['mime'] = $magic->improveTypeFromExtension( $info['file-mime'], $ext );
 
                        list( $info['major_mime'], $info['minor_mime'] ) = File::splitMime( $info['mime'] );
                        $info['media_type'] = $magic->getMediaType( $this->path, $info['mime'] );
 
-                       # Get size in bytes
-                       $info['size'] = $this->getSize();
-
                        # Height, width and metadata
                        $handler = MediaHandler::getHandler( $info['mime'] );
                        if ( $handler ) {
-                               $tempImage = (object)[]; // XXX (hack for File object)
-                               $info['metadata'] = $handler->getMetadata( $tempImage, $this->path );
-                               $gis = $handler->getImageSize( $tempImage, $this->path, $info['metadata'] );
+                               $info['metadata'] = $handler->getMetadata( $this, $this->path );
+                               /** @noinspection PhpMethodParametersCountMismatchInspection */
+                               $gis = $handler->getImageSize( $this, $this->path, $info['metadata'] );
                                if ( is_array( $gis ) ) {
                                        $info = $this->extractImageSizeInfo( $gis ) + $info;
                                }
                        }
-                       $info['sha1'] = $this->getSha1Base36();
-
-                       wfDebug( __METHOD__ . ": $this->path loaded, {$info['size']} bytes, {$info['mime']}.\n" );
-               } else {
-                       wfDebug( __METHOD__ . ": $this->path NOT FOUND!\n" );
                }
 
                return $info;
@@ -166,7 +146,11 @@ class FSFile {
         *
         * Resulting array fields include:
         *   - fileExists
+        *   - size
+        *   - file-mime (as major/minor)
         *   - mime (as major/minor)
+        *   - major_mime
+        *   - minor_mime
         *   - media_type (value to be used with the MEDIATYPE_xxx constants)
         *   - metadata (handler specific)
         *   - sha1 (in base 36)
@@ -179,6 +163,10 @@ class FSFile {
        public static function placeholderProps() {
                $info = [];
                $info['fileExists'] = false;
+               $info['size'] = 0;
+               $info['file-mime'] = null;
+               $info['major_mime'] = null;
+               $info['minor_mime'] = null;
                $info['mime'] = null;
                $info['media_type'] = MEDIATYPE_UNKNOWN;
                $info['metadata'] = '';