Extension:Whitelist Namespaces
![]() |
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 |
![]() |
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
Whitelist Namespaces Release status: beta |
|||
---|---|---|---|
Implementation | User rights | ||
Description | Whitelists an entire namespace as readable | ||
Author(s) | Bawolfftalk | ||
Latest version | 0.1-1 (03:24, 1 June 2009 (UTC)) | ||
MediaWiki | tested on 1.11.0rc1, and 1.13.2 | ||
License | GPLv2 or later | ||
Download | See the section labeled code below | ||
|
|||
|
|||
Translate the Whitelist Namespaces extension if possible |
|||
Check usage and version matrix; code metrics |
Contents
What can this extension do?[edit | edit source]
If you have a private wiki, this extension can be used to make a namespace public. This is very similar to Manual:$wgWhitelistRead just it works on entire namespaces instead. I noticed there seemed to be a lot of user authorization extensions, but they seemed to be much more complicated than they needed to be. Please note this is my first extension, its fairly simple, but its quite possible I made a mistake somewhere, so ymmv. Please also read Security issues with authorization extensions before using this extension.
Note: If you have any comments, questions, suggestions etc, please don't hesitate to contact me. (on my talk or by email).
Usage[edit | edit source]
Download instructions[edit | edit source]
Please cut and paste the code found below and place it in $IP/extensions/WhitelistNamespaces.php
. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
Installation[edit | edit source]
To install this extension, add the following to LocalSettings.php:
require_once("$IP/extensions/WhitelistNamespaces.php"); //Add Namespaces you want to be readable. use namespace number (ex 1 for talk //pages, 0 for main namespace, etc) or constants (NS_TALK, NS_MAIN, etc) //example: //$egNamespaceReadWhitelist = Array(NS_TALK, NS_MAIN, NS_HELP); //for main, talk and help namespaces. //Note: It is important this comes after the require_once line $egNamespaceReadWhitelist = Array();
You must also make the wiki private, so there is something to whitelist (ex: add $wgGroupPermissions['*']['read']=false;
to LocalSettings.php)
Configuration parameters[edit | edit source]
$egNamespaceReadWhitelist
- array of namespace numbers to whitelist. Examples:
$egNamespaceReadWhitelist = Array(NS_TALK, NS_MAIN, NS_HELP);
#this would whitelist the main, talk and help namespaces$egNamespaceReadWhitelist = Array(100, 101);
#this would whitelist the first custom namespace, and its associated talk namespace.- If you have defined a constant
NS_PUBLIC
—$egNamespaceReadWhitelist = Array(NS_PUBLIC);
would whitelist that namespace.
Code[edit | edit source]
<?php if ( ! defined( 'MEDIAWIKI' ) ) die(); /* Purpose: Have certain namespaces whitelisted so that they can be read, regardless of if the user has permission to read. For example, a public namespace, on a private wiki. @author n:en:User:Bawolff <http://en.wikinews.org/wiki/User:Bawolff> 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. http://www.gnu.org/copyleft/gpl.html To install, add following to LocalSettings.php require_once("extensions/WhitelistNamespaces.php"); $egNamespaceReadWhitelist = Array(); Note, the order of those lines are important changing the $egNamespaceReadWhitelist = Array(); to be an array of namespaces you want to whitelist. ex: $egNamespaceReadWhitelist = Array(NS_TALK, NS_MAIN, NS_HELP); for main help and talk namespaces. Note: the UserGetRights hook is useful if the wiki is world readable. In such a case the $egNamespaceActionWhitelist array defines the permissions offered to anonymous users in this namespace. Eg: $egNamespaceActionWhitelist = array('read', 'edit', 'createpage', 'createtalk'); Default right is read which must be safe. However non-world-readable wikis have not be tested extensively. Remember that 'createpage' right is given automagically with 'edit' */ // default. overide it in LocalSettings.php $egNamespaceReadWhitelist = Array(); // default. overide it in LocalSettings.php $egNamespaceActionWhitelist = Array('read'); $wgHooks['userCan'][] = 'efExtensionWhitelistNamespaces'; $wgHooks['UserGetRights'][] = 'efWhitelistedNamespaces'; $wgExtensionCredits['other'][] = array( 'name' => 'Whitelist Namespaces', 'description' => 'Allows an entire namespace to be read-whitelisted', 'url' => 'http://www.mediawiki.org/wiki/Extension:Whitelist_Namespaces', 'author' => array('Bawolff', 'Drzraf'), 'version' => '0.3' ); function efExtensionWhitelistNamespaces(&$title, &$user, $action, &$result) { global $egNamespaceReadWhitelist, $egNamespaceActionWhitelist; if (in_array($action, $egNamespaceActionWhitelist, true)) { if( in_array($title->getNamespace(), $egNamespaceReadWhitelist, true)) { $result = true; return false; } } return true; } // There was (abandonned) plans to introduce $ns as a // 3rd parameter during 1.19 cycle, see 3da36a9103 function efWhitelistedNamespaces( $user, &$aRights ) { global $egNamespaceReadWhitelist, $egNamespaceActionWhitelist; $ns = RequestContext::getMain()->getTitle()->getNamespace(); if($user->isAnon() && $ns && in_array( $ns, $egNamespaceReadWhitelist, true ) ) { $aRights = array_merge($aRights, $egNamespaceActionWhitelist); } return true; }
See also[edit | edit source]
- Extension:WhitelistedNamespaces the extensions inspiring the use of UserGetRights
- Extension:Lockdown
- Extension:NamespacePermissions
- Extension:PageSecurity
- Extension:Whitelist Regex
- Extension:NamespaceReadRestrict — works with MW v1.19