1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SubPageList; |
4
|
|
|
|
5
|
|
|
use Parser; |
6
|
|
|
use ParserHooks\HookDefinition; |
7
|
|
|
use ParserHooks\HookHandler; |
8
|
|
|
use ParserHooks\HookRegistrant; |
9
|
|
|
use SubPageList\Counter\SubPageCount; |
10
|
|
|
use SubPageList\Counter\SubPageCounter; |
11
|
|
|
use SubPageList\Lister\PageHierarchyCreator; |
12
|
|
|
use SubPageList\Lister\SimpleSubPageFinder; |
13
|
|
|
use SubPageList\Lister\SubPageList; |
14
|
|
|
use SubPageList\Lister\UI\SubPageListRenderer; |
15
|
|
|
use SubPageList\Lister\UI\WikitextSubPageListRenderer; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Top level factory for the SubPageList extension. |
19
|
|
|
* |
20
|
|
|
* @since 1.0 |
21
|
|
|
* |
22
|
|
|
* @licence GNU GPL v2+ |
23
|
|
|
* @author Jeroen De Dauw < [email protected] > |
24
|
|
|
*/ |
25
|
|
|
class Extension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @since 1.0 |
29
|
|
|
* |
30
|
|
|
* @var Settings |
31
|
|
|
*/ |
32
|
|
|
private $settings; |
33
|
|
|
|
34
|
23 |
|
public function __construct( Settings $settings ) { |
35
|
23 |
|
$this->settings = $settings; |
36
|
23 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @since 1.0 |
40
|
|
|
* |
41
|
|
|
* @return Settings |
42
|
|
|
*/ |
43
|
5 |
|
public function getSettings() { |
44
|
5 |
|
return $this->settings; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @since 1.0 |
49
|
|
|
* |
50
|
|
|
* @return DBConnectionProvider |
51
|
|
|
*/ |
52
|
24 |
|
public function getSlaveConnectionProvider() { |
53
|
24 |
|
return new LazyDBConnectionProvider( DB_SLAVE ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @since 1.0 |
58
|
|
|
* |
59
|
|
|
* @return CacheInvalidator |
60
|
|
|
*/ |
61
|
1 |
|
public function getCacheInvalidator() { |
62
|
1 |
|
return new SimpleCacheInvalidator( $this->getSubPageFinder() ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return SimpleSubPageFinder |
67
|
|
|
*/ |
68
|
19 |
|
public function getSubPageFinder() { |
69
|
19 |
|
return new SimpleSubPageFinder( $this->getSlaveConnectionProvider() ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @since 1.0 |
74
|
|
|
* |
75
|
|
|
* @return SubPageCounter |
76
|
|
|
*/ |
77
|
4 |
|
public function getSubPageCounter() { |
78
|
4 |
|
return new SimpleSubPageFinder( $this->getSlaveConnectionProvider() ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @since 1.0 |
83
|
|
|
* |
84
|
|
|
* @return TitleFactory |
85
|
|
|
*/ |
86
|
22 |
|
public function getTitleFactory() { |
87
|
22 |
|
return new TitleFactory(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @since 1.0 |
92
|
|
|
* |
93
|
|
|
* @return HookHandler |
94
|
|
|
*/ |
95
|
4 |
|
public function getCountHookHandler() { |
96
|
4 |
|
return new SubPageCount( $this->getSubPageCounter(), $this->getTitleFactory() ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @since 1.0 |
101
|
|
|
* |
102
|
|
|
* @return HookHandler |
103
|
|
|
*/ |
104
|
18 |
|
public function getListHookHandler() { |
105
|
18 |
|
return new SubPageList( |
106
|
18 |
|
$this->getSubPageFinder(), |
107
|
18 |
|
$this->getPageHierarchyCreator(), |
108
|
18 |
|
$this->newSubPageListRenderer(), |
109
|
18 |
|
$this->getTitleFactory() |
110
|
18 |
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @since 1.0 |
115
|
|
|
* |
116
|
|
|
* @return PageHierarchyCreator |
117
|
|
|
*/ |
118
|
18 |
|
public function getPageHierarchyCreator() { |
119
|
18 |
|
return new PageHierarchyCreator( $this->getTitleFactory() ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @since 1.0 |
124
|
|
|
* |
125
|
|
|
* @return SubPageListRenderer |
126
|
|
|
*/ |
127
|
18 |
|
public function newSubPageListRenderer() { |
128
|
18 |
|
return new WikitextSubPageListRenderer(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @since 1.0 |
133
|
|
|
* |
134
|
|
|
* @return HookDefinition |
135
|
|
|
*/ |
136
|
4 |
|
public function getCountHookDefinition() { |
137
|
4 |
|
return new HookDefinition( |
138
|
4 |
|
'subpagecount', |
139
|
|
|
[ |
|
|
|
|
140
|
|
|
'page' => [ |
141
|
4 |
|
'default' => '', |
142
|
4 |
|
'aliases' => 'parent', |
143
|
4 |
|
'message' => 'spl-subpages-par-page', |
144
|
4 |
|
], |
145
|
4 |
|
], |
146
|
|
|
'page' |
147
|
4 |
|
); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @since 1.0 |
152
|
|
|
* |
153
|
|
|
* @return HookDefinition |
154
|
|
|
*/ |
155
|
18 |
|
public function getListHookDefinition() { |
156
|
18 |
|
$params = []; |
157
|
|
|
|
158
|
18 |
|
$params['page'] = [ |
159
|
18 |
|
'aliases' => 'parent', |
160
|
18 |
|
'default' => '', |
161
|
|
|
]; |
162
|
|
|
|
163
|
18 |
|
$params['showpage'] = [ |
164
|
18 |
|
'type' => 'boolean', |
165
|
18 |
|
'aliases' => 'showparent', |
166
|
18 |
|
'default' => false, |
167
|
|
|
]; |
168
|
|
|
|
169
|
18 |
|
$params['sort'] = [ |
170
|
18 |
|
'aliases' => 'order', |
171
|
18 |
|
'values' => [ 'asc', 'desc' ], |
172
|
18 |
|
'tolower' => true, |
173
|
18 |
|
'default' => 'asc', |
174
|
|
|
]; |
175
|
|
|
|
176
|
18 |
|
$params['intro'] = [ |
177
|
18 |
|
'default' => '', |
178
|
|
|
]; |
179
|
|
|
|
180
|
18 |
|
$params['outro'] = [ |
181
|
18 |
|
'default' => '', |
182
|
|
|
]; |
183
|
|
|
|
184
|
18 |
|
$params['links'] = [ |
185
|
18 |
|
'type' => 'boolean', |
186
|
18 |
|
'aliases' => 'link', |
187
|
18 |
|
'default' => true, |
188
|
|
|
]; |
189
|
|
|
|
190
|
18 |
|
$params['redirects'] = [ |
191
|
18 |
|
'type' => 'boolean', |
192
|
18 |
|
'aliases' => 'redirect', |
193
|
18 |
|
'default' => false, |
194
|
|
|
]; |
195
|
|
|
|
196
|
18 |
|
$params['default'] = [ |
197
|
18 |
|
'default' => '', |
198
|
|
|
]; |
199
|
|
|
|
200
|
18 |
|
$params['limit'] = [ |
201
|
18 |
|
'type' => 'integer', |
202
|
18 |
|
'default' => 200, |
203
|
18 |
|
'range' => [ 1, 500 ], |
204
|
|
|
]; |
205
|
|
|
|
206
|
18 |
|
$params['addlevel'] = [ |
207
|
18 |
|
'type' => 'integer', |
208
|
18 |
|
'default' => 0, |
209
|
18 |
|
'range' => [ 0, 10 ], |
210
|
|
|
]; |
211
|
|
|
|
212
|
18 |
|
$params['element'] = [ |
213
|
18 |
|
'default' => 'div', |
214
|
18 |
|
'aliases' => [ 'div', 'p', 'span', 'none' ], |
215
|
|
|
]; |
216
|
|
|
|
217
|
18 |
|
$params['class'] = [ |
218
|
18 |
|
'default' => 'subpagelist', |
219
|
|
|
]; |
220
|
|
|
|
221
|
18 |
|
$params['format'] = [ |
222
|
18 |
|
'aliases' => 'liststyle', |
223
|
|
|
'values' => [ |
224
|
18 |
|
'ul', 'unordered', |
225
|
18 |
|
'ol', 'ordered', |
226
|
|
|
// 'list', 'bar' // TODO: re-implement support for these two |
227
|
18 |
|
], |
228
|
18 |
|
'tolower' => true, |
229
|
18 |
|
'default' => 'ul', |
230
|
|
|
]; |
231
|
|
|
|
232
|
18 |
|
$params['pathstyle'] = [ |
233
|
18 |
|
'aliases' => 'showpath', |
234
|
|
|
'values' => [ |
235
|
18 |
|
'none', 'no', |
236
|
18 |
|
'subpagename', 'children', 'notparent', |
237
|
18 |
|
'pagename', |
238
|
18 |
|
'full', |
239
|
|
|
'fullpagename' |
240
|
18 |
|
], |
241
|
18 |
|
'tolower' => true, |
242
|
18 |
|
'default' => 'subpagename', |
243
|
|
|
]; |
244
|
|
|
|
245
|
18 |
|
$params['kidsonly'] = [ |
246
|
18 |
|
'type' => 'boolean', |
247
|
18 |
|
'default' => false, |
248
|
|
|
]; |
249
|
|
|
|
250
|
18 |
|
$params['template'] = [ |
251
|
18 |
|
'default' => '', |
252
|
|
|
]; |
253
|
|
|
|
254
|
|
|
// TODO: re-implement support |
255
|
|
|
// $params['separator'] = array( |
256
|
|
|
// 'aliases' => 'sep', |
257
|
|
|
// 'default' => ' · ', |
258
|
|
|
// ); |
259
|
|
|
|
260
|
|
|
// Give grep a chance to find the usages: |
261
|
|
|
// spl-subpages-par-sort, spl-subpages-par-sortby, spl-subpages-par-format, spl-subpages-par-page, |
262
|
|
|
// spl-subpages-par-showpage, spl-subpages-par-pathstyle, spl-subpages-par-kidsonly, spl-subpages-par-limit, |
263
|
|
|
// spl-subpages-par-element, spl-subpages-par-class, spl-subpages-par-intro, spl-subpages-par-outro, |
264
|
|
|
// spl-subpages-par-default, spl-subpages-par-separator, spl-subpages-par-template, spl-subpages-par-links, spl-subpages-par-redirects |
265
|
18 |
|
foreach ( $params as $name => &$param ) { |
266
|
18 |
|
$param['message'] = 'spl-subpages-par-' . $name; |
267
|
18 |
|
} |
268
|
|
|
|
269
|
18 |
|
return new HookDefinition( |
270
|
18 |
|
[ 'subpagelist', 'splist', 'subpages' ], |
271
|
18 |
|
$params, |
|
|
|
|
272
|
18 |
|
[ 'page', 'format', 'pathstyle', 'sort' ] |
273
|
18 |
|
); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @since 0.1 |
278
|
|
|
* |
279
|
|
|
* @param Parser $parser |
280
|
|
|
* |
281
|
|
|
* @return HookRegistrant |
282
|
|
|
*/ |
283
|
|
|
public function getHookRegistrant( Parser &$parser ) { |
284
|
|
|
return new HookRegistrant( $parser ); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
} |
288
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: