Fix outdated comment in DefaultSettings
[lhc/web/wiklou.git] / includes / media / BitmapMetadataHandler.php
index 00b4298..2a393db 100644 (file)
  * This sort of acts as an intermediary between MediaHandler::getMetadata
  * and the various metadata extractors.
  *
- * @todo other image formats.
+ * @todo Other image formats.
  * @ingroup Media
  */
 class BitmapMetadataHandler {
-
+       /** @var array */
        private $metadata = array();
+
+       /** @var array Metadata priority */
        private $metaPriority = array(
                20 => array( 'other' ),
                40 => array( 'native' ),
@@ -44,6 +46,8 @@ class BitmapMetadataHandler {
                100 => array( 'iptc-bad-hash' ),
                120 => array( 'exif' ),
        );
+
+       /** @var string */
        private $iptcType = 'iptc-no-hash';
 
        /**
@@ -76,8 +80,8 @@ class BitmapMetadataHandler {
         *
         * Parameters are passed to the Exif class.
         *
-        * @param $filename string
-        * @param $byteOrder string
+        * @param string $filename
+        * @param string $byteOrder
         */
        function getExif( $filename, $byteOrder ) {
                global $wgShowEXIF;
@@ -89,11 +93,12 @@ class BitmapMetadataHandler {
                        }
                }
        }
+
        /** Add misc metadata. Warning: atm if the metadata category
         * doesn't have a priority, it will be silently discarded.
         *
         * @param array $metaArray array of metadata values
-        * @param string $type type. defaults to other. if two things have the same type they're merged
+        * @param string $type Type. defaults to other. if two things have the same type they're merged
         */
        function addMetadata( $metaArray, $type = 'other' ) {
                if ( isset( $this->metadata[$type] ) ) {
@@ -111,7 +116,7 @@ class BitmapMetadataHandler {
         *
         * This function is generally called by the media handlers' getMetadata()
         *
-        * @return Array metadata array
+        * @return array Metadata array
         */
        function getMetadataArray() {
                // this seems a bit ugly... This is all so its merged in right order
@@ -138,13 +143,14 @@ class BitmapMetadataHandler {
                                }
                        }
                }
+
                return $temp;
        }
 
        /** Main entry point for jpeg's.
         *
         * @param string $filename filename (with full path)
-        * @return array metadata result array.
+        * @return array Metadata result array.
         * @throws MWException on invalid file.
         */
        static function Jpeg( $filename ) {
@@ -168,7 +174,6 @@ class BitmapMetadataHandler {
                                 * is not well tested and a bit fragile.
                                 */
                                $xmp->parseExtended( $xmpExt );
-
                        }
                        $res = $xmp->getResults();
                        foreach ( $res as $type => $array ) {
@@ -178,6 +183,7 @@ class BitmapMetadataHandler {
                if ( isset( $seg['byteOrder'] ) ) {
                        $meta->getExif( $filename, $seg['byteOrder'] );
                }
+
                return $meta->getMetadataArray();
        }
 
@@ -186,15 +192,17 @@ class BitmapMetadataHandler {
         * merge the png various tEXt chunks to that
         * are interesting, but for now it only does XMP
         *
-        * @param string $filename full path to file
-        * @return Array Array for storage in img_metadata.
+        * @param string $filename Full path to file
+        * @return array Array for storage in img_metadata.
         */
        public static function PNG( $filename ) {
                $showXMP = function_exists( 'xml_parser_create_ns' );
 
                $meta = new self();
                $array = PNGMetadataExtractor::getMetadata( $filename );
-               if ( isset( $array['text']['xmp']['x-default'] ) && $array['text']['xmp']['x-default'] !== '' && $showXMP ) {
+               if ( isset( $array['text']['xmp']['x-default'] )
+                       && $array['text']['xmp']['x-default'] !== '' && $showXMP
+               ) {
                        $xmp = new XMPReader();
                        $xmp->parse( $array['text']['xmp']['x-default'] );
                        $xmpRes = $xmp->getResults();
@@ -207,6 +215,7 @@ class BitmapMetadataHandler {
                unset( $array['text'] );
                $array['metadata'] = $meta->getMetadataArray();
                $array['metadata']['_MW_PNG_VERSION'] = PNGMetadataExtractor::VERSION;
+
                return $array;
        }
 
@@ -216,7 +225,7 @@ class BitmapMetadataHandler {
         * XMP and image comment.
         *
         * @param string $filename full path to file
-        * @return Array metadata array
+        * @return array Metadata array
         */
        public static function GIF( $filename ) {
 
@@ -234,7 +243,6 @@ class BitmapMetadataHandler {
                        foreach ( $xmpRes as $type => $xmpSection ) {
                                $meta->addMetadata( $xmpSection, $type );
                        }
-
                }
 
                unset( $baseArray['comment'] );
@@ -242,6 +250,7 @@ class BitmapMetadataHandler {
 
                $baseArray['metadata'] = $meta->getMetadataArray();
                $baseArray['metadata']['_MW_GIF_VERSION'] = GIFMetadataExtractor::VERSION;
+
                return $baseArray;
        }
 
@@ -251,13 +260,12 @@ class BitmapMetadataHandler {
         * but needs some further processing because PHP's exif support
         * is stupid...)
         *
-        * @todo Add XMP support, so this function actually makes
-        * sense to put here.
+        * @todo Add XMP support, so this function actually makes sense to put here.
         *
         * The various exceptions this throws are caught later.
-        * @param $filename String
+        * @param string $filename
         * @throws MWException
-        * @return Array The metadata.
+        * @return array The metadata.
         */
        public static function Tiff( $filename ) {
                if ( file_exists( $filename ) ) {
@@ -269,6 +277,7 @@ class BitmapMetadataHandler {
                        $data = $exif->getFilteredData();
                        if ( $data ) {
                                $data['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
+
                                return $data;
                        } else {
                                throw new MWException( "Could not extract data from tiff file $filename" );
@@ -277,12 +286,13 @@ class BitmapMetadataHandler {
                        throw new MWException( "File doesn't exist - $filename" );
                }
        }
+
        /**
         * Read the first 2 bytes of a tiff file to figure out
         * Little Endian or Big Endian. Needed for exif stuff.
         *
         * @param string $filename The filename
-        * @return String 'BE' or 'LE' or false
+        * @return string 'BE' or 'LE' or false
         */
        static function getTiffByteOrder( $filename ) {
                $fh = fopen( $filename, 'rb' );