Commit a0176ae2 authored by Tobias Haider's avatar Tobias Haider
Browse files

implement #tweekihideexcept parser function

parent 5252cbae
......@@ -24,6 +24,7 @@ $magicWords = array();
/** English (English) */
$magicWords['en'] = array(
'tweekihide' => array( 0, 'tweekihide' ),
'tweekihideexcept' => array( 0, 'tweekihideexcept' ),
'tweekibodyclass' => array( 0, 'tweekibodyclass' ),
'MAG_NUMBEREDHEADINGS' => array( 0, '__NUMBEREDHEADINGS__' ),
);
......@@ -42,6 +42,7 @@ class TweekiHooks {
}
$parser->setFunctionHook( 'tweekihide', 'TweekiHooks::setHiddenElements' );
$parser->setFunctionHook( 'tweekihideexcept', 'TweekiHooks::setHiddenElementsGroups' );
$parser->setFunctionHook( 'tweekibodyclass', 'TweekiHooks::addBodyclass' );
return true;
......@@ -115,7 +116,6 @@ class TweekiHooks {
static function setHiddenElements( Parser $parser ) {
global $wgTweekiSkinHideAll, $wgTweekiSkinHideable;
$parser->disableCache();
// Argument 0 is $parser, so begin iterating at 1
for ( $i = 1; $i < func_num_args(); $i++ ) {
if ( in_array ( func_get_arg( $i ), $wgTweekiSkinHideable ) ) {
$wgTweekiSkinHideAll[] = func_get_arg( $i );
......@@ -124,6 +124,27 @@ class TweekiHooks {
return '';
}
/**
* Set elements that should be hidden except for specific groups
*
* @param $parser Parser current parser
* @return string
*/
static function setHiddenElementsGroups( Parser $parser ) {
global $wgTweekiSkinHideAll, $wgTweekiSkinHideable;
$parser->disableCache();
$groups_except = explode( ',', func_get_arg( 1 ) );
$groups_user = $parser->getUser()->getEffectiveGroups();
if( count( array_intersect( $groups_except, $groups_user ) ) == 0 ) {
for ( $i = 2; $i < func_num_args(); $i++ ) {
if ( in_array ( func_get_arg( $i ), $wgTweekiSkinHideable ) ) {
$wgTweekiSkinHideAll[] = func_get_arg( $i );
}
}
}
return '';
}
/**
* Add classes to body
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment