Exemplo n.º 1
0
 /**
  *
  * Load all semantic properties of a page as a hash
  * @param String $pagename
  * @param Integer $namespace
  * @param Boolean $normalizeTitle
  * @return an associative array with the property name as key and property value as value.
  */
 public static function &loadSemanticProperties($pagename, $namespace = NS_MAIN, $normalizeTitle = true)
 {
     //-----normalize title
     $data = null;
     if ($normalizeTitle) {
         $title = MWUtil::normalizePageTitle($pagename, false);
         $di = SMWDIWikiPage::newFromTitle($title);
         $data = smwfGetStore()->getSemanticData($di);
     } else {
         $di = new SMWDIWikiPage($pagename, $namespace, '');
         $data = smwfGetStore()->getSemanticData($di);
     }
     $valuehash = array();
     $diProperties = $data->getProperties();
     foreach ($diProperties as $diProperty) {
         $dvProperty = SMWDataValueFactory::newDataItemValue($diProperty, null);
         $name = null;
         if ($dvProperty->isVisible()) {
             $name = $diProperty->getLabel();
         } elseif ($diProperty->getKey() == '_INST') {
             $name = 'Categories';
         } else {
             continue;
             // skip this line
         }
         if (!$name) {
             continue;
         }
         $values = $data->getPropertyValues($diProperty);
         $vs = array();
         foreach ($values as $di) {
             $dv = SMWDataValueFactory::newDataItemValue($di, $diProperty);
             $vs[] = $dv->getWikiValue();
         }
         if (count($vs) == 1) {
             $valuehash[$name] = $vs[0];
         } else {
             $valuehash[$name] = $vs;
         }
     }
     #error_log(print_r($valuehash, true));
     return $valuehash;
 }
 /**
  * What we should do if the permission action is clicked.
  * @param OutputPage $output
  * @param Article $article
  * @param Title $title
  * @param User $user
  * @param WebRequest $request
  * @Param MediaWiki $wiki
  */
 static function displayACLForm($output, $article, $title, $user, $request, $wiki)
 {
     global $wgParser;
     if ($request->getVal('action') != self::$ACTION) {
         return true;
     }
     $text = "";
     $owner = MWUtil::pageOwner($title, true);
     $text .= "Page owner is '''" . $owner->getName() . "'''.";
     ACL::loadUserGroups();
     $ownergroups = ACL::getUserGroups($owner);
     $ogroups = " Owner belongs to these user groups:";
     if ($ownergroups) {
         foreach ($ownergroups as $g) {
             $ogroups .= $g['name'] . ",";
         }
     } else {
         $ogroups = " Owner does not belong to any user group";
     }
     $text .= $ogroups . "\n\n";
     $permissionpage = ACL_ACL . ":" . $article->getID();
     $permissiontitle = Title::newFromText($permissionpage);
     $ns = $title->getNSText();
     if (!$ns) {
         $ns = "Main";
     }
     $sp = SpecialPage::getPage("FormEdit");
     $sp_url = $sp->getTitle()->getLocalURL();
     $sp_url .= "?form=" . self::$FORM . "&target={$permissionpage}&ACL Page Permission[PageId]={$article->getID()}&ACL Page Permission[PageName]={$title->getDBkey()}&ACL Page Permission[Namespace]={$ns}";
     if ($permissiontitle->exists()) {
         $text .= "[[{$permissionpage}|View Page Permission]]\n\n----\n";
         $output->addWikiText($text);
         $output->addHTML("<a href='{$sp_url}'>Edit permission for this page</a>");
     } else {
         $text .= "No page specific Permission is set.";
         $output->addWikiText($text);
         $output->addHTML("<a href='{$sp_url}'>Set permission for this page</a>");
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  *
  * @return a list . Each list has three props.
  * 	name: the group name.
  *  User: the user this group belongs to.  The value should be a list.
  *  Permission: default permission this group has. The value should be a list.
  *
  */
 public static function loadUserGroups()
 {
     if (self::$allGroups != null) {
         return self::$allGroups;
     }
     $tempgroups = array();
     wfRunHooks("aclLoadGroups", $tempgroups);
     self::$allGroups = array();
     $allpages = MWUtil::allPageInNamespace(ACL_NS_USERGROUP);
     foreach ($allpages as $pagename) {
         $props = SMWUtil::loadSemanticProperties($pagename, ACL_NS_USERGROUP, false);
         //------handle group leader.
         if (!array_key_exists(self::$USERGROUP_GROUPLEADER, $props)) {
             $props[self::$USERGROUP_GROUPLEADER] = "";
         }
         //--------load the users in groups.
         if (array_key_exists(self::$USERGROUP_USERS, $props)) {
             //if there is only one user, convert the string into element of one element.
             if (!is_array($props[self::$USERGROUP_USERS])) {
                 $props[self::$USERGROUP_USERS] = array($props[self::$USERGROUP_USERS]);
             }
         } else {
             $props[self::$USERGROUP_USERS] = array();
         }
         //merge group leader into users
         if ($props[self::$USERGROUP_GROUPLEADER]) {
             array_push($props[self::$USERGROUP_USERS], $props[self::$USERGROUP_GROUPLEADER]);
             $props[self::$USERGROUP_USERS] = array_unique($props[self::$USERGROUP_USERS]);
         }
         //merge the user loading externally.
         if (array_key_exists($pagename, $tempgroups)) {
             $props[self::$USERGROUP_USERS] = array_unique(array_merge($tempgroups[$pagename], $props[self::$USERGROUP_USERS]));
         }
         //handle permission
         $ps = SMWUtil::getSemanticInternalObjects(ACL_USERGROUP . ":" . $pagename, self::$USERGROUP_PERMISSIONS, ACL_NS_USERGROUP);
         $permissions = array();
         foreach ($ps as $p) {
             if (!$p) {
                 continue;
             }
             //convert ACL PERMISSIONS to an array
             if (array_key_exists(self::$PERMISSIONS, $p)) {
                 $p[self::$PERMISSIONS] = array_map("trim", explode(",", $p[self::$PERMISSIONS]));
                 $permissions[] = $p;
             }
         }
         $props[self::$USERGROUP_PERMISSIONS] = $permissions;
         $props['name'] = $pagename;
         self::$allGroups[$pagename] = $props;
     }
     return self::$allGroups;
 }
/**
 *
 * Return all user 
 * @param unknown_type $parser
 */
function allusers(&$parser, $includeSuper = false)
{
    global $ACL_supergroups;
    if ($includeSuper) {
        return implode(",", MWUtil::getAllUsers());
    } else {
        $users = MWUtil::getAllUsers(true);
        $ret = array();
        foreach ($users as $username => $groups) {
            if (array_intersect($groups, $ACL_supergroups)) {
            } else {
                $ret[] = $username;
            }
        }
        sort($ret);
        return implode(",", $ret);
    }
}