r70485 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70484‎ | r70485 | r70486 >
Date:22:08, 4 August 2010
Author:bawolff
Status:ok
Tags:
Comment:
just running Stylize.php. no code changes.
Modified paths:
  • /branches/img_metadata/phase3/includes/media/XMP.php (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/includes/media/XMP.php
@@ -61,9 +61,9 @@
6262 */
6363 function __construct() {
6464
65 - if ( !function_exists('xml_parser_create_ns') ) {
 65+ if ( !function_exists( 'xml_parser_create_ns' ) ) {
6666 // 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' );
6868 }
6969
7070 $this->xmlParser = xml_parser_create_ns( 'UTF-8', ' ' );
@@ -108,17 +108,17 @@
109109 public function parse( $content ) {
110110 try {
111111 $ok = xml_parse( $this->xmlParser, $content, true );
112 - if (!$ok) {
 112+ if ( !$ok ) {
113113 $error = xml_error_string( xml_get_error_code( $this->xmlParser ) );
114114 $where = 'line: ' . xml_get_current_line_number( $this->xmlParser )
115115 . ' column: ' . xml_get_current_column_number( $this->xmlParser )
116116 . ' byte offset: ' . xml_get_current_byte_index( $this->xmlParser );
117117
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.
120120 return false;
121121 }
122 - } catch (MWException $e) {
 122+ } catch ( MWException $e ) {
123123 wfDebugLog( 'XMP', 'XMP parse error: ' . $e );
124124 $this->results = array();
125125 return false;
@@ -139,32 +139,32 @@
140140 */
141141 function char( $parser, $data ) {
142142
143 - $data = trim( $data );
144 - if ( trim($data) === "" ) {
 143+ $data = trim( $data );
 144+ if ( trim( $data ) === "" ) {
145145 return;
146146 }
147147
148148 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' );
150150 }
151151
152152 if ( $this->mode[0] === self::MODE_IGNORE ) return;
153153
154 - if ( $this->mode[0] !== self::MODE_SIMPLE
 154+ if ( $this->mode[0] !== self::MODE_SIMPLE
155155 && $this->mode[0] !== self::MODE_QDESC
156156 ) {
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] . ')' );
158158 }
159159
160 - //to check, how does this handle w.s.
 160+ // to check, how does this handle w.s.
161161 if ( $this->charContent === false ) {
162162 $this->charContent = $data;
163163 } else {
164164 // I don't think this should happen,
165165 // but just in case.
166166 $this->charContent .= $data;
167 - //FIXME
168 - wfDebugLog( 'XMP', 'XMP: Consecuitive CDATA');
 167+ // FIXME
 168+ wfDebugLog( 'XMP', 'XMP: Consecuitive CDATA' );
169169 }
170170
171171 }
@@ -177,13 +177,13 @@
178178 private function endElementModeIgnore ( $elm ) {
179179 if ( count( $this->curItem ) == 0 ) {
180180 // just to be paranoid.
181 - throw new MWException(' In ignore mode with no curItem');
 181+ throw new MWException( ' In ignore mode with no curItem' );
182182 }
183183 if ( $this->curItem[0] === $elm ) {
184184 array_shift( $this->curItem );
185185 array_shift( $this->mode );
186186 }
187 - return;
 187+ return;
188188
189189 }
190190 /** Hit a closing element when in MODE_SIMPLE.
@@ -198,13 +198,13 @@
199199 if ( $this->processingArray ) {
200200 // if we're processing an array, use the original element
201201 // name instead of rdf:li.
202 - list($ns, $tag) = explode(' ', $this->curItem[0], 2);
 202+ list( $ns, $tag ) = explode( ' ', $this->curItem[0], 2 );
203203 } else {
204 - list($ns, $tag) = explode(' ', $elm, 2);
 204+ list( $ns, $tag ) = explode( ' ', $elm, 2 );
205205 }
206206 $this->saveValue( $ns, $tag, $this->charContent );
207207
208 - $this->charContent = false; //reset
 208+ $this->charContent = false; // reset
209209 }
210210 array_shift( $this->curItem );
211211 array_shift( $this->mode );
@@ -226,7 +226,7 @@
227227 && !( $elm === self::NS_RDF . ' Description'
228228 && $this->mode[0] === self::MODE_STRUCT )
229229 ) {
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] . '>' );
231231 }
232232 array_shift( $this->curItem );
233233 array_shift( $this->mode );
@@ -277,16 +277,16 @@
278278 * @param $elm String namespace . ' ' . element name
279279 */
280280 function endElement( $parser, $elm ) {
281 - if ( $elm === (self::NS_RDF . ' RDF')
 281+ if ( $elm === ( self::NS_RDF . ' RDF' )
282282 || $elm === 'adobe:ns:meta/ xmpmeta' )
283283 {
284 - //ignore these.
 284+ // ignore these.
285285 return;
286286 }
287287
288288 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>' );
291291 }
292292
293293 switch( $this->mode[0] ) {
@@ -305,7 +305,7 @@
306306 if ( $elm === self::NS_RDF . ' Description' ) {
307307 array_shift( $this->mode );
308308 } else {
309 - throw new MWException('Element ended unexpected while in MODE_INITIAL');
 309+ throw new MWException( 'Element ended unexpected while in MODE_INITIAL' );
310310 }
311311 break;
312312 case self::MODE_LI:
@@ -315,7 +315,7 @@
316316 $this->endElementModeQDesc( $elm );
317317 break;
318318 default:
319 - wfDebugLog( 'XMP', __METHOD__ ." no mode (elm = $elm)");
 319+ wfDebugLog( 'XMP', __METHOD__ . " no mode (elm = $elm)" );
320320 break;
321321 }
322322 }
@@ -343,7 +343,7 @@
344344 if ( $elm === self::NS_RDF . ' Bag' ) {
345345 array_unshift( $this->mode, self::MODE_LI );
346346 } else {
347 - throw new MWException("Expected <rdf:Bag> but got $elm.");
 347+ throw new MWException( "Expected <rdf:Bag> but got $elm." );
348348 }
349349
350350 }
@@ -357,7 +357,7 @@
358358 if ( $elm === self::NS_RDF . ' Seq' ) {
359359 array_unshift( $this->mode, self::MODE_LI );
360360 } else {
361 - throw new MWException("Expected <rdf:Seq> but got $elm.");
 361+ throw new MWException( "Expected <rdf:Seq> but got $elm." );
362362 }
363363
364364 }
@@ -370,21 +370,21 @@
371371 */
372372 private function startElementModeSimple( $elm, $attribs ) {
373373 if ( $elm === self::NS_RDF . ' Description' ) {
374 - //If this value has qualifiers
 374+ // If this value has qualifiers
375375 array_unshift( $this->mode, self::MODE_QDESC );
376376 array_unshift( $this->curItem, $this->curItem[0] );
377377
378378 if ( isset( $attribs[self::NS_RDF . ' value'] ) ) {
379379 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'] );
381381 }
382382 } 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.' );
385385
386386 } 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." );
389389 array_unshift( $this->mode, self::MODE_IGNORE );
390390 array_unshift( $this->curItem, $elm );
391391
@@ -400,9 +400,9 @@
401401 */
402402 private function startElementModeQDesc( $elm ) {
403403 if ( $elm === self::NS_RDF . ' value' ) {
404 - return; //do nothing
 404+ return; // do nothing
405405 } else {
406 - //otherwise its a qualifier, which we ignore
 406+ // otherwise its a qualifier, which we ignore
407407 array_unshift( $this->mode, self::MODE_IGNORE );
408408 array_unshift( $this->curItem, $elm );
409409 }
@@ -418,7 +418,7 @@
419419 * @param $attribs Array array of attributes
420420 */
421421 private function startElementModeInitial( $ns, $tag, $attribs ) {
422 - if ($ns !== self::NS_RDF) {
 422+ if ( $ns !== self::NS_RDF ) {
423423
424424 if ( isset( XMPInfo::$items[$ns][$tag] ) ) {
425425 $mode = XMPInfo::$items[$ns][$tag]['mode'];
@@ -426,12 +426,12 @@
427427 array_unshift( $this->curItem, $ns . ' ' . $tag );
428428 if ( $mode === self::MODE_STRUCT ) {
429429 $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;
431431 }
432432 if ( $this->charContent !== false ) {
433433 // Something weird.
434434 // 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.' );
436436 }
437437 } else {
438438 array_unshift( $this->mode, self::MODE_IGNORE );
@@ -440,7 +440,7 @@
441441 }
442442
443443 }
444 - //process attributes
 444+ // process attributes
445445 $this->doAttribs( $attribs );
446446 }
447447 /** Hit an opening element when in a Struct (MODE_STRUCT)
@@ -451,23 +451,23 @@
452452 * @param $attribs Array array of attribs w/ values.
453453 */
454454 private function startElementModeStruct( $ns, $tag, $attribs ) {
455 - if ($ns !== self::NS_RDF) {
 455+ if ( $ns !== self::NS_RDF ) {
456456
457457 if ( isset( XMPInfo::$items[$ns][$tag] ) ) {
458458 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] ) )
460460 {
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." );
465465 }
466466 array_unshift( $this->mode, XMPInfo::$items[$ns][$tag]['mode'] );
467467 array_unshift( $this->curItem, $ns . ' ' . $tag );
468468 if ( $this->charContent !== false ) {
469469 // Something weird.
470470 // 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 . ")." );
472472 }
473473 } else {
474474 array_unshift( $this->mode, self::MODE_IGNORE );
@@ -491,10 +491,10 @@
492492 */
493493 private function startElementModeLi( $elm ) {
494494 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." );
496496 }
497497 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
499499 // and one is for the entire group.
500500 array_unshift( $this->curItem, $this->curItem[0] );
501501 $this->processingArray = true;
@@ -510,14 +510,14 @@
511511 */
512512 function startElement( $parser, $elm, $attribs ) {
513513
514 - if ($elm === self::NS_RDF . ' RDF'
 514+ if ( $elm === self::NS_RDF . ' RDF'
515515 || $elm === 'adobe:ns:meta/ xmpmeta' )
516516 {
517517 /* ignore */
518 - return;
 518+ return;
519519 } elseif ( $elm === self::NS_RDF . ' Description' ) {
520520 if ( count( $this->mode ) === 0 ) {
521 - //outer rdf:desc
 521+ // outer rdf:desc
522522 array_unshift( $this->mode, self::MODE_INITIAL );
523523 }
524524 } elseif ( $elm === self::NS_RDF . ' type' ) {
@@ -529,7 +529,7 @@
530530 }
531531
532532
533 - list($ns, $tag) = explode( ' ', $elm, 2 );
 533+ list( $ns, $tag ) = explode( ' ', $elm, 2 );
534534
535535 switch( $this->mode[0] ) {
536536 case self::MODE_IGNORE:
@@ -557,7 +557,7 @@
558558 $this->startElementModeQDesc( $elm );
559559 break;
560560 default:
561 - throw new MWException('StartElement in unknown mode: ' . $this->mode[0] );
 561+ throw new MWException( 'StartElement in unknown mode: ' . $this->mode[0] );
562562 break;
563563 }
564564
@@ -570,7 +570,7 @@
571571 * @param $attribs Array attribute=>value array.
572572 */
573573 private function doAttribs( $attribs ) {
574 - foreach( $attribs as $name => $val ) {
 574+ foreach ( $attribs as $name => $val ) {
575575
576576 // first check for rdf:parseType attribute, as that can change
577577 // how the attributes are interperted.
@@ -579,11 +579,11 @@
580580 && $val === 'Resource'
581581 && $this->mode[0] === self::MODE_SIMPLE )
582582 {
583 - //this is equivelent to having an inner rdf:Description
 583+ // this is equivelent to having an inner rdf:Description
584584 $this->mode[0] = self::MODE_QDESC;
585585 }
586586
587 - list($ns, $tag) = explode(' ', $name, 2);
 587+ list( $ns, $tag ) = explode( ' ', $name, 2 );
588588 if ( $ns === self::NS_RDF ) {
589589 if ( $tag === 'value' || $tag === 'resource' ) {
590590 // resource is for url.
@@ -592,7 +592,7 @@
593593 }
594594 } elseif ( isset( XMPInfo::$items[$ns][$tag] ) ) {
595595 if ( $this->mode[0] === self::MODE_SIMPLE ) {
596 - throw new MWException( __METHOD__
 596+ throw new MWException( __METHOD__
597597 . " $ns:$tag found as attribute where not allowed" );
598598 }
599599 $this->saveValue( $ns, $tag, $val );
@@ -615,13 +615,13 @@
616616 $finalName = isset( $info['map_name'] )
617617 ? $info['map_name'] : $tag;
618618 if ( isset( $info['validate'] ) ) {
619 - //FIXME
 619+ // FIXME
620620 }
621621
622622 if ( $this->ancestorStruct ) {
623623 $this->results['xmp-' . $info['map_group']][$this->ancestorStruct][$finalName] = $val;
624624 } elseif ( $this->processingArray ) {
625 - $this->results['xmp-' . $info['map_group']][$finalName][] = $val;
 625+ $this->results['xmp-' . $info['map_group']][$finalName][] = $val;
626626 } else {
627627 $this->results['xmp-' . $info['map_group']][$finalName] = $val;
628628 }

Status & tagging log