mirror of
https://github.com/octfx/mediawiki-extensions-TemplateStylesExtender.git
synced 2024-11-30 19:15:27 +00:00
bug: Fix checking of editinterface
permission
This commit is contained in:
parent
ec626cf1f6
commit
ce31917593
|
@ -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",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "TemplateStylesExtender",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"author": [
|
||||
"[https://www.mediawiki.org/wiki/User:Octfx Octfx]"
|
||||
],
|
||||
|
|
|
@ -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 <templatestyles> 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 <templatestyles> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue