Extension:WhitelistedNamespaces

What can this extension do?
For wikis that choose to restrict pages that anonymous users can see, this extension provides the capability of whitelisting an entire namespace or array of namespaces.

This extension will work in conjunction with specific pages that have been whitelisted using $wgWhitelistRead

Basic usage
To utilize this extension, a basic understanding of Group Permissions and Whitelisted Pages is needed. If you are not familiar with these concepts, please take a moment to read the following pages:


 * Manual:$wgWhitelistRead
 * Manual:User rights

Compatibility

 * MediaWiki version 1.11 and higher

Note: This extension utilizes the 'UserGetRights' hook, which was first implemented in MediaWiki version 1.11.

Installation & Setup / Changes to LocalSettings.php
To install this extension: Set $wgWhitelistedNamespaces to an array of namespace indices that you want to whitelist. For example, if you want anonymous visitors to be able to see all pages in the main namespace, but not be able to read any other pages, then insert the following into LocalSettings.php:
 * Save the code below in a file called "WhitelistedNamespaces.php" and place this file in the extensions folder of your MediaWiki installation.
 * Insert the following into your LocalSettings.php file:

It is not necessary to set $wgGroupPermissions['*']['read'] = false; in the LocalSettings.php file as this extension will set those permissions during the initialization process; however it is good practice to keep your Group Permissions settings in one place for ease of maintenance. If you choose this option, you can remove the $wgGroupPermissions settings from the code below. Of course, if you are restricting certain pages to read only access, then it probably makes sense that you turn off creating and editing pages for anonymous members as well. This extension does not set those group permission settings -- you must set those yourself.

Bug in code
If you install this extension on a recent version of MediaWiki and receive the following error message: Detected bug in an extension! Hook fnWhitelistedNamespaces failed to return a value; should return true to continue hook processing or false to abort. Warning: Parameter 1 to fnWhitelistedNamespaces expected to be a reference, value given in /share/MD0_DATA/Web/VHost_qbox4u/conf/tech/mwk/includes/Hooks.php on line 207

identical solution as below

This can be fixed by changing the following line: function fnWhitelistedNamespaces(&$user, $rights){ to this function fnWhitelistedNamespaces($user, $rights){

Alternative
This can also be done without an extension by adding something like this to LocalSettings.php. It is not completely identical and it could in theory show pages in the main namespace with a title that begins with  (assuming that   is not a valid namespace on the wiki). But it should be a perfectly fine solution in almost all cases.