r89029 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89028‎ | r89029 | r89030 >
Date:09:58, 28 May 2011
Author:hashar
Status:resolved
Tags:
Comment:
Handle old libxml when extracting SVG metadata

Mac OS X 10.5.8 comes with libxml 2.6.16, thus some methods of XMLReader
are not availabe (ex: readInnerXML()).
This patch, throw an error if the above method does not exist (only one
use in our code).

Since metadata can comes as string or an XML fragment, I have split the tests
to take care of the two usages and of the exception.
Modified paths:
  • /trunk/phase3/includes/media/SVGMetadataExtractor.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/media/SVGMetadataExtractorTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/media/SVGMetadataExtractorTest.php
@@ -10,6 +10,22 @@
1111 * @dataProvider providerSvgFiles
1212 */
1313 function testGetMetadata( $infile, $expected ) {
 14+ $this->assertMetadata( $infile, $expected );
 15+ }
 16+
 17+ /**
 18+ * @dataProvider providerSvgFilesWithXMLMetadata
 19+ */
 20+ function testGetXMLMetadata( $infile, $expected ) {
 21+ $r = new XMLReader();
 22+ if( !method_exists( $r, 'readInnerXML()' ) ) {
 23+ $this->markTestSkipped( 'XMLReader::readInnerXML() does not exist (libxml >2.6.20 needed).' );
 24+ return;
 25+ }
 26+ $this->assertMetadata( $infile, $expected );
 27+ }
 28+
 29+ function assertMetadata( $infile, $expected ) {
1430 try {
1531 $data = SVGMetadataExtractor::getMetadata( $infile );
1632 $this->assertEquals( $expected, $data, 'SVG metadata extraction test' );
@@ -46,6 +62,12 @@
4763 'height' => 60
4864 )
4965 ),
 66+ );
 67+ }
 68+
 69+ function providerSvgFilesWithXMLMetadata() {
 70+ $base = dirname( __FILE__ );
 71+ return array(
5072 array(
5173 "$base/US_states_by_total_state_tax_revenue.svg",
5274 array(
Index: trunk/phase3/includes/media/SVGMetadataExtractor.php
@@ -177,7 +177,11 @@
178178 return;
179179 }
180180 // TODO: find and store type of xml snippet. metadata['metadataType'] = "rdf"
181 - $this->metadata[$metafield] = trim( $this->reader->readInnerXML() );
 181+ if( method_exists( $this->reader, 'readInnerXML()' ) ) {
 182+ $this->metadata[$metafield] = trim( $this->reader->readInnerXML() );
 183+ } else {
 184+ throw new MWException( "The PHP XMLReader extension does not comes with readInnerXML() method. Your libxml is probably out of date (need 2.6.20 or later)." );
 185+ }
182186 $this->reader->next();
183187 }
184188

Follow-up revisions

RevisionCommit summaryAuthorDate
r89035fu r89029 - spellingnikerabbit13:03, 28 May 2011
r92634Fixup r89029. You don't include the brackets in the method name!...platonides15:13, 20 July 2011
r93426MFT to REL1_18...hashar20:20, 28 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88865Test cases for bug 27465: problems with XML namespace handling break SVGMetad...brion23:34, 25 May 2011

Status & tagging log