Difference between revisions of "Extension:SimpleSecurity2.1.php"
(allow wildcard for user/groups too) |
m |
||
Line 2: | Line 2: | ||
# Security | # Security | ||
$groups = $wgUser->getGroups(); | $groups = $wgUser->getGroups(); | ||
+ | foreach($groups as $k => $v) $groups[$k] = strtolower($v); | ||
if (!in_array('sysop',$groups)&&!in_array('directors',$groups)) { | if (!in_array('sysop',$groups)&&!in_array('directors',$groups)) { | ||
Line 23: | Line 24: | ||
# Validate extracted security against this user/groups | # Validate extracted security against this user/groups | ||
− | $security = preg_split("/\\s*,\\s*/",$security); | + | $deny = false; |
− | + | if ($security) { | |
− | + | $security = preg_split("/\\s*,\\s*/",$security); | |
− | + | if (!in_array('*',$security)) { | |
− | + | $groups[] = ucwords($wgUser->mName); | |
− | + | if (count(array_intersect($groups,$security))==0) { | |
+ | $action = 'view'; | ||
+ | $deny = true; | ||
+ | } | ||
} | } | ||
} | } | ||
Line 36: | Line 40: | ||
$wgHooks['ParserBeforeStrip'][] = 'securityRemoveLinks'; | $wgHooks['ParserBeforeStrip'][] = 'securityRemoveLinks'; | ||
function securityRemoveLinks(&$parser, &$text, &$strip_state) { | function securityRemoveLinks(&$parser, &$text, &$strip_state) { | ||
− | $text = preg_replace("/\\[{2}\\s*security\\s*:[^\\]]+?\\]{2}[\r\n]?/i",'',$text); | + | if ($GLOBALS['deny']) { |
+ | $text = new Article(Title::newFromText('Action not permitted')); | ||
+ | $text = $text->fetchContent(0, false, false); | ||
+ | } | ||
+ | else $text = preg_replace("/\\[{2}\\s*security\\s*:[^\\]]+?\\]{2}[\r\n]?/i",'',$text); | ||
} | } | ||
?> | ?> |
Revision as of 04:51, 28 November 2006
<?
- Security
$groups = $wgUser->getGroups(); foreach($groups as $k => $v) $groups[$k] = strtolower($v); if (!in_array('sysop',$groups)&&!in_array('directors',$groups)) {
# Handle moves and submits $a = $action == 'submit' ? 'edit' : $action; if ($title=='Special:Movepage' && $action=='submit') { $a = 'move'; $t = $wgRequest->getText('wpOldTitle',$wgRequest->getVal('target')); } else $t = $title;
# Extract security information for this action from this article $security = ; $text = new Article(Title::newFromText($t)); $text = $text->fetchContent(0, false, false); preg_match_all("/\\[{2}\\s*security\\s*:\\s*([^\\]]+?)\\s*\\|\\s*([^\\]]+?)\\s*\\]{2}/i",$text,$matches,PREG_SET_ORDER); foreach ($matches as $m) { $actions = preg_split("/\\s*,\\s*/",$m[1]); if (in_array($a,$actions)) $security = $m[2]; if (in_array('*',$actions) && ($security == )) $security = $m[2]; }
# Validate extracted security against this user/groups $deny = false; if ($security) { $security = preg_split("/\\s*,\\s*/",$security); if (!in_array('*',$security)) { $groups[] = ucwords($wgUser->mName); if (count(array_intersect($groups,$security))==0) { $action = 'view'; $deny = true; } } } }
- Remove the security links before wiki-parsing
$wgHooks['ParserBeforeStrip'][] = 'securityRemoveLinks'; function securityRemoveLinks(&$parser, &$text, &$strip_state) { if ($GLOBALS['deny']) { $text = new Article(Title::newFromText('Action not permitted')); $text = $text->fetchContent(0, false, false); } else $text = preg_replace("/\\[{2}\\s*security\\s*:[^\\]]+?\\]{2}[\r\n]?/i",,$text); } ?>