Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CategoryExtractor
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 getXPath
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 perform
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Flow\Parsoid\Extractor;
4
5use DOMElement;
6use Flow\Model\WikiReference;
7use Flow\Parsoid\Extractor;
8use Flow\Parsoid\ReferenceFactory;
9
10/**
11 * Runs against page content via Flow\Parsoid\ReferenceExtractor
12 * and collects all category references output by parsoid. The DOM
13 * spec states that categories are represented as such:
14 *
15 *   <link rel="mw:PageProp/Category" href="...">
16 *
17 * Flow does not currently handle the other page properties. When it becomes
18 * necessary a more generic page property extractor should be implemented and
19 * this class should be removed.
20 */
21class CategoryExtractor implements Extractor {
22    /**
23     * @inheritDoc
24     */
25    public function getXPath() {
26        return '//link[contains(concat(" ",normalize-space(@rel)," "), " mw:PageProp/Category " )]';
27    }
28
29    /**
30     * @inheritDoc
31     */
32    public function perform( ReferenceFactory $factory, DOMElement $element ) {
33        // our provided xpath guarantees there is a rel attribute
34        // with our expected format so only perform a very minimal
35        // validation.
36        $rel = $element->getAttribute( 'rel' );
37        if ( strpos( ' ' . $rel . ' ', ' mw:PageProp/Category ' ) === false ) {
38            return null;
39        }
40
41        $href = $element->getAttribute( 'href' );
42        if ( $href ) {
43            return $factory->createWikiReference(
44                WikiReference::TYPE_CATEGORY,
45                urldecode( $href )
46            );
47        } else {
48            return null;
49        }
50    }
51}