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");
}
}
}