Extension:CMS-WIKI-like

From MediaWiki.org

Jump to: navigation, search
If you need per-page or partial page access restrictions, you are advised to install an appropriate content management package. MediaWiki was not written to provide per-page access restrictions, and almost all hacks or patches promising to add them will likely have flaws somewhere, which could lead to exposure of confidential data. We are not responsible for anything being leaked, leading to loss of funds or one's job.
For further details, see Security issues with authorization extensions


Manual on MediaWiki Extensions
List of MediaWiki Extensions
CMS-WIKI-like

Release status: unknown

Implementation User rights
Description The goal is to create a CMS that it can be is easily used by anyone, Compared to a classic CMS (content management system) where the editor interface is really different to the site, making it not so evident where to start.
Author(s) Sbrunner
Download no link
Example http://www.lamargelle.ch/

Contents

[edit] The goal

The goal is the create a CMS that it can be is easily used by anyone, Compared to a classic CMS (content management system) where the editor interface is really different to the site, making it not so evident where to start.

I think that wiki system (mediawiki? Bouncingmolar)) resolved this problem, but the problem for an associations site is that we don't have edit buttons on all pages especially the main page. To solve this, I created this extension (my first implementation: La Margelle, my church ;-) ).

Another problem I have is to create a member area, to solve that the white list read is too restrictive, so I introduced a list of regular expressions (in future it can be replaced by name space but this creates some technical problems).

[edit] History

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

[edit] Features

  • Create standard pages.
  • Create member area.
  • Create wiki area.

[edit] What

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

[edit] Install

To 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(...);

[edit] 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;
  }
?>

[edit] 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.

[edit] Licence

GNU General Public License (GPL)

Author: user:sbrunner

[edit] 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 = '<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);
?>
Personal tools