1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Queryr\DumpReader\XmlReader; |
4
|
|
|
|
5
|
|
|
use DOMNode; |
6
|
|
|
use Queryr\DumpReader\DumpReaderException; |
7
|
|
|
use Queryr\DumpReader\Page; |
8
|
|
|
use Queryr\DumpReader\Revision; |
9
|
|
|
use XMLReader; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class PageNode { |
16
|
|
|
|
17
|
|
|
private $id; |
18
|
|
|
private $title; |
19
|
|
|
private $namespace; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Revision |
23
|
|
|
*/ |
24
|
|
|
private $revision; |
25
|
|
|
|
26
|
|
|
public function __construct( DOMNode $pageNode ) { |
27
|
|
|
$this->handleNodes( $pageNode ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
private function handleNodes( DOMNode $pageNode ) { |
31
|
|
|
foreach ( $pageNode->childNodes as $childNode ) { |
32
|
|
|
$this->handleNode( $childNode ); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
private function handleNode( DOMNode $node ) { |
37
|
|
|
if ( $this->hasElementName( $node, 'id' ) ) { |
38
|
|
|
$this->id = $node->textContent; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ( $this->hasElementName( $node, 'title' ) ) { |
42
|
|
|
$this->title = $node->textContent; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ( $this->hasElementName( $node, 'ns' ) ) { |
46
|
|
|
$this->namespace = $node->textContent; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ( $this->hasElementName( $node, 'revision' ) ) { |
50
|
|
|
$node = new RevisionNode( $node ); |
51
|
|
|
$this->revision = $node->asRevision(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function hasElementName( DOMNode $node, $name ) { |
56
|
|
|
return $node->nodeType === XMLReader::ELEMENT && $node->nodeName === $name; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function asPage() { |
60
|
|
|
if ( !$this->revision ) { |
61
|
|
|
throw new DumpReaderException( 'No revision node found' ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return new Page( |
65
|
|
|
$this->id, |
66
|
|
|
$this->title, |
67
|
|
|
$this->namespace, |
68
|
|
|
$this->revision |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|