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 code inside a wiki page. Please be aware that MediaWiki developers do not review or keep track of extensions that put their code on the wiki.
|
|
Whitelist Namespaces Release status: beta |
|||
|---|---|---|---|
| Implementation | User rights | ||
| Description | Whitelists an entire namespace as readable | ||
| Author(s) | BawolffTalk | ||
| Last 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 | ||
|
|||
|
|||
|
Check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
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).
[edit] Usage
[edit] Download instructions
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.
[edit] Installation
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)
[edit] Configuration parameters
$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.
[edit] Code
<?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 this will not work if the wiki is world readable. You must make the wiki not readable (ex $wgGroupPermissions['*']['read']=true;) before you can whitelist a namespace as readable. */ $egNamespaceReadWhitelist = Array(); #default. overide in LocalSettings.php $wgHooks['userCan'][] = 'efExtensionWhitelistNamespaces'; $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' => '[http://en.wikinews.org/wiki/user:Bawolff Bawolff]', 'version' => '0.1-1' ); function efExtensionWhitelistNamespaces(&$title, &$user, $action, &$result) { global $egNamespaceReadWhitelist; if ($action == 'read') { if( in_array($title->getNamespace(), $egNamespaceReadWhitelist, true)) { $result = true; return false; } } return true; }
