File size: 1,539 Bytes
039c290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227d7ba
039c290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
 * Hooks for WikibaseClientLite.
 *
 * This is not a real Wikibase Client. It only keeps imported Wikipedia
 * templates/modules from crashing in read-only/offline mirrors that do not
 * have a local Wikidata repository.
 */

if ( !defined( 'MEDIAWIKI' ) ) {
    die( 'This file is part of MediaWiki and is not a valid entry point.' );
}

class WikibaseClientLiteHooks {
    /**
     * Expose mw.wikibase to Scribunto.
     *
     * @param string $engine
     * @param array &$extraLibraries
     * @return bool
     */
    public static function onScribuntoExternalLibraries( $engine, array &$extraLibraries ) {
        $extraLibraries['mw.wikibase'] = 'Scribunto_LuaWikibaseClientLiteLibrary';
        return true;
    }

    /**
     * Quiet templates that call {{#property:...}} or {{#statements:...}}.
     * Returning an empty string matches the purpose of this shim: there are no
     * local Wikidata values, but parser output should not become a fatal error.
     *
     * The magic words for these hooks are declared in WikibaseClientLite.i18n.magic.php via ExtensionMessagesFiles. Without
     * that declaration, MediaWiki 1.43 throws "invalid magic word 'property'".
     *
     * @param Parser $parser
     * @return bool
     */
    public static function onParserFirstCallInit( Parser $parser ) {
        $empty = static function () {
            return '';
        };

        $parser->setFunctionHook( 'property', $empty );
        $parser->setFunctionHook( 'statements', $empty );
        return true;
    }
}