zhtest / WikibaseClientLite /WikibaseClientLiteHooks.php
arolstar52's picture
Upload 10 files
227d7ba verified
Raw
History Blame Contribute Delete
1.54 kB
<?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;
}
}