-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
53 lines (45 loc) · 1.35 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require dirname(__FILE__) . '/' . 'vendor' . '/' . 'autoload.php';
/**
* Class Archive
*
*
*/
class Archive {
/**
* @var integer
*/
protected $_currentPage = 0;
/**
* @param array $reader
* @param array $attributes
* @param array $userData
*/
public function callbackPage($reader, $attributes, $userData = array()) {
$requreTitle = $userData['needle'];
$currentTitle = array_key_exists('mediawiki.page.title', $attributes) ? $attributes['mediawiki.page.title'] : '';
if ($currentTitle === $requreTitle) {
var_dump($attributes);
}
$this->_currentPage ++;
// logging
echo sprintf("[%08d] %s\r", $this->_currentPage, $currentTitle);
}
/**
* Search article in MediaWiki dump
*
* @param string $name
* @param string $needle
* @return void
*/
public function search($name, $needle) {
$wikiReader = new \Wiki\Dump\Reader();
$wikiReader->setUserData(array('needle' => $needle));
$wikiReader->registerHook('afterPage', array($this, 'callbackPage'));
$wikiReader->process($name);
}
}
// Search some element
$archive = new Archive();
$searchTitle = 'Список глав государств в 497 году';
$archive->search('ruwiki-latest-pages-articles.xml', $searchTitle);