Skip to content

Commit d69cccf

Browse files
committed
Load resources only when the MultiCodeBlock is used
Changed the $parser to a reference to be able to add styles to the output dynamically.
1 parent 8dd3770 commit d69cccf

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

extension.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"MultiCodeBlock": "includes/MultiCodeBlock.php"
1212
},
1313
"Hooks": {
14-
"ParserFirstCallInit": "MultiCodeBlock::onParserFirstCallInit",
15-
"BeforePageDisplay": "MultiCodeBlock::onBeforePageDisplay"
14+
"ParserFirstCallInit": "MultiCodeBlock::onParserFirstCallInit"
1615
},
1716
"ResourceModules": {
1817
"ext.multicodeblock.styles": {

includes/MultiCodeBlock.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ public static function onParserFirstCallInit( Parser &$parser ) {
2020
$parser->setHook( 'multicodeblock', [ self::class, 'renderMultiCodeBlock' ] );
2121
}
2222

23-
public static function onBeforePageDisplay( OutputPage &$out ) {
24-
$out->addModuleStyles( [ 'ext.multicodeblock.styles' ] );
25-
$out->addModules( [ 'ext.multicodeblock.js' ] );
26-
}
27-
2823
/**
2924
* Returns a string based on the MultiCodeBlock HTML-Element
3025
*
@@ -33,7 +28,11 @@ public static function onBeforePageDisplay( OutputPage &$out ) {
3328
* @param Parser $parser The MediaWiki syntax parser
3429
* @param PPFrame $frame MediaWiki frame
3530
*/
36-
public static function renderMultiCodeBlock( $input, array $args, Parser $parser, PPFrame $frame ) {
31+
public static function renderMultiCodeBlock( string &$input, array &$args, Parser &$parser, PPFrame &$frame ) {
32+
$out = $parser->getOutput();
33+
$out->addModuleStyles( [ 'ext.multicodeblock.styles' ] );
34+
$out->addModules( [ 'ext.multicodeblock.js' ] );
35+
3736
$code = findCodeBlocks($input);
3837

3938
$replaced = str_replace($code, '', $input);

0 commit comments

Comments
 (0)