|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SESP\PropertyAnnotators; |
|
4
|
|
|
|
|
5
|
|
|
use SMW\DIProperty; |
|
6
|
|
|
use SMW\DIWikiPage; |
|
7
|
|
|
use SMW\SemanticData; |
|
8
|
|
|
use SMWDataItem as DataItem; |
|
9
|
|
|
use SESP\PropertyAnnotator; |
|
10
|
|
|
use SESP\AppFactory; |
|
11
|
|
|
use Closure; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @private |
|
15
|
|
|
* @ingroup SESP |
|
16
|
|
|
* |
|
17
|
|
|
* @license GNU GPL v2+ |
|
18
|
|
|
* @since 2.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author mwjames |
|
21
|
|
|
*/ |
|
22
|
|
|
class DispatchingPropertyAnnotator implements PropertyAnnotator { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var AppFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
private $appFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var PropertyAnnotator[] |
|
31
|
|
|
*/ |
|
32
|
|
|
private $propertyAnnotators = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var PropertyAnnotator |
|
36
|
|
|
*/ |
|
37
|
|
|
private $localPropertyAnnotator; |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @since 2.0 |
|
41
|
|
|
* |
|
42
|
|
|
* @param AppFactory $appFactory |
|
43
|
|
|
*/ |
|
44
|
17 |
|
public function __construct( AppFactory $appFactory ) { |
|
45
|
17 |
|
$this->appFactory = $appFactory; |
|
46
|
17 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @since 2.0 |
|
50
|
|
|
* |
|
51
|
|
|
* {@inheritDoc} |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function isAnnotatorFor( DIProperty $property ) { |
|
54
|
1 |
|
return true; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @since 2.0 |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $key |
|
61
|
|
|
* @param PropertyAnnotator $propertyAnnotator |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function addPropertyAnnotator( $key, PropertyAnnotator $propertyAnnotator ) { |
|
64
|
1 |
|
$this->propertyAnnotators[$key] = $propertyAnnotator; |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @since 2.0 |
|
69
|
|
|
* |
|
70
|
|
|
* {@inheritDoc} |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function addAnnotation( DIProperty $property, SemanticData $semanticData ) { |
|
73
|
1 |
|
$this->findPropertyAnnotator( $property )->addAnnotation( $property, $semanticData ); |
|
74
|
1 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @since 2.0 |
|
78
|
|
|
* |
|
79
|
|
|
* @param DIProperty $property |
|
80
|
|
|
* |
|
81
|
|
|
* @return PropertyAnnotator |
|
82
|
|
|
*/ |
|
83
|
15 |
|
public function findPropertyAnnotator( DIProperty $property ) { |
|
84
|
|
|
|
|
85
|
15 |
|
$key = $property->getKey(); |
|
86
|
|
|
|
|
87
|
15 |
|
if ( $this->propertyAnnotators === [] ) { |
|
88
|
14 |
|
$this->initDefaultPropertyAnnotators(); |
|
89
|
14 |
|
} |
|
90
|
|
|
|
|
91
|
15 |
|
if ( isset( $this->propertyAnnotators[$key] ) && is_callable( $this->propertyAnnotators[$key] ) ) { |
|
92
|
13 |
|
return call_user_func( $this->propertyAnnotators[$key], $this->appFactory ); |
|
93
|
2 |
|
} elseif( isset( $this->propertyAnnotators[$key] ) ) { |
|
94
|
1 |
|
return $this->propertyAnnotators[$key]; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
1 |
|
return new NullPropertyAnnotator(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
14 |
|
private function initDefaultPropertyAnnotators() { |
|
101
|
|
|
|
|
102
|
|
|
// Encapsulate each instance to avoid direct instantiation for unused |
|
103
|
|
|
// matches |
|
104
|
14 |
|
$this->propertyAnnotators = [ |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
CreatorPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
107
|
1 |
|
return new CreatorPropertyAnnotator( $appFactory ); |
|
108
|
14 |
|
}, |
|
109
|
|
|
|
|
110
|
|
|
PageViewsPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
111
|
1 |
|
return new PageViewsPropertyAnnotator( $appFactory ); |
|
112
|
14 |
|
}, |
|
113
|
|
|
|
|
114
|
|
|
ApprovedRevPropertyAnnotator::PROP_ID => function ( $appFactory ) { |
|
115
|
|
|
return new ApprovedRevPropertyAnnotator( $appFactory ); |
|
116
|
14 |
|
}, |
|
117
|
|
|
|
|
118
|
|
|
ApprovedByPropertyAnnotator::PROP_ID => function ( $appFactory ) { |
|
119
|
|
|
return new ApprovedByPropertyAnnotator( $appFactory ); |
|
120
|
14 |
|
}, |
|
121
|
|
|
|
|
122
|
|
|
ApprovedDatePropertyAnnotator::PROP_ID => function ( $appFactory ) { |
|
123
|
|
|
return new ApprovedDatePropertyAnnotator( $appFactory ); |
|
124
|
14 |
|
}, |
|
125
|
|
|
|
|
126
|
|
|
ApprovedStatusPropertyAnnotator::PROP_ID => function ( $appFactory ) { |
|
127
|
|
|
return new ApprovedStatusPropertyAnnotator( $appFactory ); |
|
128
|
14 |
|
}, |
|
129
|
|
|
|
|
130
|
|
|
UserRegistrationDatePropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
131
|
1 |
|
return new UserRegistrationDatePropertyAnnotator( $appFactory ); |
|
132
|
14 |
|
}, |
|
133
|
|
|
|
|
134
|
|
|
UserEditCountPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
135
|
1 |
|
return new UserEditCountPropertyAnnotator( $appFactory ); |
|
136
|
14 |
|
}, |
|
137
|
|
|
|
|
138
|
|
|
PageIDPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
139
|
1 |
|
return new PageIDPropertyAnnotator( $appFactory ); |
|
140
|
14 |
|
}, |
|
141
|
|
|
|
|
142
|
|
|
PageLengthPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
143
|
1 |
|
return new PageLengthPropertyAnnotator( $appFactory ); |
|
144
|
14 |
|
}, |
|
145
|
|
|
|
|
146
|
|
|
RevisionIDPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
147
|
1 |
|
return new RevisionIDPropertyAnnotator( $appFactory ); |
|
148
|
14 |
|
}, |
|
149
|
|
|
|
|
150
|
|
|
PageNumRevisionPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
151
|
1 |
|
return new PageNumRevisionPropertyAnnotator( $appFactory ); |
|
152
|
14 |
|
}, |
|
153
|
|
|
|
|
154
|
|
|
TalkPageNumRevisionPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
155
|
1 |
|
return new TalkPageNumRevisionPropertyAnnotator( $appFactory ); |
|
156
|
14 |
|
}, |
|
157
|
|
|
|
|
158
|
|
|
PageContributorsPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
159
|
1 |
|
return new PageContributorsPropertyAnnotator( $appFactory ); |
|
160
|
14 |
|
}, |
|
161
|
|
|
|
|
162
|
|
|
SubPagePropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
163
|
1 |
|
return new SubPagePropertyAnnotator( $appFactory ); |
|
164
|
14 |
|
}, |
|
165
|
|
|
|
|
166
|
|
|
ShortUrlPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
167
|
1 |
|
return new ShortUrlPropertyAnnotator( $appFactory ); |
|
168
|
14 |
|
}, |
|
169
|
|
|
|
|
170
|
14 |
|
ExifPropertyAnnotator::PROP_ID => function( $appFactory ) { |
|
171
|
1 |
|
return new ExifPropertyAnnotator( $appFactory ); |
|
172
|
14 |
|
}, |
|
173
|
|
|
|
|
174
|
|
|
]; |
|
175
|
14 |
|
} |
|
176
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.