maintenance: Replace custom .ext extraction with pathinfo()
authorThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Thu, 28 Feb 2019 10:47:07 +0000 (11:47 +0100)
committerThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Thu, 28 Feb 2019 10:47:52 +0000 (11:47 +0100)
Note the custom code was not working correctly for filenames that do
not contain a dot. I assume this is not relevant for the filenames this
code needs to process.

Change-Id: Id4578bc86203dcbd9f76928bbec71a2c46176e11

maintenance/importImages.php

index 7a2e0f4..1728695 100644 (file)
@@ -418,7 +418,7 @@ class ImportImages extends Maintenance {
                                $files = [];
                                while ( ( $file = readdir( $dhl ) ) !== false ) {
                                        if ( is_file( $dir . '/' . $file ) ) {
-                                               list( /* $name */, $ext ) = $this->splitFilename( $dir . '/' . $file );
+                                               $ext = pathinfo( $file, PATHINFO_EXTENSION );
                                                if ( array_search( strtolower( $ext ), $exts ) !== false ) {
                                                        $files[] = $dir . '/' . $file;
                                                }
@@ -436,21 +436,6 @@ class ImportImages extends Maintenance {
                }
        }
 
-       /**
-        * Split a filename into filename and extension
-        *
-        * @param string $filename
-        * @return array
-        */
-       private function splitFilename( $filename ) {
-               $parts = explode( '.', $filename );
-               $ext = $parts[count( $parts ) - 1];
-               unset( $parts[count( $parts ) - 1] );
-               $fname = implode( '.', $parts );
-
-               return [ $fname, $ext ];
-       }
-
        /**
         * Find an auxilliary file with the given extension, matching
         * the give base file path. $maxStrip determines how many extensions