Difference between revisions of "Extension:IsAllowedHook.php"
(experimental IsAllowed hook) |
m |
||
Line 16: | Line 16: | ||
); | ); | ||
− | # Create a new User class by extending the existing one | + | # Create a new User class by extending the existing one with an overridden isAllowed method |
$User = get_class($wgUser); | $User = get_class($wgUser); | ||
$User2 = $User.'2'; | $User2 = $User.'2'; | ||
eval("class $User2 extends $User".' { | eval("class $User2 extends $User".' { | ||
− | |||
− | |||
function isAllowed($action = "") { | function isAllowed($action = "") { | ||
$result = NULL; | $result = NULL; | ||
Line 27: | Line 25: | ||
return $result === NULL ? $result = parent::isAllowed($action) : $result; | return $result === NULL ? $result = parent::isAllowed($action) : $result; | ||
} | } | ||
− | |||
}'); | }'); | ||
Revision as of 01:31, 9 October 2007
<?php
- Extension:IsAllowedHookTemplate:Php
- - Started: 2007-10-09
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('DFO_VERSION','0.0.0, 2007-10-09');
$wgExtensionCredits['parserhook'][] = array( 'name' => "IsAllowedHook", 'author' => 'User:Nad', 'description' => 'Adds a new hook called "IsAllowed" which is called from the User::isAllowed method.', 'url' => 'http://www.organicdesign.co.nz/Extension:IsAllowedHook.php', 'version' => DFO_VERSION );
- Create a new User class by extending the existing one with an overridden isAllowed method
$User = get_class($wgUser); $User2 = $User.'2'; eval("class $User2 extends $User".' { function isAllowed($action = "") { $result = NULL; wfRunHooks("IsAllowed",array(&$this,$action,&$result)); return $result === NULL ? $result = parent::isAllowed($action) : $result; } }');
- Replace the $wgUser object with an identical User2 instance
$oldUser = $wgUser; $wgUser = new $User2(); foreach(array_keys(get_class_vars($User)) as $k) $wgUser->$k = $oldUser->$k;
?>