Extension:CMS-WIKI-like

The goal
The goal is the create a CMS that it can be is easily used by anyone, than in a classic CMS when we have an editor interface relay different than the site it is not an evidence where to start.

Than I think that wiki system resolved this problem but the problem, tor an association site we don't have edit button on all page especially the mane page. To solve that I create this extension (my first implementation: [lamargelle.ch La Margelle], my church ;-) ).

An other problem I have is to create an member area, to solve that the white list read is to restrictive than I introduce list of regular expressions (in future it can be replaced by name space but it create come technical problem).

History

 * 28 04 2006 : add blacklist ($wgRegexpBlackGroupPermissions).

Features

 * Create standard pages.
 * Create member area.
 * Create wiki area.

What
A Mediawiki extension used to manage dynamically the $wgGroupPermissions and the $wgDisabledActions.

Install
Ton install the extension :
 * copy the source to a file named CMS-WIKI-like.php.
 * copy this file in the extensions directory.
 * add include_once('extensions/CMS-WIKI-like.php'); after the $wgGroupPermissions.
 * edit MediaWiki:Nosuchaction to Prohibited action.
 * edit MediaWiki:Nosuchactiontext to You don't have access of this action be sure that you are login.
 * in the LocalSettings.php replace $wgGroupPermissions by $wgRegexpGroupPermissions, the false value to array and the true one by array('.*').
 * replace the $wgRegexpWhitelistRead = array(...); by $wgRegexpGroupPermissions['*']['read'] = array(...);

Quick start
To use it you just edit or add attribute to $wgRegexpGroupPermissions[group][action or permission] = array of regexp to allow it, if other ignore it => all access.

A user manage access is viewmenu, is is used to view the menu. we can specify css classes to hide by using the $wgMenuClass' default value is  '.editsection, #p-cactions, #p-tb' ''. then you need to add in the html header part of the skin : 

Example
A configuration example : $wgGroupPermissions['*']['createaccount'] = false; $wgGroupPermissions['user']['createaccount'] = false; $wgGroupPermissions['user']['upload'] = true; $wgGroupPermissions['sysop']['createaccount'] = true;

$wgRegexpGroupPermissions['*']['read'] = array('Main Page', 'MediaWiki:.*\.css', 'MediaWiki:.*\.js', 'Image:.*', 'Catégorie:.*', 'Special:Userlogin', 'Special:Search', 'Wiki:.*', 'Discuter:Wiki:.*'); $wgRegexpGroupPermissions['*']['viewmenu'] = array('Wiki:.*', 'Discuter:Wiki:.*'); $wgRegexpGroupPermissions['*']['edit'] = array('Wiki:.*', 'Discuter:Wiki:.*'); $wgRegexpGroupPermissions['*']['history'] = array; $wgRegexpGroupPermissions['user']['read'] = array('.*'); $wgRegexpGroupPermissions['user']['viewmenu'] = array('.*'); $wgRegexpGroupPermissions['user']['edit'] = array('.*'); $wgRegexpGroupPermissions['user']['move'] = array('.*'); $wgRegexpGroupPermissions['user']['history'] = array('.*');

$wgAddToHideMenu = "\r\n\/*<![CDATA[*\/\r\n.editor, .editsection, #p-cactions, #p-search, #p-tb { display:none; }\r\n\/*]]>*\/\r\n \r\n";

include_once('extensions/CMS-Wiki-like.php');

//End of LocalSettings.php The result is that we have a wiki part, Main Page, a restricted access part, only sysop can create accounts.

Licence
GNU General Public License (GPL)

Author: user:sbrunner

Code
if (!defined('MEDIAWIKI')) die; <?php /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * @author sbrunner * */ $wgExtensionCredits['other'][] = array(   'name' => 'CMS-WIKI-like',    'url' => 'http://www.mediawiki.org/wiki/Extension:CMS-WIKI-like',    'author' => 'Stéphane Brunner' );

require_once( 'includes/WebRequest.php' ); require_once( 'includes/Sanitizer.php' );

$wgRequest = new WebRequest;

$title = $wgRequest->getVal('title'); $title = str_replace( '_', ' ', Sanitizer::decodeCharReferences($title) ); if( preg_match( '/^[\x80-\xff]/', $title ) ) { if (function_exists('mb_strtoupper')) { $title = mb_strtoupper(mb_substr($title,0,1)).mb_substr($title,1); } else { global $wikiUpperChars; $title = preg_replace (			"/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",			"strtr ( \"\$1\", \$wikiUpperChars )",			$string ); } }

$actions = array; foreach ($wgRegexpGroupPermissions as $group => $currentRegexpPermissions) { foreach ($currentRegexpPermissions as $action => $regexpPermission) { $black = false; $blackRegexp = $wgRegexpBlackGroupPermissions[$group][$action]; if (is_array($blackRegexp)) { foreach ($blackRegexp as $pattern) { if (preg_match('/^'.$pattern.'$/', $title)) { $black = true; break; }			}		}

$enable = false; if (!$black && is_array($regexpPermission)) { foreach ($regexpPermission as $pattern) { if (preg_match('/^'.$pattern.'$/', $title)) { $enable = true; break; }			}		}

$wgGroupPermissions[$group][$action] = $enable; } }

require_once( 'includes/Setup.php' );

$action = $wgRequest->getVal( 'action', 'view' );

global $wgUser; if ($wgUser->getID != 0) { $groups = array_merge( array( '*', 'user' ), $wgUser->mGroups); } else { $groups = array('*'); }

$actionManageByPermission = array('edit'); if (!in_array($action, $actionManageByPermission)) {

$testAction = $action; // patch diff and old page => history $oldid = $wgRequest->getVal( 'oldid' ); $diff = $wgRequest->getVal( 'diff' ); if ( isset( $oldid ) || !is_null( $diff ) ) { $testAction = 'history'; }

if (strcmp($action, 'view') !== false) { $testAction = 'read'; }

if (!accessEnable($groups, $title, $testAction)) { array_push($wgDisabledActions, $action); } }

if (!accessEnable($groups, $title, 'viewmenu')) { if (!isset($wgAddToHideMenu)) { $wgAddToHideMenu = '/*<![CDATA[*/'."\r\n".'.editor, .editsection, #p-cactions, #p-search, #p-tb { display:none; }'."\r\n".'/*]]>*/ '."\r\n"; }	$wgHeaderAdds = $wgAddToHideMenu; }

function accessEnable($groups, $title, $action) { global $wgRegexpGroupPermissions, $wgRegexpBlackGroupPermissions; foreach ($groups as $group) { $black = false; $blackRegexp = $wgRegexpBlackGroupPermissions[$group][$action]; if (is_array($blackRegexp)) { foreach ($blackRegexp as $pattern) { if (preg_match('/^'.$pattern.'$/', $title)) { $black = true; break; }			}		}

$enable = false; $regexpPermission = $wgRegexpGroupPermissions[$group][$action]; if (!$black && is_array($regexpPermission)) { foreach ($regexpPermission as $pattern) { if (preg_match('/^'.$pattern.'$/', $title)) { $enable = true; break; }			}		}

if ($enable) { return true; }	}	return false; }

//debug //echo '$black: '.$black.' '; //echo $title.' '.$action.' '; //print_r($groups); //print_r($regexpPermissions); //print_r($wgGroupPermissions); //print_r ($wgDisabledActions); ?>