|
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
|
25 |
|
public function __construct( Settings $settings ) { |
|
35
|
25 |
|
$this->settings = $settings; |
|
36
|
25 |
|
} |
|
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
|
26 |
|
public function getSlaveConnectionProvider() { |
|
53
|
26 |
|
return new LazyDBConnectionProvider( DB_REPLICA ); |
|
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
|
25 |
|
public function getSubPageFinder() { |
|
69
|
25 |
|
return new SimpleSubPageFinder( $this->getSlaveConnectionProvider() ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @since 1.0 |
|
74
|
|
|
* |
|
75
|
|
|
* @return SubPageCounter |
|
76
|
|
|
*/ |
|
77
|
24 |
|
public function getSubPageCounter() { |
|
78
|
24 |
|
return new SimpleSubPageFinder( $this->getSlaveConnectionProvider() ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @since 1.0 |
|
83
|
|
|
* |
|
84
|
|
|
* @return TitleFactory |
|
85
|
|
|
*/ |
|
86
|
24 |
|
public function getTitleFactory() { |
|
87
|
24 |
|
return new TitleFactory(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @since 1.0 |
|
92
|
|
|
* |
|
93
|
|
|
* @return HookHandler |
|
94
|
|
|
*/ |
|
95
|
24 |
|
public function getCountHookHandler() { |
|
96
|
24 |
|
return new SubPageCount( $this->getSubPageCounter(), $this->getTitleFactory() ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @since 1.0 |
|
101
|
|
|
* |
|
102
|
|
|
* @return HookHandler |
|
103
|
|
|
*/ |
|
104
|
24 |
|
public function getListHookHandler() { |
|
105
|
24 |
|
return new SubPageList( |
|
106
|
24 |
|
$this->getSubPageFinder(), |
|
107
|
24 |
|
$this->getPageHierarchyCreator(), |
|
108
|
24 |
|
$this->newSubPageListRenderer(), |
|
109
|
24 |
|
$this->getTitleFactory() |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @since 1.0 |
|
115
|
|
|
* |
|
116
|
|
|
* @return PageHierarchyCreator |
|
117
|
|
|
*/ |
|
118
|
24 |
|
public function getPageHierarchyCreator() { |
|
119
|
24 |
|
return new PageHierarchyCreator( $this->getTitleFactory() ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @since 1.0 |
|
124
|
|
|
* |
|
125
|
|
|
* @return SubPageListRenderer |
|
126
|
|
|
*/ |
|
127
|
24 |
|
public function newSubPageListRenderer() { |
|
128
|
24 |
|
return new WikitextSubPageListRenderer(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @since 1.0 |
|
133
|
|
|
* |
|
134
|
|
|
* @return HookDefinition |
|
135
|
|
|
*/ |
|
136
|
24 |
|
public function getCountHookDefinition() { |
|
137
|
24 |
|
return new HookDefinition( |
|
138
|
24 |
|
'subpagecount', |
|
139
|
|
|
[ |
|
|
|
|
|
|
140
|
24 |
|
'page' => [ |
|
141
|
|
|
'default' => '', |
|
142
|
|
|
'aliases' => 'parent', |
|
143
|
|
|
'message' => 'spl-subpages-par-page', |
|
144
|
|
|
], |
|
145
|
|
|
], |
|
146
|
24 |
|
'page' |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @since 1.0 |
|
152
|
|
|
* |
|
153
|
|
|
* @return HookDefinition |
|
154
|
|
|
*/ |
|
155
|
24 |
|
public function getListHookDefinition() { |
|
156
|
24 |
|
$params = []; |
|
157
|
|
|
|
|
158
|
24 |
|
$params['page'] = [ |
|
159
|
|
|
'aliases' => 'parent', |
|
160
|
|
|
'default' => '', |
|
161
|
|
|
]; |
|
162
|
|
|
|
|
163
|
24 |
|
$params['showpage'] = [ |
|
164
|
|
|
'type' => 'boolean', |
|
165
|
|
|
'aliases' => 'showparent', |
|
166
|
|
|
'default' => false, |
|
167
|
|
|
]; |
|
168
|
|
|
|
|
169
|
24 |
|
$params['sort'] = [ |
|
170
|
|
|
'aliases' => 'order', |
|
171
|
|
|
'values' => [ 'asc', 'desc' ], |
|
172
|
|
|
'tolower' => true, |
|
173
|
|
|
'default' => 'asc', |
|
174
|
|
|
]; |
|
175
|
|
|
|
|
176
|
24 |
|
$params['intro'] = [ |
|
177
|
|
|
'default' => '', |
|
178
|
|
|
]; |
|
179
|
|
|
|
|
180
|
24 |
|
$params['outro'] = [ |
|
181
|
|
|
'default' => '', |
|
182
|
|
|
]; |
|
183
|
|
|
|
|
184
|
24 |
|
$params['links'] = [ |
|
185
|
|
|
'type' => 'boolean', |
|
186
|
|
|
'aliases' => 'link', |
|
187
|
|
|
'default' => true, |
|
188
|
|
|
]; |
|
189
|
|
|
|
|
190
|
24 |
|
$params['redirects'] = [ |
|
191
|
|
|
'type' => 'boolean', |
|
192
|
|
|
'aliases' => 'redirect', |
|
193
|
|
|
'default' => false, |
|
194
|
|
|
]; |
|
195
|
|
|
|
|
196
|
24 |
|
$params['default'] = [ |
|
197
|
|
|
'default' => '', |
|
198
|
|
|
]; |
|
199
|
|
|
|
|
200
|
24 |
|
$params['limit'] = [ |
|
201
|
|
|
'type' => 'integer', |
|
202
|
|
|
'default' => 200, |
|
203
|
|
|
'range' => [ 1, 500 ], |
|
204
|
|
|
]; |
|
205
|
|
|
|
|
206
|
24 |
|
$params['addlevel'] = [ |
|
207
|
|
|
'type' => 'integer', |
|
208
|
|
|
'default' => 0, |
|
209
|
|
|
'range' => [ 0, 10 ], |
|
210
|
|
|
]; |
|
211
|
|
|
|
|
212
|
24 |
|
$params['element'] = [ |
|
213
|
|
|
'default' => 'div', |
|
214
|
|
|
'aliases' => [ 'div', 'p', 'span', 'none' ], |
|
215
|
|
|
]; |
|
216
|
|
|
|
|
217
|
24 |
|
$params['class'] = [ |
|
218
|
|
|
'default' => 'subpagelist', |
|
219
|
|
|
]; |
|
220
|
|
|
|
|
221
|
24 |
|
$params['format'] = [ |
|
222
|
|
|
'aliases' => 'liststyle', |
|
223
|
|
|
'values' => [ |
|
224
|
|
|
'ul', 'unordered', |
|
225
|
|
|
'ol', 'ordered', |
|
226
|
|
|
// 'list', 'bar' // TODO: re-implement support for these two |
|
227
|
|
|
], |
|
228
|
|
|
'tolower' => true, |
|
229
|
|
|
'default' => 'ul', |
|
230
|
|
|
]; |
|
231
|
|
|
|
|
232
|
24 |
|
$params['pathstyle'] = [ |
|
233
|
|
|
'aliases' => 'showpath', |
|
234
|
|
|
'values' => [ |
|
235
|
|
|
'none', 'no', |
|
236
|
|
|
'subpagename', 'children', 'notparent', |
|
237
|
|
|
'pagename', |
|
238
|
|
|
'full', |
|
239
|
|
|
'fullpagename' |
|
240
|
|
|
], |
|
241
|
|
|
'tolower' => true, |
|
242
|
|
|
'default' => 'subpagename', |
|
243
|
|
|
]; |
|
244
|
|
|
|
|
245
|
24 |
|
$params['kidsonly'] = [ |
|
246
|
|
|
'type' => 'boolean', |
|
247
|
|
|
'default' => false, |
|
248
|
|
|
]; |
|
249
|
|
|
|
|
250
|
24 |
|
$params['template'] = [ |
|
251
|
|
|
'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
|
24 |
|
foreach ( $params as $name => &$param ) { |
|
266
|
24 |
|
$param['message'] = 'spl-subpages-par-' . $name; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
24 |
|
return new HookDefinition( |
|
270
|
24 |
|
[ 'subpagelist', 'splist', 'subpages' ], |
|
271
|
24 |
|
$params, |
|
|
|
|
|
|
272
|
24 |
|
[ 'page', 'format', 'pathstyle', 'sort' ] |
|
273
|
|
|
); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* @since 0.1 |
|
278
|
|
|
* |
|
279
|
|
|
* @param Parser $parser |
|
280
|
|
|
* |
|
281
|
|
|
* @return HookRegistrant |
|
282
|
|
|
*/ |
|
283
|
24 |
|
public function getHookRegistrant( Parser &$parser ) { |
|
284
|
24 |
|
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: