Search code examples
mediawikiaclaccess-control

Problems with MediaWiki's AccessControl extension


I've installed the AccessControl MediaWiki extension however it seems like it causes an access denied error if you search for anything even contained within the page that is access controlled.

Anyone using this extension?

All I want to do is hide one page in the wiki from everyone except for 5 people.

MediaWiki version 1.18.0 AccessControl version 2.1


Solution

  • I solved it by adding another namespace to put the pages I need to secure in. I then removed the namespace from being searchable by implementing the searchablenamespaces hook.

    By doing this, there will never be an access denied page displayed just by searching for text that happens to be in an access controlled page.

    Here is the code for $IP/extensions/NoSearchNameSpace/NoSearchNameSpace.php

    <?php
    // This is a quick hack to remove certain listed namespaces from being searchable
    // Just set a list of namespace IDs in the wgNoSearchNamespaces array in LocalSettings
    // ie $wgNoSearchNamespaces = array(500,501) would remove 500 and 501 from being searched
    $wgHooks['SearchableNamespaces'][] = 'noSearchNameSpace';
    function noSearchNameSpace($arr){
        global $wgNoSearchNamespaces;
        foreach($wgNoSearchNamespaces as $ns){
            unset($arr[$ns]);
        }
    
        return $arr;
    }
    

    Example LocalSettings.php entry:

    // Add two custom namespaces. One for ACL pages.
    // one for pages that will be ACL'd that should not be searched.
    $wgExtraNamespaces[500] = "ACL";
    $wgExtraNamespaces[501] = "NoSearch";
    
    
    // Include the NoSearchNamespace extension
    require_once("extensions/NoSearchNamespace/NoSearchNameSpace.php");
    $wgNoSearchNamespaces = array('500','501');