Extension:InternalWhitelist
From MediaWiki.org
|
Release status: stable |
|||
|---|---|---|---|
| Implementation | User rights | ||
| Description | Provides the capability to maintain a listing of "whitelisted" articles in the MediaWiki namespace | ||
| Author(s) | Lisa Ridley (Hoggwild5Talk) | ||
| Last Version | 0.8 beta (2 Jul 2008) | ||
| MediaWiki | MediaWiki versions 1.11 or higher | ||
| License | GPL | ||
| Download | Code below | ||
|
|||
|
check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
For wikis that choose to restrict pages that anonymous users can see, this extension provides the capability of maintaining the "whitelisted" pages from within the MediaWiki application in the MediaWiki namespace. For more information on "whitelisting", please see $wgWhitelistRead.
This extension will actually replace any previously applied settings for $wgWhitelistRead.
[edit] Compatibility
- MediaWiki version 1.11 and higher
Note: This extension utilizes the 'UserGetRights' hook, which was first implemented in MediaWiki version 1.11.
[edit] Installation & Setup / Changes to LocalSettings.php
To install this extension:
- Save the code below in a file called "InternalWhitelist.php" and place this file in the extensions folder of your MediaWiki installation.
- Insert the following into your LocalSettings.php file:
* $wgGroupPermissions['*']['read'] = false; * require_once("$IP/extensions/InternalWhitelist.php");
- Create a page titled "MediaWiki:Whitelist". List each page you wish to "whitelist" for anonymous users as a bulleted list. Comments can be added to the page by preceding each line that is a comment with a double slash ("//"). For example, to whitelist the Main Page, the discussion page for the Main Page, and the Recent Changes page, you would enter the following content in MediaWiki:Whitelist:
//Whitelisted pages //Content pages * Main Page //Discussion pages * Talk:Main Page //Special Pages * Special:RecentChanges
The lines starting with "//" will be ignored, and the bulleted lines will become an array of whitelisted pages.
[edit] Notes
If you are currently maintaining a whitelist in your LocalSettings.php script file, this listing will be discarded and replaced with the pages listed on MediaWiki:Whitelist. If you install this extension and do not create MediaWiki:Whitelist then all pages except Special:Userlogin will be unavailable to anonymous visitors.
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.
Only "//" will work properly for commented lines.
[edit] Code
<?php /** * InternalWhitelist * Author: Lisa Ridley * Date: 2 Jul 2008 * Version 0.8 beta * Copyright (C) 2008 Lisa Ridley * * 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 can find a copy of the GNU General Public License at http://www.gnu.org/copyleft/gpl.html * A paper copy can be obtained by writing to: Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * To install this extension, save this file in the "extensions" folder of your * MediaWiki installation, and add the following to LocalSettings.php * * $wgGroupPermissions['*']['read'] = false; * require_once("$IP/extensions/InternalWhitelist.php"); * * Note: any settings already established in $wgWhitelistRead will be discarded * and the "internal whitelist" will be utilized instead. * * The "internal whitelist" is stored at MediaWiki:Whitelist. * * Comments can be noted in the page by preceding a line with double slashes, like so: * //This is a comment line * * The articles to be whitelisted are listed in bullet form, with any namespace * prefixes; the actual article name can be entered with or without underscores * for spaces. * * For example, to whitelist the Main Page, Special:RecentChanges, and the * discussion page for the Main Page, the contents of MediaWiki:Whitelist would * look like: * //This is the internal whitelist * //Articles * * Main Page * //Discussion pages * * Talk:Main Page * //Special Pages * * Special:RecentChanges * */ $wgExtensionCredits['other'][] = array( 'name' => 'InternalWhitelist', 'author' => 'Lisa Ridley', 'url' => 'http://www.mediawiki.org/wiki/Extension:InternalWhitelist', 'version' => '0.8 beta', 'description' => 'Allows for the maintenance of "whitelisted" pages in the MediaWiki namespace', ); $wgExtensionFunctions[] = 'fnInternalWhitelistSetup'; /** * extension setup */ function fnInternalWhitelistSetup(){ global $wgHooks, $wgGroupPermissions; $wgGroupPermissions['*']['read'] = false; $wgHooks['UserGetRights'][] = 'fnInternalWhitelist'; } /** * Adds pages listed in MediaWiki:Whitelist to $wgWhitelistRead * Always returns true so that other extensions using the UserGetRights hook * will be executed * * @params $user User object * @params $rights array of user rights * @return boolean true */ function fnInternalWhitelist(&$user, $rights){ global $wgWhitelistRead; /** if user is not anonymous, then exit the script **/ if(!$user->isAnon()){ return true; } $pagearray = explode("\n", wfMsgForContent( 'Whitelist' ) ); foreach($pagearray as $arg){ if (strpos($arg, '//') !== false) { continue; } $wgWhitelistRead[]=trim(trim($arg, "*")); } return true; }