From MediaWiki.org
<?php
if (!defined('MEDIAWIKI')) die("MediaWiki extensions cannot be run directly.");
/**
* An extension to crudely protect pages from viewing by unathorised users.
*
* @package MediaWiki
* @subpackage Extensions
*
* @author Mark Clements <mclements at kennel17 dot co dot uk>
* @copyright Copyright © 2006, Mark Clements
* @license http://creativecommons.org/licenses/by-sa/2.5/ cc-by-sa 2.5 or later
*/
$wgExtensionCredits['other'][] = array(
'name' => "CrudeProtection",
'author' => "Mark Clements",
'description' => "an extension to crudely protect pages from viewing by unathorised users",
'url' => "http://www.mediawiki.org/wiki/Extension:CrudeProtection",
);
$pCrudeProtection_Messages = array(
'crudeprotection_title' => "Access denied",
'crudeprotection_text' => "You do not have permission to view this page.",
);
$wgExtensionFunctions[] = "wfCrudeProtection";
function wfCrudeProtection() {
global $wgMessageCache, $wgParser, $wgHooks;
global $pCrudeProtection_Messages;
$wgMessageCache->addMessages($pCrudeProtection_Messages);
// Parser hooks
$wgHooks['SkinTemplateContentActions'][] = "wfCrudeProtection_RemoveEditTab";
// Specific tags to be parsed
$wgParser->setHook( "protect", "wfCrudeProtection_Protect" );
}
function wfCrudeProtection_Protect($Input, $Args) {
global $wgOut, $wgUser;
global $pBlocked;
// Only respond to the first <protect> block. Ignore all others.
if (!isset($pBlocked)) {
if (isset($Args['type'])) {
$Type = strtolower($Args['type']);
if ($Type != "allow" && $Type != "deny")
$Type = "allow";
}
else
$Type = "allow";
// Allow "\n" to be specified as a line-break character.
if (isset($Args['separator'])) {
$Separator = $Args['separator'];
if ($Separator == "\\n")
$Separator = "\n";
}
else
$Separator = ",";
// Set appropriate default value, for if the user is not in the list of users.
if ($Type == "allow")
$pBlocked = true;
elseif ($Type == "deny")
$pBlocked = false;
// Check if the user is in the list - if so, then swap their status.
$Users = explode($Separator, $Input);
foreach ($Users as $Key => $Value) {
$Value = trim($Value);
if ($wgUser->getName() == $Value && $Value != "") {
$pBlocked = !$pBlocked;
break;
}
}
// If they are blocked, redirect to error page.
if ($pBlocked)
$wgOut->errorpage("crudeprotection_title", "crudeprotection_text");
}
return "";
}
function wfCrudeProtection_RemoveEditTab(&$ContentActions) {
global $pBlocked;
if ($pBlocked) {
unset($ContentActions['edit']);
unset($ContentActions['viewsource']);
}
return true;
}