Blacklist extension
From Gwiki
Contents |
Purpose
As far as I know, MediaWiki does not contain built-in support for hiding/exposing specific pages. I am sure that someone else has written an extension to do this, but I chose to write my own because (1) I didn't find a suitable existing solution and (2) I wanted to get a feel for how extensions work within MediaWiki. My requirements:
- Allow convenient black/white-listing of pages through the use of a content tab (e.g., "article", "discussion", etc.).
- Restrict which users can black/white-list pages and which users can view blacklisted pages.
Pretty simple.
Implementation
Most of the work is done within the extension file, which you should unzip and place in your "extensions" directory. You need not make any changes to this file; however, you will need to make the following changes:
Wiki.php (found under "includes" within the MediaWiki install directory)
Locate the following function:
function performAction( &$output, &$article, &$title, &$user, &$request )
Add two case blocks (blacklist and whitelist) at the end of the switch statement within performAction, resulting in the following:
... case 'blacklist': blackListPage($title->getDBkey()); $article->view(); break; case 'whitelist': whiteListPage($title->getDBkey()); $article->view(); break; ...
LocalSettings.php (found within the MediaWiki install directory)
Somewhere within your LocalSettings.php file (at the bottom, perhaps), include the extension code with the following:
# extension inclusions
require_once('extensions/BlackWhiteListTab.php');
Blacklisted pages are kept track of within a text file. The extension looks at the $blackListPath global variable for the path to this file. To initialize this variable, add the following to LocalSettings.php:
# path to blacklist file global $blackListPath; $blackListPath = "/var/www/wiki/extensions/blacklist.txt";
Your webserver must have permission to read and write this file.
Lastly, set up the wiki users' permissions (again, in LocalSettings.php). There are two relevant permissions, blackListPages and readBlackList. The former controls which users can black/white-list pages, and the latter controls which users can read pages on the blacklist. For example, consider the following configuration (the one I use):
$wgGroupPermissions['*']['readBlackList'] = false; $wgGroupPermissions['*']['blackListPages'] = false; $wgGroupPermissions['sysop']['readBlackList'] = true; $wgGroupPermissions['sysop']['blackListPages'] = true;
These settings allow members from the "sysop" group to black-white-list pages and also view blacklisted pages. All other users are forbidden from black/white-listing pages and viewing blacklisted pages.
Example usage
To blacklist (hide) a page from all users without the readBlackList privilege, click the "blacklist page" tab at the top of the page:
To whitelist (show) a page to all users, click the "whitelist page" tab at the top of any blacklisted page:
Neat!
![]()
All of my software can be used according to the Attribution-NonCommercial-ShareAlike 3.0 license.
