|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PPP\Wikidata\ValueParsers; |
|
4
|
|
|
|
|
5
|
|
|
use DataValues\Geo\Parsers\GlobeCoordinateParser; |
|
6
|
|
|
use ValueParsers\DispatchingValueParser; |
|
7
|
|
|
use ValueParsers\EraParser; |
|
8
|
|
|
use ValueParsers\IsoTimestampParser; |
|
9
|
|
|
use ValueParsers\MonolingualMonthNameProvider; |
|
10
|
|
|
use ValueParsers\MonthNameUnlocalizer; |
|
11
|
|
|
use ValueParsers\ParserOptions; |
|
12
|
|
|
use ValueParsers\PhpDateTimeParser; |
|
13
|
|
|
use ValueParsers\QuantityParser; |
|
14
|
|
|
use ValueParsers\ValueParser; |
|
15
|
|
|
use ValueParsers\YearMonthDayTimeParser; |
|
16
|
|
|
use ValueParsers\YearMonthTimeParser; |
|
17
|
|
|
use ValueParsers\YearTimeParser; |
|
18
|
|
|
use Wikibase\EntityStore\EntityStore; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Build a parser for Wikibase value |
|
22
|
|
|
* |
|
23
|
|
|
* @licence GPLv2+ |
|
24
|
|
|
* @author Thomas Pellissier Tanon |
|
25
|
|
|
*/ |
|
26
|
|
|
class WikibaseValueParserFactory { |
|
27
|
|
|
|
|
28
|
|
|
private static $MONTH_NAMES = array( |
|
29
|
|
|
1 => 'January', |
|
30
|
|
|
2 => 'February', |
|
31
|
|
|
3 => 'March', |
|
32
|
|
|
4 => 'April', |
|
33
|
|
|
5 => 'May', |
|
34
|
|
|
6 => 'June', |
|
35
|
|
|
7 => 'July', |
|
36
|
|
|
8 => 'August', |
|
37
|
|
|
9 => 'September', |
|
38
|
|
|
10 => 'October', |
|
39
|
|
|
11 => 'November', |
|
40
|
|
|
12 => 'December' |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string language code |
|
45
|
|
|
*/ |
|
46
|
|
|
private $languageCode; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var EntityStore |
|
50
|
|
|
*/ |
|
51
|
|
|
private $entityStore; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $languageCode |
|
55
|
|
|
* @param EntityStore $entityStore |
|
56
|
|
|
*/ |
|
57
|
8 |
|
public function __construct($languageCode, EntityStore $entityStore) { |
|
58
|
8 |
|
$this->languageCode = $languageCode; |
|
59
|
8 |
|
$this->entityStore = $entityStore; |
|
60
|
8 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return WikibaseValueParser |
|
64
|
|
|
*/ |
|
65
|
8 |
|
public function newWikibaseValueParser() { |
|
66
|
8 |
|
return new WikibaseValueParser(array( |
|
67
|
8 |
|
'commonsMedia' => new StringParser(), |
|
68
|
8 |
|
'external-id' => new StringParser(), |
|
69
|
8 |
|
'globe-coordinate' => new GlobeCoordinateParser(), |
|
70
|
8 |
|
'quantity' => new QuantityParser(), |
|
71
|
8 |
|
'monolingualtext' => new MonolingualTextParser(), |
|
72
|
8 |
|
'string' => new StringParser(), |
|
73
|
8 |
|
'time' => new DispatchingValueParser(array( |
|
74
|
8 |
|
new IsoTimestampParser(), |
|
75
|
8 |
|
new YearMonthDayTimeParser(), |
|
76
|
8 |
|
new YearMonthTimeParser(new MonolingualMonthNameProvider(self::$MONTH_NAMES)), //TODO: localisation |
|
77
|
8 |
|
new YearTimeParser(), |
|
78
|
8 |
|
new PhpDateTimeParser(new MonthNameUnlocalizer(array()), new EraParser(), new IsoTimestampParser()) |
|
79
|
8 |
|
), 'time'), |
|
80
|
8 |
|
'url' => new StringParser(), |
|
81
|
8 |
|
'wikibase-item' => $this->newWikibaseEntityParser('item'), |
|
82
|
8 |
|
'wikibase-property' => $this->newWikibaseEntityParser('property') |
|
83
|
8 |
|
)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
8 |
|
private function newWikibaseEntityParser($type) { |
|
87
|
8 |
|
$parserOptions = new ParserOptions(array( |
|
88
|
8 |
|
ValueParser::OPT_LANG => $this->languageCode, |
|
89
|
8 |
|
WikibaseEntityIdParser::OPT_ENTITY_TYPE => $type |
|
90
|
8 |
|
)); |
|
91
|
|
|
|
|
92
|
8 |
|
return new WikibaseEntityIdParser( |
|
93
|
8 |
|
$this->entityStore, |
|
94
|
|
|
$parserOptions |
|
95
|
8 |
|
); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|