diff --git a/composer.json b/composer.json index 2af2e20..1d17e74 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "octfx/template-styles-extender", - "version": "1.1.3", + "version": "1.1.4", "type": "mediawiki-extension", "description": "Extends TemplateStyles with new CSS properties", "homepage": "http://www.mediawiki.org/wiki/Extension:TemplateStylesExtender", diff --git a/extension.json b/extension.json index 6bfc8dc..af5f8e6 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "TemplateStylesExtender", - "version": "1.1.3", + "version": "1.1.4", "author": [ "[https://www.mediawiki.org/wiki/User:Octfx Octfx]" ], diff --git a/includes/Hooks/MainHooks.php b/includes/Hooks/MainHooks.php index 78c674f..3df02a8 100644 --- a/includes/Hooks/MainHooks.php +++ b/includes/Hooks/MainHooks.php @@ -9,45 +9,43 @@ use MediaWiki\MediaWikiServices; class MainHooks implements ParserFirstCallInitHook { - /** - * @throws \MWException - */ - public function onParserFirstCallInit( $parser ) { - $parser->setHook( 'templatestyles', [ __CLASS__, 'handleTag' ] ); - } + /** + * @throws \MWException + */ + public function onParserFirstCallInit( $parser ) { + $parser->setHook( 'templatestyles', [ __CLASS__, 'handleTag' ] ); + } - /** - * This is a wrapper for tags, that allows unscoping of css for users with 'edit-interface' permissions - * @see Hooks::handleTag() - */ - public static function handleTag( $text, $params, $parser, $frame ) { - if ( $parser->getOptions() === null || !MediaWikiServices::getInstance()->getMainConfig()->get( 'TemplateStylesExtenderEnableUnscopingSupport' ) ) { - return Hooks::handleTag( $text, $params, $parser, $frame ); - } + /** + * This is a wrapper for tags, that allows unscoping of css for users with 'edit-interface' permissions + * @see Hooks::handleTag() + */ + public static function handleTag( $text, $params, $parser, $frame ): string + { + if ( $parser->getOptions() === null || !MediaWikiServices::getInstance()->getMainConfig()->get( 'TemplateStylesExtenderEnableUnscopingSupport' ) ) { + return Hooks::handleTag( $text, $params, $parser, $frame ); + } - $options = $parser->getOptions(); - $wrapClass = $options->getWrapOutputClass(); + $options = $parser->getOptions(); + $wrapClass = $options->getWrapOutputClass(); - if ( isset( $params['wrapclass'] ) ) { - $userCan = MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan( - 'editinterface', - MediaWikiServices::getInstance()->getUserFactory()->newFromUserIdentity( $parser->getUserIdentity() ), - $frame->getTitle() - ); + if ( isset( $params['wrapclass'] ) ) { + $permManager = MediaWikiServices::getInstance()->getPermissionManager(); + $user = MediaWikiServices::getInstance()->getUserFactory()->newFromUserIdentity( $parser->getUserIdentity() ); - if ( $userCan ) { - $options->setOption( 'wrapclass', $params['wrapclass'] ); - } else { - return Html::element( - 'p', - [ 'class' => 'mw-message-box mw-message-box-error' ], - 'User is not allowed to unscope this css. Needs "editinterface" rights.' - ); - } - } - $out = Hooks::handleTag( $text, $params, $parser, $frame ); - $options->setOption( 'wrapclass', $wrapClass ); + if ( $permManager->userHasRight( $user, 'editinterface' ) || $permManager->userCan( 'editinterface', $user, $frame->getTitle() ) ) { + $options->setOption( 'wrapclass', $params['wrapclass'] ); + } else { + return Html::element( + 'p', + [ 'class' => 'mw-message-box mw-message-box-error' ], + 'User is not allowed to unscope this css. Needs "editinterface" rights.' + ); + } + } + $out = Hooks::handleTag( $text, $params, $parser, $frame ); + $options->setOption( 'wrapclass', $wrapClass ); - return $out; - } + return $out; + } }