Skip to content

Commit fc93ca7

Browse files
Fix addModuleStyles (#64)
* Fix crash on MW 1.43 #62 and some code clean up * don't pass in $skin
1 parent 03a3f63 commit fc93ca7

1 file changed

Lines changed: 21 additions & 26 deletions

File tree

src/HooksHandler.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use MediaWiki\Hook\ParserFirstCallInitHook;
1515
use MediaWiki\Hook\SetupAfterCacheHook;
1616
use MediaWiki\MediaWikiServices;
17-
use \Parser;
17+
use Parser;
1818
// TODO switch to then when dropping support for mw < 1.40
1919
// use MediaWiki\Parser\Parser;
2020
use SMW\Utils\File;
@@ -83,8 +83,7 @@ public function __construct(
8383
*
8484
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ScribuntoExternalLibraries
8585
*/
86-
public static function onScribuntoExternalLibraries( $engine, array &$extraLibraries ): bool
87-
{
86+
public static function onScribuntoExternalLibraries( $engine, array &$extraLibraries ): bool {
8887
if ( $engine == 'lua' ) {
8988
$extraLibraries['mw.bootstrap'] = LuaLibrary::class;
9089
}
@@ -101,12 +100,11 @@ public static function onScribuntoExternalLibraries( $engine, array &$extraLibra
101100
*
102101
* @codeCoverageIgnore trivial
103102
*
104-
* @param array $modeArray
103+
* @param array &$modeArray
105104
* @return bool
106105
*/
107106

108-
public function onGalleryGetModes( &$modeArray ): bool
109-
{
107+
public function onGalleryGetModes( &$modeArray ): bool {
110108
if (
111109
$this->getConfig()->has( 'BootstrapComponentsEnableCarouselGalleryMode' )
112110
&& $this->getConfig()->get( 'BootstrapComponentsEnableCarouselGalleryMode' )
@@ -125,24 +123,23 @@ public function onGalleryGetModes( &$modeArray ): bool
125123
*
126124
* @codeCoverageIgnore trivial
127125
*
128-
* @param $linker, always null (was \DummyLinker $linker)
129-
* @param \Title $title
130-
* @param File|\LocalFile $file
131-
* @param array $frameParams
132-
* @param array $handlerParams
133-
* @param bool|string $time
134-
* @param null|string $res
126+
* @param $linker always null (was \DummyLinker $linker)
127+
* @param \Title &$title
128+
* @param File|\LocalFile &$file
129+
* @param array &$frameParams
130+
* @param array &$handlerParams
131+
* @param bool|string &$time
132+
* @param null|string &$res
135133
* @param Parser $parser
136-
* @param string $query
137-
* @param null|int $widthOption
134+
* @param string &$query
135+
* @param null|int &$widthOption
138136
* @throws \MWException
139137
*/
140138
public function onImageBeforeProduceHTML(
141139
$linker, &$title, &$file, &$frameParams, &$handlerParams, &$time, &$res, $parser, &$query, &$widthOption
142140
): bool {
143141
if ( $this->getConfig()->has( 'BootstrapComponentsModalReplaceImageTag' ) &&
144-
$this->getConfig()->get( 'BootstrapComponentsModalReplaceImageTag' ) )
145-
{
142+
$this->getConfig()->get( 'BootstrapComponentsModalReplaceImageTag' ) ) {
146143
$imageModal = new ImageModal( $linker, $title, $file,
147144
$this->getNestingController(), $this->getBootstrapComponentsService()
148145
);
@@ -167,7 +164,7 @@ public function onImageBeforeProduceHTML(
167164
* @codeCoverageIgnore trivial
168165
*
169166
* @param Parser $parser
170-
* @param string $text
167+
* @param string &$text
171168
* @param StripState $stripState
172169
* @return bool
173170
*/
@@ -179,7 +176,6 @@ public function onInternalParseBeforeLinks( $parser, &$text, $stripState ): bool
179176
return true;
180177
}
181178

182-
183179
/**
184180
* Hook: OutputPageParserOutput
185181
*
@@ -212,24 +208,23 @@ public function onOutputPageParserOutput( $outputPage, $parserOutput ): void {
212208
* @codeCoverageIgnore trivial
213209
*
214210
* @param Parser $parser
215-
* @param string $text
211+
* @param string &$text
216212
* @param StripState $stripState
217213
* @return bool
218214
*/
219215
public function onParserAfterParse( $parser, &$text, $stripState ): bool {
220-
221216
// once, this was only loaded, when a component was paced on the page. now, we load it always
222217
// to keep the layout of all the wiki pages consistent.
223-
$parser->getOutput()->addModuleStyles( ['ext.bootstrapComponents.bootstrap.fix'] );
224-
$parser->getOutput()->addModuleStyles( ['ext.bootstrap.styles'] );
225-
$parser->getOutput()->addModules( ['ext.bootstrap.scripts'] );
218+
$parser->getOutput()->addModuleStyles( [ 'ext.bootstrapComponents.bootstrap.fix' ] );
219+
$parser->getOutput()->addModuleStyles( [ 'ext.bootstrap.styles' ] );
220+
$parser->getOutput()->addModules( [ 'ext.bootstrap.scripts' ] );
226221
$skin = $this->getBootstrapComponentsService()->getNameOfActiveSkin();
227222
foreach ( $this->getBootstrapComponentsService()->getActiveComponents() as $activeComponent ) {
228223
if ( !$this->getComponentLibrary()->isRegistered( $activeComponent ) ) {
229224
continue;
230225
}
231226
foreach ( $this->getComponentLibrary()->getModulesFor( $activeComponent ) as $module ) {
232-
$parser->getOutput()->addModuleStyles( $module, $skin );
227+
$parser->getOutput()->addModuleStyles( [ $module ] );
233228
}
234229
}
235230
return true;
@@ -287,7 +282,7 @@ protected function getComponentLibrary(): ComponentLibrary {
287282
*/
288283
protected function getConfig(): Config {
289284
if ( !isset( $this->config ) ) {
290-
$this->config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig('BootstrapComponents');
285+
$this->config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'BootstrapComponents' );
291286
}
292287
return $this->config;
293288
}

0 commit comments

Comments
 (0)