Extension:RestrictTalk

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
RestrictTalk

Release status: unknown

Implementation User rights
Description Allow permissions to be restricted for "talk" namespaces
Author(s) Aaron Axelsen
License No license specified
Download see below
Hooks used
userCan

Check usage (experimental)

RestrictTalk is a MediaWiki extension which provides flexible access management for restricting access to "Talk" namespaces. RestrictTalk is based on the NamespacePermissions Extension.

It uses separate permissions for each action (read, edit, create, move).

[edit] Usage

Add the following to the LocalSettings.php file:

$wgGroupPermissions[ 'user' ][ 'ns1_read' ] = true;
$wgGroupPermissions[ 'user' ][ 'ns1_edit' ] = true;
$wgGroupPermissions[ 'user' ][ 'ns1_create' ] = false;
$wgGroupPermissions[ 'sysop' ][ 'ns1_create' ] = true;
$wgGroupPermissions[ 'user' ][ 'ns3_read' ] = true;
$wgGroupPermissions[ 'user' ][ 'ns3_edit' ] = true;
$wgGroupPermissions[ 'user' ][ 'ns3_create' ] = true;
 
require('extensions/RestrictTalk.php');

[edit] Source of RestrictTalk.php

<?php
 /* Restrict Talk - MediaWiki extension
  *
  * Provides the ability to restrict permissions on the discussion namespaces (Default and User).
  * Based on Namespacepermission.
  *
  * Author: Aaron Axelsen
  *
  * // optional (example): allow registered users to view and edit articles in Foo
  * $wgGroupPermissions[ 'user' ][ 'ns1_read' ] = true;
  * $wgGroupPermissions[ 'user' ][ 'ns1_edit' ] = true;
  * $wgGroupPermissions[ 'user' ][ 'ns3_read' ] = true;
  * $wgGroupPermissions[ 'user' ][ 'ns3_edit' ] = true;
  * // end of optional
  * require('extensions/NamespacePermissions.php');
  *
  * Permissions provided:
  *   # ns{$num}_read
  *   # ns{$num}_edit
  *   # ns{$num}_create
  *   # ns{$num}_move
  * where {$num} - namespace number (e.g. ns100_read, ns101_create)
  *
  */
 
 $wgExtensionFunctions[] = "wfNamespacePermissions";
 
 function wfNamespacePermissions() {
     global $wgHooks;
 
     // use the userCan hook to check permissions
     $wgHooks[ 'userCan' ][] = 'namespacePermissionsCheckNamespace';
 }
 
 function namespacePermissionsCheckNamespace( $title, $user, $action, $result ) {
        if ( $title->getPrefixedText() == "Main Page" || $title->getPrefixedText() == "Special:Userlogin" ) {
                return true;
        }
        #$ns = $title->getNamespace();
        if (($ns = $title->getNamespace()) > 0 & $ns % 2) {
        #if ( ( $ns = $title->getNamespace() ) == 1 ) {
                if ( ! $user->isAllowed("ns{$ns}_{$action}") ) {
                        $result = false;
                        return false;
                }
        }
        return true;
 }
 
 /**
 * Add extension information to Special:Version
 */
 $wgExtensionCredits['other'][] = array(
        'name' => 'RestrictTalk',
        'version' => '1.0',
        'author' => 'Aaron Axelsen',
        'description' => 'Allow permissions to be restricted for "talk" namespaces',
        'url' => 'http://www.mediawiki.org/wiki/Extension:RestrictTalk'
        );
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox