Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ArticlePlaceholderLibrary | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
getImageProperty | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
getReferencePropertyToHide | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
register | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace ArticlePlaceholder\Lua; |
4 | |
5 | use MediaWiki\Config\ConfigException; |
6 | use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LibraryBase; |
7 | use MediaWiki\MediaWikiServices; |
8 | |
9 | /** |
10 | * Registers and defines functions needed by the Lua modules |
11 | * |
12 | * @license GPL-2.0-or-later |
13 | * @author Lucie-Aimée Kaffee |
14 | */ |
15 | class ArticlePlaceholderLibrary extends LibraryBase { |
16 | |
17 | /** |
18 | * @return string[] |
19 | */ |
20 | public function getImageProperty() { |
21 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
22 | $imageProperty = $config->get( 'ArticlePlaceholderImageProperty' ); |
23 | if ( |
24 | !is_string( $imageProperty ) || |
25 | $imageProperty === '' |
26 | ) { |
27 | throw new ConfigException( 'Bad value in $wgArticlePlaceholderImageProperty' ); |
28 | } |
29 | return [ $imageProperty ]; |
30 | } |
31 | |
32 | /** |
33 | * Returns an array containing the serialization of a single reference property id to hide |
34 | * |
35 | * @return string[]|null Null if $wgArticlePlaceholderReferencesBlacklist empty or not string |
36 | */ |
37 | public function getReferencePropertyToHide() { |
38 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
39 | $referencesBlacklist = $config->get( 'ArticlePlaceholderReferencesBlacklist' ); |
40 | if ( |
41 | !is_string( $referencesBlacklist ) || |
42 | $referencesBlacklist === '' |
43 | ) { |
44 | return null; |
45 | } |
46 | return [ $referencesBlacklist ]; |
47 | } |
48 | |
49 | /** |
50 | * @return array |
51 | */ |
52 | public function register() { |
53 | // These functions will be exposed to the Lua module. |
54 | // They are member functions on a Lua table which is private to the module, thus |
55 | // these can't be called from user code, unless explicitly exposed in Lua. |
56 | $lib = [ |
57 | 'getImageProperty' => [ $this, 'getImageProperty' ], |
58 | 'getReferencePropertyToHide' => [ $this, 'getReferencePropertyToHide' ], |
59 | ]; |
60 | |
61 | return $this->getEngine()->registerInterface( |
62 | __DIR__ . '/mw.ext.articlePlaceholder.entityRenderer.lua', $lib, [] |
63 | ); |
64 | } |
65 | |
66 | } |