-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWikidataContent.php
160 lines (131 loc) · 4.51 KB
/
WikidataContent.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
class WikidataContent extends Content {
const TYPE_TEXT = 'text';
const TYPE_SCALAR = 'scalar'; # unit, precision, point-in-time
const TYPE_DATE = 'date';
const TYPE_TERM = 'term'; # lang, pronunciation
const TYPE_ENTITY_REF = 'ref';
const PROP_LABEL = 'label';
const PROP_DESCRIPTION = 'description';
const PROP_ALIAS = 'alias';
public function __construct( $data ) {
parent::__construct( CONTENT_MODEL_WIKIDATA );
#TODO: assert $data is an array!
$this->mData = $data;
}
/**
* @return String a string representing the content in a way useful for building a full text search index.
* If no useful representation exists, this method returns an empty string.
*/
public function getTextForSearchIndex()
{
return ''; #TODO: recursively collect all values from all properties.
}
/**
* @return String the wikitext to include when another page includes this content, or false if the content is not
* includable in a wikitext page.
*/
public function getWikitextForTransclusion()
{
return false;
}
/**
* Returns a textual representation of the content suitable for use in edit summaries and log messages.
*
* @param int $maxlength maximum length of the summary text
* @return String the summary text
*/
public function getTextForSummary($maxlength = 250)
{
return $this->getDescription();
}
/**
* Returns native represenation of the data. Interpretation depends on the data model used,
* as given by getDataModel().
*
* @return mixed the native representation of the content. Could be a string, a nested array
* structure, an object, a binary blob... anything, really.
*/
public function getNativeData()
{
return $this->mData;
}
/**
* returns the content's nominal size in bogo-bytes.
*
* @return int
*/
public function getSize()
{
return strlen( serialize( $this->mData) ); #TODO: keep and reuse value, content object is immutable!
}
/**
* Returns true if this content is countable as a "real" wiki page, provided
* that it's also in a countable location (e.g. a current revision in the main namespace).
*
* @param $hasLinks Bool: if it is known whether this content contains links, provide this information here,
* to avoid redundant parsing to find out.
*/
public function isCountable($hasLinks = null)
{
return !empty( $this->mData[ WikidataContent::PROP_DESCRIPTION ] ); #TODO: better/more methods
}
public function isEmpty()
{
return empty( $this->mData );
}
/**
* @param null|Title $title
* @param null $revId
* @param null|ParserOptions $options
* @return ParserOutput
*/
public function getParserOutput(Title $title = null, $revId = null, ParserOptions $options = NULL)
{
// TODO: generate sensible HTML!
$flat = WikidataContentHandler::flattenArray( $this->getNativeData() );
$html = '';
foreach ( $flat as $k => $v ) {
$html .= "\t\t";
$html .= Html::openElement( 'tr' );
$html .= Html::element( 'td', null, $k );
$html .= Html::element( 'td', null, $v );
$html .= Html::closeElement( 'tr' );
$html .= "\n";
}
$html = Html::rawElement('table', array('class' => 'wikitable'), $html);
$po = new ParserOutput( $html );
return $po;
}
#=================================================================================================================
public function getPropertyNames( ) {
//TODO: implement
}
public function getSystemPropertyNames( ) {
//TODO: implement
}
public function getEditorialPropertyNames( ) {
//TODO: implement
}
public function getStatementPropertyNames( ) {
//TODO: implement
}
public function getPropertyMultilang( $name, $languages = null ) {
//TODO: implement
}
public function getProperty( $name, $languag = null ) {
//TODO: implement
}
public function getPropertyType( $name ) {
//TODO: implement
}
public function isStatementProperty( $name ) {
//TODO: implement
}
public function getDescription( $lang = null ) {
//TODO: implement
}
public function getLabel( $lang = null ) {
//TODO: implement
}
}