|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SESP; |
|
4
|
|
|
|
|
5
|
|
|
use SMW\DIProperty; |
|
6
|
|
|
use SMW\SemanticData; |
|
7
|
|
|
use SESP\PropertyAnnotators\NullPropertyAnnotator; |
|
8
|
|
|
use SESP\PropertyAnnotators\CreatorPropertyAnnotator; |
|
9
|
|
|
use SESP\PropertyAnnotators\PageViewsPropertyAnnotator; |
|
10
|
|
|
use SESP\PropertyAnnotators\LocalPropertyAnnotator; |
|
11
|
|
|
use SESP\PropertyAnnotators\UserRegistrationDatePropertyAnnotator; |
|
12
|
|
|
use SESP\PropertyAnnotators\UserEditCountPropertyAnnotator; |
|
13
|
|
|
use SESP\PropertyAnnotators\PageIDPropertyAnnotator; |
|
14
|
|
|
use SESP\PropertyAnnotators\ShortUrlPropertyAnnotator; |
|
15
|
|
|
use SESP\PropertyAnnotators\ExifPropertyAnnotator; |
|
16
|
|
|
use SESP\PropertyAnnotators\RevisionIDPropertyAnnotator; |
|
17
|
|
|
use SESP\PropertyAnnotators\PageNumRevisionPropertyAnnotator; |
|
18
|
|
|
use SESP\PropertyAnnotators\TalkPageNumRevisionPropertyAnnotator; |
|
19
|
|
|
use SESP\PropertyAnnotators\PageContributorsPropertyAnnotator; |
|
20
|
|
|
use SESP\PropertyAnnotators\SubPagePropertyAnnotator; |
|
21
|
|
|
use SESP\PropertyAnnotators\PageLengthPropertyAnnotator; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @private |
|
25
|
|
|
* |
|
26
|
|
|
* @license GNU GPL v2+ |
|
27
|
|
|
* @since 2.0 |
|
28
|
|
|
* |
|
29
|
|
|
* @author mwjames |
|
30
|
|
|
*/ |
|
31
|
|
|
class ExtraPropertyAnnotator { |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var AppFactory |
|
35
|
|
|
*/ |
|
36
|
|
|
private $appFactory; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var PropertyAnnotator[] |
|
40
|
|
|
*/ |
|
41
|
|
|
private $propertyAnnotators = array(); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var PropertyAnnotator |
|
45
|
|
|
*/ |
|
46
|
|
|
private $localPropertyAnnotator; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
private $options; |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @since 2.0 |
|
55
|
|
|
* |
|
56
|
|
|
* @param AppFactory $appFactory |
|
57
|
|
|
*/ |
|
58
|
17 |
|
public function __construct( AppFactory $appFactory ) { |
|
59
|
17 |
|
$this->appFactory = $appFactory; |
|
60
|
17 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @since 2.0 |
|
64
|
|
|
* |
|
65
|
|
|
* @param SemanticData $semanticData |
|
66
|
|
|
*/ |
|
67
|
2 |
|
public function addAnnotation( SemanticData $semanticData ) { |
|
68
|
|
|
|
|
69
|
2 |
|
$time = microtime( true ); |
|
70
|
|
|
|
|
71
|
2 |
|
if ( !$this->canAnnotate( $semanticData->getSubject() ) ) { |
|
72
|
1 |
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
$propertyDefinitions = $this->appFactory->getPropertyDefinitions(); |
|
76
|
|
|
|
|
77
|
1 |
|
foreach ( $this->appFactory->getOption( 'sespSpecialProperties', array() ) as $key ) { |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
1 |
|
if ( !$propertyDefinitions->deepHas( $key, 'id' ) ) { |
|
80
|
1 |
|
continue; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$property = new DIProperty( |
|
84
|
|
|
$propertyDefinitions->deepGet( $key, 'id' ) |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
if ( $propertyDefinitions->isLocalDef( $key ) ) { |
|
88
|
|
|
$this->localPropertyAnnotator->addAnnotation( $property, $semanticData ); |
|
89
|
|
|
} else { |
|
90
|
|
|
$this->findPropertyAnnotator( $property )->addAnnotation( $property, $semanticData ); |
|
91
|
|
|
} |
|
92
|
1 |
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
$this->appFactory->getLogger()->info( |
|
95
|
1 |
|
__METHOD__ . ' (procTime in sec: '. ( microtime( true ) - $time ) . ')' |
|
96
|
1 |
|
); |
|
97
|
1 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @since 2.0 |
|
101
|
|
|
* |
|
102
|
|
|
* @param DIProperty $property |
|
103
|
|
|
* |
|
104
|
|
|
* @return PropertyAnnotator |
|
105
|
|
|
*/ |
|
106
|
14 |
|
public function findPropertyAnnotator( DIProperty $property ) { |
|
107
|
|
|
|
|
108
|
14 |
|
$key = $property->getKey(); |
|
109
|
|
|
|
|
110
|
14 |
|
if ( $this->propertyAnnotators === array() ) { |
|
111
|
14 |
|
$this->initDefaultPropertyAnnotators(); |
|
112
|
14 |
|
} |
|
113
|
|
|
|
|
114
|
14 |
|
if ( isset( $this->propertyAnnotators[$key] ) && is_callable( $this->propertyAnnotators[$key] ) ) { |
|
115
|
13 |
|
return call_user_func( $this->propertyAnnotators[$key], $this->appFactory ); |
|
116
|
1 |
|
} elseif( isset( $this->propertyAnnotators[$key] ) ) { |
|
117
|
|
|
return $this->propertyAnnotators[$key]; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
1 |
|
return new NullPropertyAnnotator(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @since 2.0 |
|
125
|
|
|
* |
|
126
|
|
|
* @param string $key |
|
127
|
|
|
* @param Closure $callbak |
|
|
|
|
|
|
128
|
|
|
*/ |
|
129
|
|
|
public function addPropertyAnnotator( $key, Closure $callback ) { |
|
130
|
|
|
$this->propertyAnnotators[$key] = $callback; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
2 |
|
private function canAnnotate( $subject ) { |
|
134
|
|
|
|
|
135
|
2 |
|
if ( $subject === null || $subject->getTitle() === null || $subject->getTitle()->isSpecialPage() ) { |
|
136
|
1 |
|
return false; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
1 |
|
$this->initDefaultPropertyAnnotators(); |
|
140
|
|
|
|
|
141
|
1 |
|
return true; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
15 |
|
private function initDefaultPropertyAnnotators() { |
|
145
|
|
|
|
|
146
|
15 |
|
$this->localPropertyAnnotator = new LocalPropertyAnnotator( |
|
147
|
15 |
|
$this->appFactory |
|
148
|
15 |
|
); |
|
149
|
|
|
|
|
150
|
|
|
// Encapsulate each instance to avoid direct instantiation for unused |
|
151
|
|
|
// matches |
|
152
|
15 |
|
$this->propertyAnnotators = array( |
|
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
CreatorPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
155
|
1 |
|
return new CreatorPropertyAnnotator( $appFactory ); |
|
156
|
15 |
|
}, |
|
157
|
|
|
|
|
158
|
|
|
PageViewsPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
159
|
1 |
|
return new PageViewsPropertyAnnotator( $appFactory ); |
|
160
|
15 |
|
}, |
|
161
|
|
|
|
|
162
|
|
|
UserRegistrationDatePropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
163
|
1 |
|
return new UserRegistrationDatePropertyAnnotator( $appFactory ); |
|
164
|
15 |
|
}, |
|
165
|
|
|
|
|
166
|
|
|
UserEditCountPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
167
|
1 |
|
return new UserEditCountPropertyAnnotator( $appFactory ); |
|
168
|
15 |
|
}, |
|
169
|
|
|
|
|
170
|
|
|
PageIDPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
171
|
1 |
|
return new PageIDPropertyAnnotator( $appFactory ); |
|
172
|
15 |
|
}, |
|
173
|
|
|
|
|
174
|
|
|
PageLengthPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
175
|
1 |
|
return new PageLengthPropertyAnnotator( $appFactory ); |
|
176
|
15 |
|
}, |
|
177
|
|
|
|
|
178
|
|
|
RevisionIDPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
179
|
1 |
|
return new RevisionIDPropertyAnnotator( $appFactory ); |
|
180
|
15 |
|
}, |
|
181
|
|
|
|
|
182
|
|
|
PageNumRevisionPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
183
|
1 |
|
return new PageNumRevisionPropertyAnnotator( $appFactory ); |
|
184
|
15 |
|
}, |
|
185
|
|
|
|
|
186
|
|
|
TalkPageNumRevisionPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
187
|
1 |
|
return new TalkPageNumRevisionPropertyAnnotator( $appFactory ); |
|
188
|
15 |
|
}, |
|
189
|
|
|
|
|
190
|
|
|
PageContributorsPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
191
|
1 |
|
return new PageContributorsPropertyAnnotator( $appFactory ); |
|
192
|
15 |
|
}, |
|
193
|
|
|
|
|
194
|
|
|
SubPagePropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
195
|
1 |
|
return new SubPagePropertyAnnotator( $appFactory ); |
|
196
|
15 |
|
}, |
|
197
|
|
|
|
|
198
|
|
|
ShortUrlPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
199
|
1 |
|
return new ShortUrlPropertyAnnotator( $appFactory ); |
|
200
|
15 |
|
}, |
|
201
|
|
|
|
|
202
|
15 |
|
ExifPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
203
|
1 |
|
return new ExifPropertyAnnotator( $appFactory ); |
|
204
|
15 |
|
}, |
|
205
|
|
|
|
|
206
|
|
|
); |
|
207
|
15 |
|
} |
|
208
|
|
|
|
|
209
|
|
|
} |
|
210
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.