r100601 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100600‎ | r100601 | r100602 >
Date:11:49, 24 October 2011
Author:vitalif
Status:deferred
Tags:
Comment:
Fix for page numbers, do not regenerate multiple thumbnails when the first requested page exists
Modified paths:
  • /branches/vitalif/extensions/PdfHandler/PdfHandler_body.php (modified) (history)

Diff [purge]

Index: branches/vitalif/extensions/PdfHandler/PdfHandler_body.php
@@ -93,7 +93,10 @@
9494 return false;
9595 }
9696 if ( strpos( $page, '-' ) !== false ) {
97 - $page = '$N';
 97+ list( $page, $endpage ) = explode( '-', $page, 2 );
 98+ if( !$page ) {
 99+ $page = 1;
 100+ }
98101 }
99102 return "page{$page}-{$params['width']}px";
100103 }
@@ -101,7 +104,7 @@
102105 function parseParamString( $str ) {
103106 $m = false;
104107
105 - if ( preg_match( '/^page(\d+|\$N)-(\d+)px$/', $str, $m ) ) {
 108+ if ( preg_match( '/^page(\d+)-(\d+)px$/', $str, $m ) ) {
106109 return array( 'width' => $m[2], 'page' => $m[1] );
107110 }
108111
@@ -147,7 +150,8 @@
148151 if ( $endpage === '' ) {
149152 $endpage = $n;
150153 }
151 - $dstUrl = str_replace( 'page%24N', 'page$N', $dstUrl );
 154+ $dstPath = preg_replace( '/page\d+-/', 'page$N-', $dstPath );
 155+ $dstUrl = preg_replace( '/page\d+-/', 'page$N-', $dstUrl );
152156 } else {
153157 $endpage = $page;
154158 }
@@ -178,7 +182,9 @@
179183
180184 // GhostScript fails (sometimes even crashes) if output filename length is > 255 bytes.
181185 // Sometimes even when it's shorter. Workaround it by generating files in temporary directory.
 186+ // Also, filenames include the sequence number of generated image, not the page number.
182187 $dst = tempnam( wfTempDir(), 'pdf-' );
 188+ unlink( $dst );
183189 if ( $endpage > $page ) {
184190 $dst .= '%d';
185191 }
@@ -196,7 +202,7 @@
197203 // Move files from temporary directory to the destination
198204 $removed = false;
199205 for ( $i = $page; $i <= $endpage; $i++ ) {
200 - $tmp = sprintf( $dst, $i );
 206+ $tmp = sprintf( $dst, $i-$page+1 );
201207 $real = str_replace( '$N', $i, $dstPath );
202208 if ( file_exists( $tmp ) ) {
203209 rename( $tmp, $real );

Status & tagging log