Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ImageExtractor | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| getXPath | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| perform | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Parsoid\Extractor; |
| 4 | |
| 5 | use DOMElement; |
| 6 | use Flow\Model\WikiReference; |
| 7 | use Flow\Parsoid\Extractor; |
| 8 | use Flow\Parsoid\ReferenceFactory; |
| 9 | |
| 10 | /** |
| 11 | * Finds and creates References for images in parsoid HTML |
| 12 | */ |
| 13 | class ImageExtractor implements Extractor { |
| 14 | /** |
| 15 | * @inheritDoc |
| 16 | */ |
| 17 | public function getXPath() { |
| 18 | return '//*[contains(concat(" ", @typeof, " "), " mw:File " )] | ' . |
| 19 | // TODO: Remove mw:Image when version 2.4.0 of the content is no |
| 20 | // longer supported |
| 21 | '//*[contains(concat(" ", @typeof, " "), " mw:Image " )]'; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @inheritDoc |
| 26 | */ |
| 27 | public function perform( ReferenceFactory $factory, DOMElement $element ) { |
| 28 | foreach ( $element->getElementsByTagName( 'img' ) as $item ) { |
| 29 | if ( !$item instanceof DOMElement ) { |
| 30 | continue; |
| 31 | } |
| 32 | $resource = $item->getAttribute( 'resource' ); |
| 33 | if ( $resource !== '' ) { |
| 34 | return $factory->createWikiReference( |
| 35 | WikiReference::TYPE_FILE, |
| 36 | urldecode( $resource ) |
| 37 | ); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return null; |
| 42 | } |
| 43 | } |