User talk:Brett and Restrict Access by Category and Group: Difference between pages
Herbythyme (talk | contribs) New page: {{subst:welcome}} --~~~~ |
New page: = Restrict Access by Category and Group = This pretends to add Restricted view of the Wiki content. You have some Categories in your wiki and you want to make these visible only for some u... |
||
Line 1:
= Restrict Access by Category and Group =
This pretends to add Restricted view of the Wiki content.
You have some Categories in your wiki and you want to make these visible only for some users.
Basically you can add a group with the same name of the category and then everybody in that group can access to that category.
== Installing ==
This extension only make a modification on the '''LocalSettings.php''', and uses the '''Hooks/userCan''' function. Then you only must edit your '''LocalSettings.php''' and add at the end:
<pre>
# This is to add a Group/Category Restricted access (by lodopidolo).
function userCanGrupoCategoria($title, $user, $action, $result)
{
global $wgGroupPermissions;
global $wgWhitelistRead;
$categoriaValida = false;
if (count($title->getParentCategories()) == 0) {
$categoriaValida = true;
} else {
foreach( $wgGroupPermissions as $key => $value ) {
if (in_array($key, $user->getGroups()) && (array_key_exists(strtolower("category:".str_replace(" ", "_", $key)), array_change_key_case($title->getParentCategories(), CASE_LOWER)))) {
$categoriaValida = true;
}
}
}
if (($user->isLoggedIn() && $categoriaValida) || in_array($title, $wgWhitelistRead))
$result = true;
else
$result = false;
return $result;
}
$wgHooks['userCan'][] = 'userCanGrupoCategoria';
</pre>
This code tell to mediawiki that has another '''userCan''' function, an this new function is going to read all group that user belongs and if is the same one another category then validate the access. Documents without category are validated too.
You must specify '''$wgWhitelistRead''' variable with the pages that everybody can acceess: '''Main_Page''' and '''UserLogin''':
<pre>
$wgWhitelistRead = array("Main_Page", "Especial:Userlogin");
</pre>
== Use ==
After you have added this extension, you only must create groups in your '''LocalSettings.php''':
<pre>
# We create a group named Base de Datos.
$wgGroupPermissions['Base de Datos']['read'] = true;
</pre>
== In other languages ==
If you work in Spanih then you must replace '''category''' with '''categoría''' in:
<pre>
if (in_array($key, $user->getGroups()) &&
(array_key_exists(strtolower("categoría:".str_replace(" ", "_", $key)),
array_change_key_case($title->getParentCategories(), CASE_LOWER)))) {
</pre>
and in then $wgWhitelistRead specification, you must replace '''Main_page''' with '''Portada''':
<pre>
$wgWhitelistRead = array("Portada", "Especial:Userlogin");
</pre>
== Version ==
This is probed on mediawiki '''1.12.0'''.
andy (dot) orencio.org
[[Category:MediaWiki extensions]]
|
Revision as of 12:33, 1 July 2008
Restrict Access by Category and Group
This pretends to add Restricted view of the Wiki content. You have some Categories in your wiki and you want to make these visible only for some users.
Basically you can add a group with the same name of the category and then everybody in that group can access to that category.
Installing
This extension only make a modification on the LocalSettings.php, and uses the Hooks/userCan function. Then you only must edit your LocalSettings.php and add at the end:
# This is to add a Group/Category Restricted access (by lodopidolo). function userCanGrupoCategoria($title, $user, $action, $result) { global $wgGroupPermissions; global $wgWhitelistRead; $categoriaValida = false; if (count($title->getParentCategories()) == 0) { $categoriaValida = true; } else { foreach( $wgGroupPermissions as $key => $value ) { if (in_array($key, $user->getGroups()) && (array_key_exists(strtolower("category:".str_replace(" ", "_", $key)), array_change_key_case($title->getParentCategories(), CASE_LOWER)))) { $categoriaValida = true; } } } if (($user->isLoggedIn() && $categoriaValida) || in_array($title, $wgWhitelistRead)) $result = true; else $result = false; return $result; } $wgHooks['userCan'][] = 'userCanGrupoCategoria';
This code tell to mediawiki that has another userCan function, an this new function is going to read all group that user belongs and if is the same one another category then validate the access. Documents without category are validated too.
You must specify $wgWhitelistRead variable with the pages that everybody can acceess: Main_Page and UserLogin:
$wgWhitelistRead = array("Main_Page", "Especial:Userlogin");
Use
After you have added this extension, you only must create groups in your LocalSettings.php:
# We create a group named Base de Datos. $wgGroupPermissions['Base de Datos']['read'] = true;
In other languages
If you work in Spanih then you must replace category with categoría in:
if (in_array($key, $user->getGroups()) && (array_key_exists(strtolower("categoría:".str_replace(" ", "_", $key)), array_change_key_case($title->getParentCategories(), CASE_LOWER)))) {
and in then $wgWhitelistRead specification, you must replace Main_page with Portada:
$wgWhitelistRead = array("Portada", "Especial:Userlogin");
Version
This is probed on mediawiki 1.12.0.
andy (dot) orencio.org