Difference between revisions of "Extension:SimpleSecurity2.1.php"
Line 2: | Line 2: | ||
# Security | # Security | ||
$groups = $wgUser->getGroups(); | $groups = $wgUser->getGroups(); | ||
− | |||
if (!in_array('sysop',$groups)&&!in_array('directors',$groups)) { | if (!in_array('sysop',$groups)&&!in_array('directors',$groups)) { | ||
+ | |||
+ | # Handle moves and submits | ||
$a = $action == 'submit' ? 'edit' : $action; | $a = $action == 'submit' ? 'edit' : $action; | ||
if ($title=='Special:Movepage' && $action=='submit') { | if ($title=='Special:Movepage' && $action=='submit') { | ||
Line 9: | Line 10: | ||
$t = $wgRequest->getText('wpOldTitle',$wgRequest->getVal('target')); | $t = $wgRequest->getText('wpOldTitle',$wgRequest->getVal('target')); | ||
} else $t = $title; | } else $t = $title; | ||
+ | |||
+ | # Extract security information from article | ||
+ | $security = ''; | ||
$text = new Article(Title::newFromText($t)); | $text = new Article(Title::newFromText($t)); | ||
$text = $text->fetchContent(0, false, false); | $text = $text->fetchContent(0, false, false); | ||
Line 17: | Line 21: | ||
if (in_array('*',$actions) && ($security == '')) $security = $m[2]; | if (in_array('*',$actions) && ($security == '')) $security = $m[2]; | ||
} | } | ||
+ | |||
+ | # Redirect if permission violated | ||
if ($security) { | if ($security) { | ||
$groups[] = ucwords($wgUser->mName); | $groups[] = ucwords($wgUser->mName); | ||
Line 26: | Line 32: | ||
} | } | ||
} | } | ||
+ | |||
+ | # Remove the security links before wiki-parsing | ||
$wgHooks['ParserBeforeStrip'][] = 'securityRemoveLinks'; | $wgHooks['ParserBeforeStrip'][] = 'securityRemoveLinks'; | ||
function securityRemoveLinks(&$parser, &$text, &$strip_state) { | function securityRemoveLinks(&$parser, &$text, &$strip_state) { |
Revision as of 19:50, 26 November 2006
<?
- Security
$groups = $wgUser->getGroups(); 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 from 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]; }
# Redirect if permission violated if ($security) { $groups[] = ucwords($wgUser->mName); $security = preg_split("/\\s*,\\s*/",$security); if (count(array_intersect($groups,$security))==0) { $action = 'view'; $title = 'Action not permitted'; } } }
- Remove the security links before wiki-parsing
$wgHooks['ParserBeforeStrip'][] = 'securityRemoveLinks'; function securityRemoveLinks(&$parser, &$text, &$strip_state) { $text = preg_replace("/\\[{2}\\s*security\\s*:[^\\]]+?\\]{2}[\r\n]?/i",,$text); } ?>