jenkins-bot has submitted this change and it was merged.

Change subject: Remove MimeMagic depedency from FSFile and move it to /libs
......................................................................


Remove MimeMagic depedency from FSFile and move it to /libs

Change-Id: Ieaae909b49c798b6e9bed65d15961cefbdaec49b
---
M autoload.php
M includes/MimeMagic.php
M includes/filerepo/FileRepo.php
R includes/libs/filebackend/FSFile.php
R includes/libs/filebackend/TempFSFile.php
M includes/utils/MWFileProps.php
6 files changed, 50 insertions(+), 47 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index cbc079c..e5cecc9 100644
--- a/autoload.php
+++ b/autoload.php
@@ -432,7 +432,7 @@
        'ExternalStoreHttp' => __DIR__ . 
'/includes/externalstore/ExternalStoreHttp.php',
        'ExternalStoreMedium' => __DIR__ . 
'/includes/externalstore/ExternalStoreMedium.php',
        'ExternalStoreMwstore' => __DIR__ . 
'/includes/externalstore/ExternalStoreMwstore.php',
-       'FSFile' => __DIR__ . '/includes/filebackend/FSFile.php',
+       'FSFile' => __DIR__ . '/includes/libs/filebackend/FSFile.php',
        'FSFileBackend' => __DIR__ . '/includes/filebackend/FSFileBackend.php',
        'FSFileBackendDirList' => __DIR__ . 
'/includes/filebackend/FSFileBackend.php',
        'FSFileBackendFileList' => __DIR__ . 
'/includes/filebackend/FSFileBackend.php',
@@ -1403,7 +1403,7 @@
        'TableDiffFormatter' => __DIR__ . 
'/includes/diff/TableDiffFormatter.php',
        'TablePager' => __DIR__ . '/includes/pager/TablePager.php',
        'TagLogFormatter' => __DIR__ . '/includes/logging/TagLogFormatter.php',
-       'TempFSFile' => __DIR__ . '/includes/filebackend/TempFSFile.php',
+       'TempFSFile' => __DIR__ . '/includes/libs/filebackend/TempFSFile.php',
        'TempFileRepo' => __DIR__ . '/includes/filerepo/FileRepo.php',
        'TemplateParser' => __DIR__ . '/includes/TemplateParser.php',
        'TemplatesOnThisPageFormatter' => __DIR__ . 
'/includes/TemplatesOnThisPageFormatter.php',
diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php
index 5551865..54d58d2 100644
--- a/includes/MimeMagic.php
+++ b/includes/MimeMagic.php
@@ -863,10 +863,8 @@
                        $mime = "application/x-opc+zip";
                        # TODO: remove the block below, as soon as 
improveTypeFromExtension is used everywhere
                        if ( $ext !== true && $ext !== false ) {
-                               /** This is the mode used by getPropsFromPath
-                                * These MIME's are stored in the database, 
where we don't really want
-                                * x-opc+zip, because we use it only for 
internal purposes
-                                */
+                               // These MIME's are stored in the database, 
where we don't really want
+                               // x-opc+zip, because we use it only for 
internal purposes
                                if ( $this->isMatchingExtension( $ext, $mime ) 
) {
                                        /* A known file extension for an OPC 
file,
                                         * find the proper mime type for that 
file extension
diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php
index b5c5bf3..1a6c818 100644
--- a/includes/filerepo/FileRepo.php
+++ b/includes/filerepo/FileRepo.php
@@ -1540,11 +1540,11 @@
         */
        public function getFileProps( $virtualUrl ) {
                $fsFile = $this->getLocalReference( $virtualUrl );
+               $mwProps = new MWFileProps( MimeMagic::singleton() );
                if ( $fsFile ) {
-                       $mwProps = new MWFileProps( MimeMagic::singleton() );
                        $props = $mwProps->getPropsFromPath( 
$fsFile->getPath(), true );
                } else {
-                       $props = FSFile::placeholderProps();
+                       $props = $mwProps->newPlaceholderProps();
                }
 
                return $props;
diff --git a/includes/filebackend/FSFile.php 
b/includes/libs/filebackend/FSFile.php
similarity index 78%
rename from includes/filebackend/FSFile.php
rename to includes/libs/filebackend/FSFile.php
index e7e2608..d0e93da 100644
--- a/includes/filebackend/FSFile.php
+++ b/includes/libs/filebackend/FSFile.php
@@ -93,18 +93,13 @@
         *   - fileExists
         *   - size (filesize in bytes)
         *   - mime (as major/minor)
-        *   - media_type (value to be used with the MEDIATYPE_xxx constants)
-        *   - metadata (handler specific)
+        *   - file-mime (as major/minor)
         *   - sha1 (in base 36)
-        *   - width
-        *   - height
-        *   - bits (bitrate)
-        *   - file-mime
         *   - major_mime
         *   - minor_mime
         *
         * @param string|bool $ext The file extension, or true to extract it 
from the filename.
-        *             Set it to false to ignore the extension.
+        *             Set it to false to ignore the extension. Currently 
unused.
         * @return array
         */
        public function getProps( $ext = true ) {
@@ -114,27 +109,17 @@
                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();
 
+                       $mime = mime_content_type( $this->path );
                        # MIME type according to file contents
-                       $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 );
+                       $info['file-mime'] = ( $mime === false ) ? 
'unknown/unknown' : $mime;
+                       # logical MIME type
+                       $info['mime'] = $mime;
 
-                       list( $info['major_mime'], $info['minor_mime'] ) = 
File::splitMime( $info['mime'] );
-                       $info['media_type'] = $magic->getMediaType( 
$this->path, $info['mime'] );
-
-                       # Height, width and metadata
-                       $handler = MediaHandler::getHandler( $info['mime'] );
-                       if ( $handler ) {
-                               $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;
-                               }
+                       if ( strpos( $mime, '/' ) !== false ) {
+                               list( $info['major_mime'], $info['minor_mime'] 
) = explode( '/', $mime, 2 );
+                       } else {
+                               list( $info['major_mime'], $info['minor_mime'] 
) = [ $mime, 'unknown' ];
                        }
                }
 
@@ -146,17 +131,12 @@
         *
         * Resulting array fields include:
         *   - fileExists
-        *   - size
-        *   - file-mime (as major/minor)
+        *   - size (filesize in bytes)
         *   - mime (as major/minor)
+        *   - file-mime (as major/minor)
+        *   - sha1 (in base 36)
         *   - major_mime
         *   - minor_mime
-        *   - media_type (value to be used with the MEDIATYPE_xxx constants)
-        *   - metadata (handler specific)
-        *   - sha1 (in base 36)
-        *   - width
-        *   - height
-        *   - bits (bitrate)
         *
         * @return array
         */
@@ -168,12 +148,7 @@
                $info['major_mime'] = null;
                $info['minor_mime'] = null;
                $info['mime'] = null;
-               $info['media_type'] = MEDIATYPE_UNKNOWN;
-               $info['metadata'] = '';
                $info['sha1'] = '';
-               $info['width'] = 0;
-               $info['height'] = 0;
-               $info['bits'] = 0;
 
                return $info;
        }
diff --git a/includes/filebackend/TempFSFile.php 
b/includes/libs/filebackend/TempFSFile.php
similarity index 100%
rename from includes/filebackend/TempFSFile.php
rename to includes/libs/filebackend/TempFSFile.php
diff --git a/includes/utils/MWFileProps.php b/includes/utils/MWFileProps.php
index b8ecd4c..e60b9ab 100644
--- a/includes/utils/MWFileProps.php
+++ b/includes/utils/MWFileProps.php
@@ -63,7 +63,7 @@
        public function getPropsFromPath( $path, $ext ) {
                $fsFile = new FSFile( $path );
 
-               $info = FSFile::placeholderProps();
+               $info = $this->newPlaceholderProps();
                $info['fileExists'] = $fsFile->exists();
                if ( $info['fileExists'] ) {
                        $info['size'] = $fsFile->getSize(); // bytes
@@ -112,4 +112,34 @@
 
                return $info;
        }
+
+       /**
+        * Empty place holder props for non-existing files
+        *
+        * Resulting array fields include:
+        *   - fileExists
+        *   - size (filesize in bytes)
+        *   - mime (as major/minor)
+        *   - media_type (value to be used with the MEDIATYPE_xxx constants)
+        *   - metadata (handler specific)
+        *   - sha1 (in base 36)
+        *   - width
+        *   - height
+        *   - bits (bitrate)
+        *   - file-mime
+        *   - major_mime
+        *   - minor_mime
+        *
+        * @return array
+        * @since 1.28
+        */
+       public function newPlaceholderProps() {
+               return FSFile::placeholderProps() + [
+                       'metadata' => '',
+                       'width' => 0,
+                       'height' => 0,
+                       'bits' => 0,
+                       'media_type' => MEDIATYPE_UNKNOWN
+               ];
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/311366
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieaae909b49c798b6e9bed65d15961cefbdaec49b
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to