public function setUpGroupNamespaces() { global $wgExtraNamespaces, $wgNamespacePermissionLockdown, $wgNonincludableNamespaces; if (!$wgNamespacePermissionLockdown || !$wgNonincludableNamespaces) { throw new \Exception('To use the Group Namespace Feature you need to install Lockdown (https://www.mediawiki.org/wiki/Extension:Lockdown)'); } $nsCount = 200; $groups = $this->groupmanager->findGroups(); foreach ($groups as $group) { $nsName = 'NS_SF_GROUP_' . $group->getId(); $nsNameTalk = $nsName . '_TALK'; define($nsName, $nsCount++); define($nsNameTalk, $nsCount++); $groupName = $group->getName(); $groupName = strtolower($groupName); $groupName = str_replace(array(' ', ',', '.', '-'), '_', $groupName); $groupName = ucfirst($groupName); # add new namespaces $wgExtraNamespaces[constant($nsName)] = $groupName; $wgExtraNamespaces[constant($nsNameTalk)] = $groupName . '_talk'; #restrict "read" permission to logged in users $wgNamespacePermissionLockdown[constant($nsName)]['read'] = array(self::getGroupAlias($group)); $wgNamespacePermissionLockdown[constant($nsNameTalk)]['read'] = array(self::getGroupAlias($group)); #prevent inclusion of pages from that namespace $wgNonincludableNamespaces[] = constant($nsName); $wgNonincludableNamespaces[] = constant($nsNameTalk); } }
/** * Returns a specific principal, specified by it's path. * The returned structure should be the exact same as from * getPrincipalsByPrefix. * * @param string $path * @param bool $getObject * * @return array|GroupInterface|UserInterface|void * * @throws Exception */ public function getPrincipalByPath($path, $getObject = false) { $name = str_replace('principals/', '', $path); // get username from path-string, if string contains additional slashes (e.g. admin/calendar-proxy-read) if (!(strpos($name, '/') === false)) { $name = substr($name, 0, strpos($name, '/')); } $user = $this->user_manager->findUserByUsername($name); if ($user === null) { if (!$this->group_manager) { return; } // search in group-manager $group = $this->group_manager->findGroupByName($name); if ($group === null) { return; } if ($getObject === true) { return $group; } return $this->getPrincipalArray($group, true); } if ($getObject === true) { return $user; } return $this->getPrincipalArray($user, true); }