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