User:Sbrunner/CMS-WIKI-like.php: Difference between revisions
some fix ;-) |
m corr cat |
||
Line 1: | Line 1: | ||
<?php |
<?php |
||
/** [[Category: |
/** [[Category:MediaWiki extensions|CMS WIKI like]] |
||
==The goal== |
==The goal== |
||
The goal is the create a CMS that it can be is easily used my 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. |
The goal is the create a CMS that it can be is easily used my 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. |
Revision as of 13:46, 8 July 2006
<?php /**
The goal
The goal is the create a CMS that it can be is easily used my 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 :
- download this file as CMS-WIKI-like.php name
- 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 :
<?php global $wgHeaderAdds; if (isset($wgHeaderAdds)) { echo $wgHeaderAdds; } ?>
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 = "<style type=\"text/css\">\r\n\/*<![CDATA[*\/\r\n.editor, .editsection, #p-cactions, #p-search, #p-tb { display:none; }\r\n\/*]]>*\/\r\n</style>\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)
Other extensions I use
Code
*/ 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 = '<style type="text/css">/*<![CDATA[*/'."\r\n".'.editor, .editsection, #p-cactions, #p-search, #p-tb { display:none; }'."\r\n".'/*]]>*/</style>'."\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.'<br />'; //echo $title.'<br />'.$action.'<br />'; //print_r($groups); //print_r($regexpPermissions); //print_r($wgGroupPermissions); //print_r ($wgDisabledActions); /**
*/
?>