Restringir acceso en MediaWiki

En esta entrada vamos a ver como restringir el acceso por  grupos a una determinada entrada.

Para ello vamos a utilizar el siguiente plugin:

https://www.mediawiki.org/wiki/Extension:Restrict_access_by_category_and_group

Creamos el directorio donde vamos a descargar el plugin

mkdir /var/www/html/extensions/RestrictAccessByCategoryAndGroup/

agregamos el siguiente contenido

cat /var/www/html/extensions/RestrictAccessByCategoryAndGroup/RestrictAccessByCategoryAndGroup.php

<?php

if ( !defined( ‘MEDIAWIKI’ ) ) {
die( ‘Not a valid entry point.’ );
}

$wgExtensionCredits[‘parserhook’][] = array(
‘name’ => ‘Restrict access by category and group’,
‘author’ => ‘Andrés Orencio Ramirez Perez’,
‘url’ => ‘https://www.mediawiki.org/wiki/Extension:Restrict_access_by_category_and_group’,
‘description’ => ‘Allows to restrict access to pages by users groups and page categories’,
‘version’ => ‘2.0.1’
);

$wgHooks[‘userCan’][] = ‘restrictAccessByCategoryAndGroup’;

function restrictAccessByCategoryAndGroup( $title, $user, $action, $result ) {
global $wgGroupPermissions;
global $wgWhitelistRead;
global $wgLang;
global $wgHooks;
global $wgContLang;
global $wgWhitelistRead;
global $wgVersion;

//The Main Page, Login and Logout pages should always be accessible
if ( $wgVersion >= ‘1.17’ ) {
$wgWhitelistRead[] = wfMessage( ‘mainpage’ )->plain();
} else {
$wgWhitelistRead[] = wfMsgForContent( ‘mainpage’ );
}
$wgWhitelistRead[] = SpecialPage::getTitleFor( ‘Userlogin’ )->getLocalUrl();
$wgWhitelistRead[] = SpecialPage::getTitleFor( ‘Userlogout’ )->getLocalUrl();

$validCategory = false;
$groupExists = false;
$pageHasCategories = false;
$privateCategory = false;
$privateCategoryTemp = false;
$categoryNamespace = $wgLang->getNsText( NS_CATEGORY );
$whitePage = true;

//System categories
$systemCategory = array();
foreach ( array_change_key_case( $title->getParentCategories(), CASE_LOWER ) as $key => $value ) {
$formatedKey = substr( $key, ( strpos( $key, “:” ) + 1 ) );
$systemCategory[ $formatedKey ] = $value;
}

//Is this page a white page?
if ( isset( $wgWhitelistRead[0] ) ) {
$whitePage = in_array( $title, $wgWhitelistRead );
}

//If the page has no categories, it’s public.
if ( count( $title->getParentCategories() ) == 0 ) {
$validCategory = true;
} else {
//For each system categories
foreach ( $wgGroupPermissions as $key => $value ) {
//If current system category is defined as private, then tmpCatP is true
if ( isset( $wgGroupPermissions[ $key ][‘private’] ) ) {
$privateCategoryTemp = $wgGroupPermissions[ $key ][‘private’];
} else {
$privateCategoryTemp = false;
}
//If current system category exist in the document category array …
if ( array_key_exists( strtolower( str_replace( ” “, “_”, $key ) ), $systemCategory ) ) {
if ( $privateCategoryTemp and !$privateCategory ) {
$privateCategory = true;
$validCategory = false;
}
//We see that the user belongs to one of the groups (like of category)
if ( in_array( $key, $user->getGroups() ) and ( !$privateCategory or ( $privateCategoryTemp and $privateCategory ) ) ) {
$validCategory = true;
}
$groupExists = true;
}
}
$pageHasCategories = count( $title->getParentCategories() ) > 0;
}

if ( !$pageHasCategories ) {
return true;
}
if ( !$groupExists and !$whitePage ) {
return true;
}
if ( ( $user->isLoggedIn() and $validCategory ) or $whitePage ) {
return true;
}
return false;
}

Ahora editamos LocalSettings.php y agregamos la siguiente linea:

tail -5 /var/www/LocalSettings.php

require_once “$IP/extensions/RestrictAccessByCategoryAndGroup/RestrictAccessByCategoryAndGroup.php”;
$wgGroupPermissions[‘privatedata][‘private’] = true;

Reiniciamos el servicio web

service apache2 restart

Nos logamos con un usuario con permisos

https://wiki.red-orbita.com/index.php/Especial:PermisosUsuarios

Si tenemos configurada la wiki en ingles la URL será la siguiente:

https://wiki.red-orbita.com/index.php/Special:UserRights

buscamos el usuario y le agregamos a la categoría configurada anteriormente en LocalSettings.php que en mi caso es privatedata

Una vez configurado los acceso tenemos que ir al articulo en cuestión y guardarlo con la categoría configurada. En mi caso:

[[Category:privatedata ]]

 

 

Un sadudo

:wq!

One thought on “Restringir acceso en MediaWiki

  1. Pingback: Restringir acceso en MediaWiki | PlanetaLibre

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

*