-
Notifications
You must be signed in to change notification settings - Fork 0
/
Access.php
31 lines (18 loc) · 819 Bytes
/
Access.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
namespace AccessWhitelistedNamespaces;
class Access {
public static function onUserGetRights( \User $user, array &$aRights ) {
if(self::hasAccess()) $aRights[] = "read";
return true;
}
public static function hasAccess() {
global $wgWhitelistedNamespaces, $wgExtraNamespaces, $wgRequest;
// Global "$wgTitle" is deprecated, so I am getting the title as a string, from the request.
$title = $wgRequest->getVal("title");
$standardNamespaces = array(0 => null, -1 => "Special");
$allNamespaces = $standardNamespaces + $wgExtraNamespaces;
$namespace = explode(":", $title)[0];
$namespaceInt = array_search($namespace, $allNamespaces);
return in_array($namespaceInt, $wgWhitelistedNamespaces);
}
}