Page MenuHomePhabricator

Lockdown locks namespace 0 if not using array_fill
Open, Needs TriagePublic

Description

MW 1.31.0 with mod_php 7.2.12:

When simply defining

define("NS_INTERNAL",         198);
$wgNamespacePermissionLockdown[NAMESPACE]['read'] = array('MyGroup')

and nothing else namesspace 0 gets locked .

Why?
In the src/Hooks.php, function namespacegroups the global variable

global $wgNamespacePermissionLockdown;

is used. Here a condensed array is presented, having all not used array keys removed and new numeric keys are assinged. This results in an array with only one main key 0:
$wgNamespacePermissionLockdown[0]['read'] = array('MyGroup')

This could be a bug in mod_php7 handling a global array or just a new feature of PHP.

Solution:
Use array_fill to preset all array elements up to the namespace numbers one likes:

$defaultreadall['read'] = array('*');
$wgNamespacePermissionLockdown = array_fill(0,2010,$defaultreadall);
$wgNamespacePermissionLockdown[NS_INTERNAL]['read'] = array('MyGroup');

Then the Hooks.php function will see the complete array and can match the correct namespace numbers.

I don't know why this is, but an update to the documentation would be ok.

Event Timeline

Aklapper renamed this task from Lockdown locks namespace 0 if not using arrray_fill to Lockdown locks namespace 0 if not using array_fill .Dec 4 2018, 11:35 AM