Topic on Extension talk:Lockdown

Namespace lockdown doesn't work correctly in MW 1.31

5
Maude's Ideology (talkcontribs)

Use this instead, in your LocalSettings.php, to limit the NS_PRIVATE and NS_PRIVATE_TALK namespaces to WikiSysop and User2.

$wgHooks['ParserBeforeStrip'][] = 'LockDownFunction';
function LockDownFunction( &$parser, &$text, &$strip_state ) {
        global $wgUser;
        $title = $parser->getTitle();
        $namespace = $title->getNamespace();
        if ( $namespace === NS_PRIVATE || $namespace === NS_PRIVATE_TALK ) {
                $user = $parser->getUser();
                $userName = $user->getName();
                $allowed = array(
                        'WikiSysop',
                        'User2'
                );
                if ( in_array( $userName, $allowed )
                        || in_array( $wgUser, $allowed )
                ) {
                        return true;
                } else {
                        die("Access denied");
                }
        }
}
2003:D2:DBC6:8A00:ECEA:9E8D:EF51:E302 (talkcontribs)

This is Great but you have to reverse the order in in_array for it to work

in_array( $userName, $allowed )

should to be

in_array( $allowed, $userName )

Thank you so much ! I have been so tired of deprecated Extensions that dont work.

BabunaLaguna (talkcontribs)
## //Restrict namespace access to group privat 
$wgHooks['ParserBeforeStrip'][] = 'LockDownFunction';
function LockDownFunction( &$parser ) {
    $title = $parser->getTitle(); 
    $namespace = $title->getNamespace(); 
    //Groups in here are allowed to access
    $allowedgroups = 'privat'; 
    //Restricted namespaces
    $wgLockedNamespaces = array( '3000', '3001' ); 
    if ( in_array($namespace, $wgLockedNamespaces) ) { 
        $user = $parser->getUser(); 
        $userGroups = $user->getGroups(); 
        if ( !in_array( $allowedgroups, $userGroups )) { 
            die("<h1>Access denied, you dont have the necessary permissions to access this namespace.</h1>");
        }
        return true;
    }
}
AhmadF.Cheema (talkcontribs)

The directly above method noted by User:BabunaLaguna does not work when submitting an edit (&action=submit) to the protected namespace and instead throws out the "Access denied..." message at the end.

141.84.65.170 (talkcontribs)

Tested MW 1.31.0 on PHP 7.2.12 with Lockdown (dbd06b7). Wanted to lock one namespace and talk (198 and 199). This locked all pages in the wiki! But when using array_fill in LocalSettings.php, it seems to work:


$defaultreadall['read'] = array('*');

$wgNamespacePermissionLockdown = array_fill(0,2010,$defaultreadall);

$wgNamespacePermissionLockdown[NS_INTERNAL]['read'] = array('MyAllowedGroup');

$wgNamespacePermissionLockdown[NS_INTERNAL_TALK]['read'] = array('MyAllowedGroup');


The problem was, that the Lockdown-hook sees the global array wgNamespacePermissionLockdown as a collapsed one with empty indexes removed. Instead of [198, 192] it was only [0,1] as array keys.

Reply to "Namespace lockdown doesn't work correctly in MW 1.31"