-
Notifications
You must be signed in to change notification settings - Fork 8
/
ScratchblockHooks.php
47 lines (38 loc) · 1.66 KB
/
ScratchblockHooks.php
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
<?php
use MediaWiki\Hook\ParserFirstCallInitHook;
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
define('SB4_MODULE_KEY', 'ext.scratchBlocks4');
class Scratchblock4Hook implements ParserFirstCallInitHook, ResourceLoaderGetConfigVarsHook {
// Ouput HTML for <scratchblocks> tag
public function onParserFirstCallInit($parser) {
// Register <scratchblocks> and <sb> tag
$parser->setHook('scratchblocks', array("Scratchblock4Hook", 'sb4RenderTag'));
$parser->setHook('sb', array("Scratchblock4Hook", 'sb4RenderInlineTag'));
//throw new Exception(var_dump($parser));
return true;
}
public function onResourceLoaderGetConfigVars(array &$vars, $skin, Config $config): void {
$vars['wgScratchBlocks4Langs'] = $config->get('ScratchBlocks4Langs');
$vars['wgScratchBlocks4BlockVersion'] = $config->get('ScratchBlocks4BlockVersion');
}
public static function sb4Setup(Parser $parser) {
$out = $parser->getOutput();
if (!in_array(SB4_MODULE_KEY, $out->getModules())) {
$out->addModules([ SB4_MODULE_KEY ]);
}
}
public static function sb4RenderTagGeneric($input, array $args, $parser, $tag) {
self::sb4Setup($parser);
return Html::element($tag, [
'class' => 'blocks' . (isset($args['version']) ? '-' . $args['version'] : '')
], $input);
}
// Output HTML for <scratchblocks> tag
public static function sb4RenderTag($input, array $args, Parser $parser, PPFrame $frame) {
return self::sb4RenderTagGeneric($input, $args, $parser, 'pre');
}
// Output HTML for inline <sb> tag
public static function sb4RenderInlineTag($input, array $args, Parser $parser, PPFrame $frame) {
return self::sb4RenderTagGeneric($input, $args, $parser, 'code');
}
}