r86148 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86147‎ | r86148 | r86149 >
Date:22:54, 15 April 2011
Author:bawolff
Status:ok
Tags:
Comment:
Fix some comments on the XMP file. 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
@@ -1,9 +1,8 @@
22 <?php
3 -/** Class for reading xmp data containing properties relevant to
 3+/**
 4+* Class for reading xmp data containing properties relevant to
45 * images, and spitting out an array that FormatExif accepts.
56 *
6 -* It should be noted this is not done yet
7 -*
87 * Note, this is not meant to recognize every possible thing you can
98 * encode in XMP. It should recognize all the properties we want.
109 * For example it doesn't have support for structures with multiple
@@ -20,6 +19,10 @@
2120 * - getResults
2221 * Outputs a results array.
2322 *
 23+* Note XMP kind of looks like rdf. They are not the same thing - XMP is
 24+* encoded as a specific subset of rdf. This class can read XMP. It cannot
 25+* read rdf.
 26+*
2427 */
2528 class XMPReader {
2629
@@ -66,7 +69,8 @@
6770 const NS_XML = 'http://www.w3.org/XML/1998/namespace';
6871
6972
70 - /** Constructor.
 73+ /**
 74+ * Constructor.
7175 *
7276 * Primary job is to initialize the XMLParser
7377 */
@@ -108,7 +112,7 @@
109113
110114 /** Destroy the xml parser
111115 *
112 - * not sure if this is actually needed.
 116+ * Not sure if this is actually needed.
113117 */
114118 function __destruct() {
115119 // not sure if this is needed.
@@ -338,13 +342,18 @@
339343 return $this->parse( $actualContent, $atEnd );
340344 }
341345
342 - /** Character data handler
 346+ /**
 347+ * Character data handler
343348 * Called whenever character data is found in the xmp document.
344349 *
345350 * does nothing if we're in MODE_IGNORE or if the data is whitespace
346351 * throws an error if we're not in MODE_SIMPLE (as we're not allowed to have character
347352 * data in the other modes).
348353 *
 354+ * As an example, this happens when we encounter XMP like:
 355+ * <exif:DigitalZoomRatio>0/10</exif:DigitalZoomRatio>
 356+ * and are processing the 0/10 bit.
 357+ *
349358 * @param $parser XMLParser reference to the xml parser
350359 * @param $data String Character data
351360 * @throws MWException on invalid data
@@ -391,11 +400,19 @@
392401 return;
393402
394403 }
395 - /** Hit a closing element when in MODE_SIMPLE.
 404+ /**
 405+ * Hit a closing element when in MODE_SIMPLE.
396406 * This generally means that we finished processing a
397407 * property value, and now have to save the result to the
398408 * results array
399409 *
 410+ * For example, when processing:
 411+ * <exif:DigitalZoomRatio>0/10</exif:DigitalZoomRatio>
 412+ * this deals with when we hit </exif:DigitalZoomRatio>.
 413+ *
 414+ * Or it could be if we hit the end element of a property
 415+ * of a compound data structure (like a member of an array).
 416+ *
400417 * @param $elm String namespace, space, and tag name.
401418 */
402419 private function endElementModeSimple ( $elm ) {
@@ -415,12 +432,19 @@
416433 array_shift( $this->mode );
417434
418435 }
419 - /** Hit a closing element in MODE_STRUCT, MODE_SEQ, MODE_BAG
 436+ /**
 437+ * Hit a closing element in MODE_STRUCT, MODE_SEQ, MODE_BAG
420438 * generally means we've finished processing a nested structure.
421439 * resets some internal variables to indicate that.
422440 *
423441 * Note this means we hit the </closing element> not the </rdf:Seq>.
424442 *
 443+ * For example, when processing:
 444+ * <exif:ISOSpeedRatings> <rdf:Seq> <rdf:li>64</rdf:li>
 445+ * </rdf:Seq> </exif:ISOSpeedRatings>
 446+ *
 447+ * This method is called when we hit the </exif:ISOSpeedRatings> tag.
 448+ *
425449 * @param $elm String namespace . space . tag name.
426450 */
427451 private function endElementNested( $elm ) {
@@ -470,11 +494,21 @@
471495 $this->processingArray = false;
472496 $this->itemLang = false;
473497 }
474 - /** Hit a closing element in MODE_LI (either rdf:Seq, or rdf:Bag )
 498+
 499+ /**
 500+ * Hit a closing element in MODE_LI (either rdf:Seq, or rdf:Bag )
475501 * Add information about what type of element this is.
476502 *
477 - * note we still have to hit the outer </property>
 503+ * Note we still have to hit the outer </property>
478504 *
 505+ * For example, when processing:
 506+ * <exif:ISOSpeedRatings> <rdf:Seq> <rdf:li>64</rdf:li>
 507+ * </rdf:Seq> </exif:ISOSpeedRatings>
 508+ *
 509+ * This method is called when we hit the </rdf:Seq>.
 510+ * (For comparison, we call endElementModeSimple when we
 511+ * hit the </rdf:li>)
 512+ *
479513 * @param $elm String namespace . ' ' . element name
480514 */
481515 private function endElementModeLi( $elm ) {
@@ -505,10 +539,14 @@
506540 throw new MWException( __METHOD__ . " expected </rdf:seq> or </rdf:bag> but instead got $elm." );
507541 }
508542 }
509 - /** end element while in MODE_QDESC
 543+ /**
 544+ * End element while in MODE_QDESC
510545 * mostly when ending an element when we have a simple value
511 - * that has qualifiers
 546+ * that has qualifiers.
512547 *
 548+ * Qualifiers aren't all that common, and we don't do anything
 549+ * with them.
 550+ *
513551 * @param $elm String namespace and element
514552 */
515553 private function endElementModeQDesc( $elm ) {
@@ -524,10 +562,15 @@
525563
526564
527565 }
528 - /** Handler for hitting a closing element.
 566+ /**
 567+ * Handler for hitting a closing element.
529568 *
530 - * generally just calls a helper function depending on what mode we're in.
531 - * Ignores the outer wrapping elements that are optional in xmp and have no meaning.
 569+ * generally just calls a helper function depending on what
 570+ * mode we're in.
 571+ *
 572+ * Ignores the outer wrapping elements that are optional in
 573+ * xmp and have no meaning.
 574+ *
532575 * @param $parser XMLParser
533576 * @param $elm String namespace . ' ' . element name
534577 */
@@ -542,17 +585,22 @@
543586
544587 if ( $elm === self::NS_RDF . ' type' ) {
545588 // these aren't really supported properly yet.
 589+ // However, it appears they almost never used.
546590 wfDebugLog( 'XMP', __METHOD__ . ' encountered <rdf:type>' );
547591 }
548592
549593 if ( strpos( $elm, ' ' ) === false ) {
550594 // This probably shouldn't happen.
 595+ // However, there is a bug in an adobe product
 596+ // that forgets the namespace on some things.
 597+ // (Luckily they are unimportant things).
551598 wfDebugLog( 'XMP', __METHOD__ . " Encountered </$elm> which has no namespace. Skipping." );
552599 return;
553600 }
554601
555602 if ( count( $this->mode[0] ) === 0 ) {
556 - // This should never ever happen.
 603+ // This should never ever happen and means
 604+ // there is a pretty major bug in this class.
557605 throw new MWException( 'Encountered end element with no mode' );
558606 }
559607
@@ -580,7 +628,7 @@
581629 if ( $elm === self::NS_RDF . ' Description' ) {
582630 array_shift( $this->mode );
583631 } else {
584 - throw new MWException( 'Element ended unexpected while in MODE_INITIAL' );
 632+ throw new MWException( 'Element ended unexpectedly while in MODE_INITIAL' );
585633 }
586634 break;
587635 case self::MODE_LI:
@@ -597,9 +645,14 @@
598646 }
599647
600648
601 - /** Hit an opening element while in MODE_IGNORE
 649+ /**
 650+ * Hit an opening element while in MODE_IGNORE
602651 *
 652+ * XMP is extensible, so ignore any tag we don't understand.
 653+ *
603654 * Mostly ignores, unless we encounter the element that we are ignoring.
 655+ * in which case we add it to the item stack, so we can ignore things
 656+ * that are nested, correctly.
604657 *
605658 * @param $elm String namespace . ' ' . tag name
606659 */
@@ -609,7 +662,8 @@
610663 array_unshift( $this->mode, self::MODE_IGNORE );
611664 }
612665 }
613 - /* Start element in MODE_BAG
 666+ /**
 667+ * Start element in MODE_BAG (unordered array)
614668 * this should always be <rdf:Bag>
615669 *
616670 * @param $elm String namespace . ' ' . tag
@@ -623,7 +677,8 @@
624678 }
625679
626680 }
627 - /* Start element in MODE_SEQ
 681+ /**
 682+ * Start element in MODE_SEQ (ordered array)
628683 * this should always be <rdf:Seq>
629684 *
630685 * @param $elm String namespace . ' ' . tag
@@ -642,9 +697,17 @@
643698 }
644699
645700 }
646 - /* Start element in MODE_LANG (language alternative)
 701+ /**
 702+ * Start element in MODE_LANG (language alternative)
647703 * this should always be <rdf:Alt>
648704 *
 705+ * This tag tends to be used for metadata like describe this
 706+ * picture, which can be translated into multiple languages.
 707+ *
 708+ * XMP supports non-linguistic alternative selections,
 709+ * which are really only used for thumbnails, which
 710+ * we don't care about.
 711+ *
649712 * @param $elm String namespace . ' ' . tag
650713 * @throws MWException if we have an element that's not <rdf:Alt>
651714 */
@@ -656,12 +719,22 @@
657720 }
658721
659722 }
660 - /** Handle an opening element when in MODE_SIMPLE
 723+ /**
 724+ * Handle an opening element when in MODE_SIMPLE
 725+ *
661726 * This should not happen often. This is for if a simple element
662727 * already opened has a child element. Could happen for a
663728 * qualified element.
664729 *
 730+ * For example:
 731+ * <exif:DigitalZoomRatio><rdf:Description><rdf:value>0/10</rdf:value>
 732+ * <foo:someQualifier>Bar</foo:someQualifier> </rdf:Description>
 733+ * </exif:DigitalZoomRatio>
 734+ *
 735+ * This method is called when processing the <rdf:Description> element
 736+ *
665737 * @param $elm String namespace and tag names separated by space.
 738+ * @param $attribs Array Attributes of the element.
666739 */
667740 private function startElementModeSimple( $elm, $attribs ) {
668741 if ( $elm === self::NS_RDF . ' Description' ) {
@@ -686,10 +759,17 @@
687760 }
688761
689762 }
690 - /** Start an element when in MODE_QDESC.
 763+ /**
 764+ * Start an element when in MODE_QDESC.
691765 * This generally happens when a simple element has an inner
692766 * rdf:Description to hold qualifier elements.
693767 *
 768+ * For example in:
 769+ * <exif:DigitalZoomRatio><rdf:Description><rdf:value>0/10</rdf:value>
 770+ * <foo:someQualifier>Bar</foo:someQualifier> </rdf:Description>
 771+ * </exif:DigitalZoomRatio>
 772+ * Called when processing the <rdf:value> or <foo:someQualifier>.
 773+ *
694774 * @param $elm String namespace and tag name separated by a space.
695775 *
696776 */
@@ -702,11 +782,12 @@
703783 array_unshift( $this->curItem, $elm );
704784 }
705785 }
706 - /** Starting an element when in MODE_INITIAL
 786+ /**
 787+ * Starting an element when in MODE_INITIAL
707788 * This usually happens when we hit an element inside
708789 * the outer rdf:Description
709790 *
710 - * This is generally where most props start
 791+ * This is generally where most properties start.
711792 *
712793 * @param $ns String Namespace
713794 * @param $tag String tag name (without namespace prefix)
@@ -753,9 +834,20 @@
754835 // process attributes
755836 $this->doAttribs( $attribs );
756837 }
757 - /** Hit an opening element when in a Struct (MODE_STRUCT)
758 - * This is generally for fields of a compound property
 838+ /**
 839+ * Hit an opening element when in a Struct (MODE_STRUCT)
 840+ * This is generally for fields of a compound property.
759841 *
 842+ * Example of a struct (abbreviated; flash has more properties):
 843+ *
 844+ * <exif:Flash> <rdf:Description> <exif:Fired>True</exif:Fired>
 845+ * <exif:Mode>1</exif:Mode></rdf:Description></exif:Flash>
 846+ *
 847+ * or:
 848+ *
 849+ * <exif:Flash rdf:parseType='Resource'> <exif:Fired>True</exif:Fired>
 850+ * <exif:Mode>1</exif:Mode></exif:Flash>
 851+ *
760852 * @param $ns String namespace
761853 * @param $tag String tag name (no ns)
762854 * @param $attribs Array array of attribs w/ values.
@@ -793,9 +885,15 @@
794886 array_unshift( $this->curItem, $this->curItem[0] );
795887 }
796888 }
797 - /** opening element in MODE_LI
798 - * process elements of arrays
 889+ /**
 890+ * opening element in MODE_LI
 891+ * process elements of arrays.
799892 *
 893+ * Example:
 894+ * <exif:ISOSpeedRatings> <rdf:Seq> <rdf:li>64</rdf:li>
 895+ * </rdf:Seq> </exif:ISOSpeedRatings>
 896+ * This method is called when we hit the <rdf:li> element.
 897+ *
800898 * @param $elm String: namespace . ' ' . tagname
801899 * @param $attribs Array: Attributes. (needed for BAGSTRUCTS)
802900 * @throws MWException if gets a tag other than <rdf:li>
@@ -837,9 +935,16 @@
838936 }
839937
840938 }
841 - /** opening element in MODE_LI_LANG
 939+ /**
 940+ * Opening element in MODE_LI_LANG.
842941 * process elements of language alternatives
843942 *
 943+ * Example:
 944+ * <dc:title> <rdf:Alt> <rdf:li xml:lang="x-default">My house
 945+ * </rdf:li> </rdf:Alt> </dc:title>
 946+ *
 947+ * This method is called when we hit the <rdf:li> element.
 948+ *
844949 * @param $elm String namespace . ' ' . tag
845950 * @param $attribs array array of elements (most importantly xml:lang)
846951 * @throws MWException if gets a tag other than <rdf:li> or if no xml:lang
@@ -865,7 +970,8 @@
866971 $this->processingArray = true;
867972 }
868973
869 - /** Hits an opening element.
 974+ /**
 975+ * Hits an opening element.
870976 * Generally just calls a helper based on what MODE we're in.
871977 * Also does some initial set up for the wrapper element
872978 *
@@ -951,9 +1057,16 @@
9521058
9531059
9541060 }
955 - /** process attributes.
 1061+ /**
 1062+ * Process attributes.
9561063 * Simple values can be stored as either a tag or attribute
9571064 *
 1065+ * Often the initial <rdf:Description> tag just has all the simple
 1066+ * properties as attributes.
 1067+ *
 1068+ * Example:
 1069+ * <rdf:Description rdf:about="" xmlns:exif="http://ns.adobe.com/exif/1.0/" exif:DigitalZoomRatio="0/10">
 1070+ *
9581071 * @param $attribs Array attribute=>value array.
9591072 */
9601073 private function doAttribs( $attribs ) {
@@ -996,7 +1109,8 @@
9971110 }
9981111 }
9991112 }
1000 - /** Given a value, save it to results array
 1113+ /**
 1114+ * Given an extracted value, save it to results array
10011115 *
10021116 * note also uses $this->ancestorStruct and
10031117 * $this->processingArray to determine what name to

Status & tagging log