Merge "ApiFeedWatchlist: Use guessSectionNameFromWikiText()"
[lhc/web/wiklou.git] / includes / libs / xmp / XMP.php
index 9d886bf..be823a8 100644 (file)
@@ -130,12 +130,10 @@ class XMPReader implements LoggerAwareInterface {
        private $logger;
 
        /**
-        * Constructor.
-        *
         * Primary job is to initialize the XMLParser
+        * @param LoggerInterface|null $logger
         */
        function __construct( LoggerInterface $logger = null ) {
-
                if ( !function_exists( 'xml_parser_create_ns' ) ) {
                        // this should already be checked by this point
                        throw new RuntimeException( 'XMP support requires XML Parser' );
@@ -174,7 +172,6 @@ class XMPReader implements LoggerAwareInterface {
         * For example in jpeg's with extendedXMP
         */
        private function resetXMLParser() {
-
                $this->destroyXMLParser();
 
                $this->xmlParser = xml_parser_create_ns( 'UTF-8', ' ' );
@@ -193,6 +190,7 @@ class XMPReader implements LoggerAwareInterface {
 
        /**
         * Check if this instance supports using this class
+        * @return bool
         */
        public static function isSupported() {
                return function_exists( 'xml_parser_create_ns' ) && class_exists( 'XMLReader' );
@@ -372,7 +370,7 @@ class XMPReader implements LoggerAwareInterface {
                                $col = xml_get_current_column_number( $this->xmlParser );
                                $offset = xml_get_current_byte_index( $this->xmlParser );
 
-                               $this->logger->warning(
+                               $this->logger->info(
                                        '{method} : Error reading XMP content: {error} ' .
                                        '(line: {line} column: {column} byte offset: {offset})',
                                        [
@@ -390,7 +388,7 @@ class XMPReader implements LoggerAwareInterface {
                        }
                } catch ( Exception $e ) {
                        $this->logger->warning(
-                               '{method} Exception caught while parsing: ' . $e->getMessage(),
+                               '{method} {exception}',
                                [
                                        'method' => __METHOD__,
                                        'exception' => $e,
@@ -422,7 +420,8 @@ class XMPReader implements LoggerAwareInterface {
                        || $this->results['xmp-special']['HasExtendedXMP'] !== $guid
                ) {
                        $this->logger->info( __METHOD__ .
-                               " Ignoring XMPExtended block due to wrong guid (guid= '$guid')" );
+                               " Ignoring XMPExtended block due to wrong guid (guid= '{guid}')",
+                               [ 'guid' => 'guid' ] );
 
                        return false;
                }
@@ -495,7 +494,6 @@ class XMPReader implements LoggerAwareInterface {
         * @throws RuntimeException On invalid data
         */
        function char( $parser, $data ) {
-
                $data = trim( $data );
                if ( trim( $data ) === "" ) {
                        return;
@@ -644,7 +642,6 @@ class XMPReader implements LoggerAwareInterface {
         * @throws RuntimeException
         */
        private function endElementNested( $elm ) {
-
                /* cur item must be the same as $elm, unless if in MODE_STRUCT
                 * in which case it could also be rdf:Description */
                if ( $this->curItem[0] !== $elm
@@ -754,7 +751,6 @@ class XMPReader implements LoggerAwareInterface {
         * @param string $elm Namespace and element
         */
        private function endElementModeQDesc( $elm ) {
-
                if ( $elm === self::NS_RDF . ' value' ) {
                        list( $ns, $tag ) = explode( ' ', $this->curItem[0], 2 );
                        $this->saveValue( $ns, $tag, $this->charContent );
@@ -959,8 +955,8 @@ class XMPReader implements LoggerAwareInterface {
                } else {
                        // something else we don't recognize, like a qualifier maybe.
                        $this->logger->info( __METHOD__ .
-                               " Encountered element <$elm> where only expecting character data as value of " .
-                               $this->curItem[0] );
+                               " Encountered element <{element}> where only expecting character data as value of {curitem}",
+                               [ 'element' => $elm, 'curitem' => $this->curItem[0] ] );
                        array_unshift( $this->mode, self::MODE_IGNORE );
                        array_unshift( $this->curItem, $elm );
                }
@@ -1010,8 +1006,10 @@ class XMPReader implements LoggerAwareInterface {
                                        // a child of a struct), then something weird is
                                        // happening, so ignore this element and its children.
 
-                                       $this->logger->warning( "Encountered <$ns:$tag> outside"
-                                               . " of its expected parent. Ignoring." );
+                                       $this->logger->warning(
+                                               'Encountered <{element}> outside of its expected parent. Ignoring.',
+                                               [ 'element' => "$ns:$tag" ]
+                                       );
 
                                        array_unshift( $this->mode, self::MODE_IGNORE );
                                        array_unshift( $this->curItem, $ns . ' ' . $tag );
@@ -1032,7 +1030,8 @@ class XMPReader implements LoggerAwareInterface {
                                }
                        } else {
                                // This element is not on our list of allowed elements so ignore.
-                               $this->logger->debug( __METHOD__ . " Ignoring unrecognized element <$ns:$tag>." );
+                               $this->logger->debug( __METHOD__ . ' Ignoring unrecognized element <{element}>.',
+                                       [ 'element' => "$ns:$tag" ] );
                                array_unshift( $this->mode, self::MODE_IGNORE );
                                array_unshift( $this->curItem, $ns . ' ' . $tag );
 
@@ -1191,7 +1190,6 @@ class XMPReader implements LoggerAwareInterface {
         * @throws RuntimeException
         */
        function startElement( $parser, $elm, $attribs ) {
-
                if ( $elm === self::NS_RDF . ' RDF'
                        || $elm === 'adobe:ns:meta/ xmpmeta'
                        || $elm === 'adobe:ns:meta/ xapmeta'
@@ -1332,7 +1330,6 @@ class XMPReader implements LoggerAwareInterface {
         * @param string $val Value to save
         */
        private function saveValue( $ns, $tag, $val ) {
-
                $info =& $this->items[$ns][$tag];
                $finalName = isset( $info['map_name'] )
                        ? $info['map_name'] : $tag;