Ori.livneh has submitted this change and it was merged.

Change subject: (bug 37692) Enforce one-based page numbers
......................................................................


(bug 37692) Enforce one-based page numbers

ImageMagick identify >= 6.6.8-10 returns zero-based page numbers, which
breaks this extension and leads to an error "The uploaded file contains
errors: inconsistent page numbering in TIFF directory".

This change maps the page numbers as returned by identify to a one-based
sequence.

Change-Id: I25052af7adb6f116c3f6a06652b5c0ce92c9d3a5
---
M PagedTiffHandler.image.php
1 file changed, 20 insertions(+), 4 deletions(-)

Approvals:
  Ori.livneh: Verified; Looks good to me, approved
  Reedy: Looks good to me, but someone else must approve



diff --git a/PagedTiffHandler.image.php b/PagedTiffHandler.image.php
index 88b919a..27d618f 100644
--- a/PagedTiffHandler.image.php
+++ b/PagedTiffHandler.image.php
@@ -338,6 +338,11 @@
 
                $infos = null;
                preg_match_all( '/\[BEGIN\](.+?)\[END\]/si', $dump, $infos, 
PREG_SET_ORDER );
+               // ImageMagick < 6.6.8-10 starts page numbering at 1; >= 
6.6.8-10 starts at zero. Handle both
+               // and map to one-based page numbers (which are assumed in 
various other parts of the support
+               // for displaying multi-page files).
+               $pageSeen = false;
+               $pageOffset = 0;
                foreach ( $infos as $info ) {
                        $state->resetPage();
                        $lines = explode( "\n", $info[1] );
@@ -346,11 +351,13 @@
                                        continue;
                                }
                                $parts = explode( '=', $line );
-                               if ( trim( $parts[0] ) == 'alpha' && trim( 
$parts[1] ) == '%A' ) {
+                               $key = trim( $parts[0] );
+                               $value = trim( $parts[1] );
+                               if ( $key === 'alpha' && $value === '%A' ) {
                                        continue;
                                }
-                               if ( trim( $parts[0] ) == 'alpha2' && 
!$state->hasPageProperty( 'alpha' ) ) {
-                                       switch( trim( $parts[1] ) ) {
+                               if ( $key === 'alpha2' && 
!$state->hasPageProperty( 'alpha' ) ) {
+                                       switch( $value ) {
                                                case 'DirectClassRGBMatte':
                                                case 'DirectClassRGBA':
                                                        
$state->setPageProperty('alpha', 'true');
@@ -361,7 +368,16 @@
                                        }
                                        continue;
                                }
-                               $state->setPageProperty( trim( $parts[0] ), 
trim( $parts[1] ) );
+                               if ( $key === 'page' ) {
+                                       if ( !$pageSeen ) {
+                                               $pageSeen = true;
+                                               $pageOffset = 1 - intval( 
$value );
+                                       }
+                                       if ( $pageOffset !== 0 ) {
+                                               $value = intval( $value ) + 
$pageOffset;
+                                       }
+                               }
+                               $state->setPageProperty( $key, $value );
                        }
                        $state->finishPage();
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I25052af7adb6f116c3f6a06652b5c0ce92c9d3a5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PagedTiffHandler
Gerrit-Branch: master
Gerrit-Owner: Lupo <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to