Index: branches/img_metadata/phase3/includes/media/XMP.php |
— | — | @@ -61,9 +61,9 @@ |
62 | 62 | */ |
63 | 63 | function __construct() { |
64 | 64 | |
65 | | - if ( !function_exists('xml_parser_create_ns') ) { |
| 65 | + if ( !function_exists( 'xml_parser_create_ns' ) ) { |
66 | 66 | // this should already be checked by this point |
67 | | - throw new MWException('XMP support requires XML Parser'); |
| 67 | + throw new MWException( 'XMP support requires XML Parser' ); |
68 | 68 | } |
69 | 69 | |
70 | 70 | $this->xmlParser = xml_parser_create_ns( 'UTF-8', ' ' ); |
— | — | @@ -108,17 +108,17 @@ |
109 | 109 | public function parse( $content ) { |
110 | 110 | try { |
111 | 111 | $ok = xml_parse( $this->xmlParser, $content, true ); |
112 | | - if (!$ok) { |
| 112 | + if ( !$ok ) { |
113 | 113 | $error = xml_error_string( xml_get_error_code( $this->xmlParser ) ); |
114 | 114 | $where = 'line: ' . xml_get_current_line_number( $this->xmlParser ) |
115 | 115 | . ' column: ' . xml_get_current_column_number( $this->xmlParser ) |
116 | 116 | . ' byte offset: ' . xml_get_current_byte_index( $this->xmlParser ); |
117 | 117 | |
118 | | - wfDebugLog( 'XMP', "XMPReader::parse : Error reading XMP content: $error ($where)"); |
119 | | - $this->results = array(); //blank if error. |
| 118 | + wfDebugLog( 'XMP', "XMPReader::parse : Error reading XMP content: $error ($where)" ); |
| 119 | + $this->results = array(); // blank if error. |
120 | 120 | return false; |
121 | 121 | } |
122 | | - } catch (MWException $e) { |
| 122 | + } catch ( MWException $e ) { |
123 | 123 | wfDebugLog( 'XMP', 'XMP parse error: ' . $e ); |
124 | 124 | $this->results = array(); |
125 | 125 | return false; |
— | — | @@ -139,32 +139,32 @@ |
140 | 140 | */ |
141 | 141 | function char( $parser, $data ) { |
142 | 142 | |
143 | | - $data = trim( $data ); |
144 | | - if ( trim($data) === "" ) { |
| 143 | + $data = trim( $data ); |
| 144 | + if ( trim( $data ) === "" ) { |
145 | 145 | return; |
146 | 146 | } |
147 | 147 | |
148 | 148 | if ( !isset( $this->mode[0] ) ) { |
149 | | - throw new MWException('Unexpected character data before first rdf:Description element'); |
| 149 | + throw new MWException( 'Unexpected character data before first rdf:Description element' ); |
150 | 150 | } |
151 | 151 | |
152 | 152 | if ( $this->mode[0] === self::MODE_IGNORE ) return; |
153 | 153 | |
154 | | - if ( $this->mode[0] !== self::MODE_SIMPLE |
| 154 | + if ( $this->mode[0] !== self::MODE_SIMPLE |
155 | 155 | && $this->mode[0] !== self::MODE_QDESC |
156 | 156 | ) { |
157 | | - throw new MWException('character data where not expected. (mode ' . $this->mode[0] . ')'); |
| 157 | + throw new MWException( 'character data where not expected. (mode ' . $this->mode[0] . ')' ); |
158 | 158 | } |
159 | 159 | |
160 | | - //to check, how does this handle w.s. |
| 160 | + // to check, how does this handle w.s. |
161 | 161 | if ( $this->charContent === false ) { |
162 | 162 | $this->charContent = $data; |
163 | 163 | } else { |
164 | 164 | // I don't think this should happen, |
165 | 165 | // but just in case. |
166 | 166 | $this->charContent .= $data; |
167 | | - //FIXME |
168 | | - wfDebugLog( 'XMP', 'XMP: Consecuitive CDATA'); |
| 167 | + // FIXME |
| 168 | + wfDebugLog( 'XMP', 'XMP: Consecuitive CDATA' ); |
169 | 169 | } |
170 | 170 | |
171 | 171 | } |
— | — | @@ -177,13 +177,13 @@ |
178 | 178 | private function endElementModeIgnore ( $elm ) { |
179 | 179 | if ( count( $this->curItem ) == 0 ) { |
180 | 180 | // just to be paranoid. |
181 | | - throw new MWException(' In ignore mode with no curItem'); |
| 181 | + throw new MWException( ' In ignore mode with no curItem' ); |
182 | 182 | } |
183 | 183 | if ( $this->curItem[0] === $elm ) { |
184 | 184 | array_shift( $this->curItem ); |
185 | 185 | array_shift( $this->mode ); |
186 | 186 | } |
187 | | - return; |
| 187 | + return; |
188 | 188 | |
189 | 189 | } |
190 | 190 | /** Hit a closing element when in MODE_SIMPLE. |
— | — | @@ -198,13 +198,13 @@ |
199 | 199 | if ( $this->processingArray ) { |
200 | 200 | // if we're processing an array, use the original element |
201 | 201 | // name instead of rdf:li. |
202 | | - list($ns, $tag) = explode(' ', $this->curItem[0], 2); |
| 202 | + list( $ns, $tag ) = explode( ' ', $this->curItem[0], 2 ); |
203 | 203 | } else { |
204 | | - list($ns, $tag) = explode(' ', $elm, 2); |
| 204 | + list( $ns, $tag ) = explode( ' ', $elm, 2 ); |
205 | 205 | } |
206 | 206 | $this->saveValue( $ns, $tag, $this->charContent ); |
207 | 207 | |
208 | | - $this->charContent = false; //reset |
| 208 | + $this->charContent = false; // reset |
209 | 209 | } |
210 | 210 | array_shift( $this->curItem ); |
211 | 211 | array_shift( $this->mode ); |
— | — | @@ -226,7 +226,7 @@ |
227 | 227 | && !( $elm === self::NS_RDF . ' Description' |
228 | 228 | && $this->mode[0] === self::MODE_STRUCT ) |
229 | 229 | ) { |
230 | | - throw new MWException("nesting mismatch. got a </$elm> but expected a </" . $this->curItem[0] . '>'); |
| 230 | + throw new MWException( "nesting mismatch. got a </$elm> but expected a </" . $this->curItem[0] . '>' ); |
231 | 231 | } |
232 | 232 | array_shift( $this->curItem ); |
233 | 233 | array_shift( $this->mode ); |
— | — | @@ -277,16 +277,16 @@ |
278 | 278 | * @param $elm String namespace . ' ' . element name |
279 | 279 | */ |
280 | 280 | function endElement( $parser, $elm ) { |
281 | | - if ( $elm === (self::NS_RDF . ' RDF') |
| 281 | + if ( $elm === ( self::NS_RDF . ' RDF' ) |
282 | 282 | || $elm === 'adobe:ns:meta/ xmpmeta' ) |
283 | 283 | { |
284 | | - //ignore these. |
| 284 | + // ignore these. |
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | 288 | if ( $elm === self::NS_RDF . ' type' ) { |
289 | | - //these aren't really supported properly yet. |
290 | | - wfDebugLog('XMP', __METHOD__ . ' encoutered <rdf:type>'); |
| 289 | + // these aren't really supported properly yet. |
| 290 | + wfDebugLog( 'XMP', __METHOD__ . ' encoutered <rdf:type>' ); |
291 | 291 | } |
292 | 292 | |
293 | 293 | switch( $this->mode[0] ) { |
— | — | @@ -305,7 +305,7 @@ |
306 | 306 | if ( $elm === self::NS_RDF . ' Description' ) { |
307 | 307 | array_shift( $this->mode ); |
308 | 308 | } else { |
309 | | - throw new MWException('Element ended unexpected while in MODE_INITIAL'); |
| 309 | + throw new MWException( 'Element ended unexpected while in MODE_INITIAL' ); |
310 | 310 | } |
311 | 311 | break; |
312 | 312 | case self::MODE_LI: |
— | — | @@ -315,7 +315,7 @@ |
316 | 316 | $this->endElementModeQDesc( $elm ); |
317 | 317 | break; |
318 | 318 | default: |
319 | | - wfDebugLog( 'XMP', __METHOD__ ." no mode (elm = $elm)"); |
| 319 | + wfDebugLog( 'XMP', __METHOD__ . " no mode (elm = $elm)" ); |
320 | 320 | break; |
321 | 321 | } |
322 | 322 | } |
— | — | @@ -343,7 +343,7 @@ |
344 | 344 | if ( $elm === self::NS_RDF . ' Bag' ) { |
345 | 345 | array_unshift( $this->mode, self::MODE_LI ); |
346 | 346 | } else { |
347 | | - throw new MWException("Expected <rdf:Bag> but got $elm."); |
| 347 | + throw new MWException( "Expected <rdf:Bag> but got $elm." ); |
348 | 348 | } |
349 | 349 | |
350 | 350 | } |
— | — | @@ -357,7 +357,7 @@ |
358 | 358 | if ( $elm === self::NS_RDF . ' Seq' ) { |
359 | 359 | array_unshift( $this->mode, self::MODE_LI ); |
360 | 360 | } else { |
361 | | - throw new MWException("Expected <rdf:Seq> but got $elm."); |
| 361 | + throw new MWException( "Expected <rdf:Seq> but got $elm." ); |
362 | 362 | } |
363 | 363 | |
364 | 364 | } |
— | — | @@ -370,21 +370,21 @@ |
371 | 371 | */ |
372 | 372 | private function startElementModeSimple( $elm, $attribs ) { |
373 | 373 | if ( $elm === self::NS_RDF . ' Description' ) { |
374 | | - //If this value has qualifiers |
| 374 | + // If this value has qualifiers |
375 | 375 | array_unshift( $this->mode, self::MODE_QDESC ); |
376 | 376 | array_unshift( $this->curItem, $this->curItem[0] ); |
377 | 377 | |
378 | 378 | if ( isset( $attribs[self::NS_RDF . ' value'] ) ) { |
379 | 379 | list( $ns, $tag ) = explode( ' ', $this->curItem[0], 2 ); |
380 | | - $this->saveValue( $ns, $tag, $attribs[self::NS_RDF . ' value']); |
| 380 | + $this->saveValue( $ns, $tag, $attribs[self::NS_RDF . ' value'] ); |
381 | 381 | } |
382 | 382 | } elseif ( $elm === self::NS_RDF . ' value' ) { |
383 | | - //This should not be here. |
384 | | - throw new MWException(__METHOD__ . ' Encountered <rdf:value> where it was unexpected.'); |
| 383 | + // This should not be here. |
| 384 | + throw new MWException( __METHOD__ . ' Encountered <rdf:value> where it was unexpected.' ); |
385 | 385 | |
386 | 386 | } else { |
387 | | - //something else we don't recognize, like a qualifier maybe. |
388 | | - wfDebugLog( 'XMP', __METHOD__ . " Encoutered element <$elm> where only expecting character data."); |
| 387 | + // something else we don't recognize, like a qualifier maybe. |
| 388 | + wfDebugLog( 'XMP', __METHOD__ . " Encoutered element <$elm> where only expecting character data." ); |
389 | 389 | array_unshift( $this->mode, self::MODE_IGNORE ); |
390 | 390 | array_unshift( $this->curItem, $elm ); |
391 | 391 | |
— | — | @@ -400,9 +400,9 @@ |
401 | 401 | */ |
402 | 402 | private function startElementModeQDesc( $elm ) { |
403 | 403 | if ( $elm === self::NS_RDF . ' value' ) { |
404 | | - return; //do nothing |
| 404 | + return; // do nothing |
405 | 405 | } else { |
406 | | - //otherwise its a qualifier, which we ignore |
| 406 | + // otherwise its a qualifier, which we ignore |
407 | 407 | array_unshift( $this->mode, self::MODE_IGNORE ); |
408 | 408 | array_unshift( $this->curItem, $elm ); |
409 | 409 | } |
— | — | @@ -418,7 +418,7 @@ |
419 | 419 | * @param $attribs Array array of attributes |
420 | 420 | */ |
421 | 421 | private function startElementModeInitial( $ns, $tag, $attribs ) { |
422 | | - if ($ns !== self::NS_RDF) { |
| 422 | + if ( $ns !== self::NS_RDF ) { |
423 | 423 | |
424 | 424 | if ( isset( XMPInfo::$items[$ns][$tag] ) ) { |
425 | 425 | $mode = XMPInfo::$items[$ns][$tag]['mode']; |
— | — | @@ -426,12 +426,12 @@ |
427 | 427 | array_unshift( $this->curItem, $ns . ' ' . $tag ); |
428 | 428 | if ( $mode === self::MODE_STRUCT ) { |
429 | 429 | $this->ancestorStruct = isset( XMPInfo::$items[$ns][$tag]['map_name'] ) |
430 | | - ? XMPInfo::$items[$ns][$tag]['map_name'] : $tag; |
| 430 | + ? XMPInfo::$items[$ns][$tag]['map_name'] : $tag; |
431 | 431 | } |
432 | 432 | if ( $this->charContent !== false ) { |
433 | 433 | // Something weird. |
434 | 434 | // Should not happen in valid XMP. |
435 | | - throw new MWException('tag nested in non-whitespace characters.'); |
| 435 | + throw new MWException( 'tag nested in non-whitespace characters.' ); |
436 | 436 | } |
437 | 437 | } else { |
438 | 438 | array_unshift( $this->mode, self::MODE_IGNORE ); |
— | — | @@ -440,7 +440,7 @@ |
441 | 441 | } |
442 | 442 | |
443 | 443 | } |
444 | | - //process attributes |
| 444 | + // process attributes |
445 | 445 | $this->doAttribs( $attribs ); |
446 | 446 | } |
447 | 447 | /** Hit an opening element when in a Struct (MODE_STRUCT) |
— | — | @@ -451,23 +451,23 @@ |
452 | 452 | * @param $attribs Array array of attribs w/ values. |
453 | 453 | */ |
454 | 454 | private function startElementModeStruct( $ns, $tag, $attribs ) { |
455 | | - if ($ns !== self::NS_RDF) { |
| 455 | + if ( $ns !== self::NS_RDF ) { |
456 | 456 | |
457 | 457 | if ( isset( XMPInfo::$items[$ns][$tag] ) ) { |
458 | 458 | if ( isset( XMPInfo::$items[$ns][$this->ancestorStruct]['children'] ) |
459 | | - && !isset(XMPInfo::$items[$ns][$this->ancestorStruct]['children'][$tag]) ) |
| 459 | + && !isset( XMPInfo::$items[$ns][$this->ancestorStruct]['children'][$tag] ) ) |
460 | 460 | { |
461 | | - //This assumes that we don't have inter-namespace nesting |
462 | | - //which we don't in all the properties we're interested in. |
463 | | - throw new MWException(" <$tag> appeared nested in <" . $this->ancestorStruct |
464 | | - . "> where it is not allowed."); |
| 461 | + // This assumes that we don't have inter-namespace nesting |
| 462 | + // which we don't in all the properties we're interested in. |
| 463 | + throw new MWException( " <$tag> appeared nested in <" . $this->ancestorStruct |
| 464 | + . "> where it is not allowed." ); |
465 | 465 | } |
466 | 466 | array_unshift( $this->mode, XMPInfo::$items[$ns][$tag]['mode'] ); |
467 | 467 | array_unshift( $this->curItem, $ns . ' ' . $tag ); |
468 | 468 | if ( $this->charContent !== false ) { |
469 | 469 | // Something weird. |
470 | 470 | // Should not happen in valid XMP. |
471 | | - throw new MWException("tag <$tag> nested in non-whitespace characters (" . $this->charContent . ")."); |
| 471 | + throw new MWException( "tag <$tag> nested in non-whitespace characters (" . $this->charContent . ")." ); |
472 | 472 | } |
473 | 473 | } else { |
474 | 474 | array_unshift( $this->mode, self::MODE_IGNORE ); |
— | — | @@ -491,10 +491,10 @@ |
492 | 492 | */ |
493 | 493 | private function startElementModeLi( $elm ) { |
494 | 494 | if ( $elm !== self::NS_RDF . ' li' ) { |
495 | | - throw new MWException("<rdf:li> expected but got $elm."); |
| 495 | + throw new MWException( "<rdf:li> expected but got $elm." ); |
496 | 496 | } |
497 | 497 | array_unshift( $this->mode, self::MODE_SIMPLE ); |
498 | | - //need to add curItem[0] on again since one is for the specific item |
| 498 | + // need to add curItem[0] on again since one is for the specific item |
499 | 499 | // and one is for the entire group. |
500 | 500 | array_unshift( $this->curItem, $this->curItem[0] ); |
501 | 501 | $this->processingArray = true; |
— | — | @@ -510,14 +510,14 @@ |
511 | 511 | */ |
512 | 512 | function startElement( $parser, $elm, $attribs ) { |
513 | 513 | |
514 | | - if ($elm === self::NS_RDF . ' RDF' |
| 514 | + if ( $elm === self::NS_RDF . ' RDF' |
515 | 515 | || $elm === 'adobe:ns:meta/ xmpmeta' ) |
516 | 516 | { |
517 | 517 | /* ignore */ |
518 | | - return; |
| 518 | + return; |
519 | 519 | } elseif ( $elm === self::NS_RDF . ' Description' ) { |
520 | 520 | if ( count( $this->mode ) === 0 ) { |
521 | | - //outer rdf:desc |
| 521 | + // outer rdf:desc |
522 | 522 | array_unshift( $this->mode, self::MODE_INITIAL ); |
523 | 523 | } |
524 | 524 | } elseif ( $elm === self::NS_RDF . ' type' ) { |
— | — | @@ -529,7 +529,7 @@ |
530 | 530 | } |
531 | 531 | |
532 | 532 | |
533 | | - list($ns, $tag) = explode( ' ', $elm, 2 ); |
| 533 | + list( $ns, $tag ) = explode( ' ', $elm, 2 ); |
534 | 534 | |
535 | 535 | switch( $this->mode[0] ) { |
536 | 536 | case self::MODE_IGNORE: |
— | — | @@ -557,7 +557,7 @@ |
558 | 558 | $this->startElementModeQDesc( $elm ); |
559 | 559 | break; |
560 | 560 | default: |
561 | | - throw new MWException('StartElement in unknown mode: ' . $this->mode[0] ); |
| 561 | + throw new MWException( 'StartElement in unknown mode: ' . $this->mode[0] ); |
562 | 562 | break; |
563 | 563 | } |
564 | 564 | |
— | — | @@ -570,7 +570,7 @@ |
571 | 571 | * @param $attribs Array attribute=>value array. |
572 | 572 | */ |
573 | 573 | private function doAttribs( $attribs ) { |
574 | | - foreach( $attribs as $name => $val ) { |
| 574 | + foreach ( $attribs as $name => $val ) { |
575 | 575 | |
576 | 576 | // first check for rdf:parseType attribute, as that can change |
577 | 577 | // how the attributes are interperted. |
— | — | @@ -579,11 +579,11 @@ |
580 | 580 | && $val === 'Resource' |
581 | 581 | && $this->mode[0] === self::MODE_SIMPLE ) |
582 | 582 | { |
583 | | - //this is equivelent to having an inner rdf:Description |
| 583 | + // this is equivelent to having an inner rdf:Description |
584 | 584 | $this->mode[0] = self::MODE_QDESC; |
585 | 585 | } |
586 | 586 | |
587 | | - list($ns, $tag) = explode(' ', $name, 2); |
| 587 | + list( $ns, $tag ) = explode( ' ', $name, 2 ); |
588 | 588 | if ( $ns === self::NS_RDF ) { |
589 | 589 | if ( $tag === 'value' || $tag === 'resource' ) { |
590 | 590 | // resource is for url. |
— | — | @@ -592,7 +592,7 @@ |
593 | 593 | } |
594 | 594 | } elseif ( isset( XMPInfo::$items[$ns][$tag] ) ) { |
595 | 595 | if ( $this->mode[0] === self::MODE_SIMPLE ) { |
596 | | - throw new MWException( __METHOD__ |
| 596 | + throw new MWException( __METHOD__ |
597 | 597 | . " $ns:$tag found as attribute where not allowed" ); |
598 | 598 | } |
599 | 599 | $this->saveValue( $ns, $tag, $val ); |
— | — | @@ -615,13 +615,13 @@ |
616 | 616 | $finalName = isset( $info['map_name'] ) |
617 | 617 | ? $info['map_name'] : $tag; |
618 | 618 | if ( isset( $info['validate'] ) ) { |
619 | | - //FIXME |
| 619 | + // FIXME |
620 | 620 | } |
621 | 621 | |
622 | 622 | if ( $this->ancestorStruct ) { |
623 | 623 | $this->results['xmp-' . $info['map_group']][$this->ancestorStruct][$finalName] = $val; |
624 | 624 | } elseif ( $this->processingArray ) { |
625 | | - $this->results['xmp-' . $info['map_group']][$finalName][] = $val; |
| 625 | + $this->results['xmp-' . $info['map_group']][$finalName][] = $val; |
626 | 626 | } else { |
627 | 627 | $this->results['xmp-' . $info['map_group']][$finalName] = $val; |
628 | 628 | } |