}
if ( $this->charset !== 'UTF-8' ) {
//don't convert if already utf-8
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$content = iconv( $this->charset, 'UTF-8//IGNORE', $content );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
}
// Ensure the XMP block does not have an xml doctype declaration, which
// could declare entities unsafe to parse with xml_parse (T85848/T71210).
if ( $this->parsable !== self::PARSABLE_OK ) {
if ( $this->parsable === self::PARSABLE_NO ) {
- throw new Exception( 'Unsafe doctype declaration in XML.' );
+ throw new RuntimeException( 'Unsafe doctype declaration in XML.' );
}
$content = $this->xmlParsableBuffer . $content;
$msg = ( $this->parsable === self::PARSABLE_NO ) ?
'Unsafe doctype declaration in XML.' :
'No root element found in XML.';
- throw new Exception( $msg );
+ throw new RuntimeException( $msg );
}
}
$ok = xml_parse( $this->xmlParser, $content, $allOfIt );
if ( !$ok ) {
- $error = xml_error_string( xml_get_error_code( $this->xmlParser ) );
- $where = 'line: ' . xml_get_current_line_number( $this->xmlParser )
- . ' column: ' . xml_get_current_column_number( $this->xmlParser )
- . ' byte offset: ' . xml_get_current_byte_index( $this->xmlParser );
-
- $this->logger->info( "XMPReader::parse : Error reading XMP content: $error ($where)" );
+ $code = xml_get_error_code( $this->xmlParser );
+ $error = xml_error_string( $code );
+ $line = xml_get_current_line_number( $this->xmlParser );
+ $col = xml_get_current_column_number( $this->xmlParser );
+ $offset = xml_get_current_byte_index( $this->xmlParser );
+
+ $this->logger->warning(
+ '{method} : Error reading XMP content: {error} ' .
+ '(line: {line} column: {column} byte offset: {offset})',
+ array(
+ 'method' => __METHOD__,
+ 'error_code' => $code,
+ 'error' => $error,
+ 'line' => $line,
+ 'column' => $col,
+ 'offset' => $offset,
+ 'content' => $content,
+ ) );
$this->results = array(); // blank if error.
$this->destroyXMLParser();
return false;
}
} catch ( Exception $e ) {
- $this->logger->info( 'XMP parse error: ' . $e );
+ $this->logger->warning(
+ '{method} Exception caught while parsing: ' . $e->getMessage(),
+ array(
+ 'method' => __METHOD__,
+ 'exception' => $e,
+ 'content' => $content,
+ )
+ );
$this->results = array();
-
- if ( $allOfIt ) {
- $this->destroyXMLParser();
- }
return false;
}
if ( $allOfIt ) {
$len = unpack( 'Nlength/Noffset', substr( $content, 32, 8 ) );
if ( !$len || $len['length'] < 4 || $len['offset'] < 0 || $len['offset'] > $len['length'] ) {
- $this->logger->info( __METHOD__ . 'Error reading extended XMP block, invalid length or offset.' );
+ $this->logger->info( __METHOD__ . 'Error reading extended XMP block, invalid length or offset.' );
return false;
}
);
$oldDisable = libxml_disable_entity_loader( true );
+ /** @noinspection PhpUnusedLocalVariableInspection */
$reset = new ScopedCallback(
'libxml_disable_entity_loader',
array( $oldDisable )
// Even with LIBXML_NOWARNING set, XMLReader::read gives a warning
// when parsing truncated XML, which causes unit tests to fail.
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
while ( $reader->read() ) {
if ( $reader->nodeType === XMLReader::ELEMENT ) {
// Reached the first element without hitting a doctype declaration
break;
}
}
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( !is_null( $result ) ) {
return $result;
// Validate structures.
list( $ns, $tag ) = explode( ' ', $elm, 2 );
if ( isset( $this->items[$ns][$tag]['validate'] ) ) {
-
$info =& $this->items[$ns][$tag];
$finalName = isset( $info['map_name'] )
? $info['map_name'] : $tag;