Search code examples
linuxmediawikiwikilockdown

MediaWiki - restrict access to namespace


Within MediaWiki 1.31.8, I need to restrict access to pages in a namespace so only members of a group would be able to use/view it.

The wiki has over 500 pages that begin with "MARKETING:"

I have created a namespace by adding this to LocalSettings.php:

"$wgExtraNamespaces =
       array (104 => "MARKETING",
             105 => "MARKETING_Talk");

I then installed Lockdown and added this line to LocalSettings.php:

$wgNamespacePermissionLockdown[MARKETING]['*'] = ['marketing'];
(I've seen some users have "marketing" as their group in the wiki "ListUsers" webpage)

I then went to test it in incognito (to avoid cookies error) with a dummy user that has no groups with the expectation that he won't have any privileges but it just didn't work. I've noticed that I can enter gibberish into the code above and it doesn't change anything or even throw logs. Would really appreciate the help, thanks ahead.

EDIT: SOLVED. Turns out since the marketing namespace is set with an array, I have had to use the syntax for an array:

$wgNamespacePermissionLockdown = array_fill( 104, 105, [  '*' => [ 'marketinhRW'  ] ] );

Solution

  • You are confusing namespace names, IDs and constants. 104 is the namespace ID, MARKETING is the namespace name. Almost everything takes a namespace ID (not name) as key, $wgNamespacePermissionLockdown included.

    Conventionally, you'd define a human-readable constant for the namespace ID, by putting define( 'NS_MARKETING', 104 ) somewhere in your configuration, and then write $wgNamespacePermissionLockdown[NS_MARKETING]['*'] = ['marketing']; which will index by ID. If you instead write $wgNamespacePermissionLockdown[MARKETING], since there is no MARKETING constant, PHP will assume you meant to write 'MARKETING', and treat it as a string, so there will be no permissions defined for the namespace ID.