|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SESP; |
|
4
|
|
|
|
|
5
|
|
|
use Psr\Log\NullLogger; |
|
6
|
|
|
use Psr\Log\LoggerInterface; |
|
7
|
|
|
use Psr\Log\LoggerAwareInterface; |
|
8
|
|
|
use Onoi\Cache\Cache; |
|
9
|
|
|
use Onoi\Cache\NullCache; |
|
10
|
|
|
use Title; |
|
11
|
|
|
use WikiPage; |
|
12
|
|
|
use User; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @ingroup SESP |
|
16
|
|
|
* |
|
17
|
|
|
* @license GNU GPL v2+ |
|
18
|
|
|
* @since 1.3 |
|
19
|
|
|
* |
|
20
|
|
|
* @author mwjames |
|
21
|
|
|
*/ |
|
22
|
|
|
class AppFactory implements LoggerAwareInterface { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
private $options; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Cache |
|
31
|
|
|
*/ |
|
32
|
|
|
private $cache; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
private $connection; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var LoggerInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
private $logger; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var PropertyDefinitions |
|
46
|
|
|
*/ |
|
47
|
|
|
private $propertyDefinitions; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @since 2.0 |
|
51
|
|
|
* |
|
52
|
|
|
* @param array $options |
|
53
|
|
|
* @param Cache|null $cache |
|
54
|
|
|
*/ |
|
55
|
9 |
|
public function __construct( array $options = array(), Cache $cache = null ) { |
|
56
|
9 |
|
$this->options = $options; |
|
57
|
9 |
|
$this->cache = $cache; |
|
58
|
9 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @since 2.0 |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function setConnection( \DatabaseBase $connection ) { |
|
64
|
1 |
|
$this->connection = $connection; |
|
|
|
|
|
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @since 1.3 |
|
69
|
|
|
* |
|
70
|
|
|
* @return DatabaseBase |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function getConnection() { |
|
73
|
|
|
|
|
74
|
1 |
|
if ( $this->connection === null ) { |
|
75
|
|
|
$this->connection = wfGetDB( DB_SLAVE ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
return $this->connection; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @see LoggerAwareInterface::setLogger |
|
83
|
|
|
* |
|
84
|
|
|
* @since 2.0 |
|
85
|
|
|
* |
|
86
|
|
|
* @param LoggerInterface $logger |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function setLogger( LoggerInterface $logger ) { |
|
89
|
1 |
|
$this->logger = $logger; |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @since 2.0 |
|
94
|
|
|
* |
|
95
|
|
|
* @param LoggerInterface |
|
96
|
|
|
*/ |
|
97
|
1 |
|
public function getLogger() { |
|
98
|
|
|
|
|
99
|
1 |
|
if ( $this->logger === null ) { |
|
100
|
1 |
|
return new NullLogger(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
return $this->logger; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @since 2.0 |
|
108
|
|
|
* |
|
109
|
|
|
* @param string $key |
|
110
|
|
|
* @param $default $mixed |
|
|
|
|
|
|
111
|
|
|
* |
|
112
|
|
|
* @return mixed|false |
|
113
|
|
|
*/ |
|
114
|
2 |
|
public function getOption( $key, $default = false ) { |
|
115
|
|
|
|
|
116
|
2 |
|
if ( isset( $this->options[$key] ) ) { |
|
117
|
2 |
|
return $this->options[$key]; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
1 |
|
return $default; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @since 2.0 |
|
125
|
|
|
* |
|
126
|
|
|
* @return PropertyDefinitions |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function getPropertyDefinitions() { |
|
129
|
|
|
|
|
130
|
1 |
|
if ( $this->propertyDefinitions !== null ) { |
|
131
|
1 |
|
return $this->propertyDefinitions; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
1 |
|
$labelFetcher = new LabelFetcher( |
|
135
|
1 |
|
$this->cache, |
|
136
|
1 |
|
$GLOBALS['wgLang']->getCode() |
|
137
|
1 |
|
); |
|
138
|
|
|
|
|
139
|
1 |
|
$labelFetcher->setLabelCacheVersion( |
|
140
|
1 |
|
$this->getOption( 'sespLabelCacheVersion', 0 ) |
|
|
|
|
|
|
141
|
1 |
|
); |
|
142
|
|
|
|
|
143
|
1 |
|
$this->propertyDefinitions = new PropertyDefinitions( |
|
144
|
1 |
|
$labelFetcher, |
|
145
|
1 |
|
$this->getOption( 'sespPropertyDefinitionFile' ) |
|
146
|
1 |
|
); |
|
147
|
|
|
|
|
148
|
1 |
|
$this->propertyDefinitions->setLocalPropertyDefinitions( |
|
149
|
1 |
|
$this->getOption( 'sespLocalPropertyDefinitions', array() ) |
|
|
|
|
|
|
150
|
1 |
|
); |
|
151
|
|
|
|
|
152
|
1 |
|
return $this->propertyDefinitions; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @since 1.3 |
|
157
|
|
|
* |
|
158
|
|
|
* @param Title $title |
|
159
|
|
|
* |
|
160
|
|
|
* @return WikiPage |
|
161
|
|
|
*/ |
|
162
|
2 |
|
public function newWikiPage( Title $title ) { |
|
163
|
|
|
|
|
164
|
|
|
// #55 |
|
165
|
|
|
// Fight a possible DB corruption and avoid "NS_MEDIA is a virtual namespace; use NS_FILE" |
|
166
|
2 |
|
if ( $title->getNamespace() === NS_MEDIA ) { |
|
167
|
1 |
|
$title = Title::makeTitleSafe( |
|
168
|
1 |
|
NS_FILE, |
|
169
|
1 |
|
$title->getDBkey(), |
|
170
|
1 |
|
$title->getInterwiki(), |
|
171
|
1 |
|
$title->getFragment() |
|
172
|
1 |
|
); |
|
173
|
1 |
|
} |
|
174
|
|
|
|
|
175
|
2 |
|
return WikiPage::factory( $title ); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @since 1.3 |
|
180
|
|
|
* |
|
181
|
|
|
* @param Title $title |
|
182
|
|
|
* |
|
183
|
|
|
* @return User |
|
184
|
|
|
*/ |
|
185
|
1 |
|
public function newUserFromTitle( Title $title ) { |
|
186
|
1 |
|
return User::newFromName( $title->getText() ); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @since 1.3 |
|
191
|
|
|
* |
|
192
|
|
|
* @param $id |
|
193
|
|
|
* |
|
194
|
|
|
* @return User |
|
195
|
|
|
*/ |
|
196
|
1 |
|
public function newUserFromID( $id ) { |
|
197
|
1 |
|
return User::newFromId( $id ); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..