r86212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86211‎ | r86212 | r86213 >
Date:15:53, 16 April 2011
Author:bawolff
Status:ok (Comments)
Tags:
Comment:
(Follow-up r86169) Needed supress warnings around iconv
Also make it try to detect if a jpeg file comment has textual data, or is random binary stuff.
Modified paths:
  • /trunk/phase3/includes/media/Exif.php (modified) (history)
  • /trunk/phase3/includes/media/IPTC.php (modified) (history)
  • /trunk/phase3/includes/media/JpegMetadataExtractor.php (modified) (history)
  • /trunk/phase3/includes/media/XMP.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/media/Exif.php
@@ -435,13 +435,17 @@
436436 // This could possibly check to see if iconv is really installed
437437 // or if we're using the compatibility wrapper in globalFunctions.php
438438 if ($charset) {
 439+ wfSuppressWarnings();
439440 $val = iconv($charset, 'UTF-8//IGNORE', $val);
 441+ wfRestoreWarnings();
440442 } else {
441443 // if valid utf-8, assume that, otherwise assume windows-1252
442444 $valCopy = $val;
443445 UtfNormal::quickIsNFCVerify( $valCopy ); //validates $valCopy.
444446 if ( $valCopy !== $val ) {
 447+ wfSuppressWarnings();
445448 $val = iconv('Windows-1252', 'UTF-8//IGNORE', $val);
 449+ wfRestoreWarnings();
446450 }
447451 }
448452
Index: trunk/phase3/includes/media/IPTC.php
@@ -418,7 +418,9 @@
419419 */
420420 private static function convIPTCHelper ( $data, $charset ) {
421421 if ( $charset ) {
 422+ wfSuppressWarnings();
422423 $data = iconv($charset, "UTF-8//IGNORE", $data);
 424+ wfRestoreWarnings();
423425 if ($data === false) {
424426 $data = "";
425427 wfDebugLog('iptc', __METHOD__ . " Error converting iptc data charset $charset to utf-8");
Index: trunk/phase3/includes/media/XMP.php
@@ -260,7 +260,9 @@
261261 }
262262 if ( $this->charset !== 'UTF-8' ) {
263263 //don't convert if already utf-8
 264+ wfSuppressWarnings();
264265 $content = iconv( $this->charset, 'UTF-8//IGNORE', $content );
 266+ wfRestoreWarnings();
265267 }
266268
267269 $ok = xml_parse( $this->xmlParser, $content, $allOfIt );
Index: trunk/phase3/includes/media/JpegMetadataExtractor.php
@@ -56,14 +56,22 @@
5757 // First see if valid utf-8,
5858 // if not try to convert it to windows-1252.
5959 $com = $oldCom = trim( self::jpegExtractMarker( $fh ) );
60 -
6160 UtfNormal::quickIsNFCVerify( $com );
6261 // turns $com to valid utf-8.
6362 // thus if no change, its utf-8, otherwise its something else.
6463 if ( $com !== $oldCom ) {
65 - $oldCom = iconv( 'windows-1252', 'UTF-8//IGNORE', $oldCom );
 64+ wfSuppressWarnings();
 65+ $com = $oldCom = iconv( 'windows-1252', 'UTF-8//IGNORE', $oldCom );
 66+ wfRestoreWarnings();
6667 }
67 - $segments["COM"][] = $oldCom;
 68+ // Try it again, if its still not a valid string, then probably
 69+ // binary junk or some really weird encoding, so don't extract.
 70+ UtfNormal::quickIsNFCVerify( $com );
 71+ if ( $com === $oldCom ) {
 72+ $segments["COM"][] = $oldCom;
 73+ } else {
 74+ wfDebug( __METHOD__ . ' Ignoring JPEG comment as is garbage.' );
 75+ }
6876
6977 } elseif ( $buffer === "\xE1" && $showXMP ) {
7078 // APP1 section (Exif, XMP, and XMP extended)

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86169Merge to trunk everything in img_metadata branch....bawolff01:23, 16 April 2011

Comments

#Comment by Bryan (talk | contribs)   14:37, 15 May 2011

If there should always be a wfSurpressWarnings() around iconv, there should be a wrapper function which does that. This function could then also invoke the compat iconv.

function wfIconv( $src, $target, $str ) {
 if ( function_exists( 'iconv' ) {
  wfSurpressWarnings();
  iconv( $src, $target, $str );
  wfRestoreWarnings();
 } else {
  Fallback::iconv( $src, $target, $str );
 }
}

Status & tagging log