1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SESP; |
4
|
|
|
|
5
|
|
|
use SESP\Annotator\ShortUrlAnnotator; |
6
|
|
|
use SESP\Annotator\ExifDataAnnotator; |
7
|
|
|
use SMW\SemanticData; |
8
|
|
|
use File; |
9
|
|
|
use Title; |
10
|
|
|
use Psr\Log\NullLogger; |
11
|
|
|
use Psr\Log\LoggerInterface; |
12
|
|
|
use Psr\Log\LoggerAwareInterface; |
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 $connection; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $options; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var LoggerInterface |
36
|
|
|
*/ |
37
|
|
|
private $logger; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var PropertyDefinitions |
41
|
|
|
*/ |
42
|
|
|
private $propertyDefinitions; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @since 2.0 |
46
|
|
|
* |
47
|
|
|
* @param Database $connection |
48
|
|
|
* @param array $options |
49
|
|
|
*/ |
50
|
|
|
public function __construct( $connection, array $options = array() ) { |
51
|
|
|
$this->connection = $connection; |
|
|
|
|
52
|
|
|
$this->options = $options; |
53
|
|
|
$this->logger = new NullLogger(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @see LoggerAwareInterface::setLogger |
58
|
|
|
* |
59
|
|
|
* @since 2.5 |
60
|
|
|
* |
61
|
|
|
* @param LoggerInterface $logger |
62
|
|
|
*/ |
63
|
|
|
public function setLogger( LoggerInterface $logger ) { |
64
|
|
|
$this->logger = $logger; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @since 3.0 |
69
|
|
|
* |
70
|
|
|
* @param LoggerInterface |
71
|
|
|
*/ |
72
|
|
|
public function getLogger() { |
73
|
|
|
return $this->logger; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @since 2.4 |
78
|
|
|
* |
79
|
|
|
* @param string $key |
80
|
|
|
* @param $default $mixed |
|
|
|
|
81
|
|
|
* |
82
|
|
|
* @return mixed|false |
83
|
|
|
*/ |
84
|
|
|
public function getOption( $key, $default = false ) { |
85
|
|
|
|
86
|
|
|
if ( isset( $this->options[$key] ) ) { |
87
|
|
|
return $this->options[$key]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $default; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @since 2.0 |
95
|
|
|
* |
96
|
|
|
* @return PropertyDefinitions |
97
|
|
|
*/ |
98
|
|
|
public function getPropertyDefinitions() { |
99
|
|
|
|
100
|
|
|
if ( $this->propertyDefinitions !== null ) { |
101
|
|
|
return $this->propertyDefinitions; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$this->propertyDefinitions = new PropertyDefinitions( |
105
|
|
|
$this->getOption( 'sespPropertyDefinitionFile' ) |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$this->propertyDefinitions->setLocalPropertyDefinitions( |
109
|
|
|
$this->getOption( 'sespLocalPropertyDefinitions', array() ) |
|
|
|
|
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
return $this->propertyDefinitions; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @since 1.3 |
117
|
|
|
* |
118
|
|
|
* @return DatabaseBase |
119
|
|
|
*/ |
120
|
|
|
public function getConnection() { |
121
|
|
|
return $this->connection; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @since 1.3 |
126
|
|
|
* |
127
|
|
|
* @param Title $title |
128
|
|
|
* |
129
|
|
|
* @return WikiPage |
130
|
|
|
*/ |
131
|
|
|
public function newWikiPage( Title $title ) { |
132
|
|
|
|
133
|
|
|
// #55 |
134
|
|
|
// Fight a possible DB corruption and avoid "NS_MEDIA is a virtual namespace; use NS_FILE" |
135
|
|
|
if ( $title->getNamespace() === NS_MEDIA ) { |
136
|
|
|
$title = Title::makeTitleSafe( |
137
|
|
|
NS_FILE, |
138
|
|
|
$title->getDBkey(), |
139
|
|
|
$title->getInterwiki(), |
140
|
|
|
$title->getFragment() |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return \WikiPage::factory( $title ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @since 1.3 |
149
|
|
|
* |
150
|
|
|
* @param Title $title |
151
|
|
|
* |
152
|
|
|
* @return User |
153
|
|
|
*/ |
154
|
|
|
public function newUserFromTitle( Title $title ) { |
155
|
|
|
return \User::newFromName( $title->getText() ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @since 1.3 |
160
|
|
|
* |
161
|
|
|
* @param $id |
162
|
|
|
* |
163
|
|
|
* @return User |
164
|
|
|
*/ |
165
|
|
|
public function newUserFromID( $id ) { |
166
|
|
|
return \User::newFromId( $id ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
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..