Handle client disconnects in scoped timeout blocks.
[lhc/web/wiklou.git] / includes / media / IPTC.php
index 3db845b..8fd3552 100644 (file)
@@ -1,8 +1,31 @@
 <?php
 /**
-*Class for some IPTC functions.
+ * Class for some IPTC functions.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Media
+ */
 
-*/
+/**
+ * Class for some IPTC functions.
+ *
+ * @ingroup Media
+ */
 class IPTC {
 
        /**
@@ -12,7 +35,7 @@ class IPTC {
        *
        * @see http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf
        *
-       * @param String $data app13 block from jpeg containing iptc/iim data
+       * @param $rawData String app13 block from jpeg containing iptc/iim data
        * @return Array iptc metadata array
        */
        static function parse( $rawData ) {
@@ -102,7 +125,7 @@ class IPTC {
                                        break;
                                case '2#115': /* source */
                                        /* "Identifies the original owner of the intellectual content of the
-                                        *objectdata. This could be an agency, a member of an agency or 
+                                        *objectdata. This could be an agency, a member of an agency or
                                         *an individual." */
                                        $data['Source'] = self::convIPTC( $val, $c );
                                        break;
@@ -157,8 +180,6 @@ class IPTC {
                                        } else {
                                                $data['Software'] = $software;
                                        }
-
-
                                        break;
                                case '2#075':
                                        /* Object cycle.
@@ -331,9 +352,10 @@ class IPTC {
        /**
        * Convert an iptc date and time tags into the exif format
        *
-       * @todo Potentially this should also capture the timezone offset. 
+       * @todo Potentially this should also capture the timezone offset.
        * @param Array $date The date tag
        * @param Array $time The time tag
+       * @param $c
        * @return String Date in exif format.
        */
        private static function timeHelper( $date, $time, $c ) {
@@ -353,7 +375,7 @@ class IPTC {
                        $dateOnly = true;
                }
 
-               if ( ! ( preg_match('/\d\d\d\d\d\d[-+]\d\d\d\d/', $time) 
+               if ( ! ( preg_match('/\d\d\d\d\d\d[-+]\d\d\d\d/', $time)
                        && preg_match('/\d\d\d\d\d\d\d\d/', $date)
                        && substr($date, 0, 4) !== '0000'
                        && substr($date, 4, 2) !== '00'
@@ -392,22 +414,22 @@ class IPTC {
                } else {
                        return $finalTimestamp;
                }
-
        }
 
        /**
        * Helper function to convert charset for iptc values.
-       * @param $data Mixed String or Array: The iptc string
+       * @param $data string|array The iptc string
        * @param $charset String: The charset
+        *
+        * @return string|array
        */
        private static function convIPTC ( $data, $charset ) {
-               global $wgLang;
                if ( is_array( $data ) ) {
                        foreach ($data as &$val) {
                                $val = self::convIPTCHelper( $val, $charset );
                        }
                } else {
-                       $data = self::convIPTCHelper ( $data, $charset );
+                       $data = self::convIPTCHelper( $data, $charset );
                }
 
                return $data;
@@ -416,10 +438,14 @@ class IPTC {
        * Helper function of a helper function to convert charset for iptc values.
        * @param $data Mixed String or Array: The iptc string
        * @param $charset String: The charset
+       *
+       * @return string
        */
        private static function convIPTCHelper ( $data, $charset ) {
                if ( $charset ) {
+                       wfSuppressWarnings();
                        $data = iconv($charset, "UTF-8//IGNORE", $data);
+                       wfRestoreWarnings();
                        if ($data === false) {
                                $data = "";
                                wfDebugLog('iptc', __METHOD__ . " Error converting iptc data charset $charset to utf-8");
@@ -429,16 +455,19 @@ class IPTC {
                        // most of the time if there is no 1:90 tag, it is either ascii, latin1, or utf-8
                        $oldData = $data;
                        UtfNormal::quickIsNFCVerify( $data ); //make $data valid utf-8
-                       if ($data === $oldData) return $data; //if validation didn't change $data
-                       else return self::convIPTCHelper ( $oldData, 'Windows-1252' );
+                       if ($data === $oldData) {
+                               return $data; //if validation didn't change $data
+                       } else {
+                               return self::convIPTCHelper( $oldData, 'Windows-1252' );
+                       }
                }
                return trim( $data );
        }
 
        /**
        * take the value of 1:90 tag and returns a charset
-       * @param String $tag 1:90 tag. 
-       * @return charset name or "?"
+       * @param String $tag 1:90 tag.
+       * @return string charset name or "?"
        * Warning, this function does not (and is not intended to) detect
        * all iso 2022 escape codes. In practise, the code for utf-8 is the
        * only code that seems to have wide use. It does detect that code.
@@ -508,7 +537,7 @@ class IPTC {
                                $c = "NS_4551-1";
                                break;
                        case "\x1b(f": //iso646-FR
-                               $c = "NF_Z_62-010"; 
+                               $c = "NF_Z_62-010";
                                break;
                        case "\x1b(g":
                                $c = "PT2"; //iso646-PT2
@@ -561,7 +590,7 @@ class IPTC {
                                $c = 'CSN_369103';
                                break;
                        default:
-                               wfDebugLog('iptc', __METHOD__ . 'Unknown charset in iptc 1:90: ' . bin2hex( $tag ) ); 
+                               wfDebugLog('iptc', __METHOD__ . 'Unknown charset in iptc 1:90: ' . bin2hex( $tag ) );
                                //at this point just give up and refuse to parse iptc?
                                $c = false;
                }