r65159 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65158‎ | r65159 | r65160 >
Date:14:22, 17 April 2010
Author:catrope
Status:deferred
Tags:
Comment:
PagedTiffHandler: Run stylize.php, convert spaces to tabs
Modified paths:
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/TiffReader.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PagedTiffHandler/TiffReader.php
@@ -7,341 +7,341 @@
88
99 // This is still experimental
1010 class TiffReader {
11 - protected $time = NULL;
12 - protected $file = NULL;
13 - protected $file_handle = NULL;
14 - protected $order = NULL;
15 - protected $the_answer = NULL;
16 - protected $embed_files = 0;
17 - protected $ifd_offsets = array();
18 - protected $real_eof = 0;
19 - protected $highest_addr = 0;
 11+ protected $time = NULL;
 12+ protected $file = NULL;
 13+ protected $file_handle = NULL;
 14+ protected $order = NULL;
 15+ protected $the_answer = NULL;
 16+ protected $embed_files = 0;
 17+ protected $ifd_offsets = array();
 18+ protected $real_eof = 0;
 19+ protected $highest_addr = 0;
2020
21 - protected $unknown_fields = false;
 21+ protected $unknown_fields = false;
2222
23 - protected $hex = NULL;
24 - protected $short = NULL;
25 - protected $long = NULL;
 23+ protected $hex = NULL;
 24+ protected $short = NULL;
 25+ protected $long = NULL;
2626
27 - public function __construct($file) {
28 - $this->time = microtime(true);
29 - $this->file = $file;
30 - // set file-pointer
31 - $this->file_handle = fopen($this->file, 'rb');
32 - // read the tiff-header
33 - $this->order = (fread($this->file_handle, 2) == 'II');
34 - if($this->order) {
35 - $this->hex = 'h*';
36 - $this->short = 'v*';
37 - $this->long = 'V*';
38 - }
39 - else {
40 - $this->hex = 'H*';
41 - $this->short = 'n*';
42 - $this->long = 'N*';
43 - }
44 - $this->the_answer = unpack($this->short, fread($this->file_handle, 2));
45 - // set the offset of the first ifd
46 - $offset = unpack($this->long, fread($this->file_handle, 4));
47 - $this->ifd_offsets[]['offset'] = $offset[1];
48 - fseek($this->file_handle, 0, SEEK_END);
49 - $this->real_eof = ftell($this->file_handle);
50 - }
 27+ public function __construct( $file ) {
 28+ $this->time = microtime( true );
 29+ $this->file = $file;
 30+ // set file-pointer
 31+ $this->file_handle = fopen( $this->file, 'rb' );
 32+ // read the tiff-header
 33+ $this->order = ( fread( $this->file_handle, 2 ) == 'II' );
 34+ if ( $this->order ) {
 35+ $this->hex = 'h*';
 36+ $this->short = 'v*';
 37+ $this->long = 'V*';
 38+ }
 39+ else {
 40+ $this->hex = 'H*';
 41+ $this->short = 'n*';
 42+ $this->long = 'N*';
 43+ }
 44+ $this->the_answer = unpack( $this->short, fread( $this->file_handle, 2 ) );
 45+ // set the offset of the first ifd
 46+ $offset = unpack( $this->long, fread( $this->file_handle, 4 ) );
 47+ $this->ifd_offsets[]['offset'] = $offset[1];
 48+ fseek( $this->file_handle, 0, SEEK_END );
 49+ $this->real_eof = ftell( $this->file_handle );
 50+ }
5151
52 - public function checkScriptAtEnd($size = 1) {
53 - $size = $size * 1024 * 1024;
54 - if($size > $this->real_eof) {
55 - fseek($this->file_handle, 0, SEEK_SET);
56 - $chunk = fread($this->file_handle, $this->real_eof);
57 - }
58 - else {
59 - fseek($this->file_handle, ($this->real_eof - $size), SEEK_SET);
60 - $chunk = fread($this->file_handle, $size);
61 - }
62 - #check for HTML doctype
63 - if (preg_match('/<!DOCTYPE *X?HTML/', $chunk)) return true;
 52+ public function checkScriptAtEnd( $size = 1 ) {
 53+ $size = $size * 1024 * 1024;
 54+ if ( $size > $this->real_eof ) {
 55+ fseek( $this->file_handle, 0, SEEK_SET );
 56+ $chunk = fread( $this->file_handle, $this->real_eof );
 57+ }
 58+ else {
 59+ fseek( $this->file_handle, ( $this->real_eof - $size ), SEEK_SET );
 60+ $chunk = fread( $this->file_handle, $size );
 61+ }
 62+ # check for HTML doctype
 63+ if ( preg_match( '/<!DOCTYPE *X?HTML/', $chunk ) ) return true;
6464
65 - $tags = array('<a href',
66 - '<body',
67 - '<head',
68 - '<html',
69 - '<img',
70 - '<pre',
71 - '<script',
72 - '<table',
73 - '<title');
74 - foreach( $tags as $tag ) {
75 - if( false !== strpos( $chunk, $tag ) ) {
76 - return true;
77 - }
78 - }
79 - #look for script-types
80 - if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim',$chunk)) return true;
 65+ $tags = array( '<a href',
 66+ '<body',
 67+ '<head',
 68+ '<html',
 69+ '<img',
 70+ '<pre',
 71+ '<script',
 72+ '<table',
 73+ '<title' );
 74+ foreach ( $tags as $tag ) {
 75+ if ( false !== strpos( $chunk, $tag ) ) {
 76+ return true;
 77+ }
 78+ }
 79+ # look for script-types
 80+ if ( preg_match( '!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk ) ) return true;
8181
82 - #look for html-style script-urls
83 - if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true;
 82+ # look for html-style script-urls
 83+ if ( preg_match( '!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) return true;
8484
85 - #look for css-style script-urls
86 - if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true;
87 - }
 85+ # look for css-style script-urls
 86+ if ( preg_match( '!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) return true;
 87+ }
8888
89 - public function checkSize() {
90 - $diff = $this->real_eof - $this->highest_addr;
91 - if($diff) {
92 - if($diff < 0) {
93 - return true;
94 - }
95 - fseek($this->file_handle, $this->highest_addr, SEEK_SET);
96 - $diffstr = fread($this->file_handle, $diff);
97 - if(preg_match('/^\0+$/', $diffstr)) {
98 - return true;
99 - }
100 - return false;
101 - }
102 - return true;
103 - }
 89+ public function checkSize() {
 90+ $diff = $this->real_eof - $this->highest_addr;
 91+ if ( $diff ) {
 92+ if ( $diff < 0 ) {
 93+ return true;
 94+ }
 95+ fseek( $this->file_handle, $this->highest_addr, SEEK_SET );
 96+ $diffstr = fread( $this->file_handle, $diff );
 97+ if ( preg_match( '/^\0+$/', $diffstr ) ) {
 98+ return true;
 99+ }
 100+ return false;
 101+ }
 102+ return true;
 103+ }
104104
105 - public function isValidTiff() {
106 - return $this->the_answer[1] == 42;
107 - }
 105+ public function isValidTiff() {
 106+ return $this->the_answer[1] == 42;
 107+ }
108108
109 - public function check($debug = false) {
110 - $offset = $this->ifd_offsets[$this->embed_files]['offset'];
111 - $rounds = 0;
112 - // loop over all ifd
113 - while($offset && $offset <= $this->real_eof) {
114 - // save the offset if it is the highest one
115 - if($offset > $this->highest_addr) {
116 - $this->highest_addr = $offset;
117 - }
118 - // set file-pointer to address with given offset
119 - fseek($this->file_handle, $offset, SEEK_SET);
120 - // read amount of ifd-entries
121 - $entries = unpack($this->short, fread($this->file_handle, 2));
122 - if(!is_array($entries) || !isset($entries[1])) {
 109+ public function check( $debug = false ) {
 110+ $offset = $this->ifd_offsets[$this->embed_files]['offset'];
 111+ $rounds = 0;
 112+ // loop over all ifd
 113+ while ( $offset && $offset <= $this->real_eof ) {
 114+ // save the offset if it is the highest one
 115+ if ( $offset > $this->highest_addr ) {
 116+ $this->highest_addr = $offset;
 117+ }
 118+ // set file-pointer to address with given offset
 119+ fseek( $this->file_handle, $offset, SEEK_SET );
 120+ // read amount of ifd-entries
 121+ $entries = unpack( $this->short, fread( $this->file_handle, 2 ) );
 122+ if ( !is_array( $entries ) || !isset( $entries[1] ) ) {
123123 $this->the_answer = 0;
124124 return false;
125125 }
126 - $entries = $entries[1];
 126+ $entries = $entries[1];
127127
128 - $address = $offset + 2 + ($entries * 12);
129 - if($address > $this->highest_addr) {
130 - $this->highest_addr = $address;
131 - }
 128+ $address = $offset + 2 + ( $entries * 12 );
 129+ if ( $address > $this->highest_addr ) {
 130+ $this->highest_addr = $address;
 131+ }
132132
133 - // run through all entries of this ifd an read them out
134 - for($i = 0; $i < $entries; $i++) {
135 - $tmp = $this->readIFDEntry();
136 - if(!$tmp) { return false; }
137 - $this->ifd_offsets[$this->embed_files]['data'][$tmp['tag']] = $tmp;
138 - }
 133+ // run through all entries of this ifd an read them out
 134+ for ( $i = 0; $i < $entries; $i++ ) {
 135+ $tmp = $this->readIFDEntry();
 136+ if ( !$tmp ) { return false; }
 137+ $this->ifd_offsets[$this->embed_files]['data'][$tmp['tag']] = $tmp;
 138+ }
139139
140 - // set the offset of the next ifd or null if this is the last one
141 - $offset = unpack($this->long, fread($this->file_handle, 4));
142 - if(!is_array($offset) || !isset($offset[1])) {
 140+ // set the offset of the next ifd or null if this is the last one
 141+ $offset = unpack( $this->long, fread( $this->file_handle, 4 ) );
 142+ if ( !is_array( $offset ) || !isset( $offset[1] ) ) {
143143 $this->the_answer = 0;
144144 return false;
145145 }
146 - $offset = $offset[1];
147 - if($offset) {
148 - $this->ifd_offsets[]['offset'] = $offset;
149 - }
150 - $this->embed_files++;
151 - }
152 - $this->calculateDataRange();
153 -
154 - if($debug) {
155 - echo "<h2>TiffReader-Debug:</h2>\n";
156 - echo "<b>File: </b>".$this->file."<br />\n";
157 - if($this->order) {
158 - echo "<b>Byte-Order: </b>little Endian<br />\n";
159 - }
160 - else {
161 - echo "<b>Byte-Order: </b>big Endian<br />\n";
162 - }
163 - echo "<b>Valid Tiff: </b>";
164 - if($this->the_answer[1] == 42) {
165 - echo "yes<br />\n";
166 - }
167 - else {
168 - echo "no<br />\n";
169 - }
170 - echo "<b>Physicaly Size: </b>".$this->real_eof." bytes<br />\n";
171 - echo "<b>Calculated Size: </b>".$this->highest_addr." bytes<br />\n";
172 - echo "<b>Difference in Size: </b>".($this->real_eof - $this->highest_addr)." bytes<br />\n";
173 - echo "<b>Unknown Fields: </b>";
174 - if($this->unknown_fields) {
175 - echo "yes<br />\n";
176 - }
177 - else {
178 - echo "no<br />\n";
179 - }
180 - echo "<b>Embed Files: </b>".$this->embed_files."<br />\n";
181 - echo "<b>Runtime: </b>".round((microtime(true) - $this->time), 6)." seconds<br />\n";
182 - }
183 - }
 146+ $offset = $offset[1];
 147+ if ( $offset ) {
 148+ $this->ifd_offsets[]['offset'] = $offset;
 149+ }
 150+ $this->embed_files++;
 151+ }
 152+ $this->calculateDataRange();
 153+
 154+ if ( $debug ) {
 155+ echo "<h2>TiffReader-Debug:</h2>\n";
 156+ echo "<b>File: </b>" . $this->file . "<br />\n";
 157+ if ( $this->order ) {
 158+ echo "<b>Byte-Order: </b>little Endian<br />\n";
 159+ }
 160+ else {
 161+ echo "<b>Byte-Order: </b>big Endian<br />\n";
 162+ }
 163+ echo "<b>Valid Tiff: </b>";
 164+ if ( $this->the_answer[1] == 42 ) {
 165+ echo "yes<br />\n";
 166+ }
 167+ else {
 168+ echo "no<br />\n";
 169+ }
 170+ echo "<b>Physicaly Size: </b>" . $this->real_eof . " bytes<br />\n";
 171+ echo "<b>Calculated Size: </b>" . $this->highest_addr . " bytes<br />\n";
 172+ echo "<b>Difference in Size: </b>" . ( $this->real_eof - $this->highest_addr ) . " bytes<br />\n";
 173+ echo "<b>Unknown Fields: </b>";
 174+ if ( $this->unknown_fields ) {
 175+ echo "yes<br />\n";
 176+ }
 177+ else {
 178+ echo "no<br />\n";
 179+ }
 180+ echo "<b>Embed Files: </b>" . $this->embed_files . "<br />\n";
 181+ echo "<b>Runtime: </b>" . round( ( microtime( true ) - $this->time ), 6 ) . " seconds<br />\n";
 182+ }
 183+ }
184184
185 - protected function readIFDEntry() {
186 - $tag = unpack($this->short, fread($this->file_handle, 2));
187 - $type = unpack($this->short, fread($this->file_handle, 2));
188 - $count = unpack($this->long, fread($this->file_handle, 4));
189 - $value = unpack($this->long, fread($this->file_handle, 4));
190 - if(!is_array($tag) || !is_array($type) || !is_array($count) || !is_array($value) ||
191 - !isset($tag[1]) || !isset($type[1]) || !isset($count[1]) || !isset($value[1])) {
 185+ protected function readIFDEntry() {
 186+ $tag = unpack( $this->short, fread( $this->file_handle, 2 ) );
 187+ $type = unpack( $this->short, fread( $this->file_handle, 2 ) );
 188+ $count = unpack( $this->long, fread( $this->file_handle, 4 ) );
 189+ $value = unpack( $this->long, fread( $this->file_handle, 4 ) );
 190+ if ( !is_array( $tag ) || !is_array( $type ) || !is_array( $count ) || !is_array( $value ) ||
 191+ !isset( $tag[1] ) || !isset( $type[1] ) || !isset( $count[1] ) || !isset( $value[1] ) ) {
192192 $this->the_answer = 0;
193193 return false;
194194 }
195 - return array('tag' => $tag[1],
196 - 'type' => $type[1],
197 - 'count' => $count[1],
198 - 'value' => $value[1]);
199 - }
 195+ return array( 'tag' => $tag[1],
 196+ 'type' => $type[1],
 197+ 'count' => $count[1],
 198+ 'value' => $value[1] );
 199+ }
200200
201 - protected function calculateDataRange() {
202 - foreach($this->ifd_offsets as $number => $ifd) {
203 - foreach($ifd['data'] as $tag => $data) {
204 - // ignore all entries with local values
205 - if(($data['type'] == 1 && $data['count'] <= 4) ||
206 - ($data['type'] == 2 && $data['count'] <= 4) ||
207 - ($data['type'] == 3 && $data['count'] <= 2) ||
208 - ($data['type'] == 4 && $data['count'] <= 1) ||
209 - ($data['type'] == 6 && $data['count'] <= 4) ||
210 - ($data['type'] == 7 && $data['count'] <= 4) ||
211 - ($data['type'] == 8 && $data['count'] <= 2) ||
212 - ($data['type'] == 9 && $data['count'] <= 1)) {
213 - continue;
214 - }
215 - // set value size
216 - switch($data['type']) {
217 - case 1:
218 - case 2:
219 - case 6:
220 - case 7:
221 - $size = 1;
222 - break;
223 - case 3:
224 - case 8:
225 - $size = 2;
226 - break;
227 - case 4:
228 - case 9:
229 - case 11:
230 - $size = 4;
231 - break;
232 - case 5:
233 - case 10;
234 - case 12:
235 - $size = 8;
236 - break;
237 - default:
238 - $size = 4;
239 - $this->unknown_fields = true;
240 - break;
241 - }
242 - // calculate the range of memory, the data need
243 - $size = $data['value'] + ($size * $data['count']);
244 - if($size > $this->highest_addr) {
245 - $this->highest_addr = $size;
246 - }
247 - }
248 - // check if more calculations needed
249 - if($this->highest_addr == $this->real_eof) {
250 - break;
251 - }
252 - // check if image data have to calculate
253 - if(isset($ifd['data'][273]) && isset($ifd['data'][279])) {
254 - // set file pointer to the offset for values from field 273
255 - fseek($this->file_handle, $ifd['data'][273]['value'], SEEK_SET);
256 - // get all offsets of the ImageStripes
257 - $stripes = array();
258 - if($ifd['data'][273]['type'] == 3) {
259 - for($i = 0; $i < $ifd['data'][273]['count']; $i++) {
260 - $stripes[] = unpack($this->short, fread($this->file_handle, 2));
261 - }
262 - }
263 - else {
264 - for($i = 0; $i < $ifd['data'][273]['count']; $i++) {
265 - $stripes[] = unpack($this->long, fread($this->file_handle, 4));
266 - }
267 - }
 201+ protected function calculateDataRange() {
 202+ foreach ( $this->ifd_offsets as $number => $ifd ) {
 203+ foreach ( $ifd['data'] as $tag => $data ) {
 204+ // ignore all entries with local values
 205+ if ( ( $data['type'] == 1 && $data['count'] <= 4 ) ||
 206+ ( $data['type'] == 2 && $data['count'] <= 4 ) ||
 207+ ( $data['type'] == 3 && $data['count'] <= 2 ) ||
 208+ ( $data['type'] == 4 && $data['count'] <= 1 ) ||
 209+ ( $data['type'] == 6 && $data['count'] <= 4 ) ||
 210+ ( $data['type'] == 7 && $data['count'] <= 4 ) ||
 211+ ( $data['type'] == 8 && $data['count'] <= 2 ) ||
 212+ ( $data['type'] == 9 && $data['count'] <= 1 ) ) {
 213+ continue;
 214+ }
 215+ // set value size
 216+ switch( $data['type'] ) {
 217+ case 1:
 218+ case 2:
 219+ case 6:
 220+ case 7:
 221+ $size = 1;
 222+ break;
 223+ case 3:
 224+ case 8:
 225+ $size = 2;
 226+ break;
 227+ case 4:
 228+ case 9:
 229+ case 11:
 230+ $size = 4;
 231+ break;
 232+ case 5:
 233+ case 10;
 234+ case 12:
 235+ $size = 8;
 236+ break;
 237+ default:
 238+ $size = 4;
 239+ $this->unknown_fields = true;
 240+ break;
 241+ }
 242+ // calculate the range of memory, the data need
 243+ $size = $data['value'] + ( $size * $data['count'] );
 244+ if ( $size > $this->highest_addr ) {
 245+ $this->highest_addr = $size;
 246+ }
 247+ }
 248+ // check if more calculations needed
 249+ if ( $this->highest_addr == $this->real_eof ) {
 250+ break;
 251+ }
 252+ // check if image data have to calculate
 253+ if ( isset( $ifd['data'][273] ) && isset( $ifd['data'][279] ) ) {
 254+ // set file pointer to the offset for values from field 273
 255+ fseek( $this->file_handle, $ifd['data'][273]['value'], SEEK_SET );
 256+ // get all offsets of the ImageStripes
 257+ $stripes = array();
 258+ if ( $ifd['data'][273]['type'] == 3 ) {
 259+ for ( $i = 0; $i < $ifd['data'][273]['count']; $i++ ) {
 260+ $stripes[] = unpack( $this->short, fread( $this->file_handle, 2 ) );
 261+ }
 262+ }
 263+ else {
 264+ for ( $i = 0; $i < $ifd['data'][273]['count']; $i++ ) {
 265+ $stripes[] = unpack( $this->long, fread( $this->file_handle, 4 ) );
 266+ }
 267+ }
268268
269 - // set file pointer to the offset for values from field 279
270 - fseek($this->file_handle, $ifd['data'][279]['value'], SEEK_SET);
271 - // get all offsets of the StripeByteCounts
272 - $stripebytes = array();
273 - if($ifd['data'][279]['type'] == 3) {
274 - for($i = 0; $i < $ifd['data'][279]['count']; $i++) {
275 - $stripebytes[] = unpack($this->short, fread($this->file_handle, 2));
276 - }
277 - }
278 - else {
279 - for($i = 0; $i < $ifd['data'][279]['count']; $i++) {
280 - $stripebytes[] = unpack($this->long, fread($this->file_handle, 4));
281 - }
282 - }
283 - // calculate the memory range of the image stripes
284 - for($i = 0; $i < count($stripes); $i++) {
285 - $size = $stripes[$i][1] + $stripebytes[$i][1];
286 - if($size > $this->highest_addr) {
287 - $this->highest_addr = $size;
288 - }
289 - }
290 - }
291 - if(isset($ifd['data'][324]) && isset($ifd['data'][325])) {
292 - // set file pointer to the offset for values from field 324
293 - fseek($this->file_handle, $ifd['data'][324]['value'], SEEK_SET);
294 - // get all offsets of the ImageTiles
295 - $tiles = array();
296 - for($i = 0; $i < $ifd['data'][324]['count']; $i++) {
297 - $tiles[] = unpack($this->long, fread($this->file_handle, 4));
298 - }
 269+ // set file pointer to the offset for values from field 279
 270+ fseek( $this->file_handle, $ifd['data'][279]['value'], SEEK_SET );
 271+ // get all offsets of the StripeByteCounts
 272+ $stripebytes = array();
 273+ if ( $ifd['data'][279]['type'] == 3 ) {
 274+ for ( $i = 0; $i < $ifd['data'][279]['count']; $i++ ) {
 275+ $stripebytes[] = unpack( $this->short, fread( $this->file_handle, 2 ) );
 276+ }
 277+ }
 278+ else {
 279+ for ( $i = 0; $i < $ifd['data'][279]['count']; $i++ ) {
 280+ $stripebytes[] = unpack( $this->long, fread( $this->file_handle, 4 ) );
 281+ }
 282+ }
 283+ // calculate the memory range of the image stripes
 284+ for ( $i = 0; $i < count( $stripes ); $i++ ) {
 285+ $size = $stripes[$i][1] + $stripebytes[$i][1];
 286+ if ( $size > $this->highest_addr ) {
 287+ $this->highest_addr = $size;
 288+ }
 289+ }
 290+ }
 291+ if ( isset( $ifd['data'][324] ) && isset( $ifd['data'][325] ) ) {
 292+ // set file pointer to the offset for values from field 324
 293+ fseek( $this->file_handle, $ifd['data'][324]['value'], SEEK_SET );
 294+ // get all offsets of the ImageTiles
 295+ $tiles = array();
 296+ for ( $i = 0; $i < $ifd['data'][324]['count']; $i++ ) {
 297+ $tiles[] = unpack( $this->long, fread( $this->file_handle, 4 ) );
 298+ }
299299
300 - // set file pointer to the offset for values from field 325
301 - fseek($this->file_handle, $ifd['data'][325]['value'], SEEK_SET);
302 - // get all offsets of the TileByteCounts
303 - $tilebytes = array();
304 - if($ifd['data'][325]['type'] == 3) {
305 - for($i = 0; $i < $ifd['data'][325]['count']; $i++) {
306 - $tilebytes[] = unpack($this->short, fread($this->file_handle, 2));
307 - }
308 - }
309 - else {
310 - for($i = 0; $i < $ifd['data'][325]['count']; $i++) {
311 - $tilebytes[] = unpack($this->long, fread($this->file_handle, 4));
312 - }
313 - }
314 - // calculate the memory range of the image tiles
315 - for($i = 0; $i < count($tiles); $i++) {
316 - $size = $tiles[$i][1] + $tilebytes[$i][1];
317 - if($size > $this->highest_addr) {
318 - $this->highest_addr = $size;
319 - }
320 - }
321 - }
322 - if(isset($ifd['data'][288]) && isset($ifd['data'][289])) {
323 - // set file pointer to the offset for values from field 288
324 - fseek($this->file_handle, $ifd['data'][288]['value'], SEEK_SET);
325 - // get all offsets of the ImageTiles
326 - $free = array();
327 - for($i = 0; $i < $ifd['data'][288]['count']; $i++) {
328 - $free[] = unpack($this->long, fread($this->file_handle, 4));
329 - }
 300+ // set file pointer to the offset for values from field 325
 301+ fseek( $this->file_handle, $ifd['data'][325]['value'], SEEK_SET );
 302+ // get all offsets of the TileByteCounts
 303+ $tilebytes = array();
 304+ if ( $ifd['data'][325]['type'] == 3 ) {
 305+ for ( $i = 0; $i < $ifd['data'][325]['count']; $i++ ) {
 306+ $tilebytes[] = unpack( $this->short, fread( $this->file_handle, 2 ) );
 307+ }
 308+ }
 309+ else {
 310+ for ( $i = 0; $i < $ifd['data'][325]['count']; $i++ ) {
 311+ $tilebytes[] = unpack( $this->long, fread( $this->file_handle, 4 ) );
 312+ }
 313+ }
 314+ // calculate the memory range of the image tiles
 315+ for ( $i = 0; $i < count( $tiles ); $i++ ) {
 316+ $size = $tiles[$i][1] + $tilebytes[$i][1];
 317+ if ( $size > $this->highest_addr ) {
 318+ $this->highest_addr = $size;
 319+ }
 320+ }
 321+ }
 322+ if ( isset( $ifd['data'][288] ) && isset( $ifd['data'][289] ) ) {
 323+ // set file pointer to the offset for values from field 288
 324+ fseek( $this->file_handle, $ifd['data'][288]['value'], SEEK_SET );
 325+ // get all offsets of the ImageTiles
 326+ $free = array();
 327+ for ( $i = 0; $i < $ifd['data'][288]['count']; $i++ ) {
 328+ $free[] = unpack( $this->long, fread( $this->file_handle, 4 ) );
 329+ }
330330
331 - // set file pointer to the offset for values from field 289
332 - fseek($this->file_handle, $ifd['data'][289]['value'], SEEK_SET);
333 - // get all offsets of the TileByteCounts
334 - $freebytes = array();
335 - for($i = 0; $i < $ifd['data'][289]['count']; $i++) {
336 - $freebytes[] = unpack($this->long, fread($this->file_handle, 4));
337 - }
338 - // calculate the memory range of the image tiles
339 - for($i = 0; $i < count($tiles); $i++) {
340 - $size = $free[$i][1] + $freebytes[$i][1];
341 - if($size > $this->highest_addr) {
342 - $this->highest_addr = $size;
343 - }
344 - }
345 - }
346 - }
347 - }
 331+ // set file pointer to the offset for values from field 289
 332+ fseek( $this->file_handle, $ifd['data'][289]['value'], SEEK_SET );
 333+ // get all offsets of the TileByteCounts
 334+ $freebytes = array();
 335+ for ( $i = 0; $i < $ifd['data'][289]['count']; $i++ ) {
 336+ $freebytes[] = unpack( $this->long, fread( $this->file_handle, 4 ) );
 337+ }
 338+ // calculate the memory range of the image tiles
 339+ for ( $i = 0; $i < count( $tiles ); $i++ ) {
 340+ $size = $free[$i][1] + $freebytes[$i][1];
 341+ if ( $size > $this->highest_addr ) {
 342+ $this->highest_addr = $size;
 343+ }
 344+ }
 345+ }
 346+ }
 347+ }
348348 }
\ No newline at end of file
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php
@@ -113,7 +113,7 @@
114114
115115 // NOTE: in future, it will become possible to pass parameters
116116 // $error = array( 'tiff_bad_file' , join('<br />', $meta['errors']) );
117 - // does that work now? ^DK
 117+ // does that work now? ^DK
118118
119119 wfDebug( __METHOD__ . ": $error ($saveName) " . join( '; ', $meta['errors'] ) . "\n" );
120120 return false;
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php
@@ -1,7 +1,7 @@
22 <?php
33 /**
44 *
5 - * Copyright (C) Wikimedia Deuschland, 2009
 5+ * Copyright (C) Wikimedia Deutschland, 2009
66 * Authors Hallo Welt! Medienwerkstatt GmbH
77 * Authors Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser
88 *
@@ -47,7 +47,7 @@
4848 * Called by MimeMagick functions.
4949 */
5050 public function isValid() {
51 - return count($this->retrieveMetaData());
 51+ return count( $this->retrieveMetaData() );
5252 }
5353
5454 /**
@@ -57,7 +57,7 @@
5858 $data = $this->retrieveMetaData();
5959 $size = $this->getPageSize( $data, 1 );
6060
61 - if( $size ) {
 61+ if ( $size ) {
6262 $width = $size['width'];
6363 $height = $size['height'];
6464 return array( $width, $height, 'Tiff',
@@ -70,9 +70,9 @@
7171 * Returns an array with width and height of the tiff page.
7272 */
7373 public static function getPageSize( $data, $page ) {
74 - if( isset( $data['page_data'][$page] ) ) {
75 - return array('width' => $data['page_data'][$page]['width'],
76 - 'height' => $data['page_data'][$page]['height']);
 74+ if ( isset( $data['page_data'][$page] ) ) {
 75+ return array( 'width' => $data['page_data'][$page]['width'],
 76+ 'height' => $data['page_data'][$page]['height'] );
7777 }
7878 return false;
7979 }
@@ -89,14 +89,14 @@
9090 public function retrieveMetaData() {
9191 global $wgImageMagickIdentifyCommand, $wgTiffExivCommand, $wgTiffUseExiv, $wgMemc, $wgTiffErrorCacheTTL;
9292
93 - $imgKey = wfMemcKey('PagedTiffHandler-ThumbnailGeneration', $this->mFilename);
94 - $isCached = $wgMemc->get($imgKey);
95 - if($isCached) {
96 - return -1;
 93+ $imgKey = wfMemcKey( 'PagedTiffHandler-ThumbnailGeneration', $this->mFilename );
 94+ $isCached = $wgMemc->get( $imgKey );
 95+ if ( $isCached ) {
 96+ return - 1;
9797 }
98 - $wgMemc->add($imgKey, 1, $wgTiffErrorCacheTTL);
 98+ $wgMemc->add( $imgKey, 1, $wgTiffErrorCacheTTL );
9999
100 - if($this->_meta === NULL) {
 100+ if ( $this->_meta === NULL ) {
101101 if ( $wgImageMagickIdentifyCommand ) {
102102
103103 wfProfileIn( 'PagedTiffImage::retrieveMetaData' );
@@ -109,52 +109,52 @@
110110 wfEscapeShellArg( $this->mFilename ) . ' 2>&1';
111111
112112 wfProfileIn( 'identify' );
113 - wfDebug( __METHOD__.": $cmd\n" );
 113+ wfDebug( __METHOD__ . ": $cmd\n" );
114114 $dump = wfShellExec( $cmd, $retval );
115115 wfProfileOut( 'identify' );
116 - if($retval) {
 116+ if ( $retval ) {
117117 return false;
118118 }
119119 $this->_meta = $this->convertDumpToArray( $dump );
120120 $this->_meta['exif'] = array();
121121
122 - if($wgTiffUseExiv) {
 122+ if ( $wgTiffUseExiv ) {
123123 $cmd = wfEscapeShellArg( $wgTiffExivCommand ) .
124124 ' -u -psix -Pnt ' . // read EXIF, XMP, IPTC as name-tag => interpreted data -ignore unknown fields
125125 // exiv2-doc @link http://www.exiv2.org/sample.html
126 - ## In der Linux-Version von exiv2 gibt es einen Bug, sodass diese Parameter dort nicht funktionieren. ^SU
 126+ # # In der Linux-Version von exiv2 gibt es einen Bug, sodass diese Parameter dort nicht funktionieren. ^SU
127127 wfEscapeShellArg( $this->mFilename );
128128
129129 wfRunHooks( "PagedTiffHandlerExivCommand", array( &$cmd, $this->mFilename ) );
130130
131131 wfProfileIn( 'exiv2' );
132 - wfDebug( __METHOD__.": $cmd\n" );
 132+ wfDebug( __METHOD__ . ": $cmd\n" );
133133 $dump = wfShellExec( $cmd, $retval );
134134 wfProfileOut( 'exiv2' );
135135 $result = array();
136 - preg_match_all('/(\w+)\s+(.+)/', $dump, $result, PREG_SET_ORDER);
 136+ preg_match_all( '/(\w+)\s+(.+)/', $dump, $result, PREG_SET_ORDER );
137137
138 - foreach($result as $data) {
 138+ foreach ( $result as $data ) {
139139 $this->_meta['exif'][$data[1]] = $data[2];
140140 }
141141 }
142142 else {
143143 $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) .
144144 ' -verbose ' .
145 - wfEscapeShellArg( $this->mFilename )."[0]";
 145+ wfEscapeShellArg( $this->mFilename ) . "[0]";
146146
147147 wfProfileIn( 'identify -verbose' );
148 - wfDebug( __METHOD__.": $cmd\n" );
 148+ wfDebug( __METHOD__ . ": $cmd\n" );
149149 $dump = wfShellExec( $cmd, $retval );
150150 wfProfileOut( 'identify -verbose' );
151 - $this->_meta['exif'] = $this->parseVerbose($dump);
 151+ $this->_meta['exif'] = $this->parseVerbose( $dump );
152152 }
153153 wfProfileOut( 'PagedTiffImage::retrieveMetaData' );
154154 }
155155 }
156 - unset($this->_meta['exif']['Image']);
157 - unset($this->_meta['exif']['filename']);
158 - unset($this->_meta['exif']['Base filename']);
 156+ unset( $this->_meta['exif']['Image'] );
 157+ unset( $this->_meta['exif']['filename'] );
 158+ unset( $this->_meta['exif']['Base filename'] );
159159 return $this->_meta;
160160 }
161161
@@ -166,23 +166,23 @@
167167 global $wgTiffIdentifyRejectMessages, $wgTiffIdentifyBypassMessages;
168168 if ( strval( $dump ) == '' ) return false;
169169 $infos = NULL;
170 - preg_match_all('/\[BEGIN\](.+?)\[END\]/si', $dump, $infos, PREG_SET_ORDER);
 170+ preg_match_all( '/\[BEGIN\](.+?)\[END\]/si', $dump, $infos, PREG_SET_ORDER );
171171 $data = array();
172 - $data['page_amount'] = count($infos);
 172+ $data['page_amount'] = count( $infos );
173173 $data['page_data'] = array();
174 - foreach($infos as $info) {
 174+ foreach ( $infos as $info ) {
175175 $entry = array();
176 - $lines = explode("\n", $info[1]);
177 - foreach($lines as $line) {
178 - if(trim($line) == '') {
 176+ $lines = explode( "\n", $info[1] );
 177+ foreach ( $lines as $line ) {
 178+ if ( trim( $line ) == '' ) {
179179 continue;
180180 }
181 - $parts = explode('=', $line);
182 - if(trim($parts[0]) == 'alpha' && trim($parts[1]) == '%A') {
 181+ $parts = explode( '=', $line );
 182+ if ( trim( $parts[0] ) == 'alpha' && trim( $parts[1] ) == '%A' ) {
183183 continue;
184184 }
185 - if(trim($parts[0]) == 'alpha2' && !isset($entry['alpha'])) {
186 - switch(trim($parts[1])) {
 185+ if ( trim( $parts[0] ) == 'alpha2' && !isset( $entry['alpha'] ) ) {
 186+ switch( trim( $parts[1] ) ) {
187187 case 'DirectClassRGBMatte':
188188 case 'DirectClassRGBA':
189189 $entry['alpha'] = 'true';
@@ -193,35 +193,35 @@
194194 }
195195 continue;
196196 }
197 - $entry[trim($parts[0])] = trim($parts[1]);
 197+ $entry[trim( $parts[0] )] = trim( $parts[1] );
198198 }
199199 $entry['pixels'] = $entry['height'] * $entry['width'];
200200 $data['page_data'][$entry['page']] = $entry;
201201 }
202202
203 - $dump = preg_replace('/\[BEGIN\](.+?)\[END\]/si', '', $dump);
204 - if(strlen($dump)) {
205 - $errors = explode("\n", $dump);
206 - foreach($errors as $error) {
 203+ $dump = preg_replace( '/\[BEGIN\](.+?)\[END\]/si', '', $dump );
 204+ if ( strlen( $dump ) ) {
 205+ $errors = explode( "\n", $dump );
 206+ foreach ( $errors as $error ) {
207207 $knownError = false;
208 - foreach($wgTiffIdentifyRejectMessages as $msg) {
209 - if (preg_match($msg, trim($error))) {
 208+ foreach ( $wgTiffIdentifyRejectMessages as $msg ) {
 209+ if ( preg_match( $msg, trim( $error ) ) ) {
210210 $data['errors'][] = $error;
211211 $knownError = true;
212212 break;
213213 }
214214 }
215 - if(!$knownError) {
216 - ## BypassMessages werden nicht gespeichert ^SU
217 - foreach($wgTiffIdentifyBypassMessages as $msg) {
218 - if (preg_match($msg, trim($error))) {
219 - //$data['warnings'][] = $error;
 215+ if ( !$knownError ) {
 216+ # # BypassMessages werden nicht gespeichert ^SU
 217+ foreach ( $wgTiffIdentifyBypassMessages as $msg ) {
 218+ if ( preg_match( $msg, trim( $error ) ) ) {
 219+ // $data['warnings'][] = $error;
220220 $knownError = true;
221221 break;
222222 }
223223 }
224224 }
225 - if(!$knownError) {
 225+ if ( !$knownError ) {
226226 $data['warning'][] = $error;
227227 }
228228 }
@@ -233,25 +233,25 @@
234234 * helper function of retrieveMetaData().
235235 * parses shell return from identify-verbose-command into an array.
236236 */
237 - protected function parseVerbose($dump) {
 237+ protected function parseVerbose( $dump ) {
238238 $data = array();
239 - $dump = explode("\n", $dump);
 239+ $dump = explode( "\n", $dump );
240240 $lastwhite = 0;
241241 $lastkey = false;
242 - foreach($dump as $line) {
243 - if(preg_match('/^(\s*?)(\w([\w\s]+?)?):(.*?)$/sim', $line, $res)) {
244 - if($lastwhite == 0 || strlen($res[1]) == $lastwhite) {
245 - if(strlen(trim($res[4]))) {
246 - $data[trim($res[2])] = trim($res[4]);
 242+ foreach ( $dump as $line ) {
 243+ if ( preg_match( '/^(\s*?)(\w([\w\s]+?)?):(.*?)$/sim', $line, $res ) ) {
 244+ if ( $lastwhite == 0 || strlen( $res[1] ) == $lastwhite ) {
 245+ if ( strlen( trim( $res[4] ) ) ) {
 246+ $data[trim( $res[2] )] = trim( $res[4] );
247247 }
248248 else {
249 - $data[trim($res[2])] = " Data:\n";
 249+ $data[trim( $res[2] )] = " Data:\n";
250250 }
251 - $lastkey = trim($res[2]);
252 - $lastwhite = strlen($res[1]);
 251+ $lastkey = trim( $res[2] );
 252+ $lastwhite = strlen( $res[1] );
253253 }
254254 else {
255 - $data[$lastkey] .= $line."\n";
 255+ $data[$lastkey] .= $line . "\n";
256256 }
257257 }
258258 }

Status & tagging log