]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/PagePerm.php
support for SetAclSimple
[SourceForge/phpwiki.git] / lib / PagePerm.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PagePerm.php,v 1.20 2004-06-07 18:39:03 rurban Exp $');
3 /*
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24    Permissions per page and action based on current user, 
25    ownership and group membership implemented with ACL's (Access Control Lists),
26    opposed to the simplier unix like ugo:rwx system.
27    The previous system was only based on action and current user. (lib/main.php)
28
29    Permissions may be inherited from its parent pages, a optional the 
30    optional master page ("."), and predefined default permissions, if "." 
31    is not defined.
32    Pagenames starting with "." have special default permissions.
33    For Authentication see WikiUserNew.php, WikiGroup.php and main.php
34    Page Permissions are in PhpWiki since v1.3.9 and enabled since v1.4.0
35
36    This file might replace the following functions from main.php:
37      Request::_notAuthorized($require_level)
38        display the denied message and optionally a login form 
39        to gain higher privileges
40      Request::getActionDescription($action)
41        helper to localize the _notAuthorized message per action, 
42        when login is tried.
43      Request::getDisallowedActionDescription($action)
44        helper to localize the _notAuthorized message per action, 
45        when it aborts
46      Request::requiredAuthority($action)
47        returns the needed user level
48        has a hook for plugins on POST
49      Request::requiredAuthorityForAction($action)
50        just returns the level per action, will be replaced with the 
51        action + page pair
52
53      The defined main.php actions map to simplier access types:
54        browse => view
55        edit   => edit
56        create => edit or create
57        remove => remove
58        rename => change
59        store prefs => change
60        list in PageList => list
61 */
62
63 /* Symbolic special ACL groups. Untranslated to be stored in page metadata*/
64 define('ACL_EVERY',        '_EVERY');
65 define('ACL_ANONYMOUS',    '_ANONYMOUS');
66 define('ACL_BOGOUSER',     '_BOGOUSER');
67 define('ACL_HASHOMEPAGE',  '_HASHOMEPAGE');
68 define('ACL_SIGNED',       '_SIGNED');
69 define('ACL_AUTHENTICATED','_AUTHENTICATED');
70 define('ACL_ADMIN',        '_ADMIN');
71 define('ACL_OWNER',        '_OWNER');
72 define('ACL_CREATOR',      '_CREATOR');
73
74 // Return an page permissions array for this page.
75 // To provide ui helpers to view and change page permissions:
76 //   <tr><th>Group</th><th>Access</th><th>Allow or Forbid</th></tr>
77 //   <tr><td>$group</td><td>_($access)</td><td> [ ] </td></tr>
78 function pagePermissions($pagename) {
79     global $request;
80     $page = $request->getPage($pagename);
81     // Page not found (new page); returned inherited permissions, to be displayed in gray
82     if (! $page->exists() ) {
83         if ($pagename == '.') // stop recursion
84             return array('default',new PagePermission());
85         else {
86             return array('inherited',pagePermissions(getParentPage($pagename)));
87         }
88     } elseif ($perm = getPagePermissions($page)) {
89         return array('page',$perm);
90     // or no permissions defined; returned inherited permissions, to be displayed in gray
91     } else {
92         return array('inherited',pagePermissions(getParentPage($pagename)));
93     }
94 }
95
96 function pagePermissionsSimpleFormat($perm_tree,$owner,$group=false) {
97     list($type,$perm) = pagePermissionsAcl($perm_tree[0], $perm_tree);
98     /*
99     $type = $perm_tree[0];
100     $perm = pagePermissionsAcl($perm_tree);
101     if (is_object($perm_tree[1]))
102         $perm = $perm_tree[1];
103     elseif (is_array($perm_tree[1])) {
104         $perm_tree = pagePermissionsSimpleFormat($perm_tree[1],$owner,$group);
105         if (isa($perm_tree[1],'pagepermission'))
106             $perm = $perm_tree[1];
107         elseif (isa($perm_tree,'htmlelement'))
108             return $perm_tree;
109     }
110     */
111     if ($type == 'page')
112         return HTML::tt(HTML::bold($perm->asRwxString($owner,$group).'+'));
113     elseif ($type == 'default')
114         return HTML::tt($perm->asRwxString($owner,$group));
115     elseif ($type == 'inherited') {
116         return HTML::tt(array('class'=>'inherited','style'=>'color:#aaa;'),
117                         $perm->asRwxString($owner,$group));
118     }
119 }
120
121 function pagePermissionsAcl($type,$perm_tree) {
122     $perm = $perm_tree[1];
123     while (!is_object($perm)) {
124         $perm_tree = pagePermissionsAcl($type, $perm);
125         $perm = $perm_tree[1];
126     }
127     return array($type,$perm);
128 }
129
130 // view => who
131 // edit => who
132 function pagePermissionsAclFormat($perm_tree, $editable=false) {
133     list($type,$perm) = pagePermissionsAcl($perm_tree[0], $perm_tree);
134     if ($editable)
135         return $perm->asEditableTable($type);
136     else
137         return $perm->asTable($type);
138 }
139
140 /**
141  * Check permission per page.
142  * Returns true or false.
143  */
144 function mayAccessPage ($access, $pagename) {
145     if (ENABLE_PAGEPERM)
146         return _requiredAuthorityForPagename($access, $pagename);
147     else
148         return true;
149 }
150
151 /** 
152  * Check the permissions for the current action.
153  * Walk down the inheritance tree. Collect all permissions until 
154  * the minimum required level is gained, which is not 
155  * overruled by more specific forbid rules.
156  * Todo: cache result per access and page in session?
157  */
158 function requiredAuthorityForPage ($action) {
159     $auth = _requiredAuthorityForPagename(action2access($action),
160                                           $GLOBALS['request']->getArg('pagename'));
161     assert($auth !== -1);
162     if ($auth)
163         return $GLOBALS['request']->_user->_level;
164     else
165         return WIKIAUTH_UNOBTAINABLE;
166 }
167
168 // Translate action or plugin to the simplier access types:
169 function action2access ($action) {
170     global $request;
171     switch ($action) {
172     case 'browse':
173     case 'viewsource':
174     case 'diff':
175     case 'select':
176     case 'xmlrpc':
177     case 'search':
178     case 'pdf':
179         return 'view';
180     case 'zip':
181     case 'ziphtml':
182     case 'dumpserial':
183     case 'dumphtml':
184         return 'dump';
185     case 'edit':
186         return 'edit';
187     case 'create':
188         $page = $request->getPage();
189         $current = $page->getCurrentRevision();
190         if ($current->hasDefaultContents())
191             return 'edit';
192         else
193             return 'view'; 
194         break;
195     case 'upload':
196     case 'loadfile': 
197         // probably create/edit but we cannot check all page permissions, can we?
198     case 'remove':
199     case 'lock':
200     case 'unlock':
201     case 'upgrade':
202             return 'change';
203     default:
204         //Todo: Plugins should be able to override its access type
205         if (isWikiWord($action))
206             return 'view';
207         else
208             return 'change';
209         break;
210     }
211 }
212
213 // Recursive helper to do the real work
214 function _requiredAuthorityForPagename($access, $pagename) {
215     global $request;
216     $page = $request->getPage($pagename);
217     // Page not found; check against default permissions
218     if (! $page->exists() ) {
219         $perm = new PagePermission();
220         return ($perm->isAuthorized($access, $request->_user) === true);
221     }
222     // no ACL defined; check for special dotfile or walk down
223     if (! ($perm = getPagePermissions($page))) { 
224         if ($pagename[0] == '.') {
225             $perm = new PagePermission(PagePermission::dotPerms());
226             return ($perm->isAuthorized($access, $request->_user) === true);
227         }
228         return _requiredAuthorityForPagename($access, getParentPage($pagename));
229     }
230     // ACL defined; check if isAuthorized returns true or false or undecided
231     $authorized = $perm->isAuthorized($access, $request->_user);
232     if ($authorized != -1) // -1 for undecided
233         return $authorized;
234     else
235         return _requiredAuthorityForPagename($access, getParentPage($pagename));
236 }
237
238 /**
239  * @param  string $pagename   page from which the parent page is searched.
240  * @return string parent      pagename or the (possibly pseudo) dot-pagename.
241  */
242 function getParentPage($pagename) {
243     if (isSubPage($pagename)) {
244         return subPageSlice($pagename,0);
245     } else {
246         return '.';
247     }
248 }
249
250 // Read the ACL from the page
251 // Done: Not existing pages should NOT be queried. 
252 // Check the parent page instead and don't take the default ACL's
253 function getPagePermissions ($page) {
254     if ($hash = $page->get('perm'))  // hash => object
255         return new PagePermission(unserialize($hash));
256     else 
257         return false;
258 }
259
260 // Store the ACL in the page
261 function setPagePermissions ($page,$perm) {
262     $perm->store($page);
263 }
264
265 function getAccessDescription($access) {
266     static $accessDescriptions;
267     if (! $accessDescriptions) {
268         $accessDescriptions = array(
269                                     'list'     => _("List this page and all subpages"),
270                                     'view'     => _("View this page and all subpages"),
271                                     'edit'     => _("Edit this page and all subpages"),
272                                     'create'   => _("Create a new (sub)page"),
273                                     'dump'     => _("Download the page contents"),
274                                     'change'   => _("Change page attributes"),
275                                     'remove'   => _("Remove this page"),
276                                     );
277     }
278     if (in_array($access, array_keys($accessDescriptions)))
279         return $accessDescriptions[$access];
280     else
281         return $access;
282 }
283
284 // from php.net docs
285 function array_diff_assoc_recursive($array1, $array2) {
286     foreach ($array1 as $key => $value) {
287          if (is_array($value)) {
288              if (!is_array($array2[$key])) {
289                  $difference[$key] = $value;
290              } else {
291                  $new_diff = array_diff_assoc_recursive($value, $array2[$key]);
292                  if ($new_diff != false) {
293                      $difference[$key] = $new_diff;
294                  } 
295              }
296          } elseif(!isset($array2[$key]) || $array2[$key] != $value) {
297              $difference[$key] = $value;
298          }
299     }
300     return !isset($difference) ? 0 : $difference;
301 }
302
303 /**
304  * The ACL object per page. It is stored in a page, but can also 
305  * be merged with ACL's from other pages or taken from the master (pseudo) dot-file.
306  *
307  * A hash of "access" => "requires" pairs.
308  *   "access"   is a shortcut for common actions, which map to main.php actions
309  *   "requires" required username or groupname or any special group => true or false
310  *
311  * Define any special rules here, like don't list dot-pages.
312  */ 
313 class PagePermission {
314     var $perm;
315
316     function PagePermission($hash = array()) {
317         $this->_group = &WikiGroup::getGroup($GLOBALS['request']);
318         if (is_array($hash) and !empty($hash)) {
319             $accessTypes = $this->accessTypes();
320             foreach ($hash as $access => $requires) {
321                 if (in_array($access, $accessTypes))
322                     $this->perm[$access] = $requires;
323                 else
324                     trigger_error(sprintf(_("Unsupported ACL access type %s ignored."), $access),
325                                   E_USER_WARNING);
326             }
327         } else {
328             // set default permissions, the so called dot-file acl's
329             $this->perm = $this->defaultPerms();
330         }
331         return $this;
332     }
333
334     /**
335      * The workhorse to check the user against the current ACL pairs.
336      * Must translate the various special groups to the actual users settings 
337      * (userid, group membership).
338      */
339     function isAuthorized($access,$user) {
340         if (!empty($this->perm{$access})) {
341             foreach ($this->perm[$access] as $group => $bool) {
342                 if ($this->isMember($user,$group)) {
343                     return $bool;
344                 }
345             }
346         }
347         return -1; // undecided
348     }
349
350     /**
351      * Translate the various special groups to the actual users settings 
352      * (userid, group membership).
353      */
354     function isMember($user, $group) {
355         global $request;
356         if ($group === ACL_EVERY) return true;
357         if (!isset($this->_group)) $member =& WikiGroup::getGroup($request);
358         else $member =& $this->_group;
359         //$user = & $request->_user;
360         if ($group === ACL_ADMIN)   // WIKI_ADMIN or member of _("Administrators")
361             return $user->isAdmin() or 
362                    ($user->isAuthenticated() and 
363                    $member->isMember(GROUP_ADMIN));
364         if ($group === ACL_ANONYMOUS) 
365             return ! $user->isSignedIn();
366         if ($group === ACL_BOGOUSER)
367             if (ENABLE_USER_NEW)
368                 return isa($user,'_BogoUser') or 
369                       (isWikiWord($user->_userid) and $user->_level >= WIKIAUTH_BOGO);
370             else return isWikiWord($user->UserName());
371         if ($group === ACL_HASHOMEPAGE)
372             return $user->hasHomePage();
373         if ($group === ACL_SIGNED)
374             return $user->isSignedIn();
375         if ($group === ACL_AUTHENTICATED)
376             return $user->isAuthenticated();
377         if ($group === ACL_OWNER) {
378             $page = $request->getPage();
379             return ($user->isAuthenticated() and 
380                     $page->getOwner() === $user->UserName());
381         }
382         if ($group === ACL_CREATOR) {
383             $page = $request->getPage();
384             return ($user->isAuthenticated() and 
385                     $page->getCreator() === $user->UserName());
386         }
387         /* Or named groups or usernames.
388            Note: We don't seperate groups and users here. 
389            Users overrides groups with the same name. 
390         */
391         return $user->UserName() === $group or
392                $member->isMember($group);
393     }
394
395     /**
396      * returns hash of default permissions.
397      * check if the page '.' exists and returns this instead.
398      */
399     function defaultPerms() {
400         //Todo: check for the existance of '.' and take this instead.
401         //Todo: honor more config.ini auth settings here
402         $perm = array('view'   => array(ACL_EVERY => true),
403                       'edit'   => array(ACL_EVERY => true),
404                       'create' => array(ACL_EVERY => true),
405                       'list'   => array(ACL_EVERY => true),
406                       'remove' => array(ACL_ADMIN => true,
407                                         ACL_OWNER => true),
408                       'change' => array(ACL_ADMIN => true,
409                                         ACL_OWNER => true));
410         if (ZIPDUMP_AUTH)
411             $perm['dump'] = array(ACL_ADMIN => true,
412                                   ACL_OWNER => true);
413         else
414             $perm['dump'] = array(ACL_EVERY => true);
415         // view:
416         if (!ALLOW_ANON_USER) {
417             if (!ALLOW_USER_PASSWORDS) 
418                 $perm['view'] = array(ACL_SIGNED => true);
419             else                
420                 $perm['view'] = array(ACL_AUTHENTICATED => true);
421             $perm['view'][ACL_BOGOUSER] = ALLOW_BOGO_LOGIN ? true : false;
422         }
423         // edit:
424         if (!ALLOW_ANON_EDIT) {
425             if (!ALLOW_USER_PASSWORDS) 
426                 $perm['edit'] = array(ACL_SIGNED => true);
427             else                
428                 $perm['edit'] = array(ACL_AUTHENTICATED => true);
429             $perm['edit'][ACL_BOGOUSER] = ALLOW_BOGO_LOGIN ? true : false;
430             $perm['create'] = $perm['edit'];
431         }
432         return $perm;
433     }
434
435     function sanify() {
436         foreach ($this->perm as $access => $groups) {
437             foreach ($groups as $group => $bool) {
438                 $this->perm[$access][$group] = (boolean) $bool;
439             }
440         }
441     }
442
443     /**
444      * do a recursive comparison
445      */
446     function equal($otherperm) {
447         $diff = array_diff_assoc_recursive($this->perm, $otherperm);
448         return empty($diff);
449     }
450     
451     /**
452      * returns list of all supported access types.
453      */
454     function accessTypes() {
455         return array_keys(PagePermission::defaultPerms());
456     }
457
458     /**
459      * special permissions for dot-files, beginning with '.'
460      * maybe also for '_' files?
461      */
462     function dotPerms() {
463         $def = array(ACL_ADMIN => true,
464                      ACL_OWNER => true);
465         $perm = array();
466         foreach (PagePermission::accessTypes() as $access) {
467             $perm[$access] = $def;
468         }
469         return $perm;
470     }
471
472     /**
473      *  dead code. not needed inside the object. see getPagePermissions($page)
474      */
475     function retrieve($page) {
476         $hash = $page->get('perm');
477         if ($hash)  // hash => object
478             $perm = new PagePermission(unserialize($hash));
479         else 
480             $perm = new PagePermission();
481         $perm->sanify();
482         return $perm;
483     }
484
485     function store($page) {
486         // object => hash
487         $this->sanify();
488         return $page->set('perm',serialize($this->perm));
489     }
490
491     function groupName ($group) {
492         if ($group[0] == '_') return constant("GROUP".$group);
493         else return $group;
494     }
495     
496     /* type: page, default, inherited */
497     function asTable($type) {
498         $table = HTML::table();
499         foreach ($this->perm as $access => $perms) {
500             $td = HTML::table(array('class' => 'cal','valign' => 'top'));
501             foreach ($perms as $group => $bool) {
502                 $td->pushContent(HTML::tr(HTML::td(array('align'=>'right'),$group),
503                                                    HTML::td($bool ? '[X]' : '[ ]')));
504             }
505             $table->pushContent(HTML::tr(array('valign' => 'top'),
506                                          HTML::td($access),HTML::td($td)));
507         }
508         if ($type == 'default')
509             $table->setAttr('style','border: dotted thin black; background-color:#eee;');
510         elseif ($type == 'inherited')
511             $table->setAttr('style','border: dotted thin black; background-color:#ddd;');
512         elseif ($type == 'page')
513             $table->setAttr('style','border: solid thin black; font-weight: bold;');
514         return $table;
515     }
516     
517     /* type: page, default, inherited */
518     function asEditableTable($type) {
519         global $Theme;
520         if (!isset($this->_group)) { 
521             $this->_group =& WikiGroup::getGroup($GLOBALS['request']);
522         }
523         $table = HTML::table();
524         $table->pushContent(HTML::tr(
525                                      HTML::th(array('align' => 'left'),
526                                               _("Access")),
527                                      HTML::th(array('align'=>'right'),
528                                               _("Group/User")),
529                                      HTML::th(_("Grant")),
530                                      HTML::th(_("Del/+")),
531                                      HTML::th(_("Description"))));
532         
533         $allGroups = $this->_group->_specialGroups();
534         foreach ($this->_group->getAllGroupsIn() as $group) {
535             if (!in_array($group,$this->_group->specialGroups()))
536                 $allGroups[] = $group;
537         }
538         //array_unique(array_merge($this->_group->getAllGroupsIn(),
539         $deletesrc = $Theme->_findData('images/delete.png');
540         $addsrc = $Theme->_findData('images/add.png');
541         $nbsp = HTML::raw('&nbsp;');
542         foreach ($this->perm as $access => $groups) {
543             //$permlist = HTML::table(array('class' => 'cal','valign' => 'top'));
544             $first_only = true;
545             $newperm = HTML::input(array('type' => 'checkbox',
546                                          'name' => "acl[_new_perm][$access]",
547                                          'value' => 1));
548             $addbutton = HTML::input(array('type' => 'checkbox',
549                                            'name' => "acl[_add_group][$access]",
550                                            //'src'  => $addsrc,
551                                            //'alt'   => "Add",
552                                            'title' => _("Add this ACL"),
553                                            'value' => 1));
554             $newgroup = HTML::select(array('name' => "acl[_new_group][$access]",
555                                            'style'=> 'text-align: right;',
556                                            'size' => 1));
557             foreach ($allGroups as $groupname) {
558                 if (!isset($groups[$groupname]))
559                     $newgroup->pushContent(HTML::option(array('value' => $groupname),
560                                                         $this->groupName($groupname)));
561             }
562             if (empty($groups)) {
563                 $addbutton->setAttr('checked','checked');
564                 $newperm->setAttr('checked','checked');
565                 $table->pushContent(
566                     HTML::tr(array('valign' => 'top'),
567                              HTML::td(HTML::strong($access.":")),
568                              HTML::td($newgroup),
569                              HTML::td($nbsp,$newperm),
570                              HTML::td($nbsp,$addbutton),
571                              HTML::td(HTML::em(getAccessDescription($access)))));
572             }
573             foreach ($groups as $group => $bool) {
574                 $checkbox = HTML::input(array('type' => 'checkbox',
575                                               'name' => "acl[$access][$group]",
576                                               'title' => _("Allow / Deny"),
577                                               'value' => 1));
578                 if ($bool) $checkbox->setAttr('checked','checked');
579                 $checkbox = HTML(HTML::input(array('type' => 'hidden',
580                                                    'name' => "acl[$access][$group]",
581                                                    'value' => 0)),
582                                  $checkbox);
583                 $deletebutton = HTML::input(array('type' => 'checkbox',
584                                                   'name' => "acl[_del_group][$access][$group]",
585                                                   'style' => 'background: #aaa url('.$deletesrc.')',
586                                                   //'src'  => $deletesrc,
587                                                   //'alt'   => "Del",
588                                                   'title' => _("Delete this ACL"),
589                                                   'value' => 1));
590                 if ($first_only) {
591                     $table->pushContent(
592                         HTML::tr(
593                                  HTML::td(HTML::strong($access.":")),
594                                  HTML::td(array('class' => 'cal-today','align'=>'right'),
595                                           HTML::strong($this->groupName($group))),
596                                  HTML::td(array('align'=>'center'),$nbsp,$checkbox),
597                                  HTML::td(array('align'=>'right','style' => 'background: #aaa url('.$deletesrc.') no-repeat'),$deletebutton),
598                                  HTML::td(HTML::em(getAccessDescription($access)))));
599                     $first_only = false;
600                 } else {
601                     $table->pushContent(
602                         HTML::tr(
603                                  HTML::td(),
604                                  HTML::td(array('class' => 'cal-today','align'=>'right'),
605                                           HTML::strong($this->groupName($group))),
606                                  HTML::td(array('align'=>'center'),$nbsp,$checkbox),
607                                  HTML::td(array('align'=>'right','style' => 'background: #aaa url('.$deletesrc.') no-repeat'),$deletebutton),
608                                  HTML::td()));
609                 }
610             }
611             if (!empty($groups))
612                 $table->pushContent(
613                     HTML::tr(array('valign' => 'top'),
614                              HTML::td(array('align'=>'right'),_("add ")),
615                              HTML::td($newgroup),
616                              HTML::td(array('align'=>'center'),$nbsp,$newperm),
617                              HTML::td(array('align'=>'right','style' => 'background: #ccc url('.$addsrc.') no-repeat'),$addbutton),
618                              HTML::td(HTML::small(_("Check to add this Acl")))));
619         }
620         if ($type == 'default')
621             $table->setAttr('style','border: dotted thin black; background-color:#eee;');
622         elseif ($type == 'inherited')
623             $table->setAttr('style','border: dotted thin black; background-color:#ddd;');
624         elseif ($type == 'page')
625             $table->setAttr('style','border: solid thin black; font-weight: bold;');
626         return $table;
627     }
628
629     // Print ACL as lines of [+-]user[,group,...]:access[,access...]
630     // Seperate acl's by whitespace (here "\n", but " " is also acceptable on reading)
631     // See http://opag.ca/wiki/HelpOnAccessControlLists
632     // As used by WikiAdminSetAclSimple
633     function asAclLines($owner,$group=false) {
634         $s = '';
635         foreach ($this->perm as $access => $groups) {
636             // TODO: unify groups for same access+bool
637             //    +CREATOR,OWNER:view
638             // TODO: unify access for same groups+bool
639             //    +OWNER:view,edit
640             foreach ($groups as $group => $bool) {
641                 $s .= ($bool?'+':'-').$this->groupName($group).':'.$access."\n";
642             }
643         }
644         return $s;
645     }
646
647
648     // This is just a bad hack for testing.
649     // Simplify the ACL to a unix-like "rwx------+" string
650     // See getfacl(8)
651     function asRwxString($owner,$group=false) {
652         global $request;
653         // simplify object => rwxrw---x+ string as in cygwin (+ denotes additional ACLs)
654         $perm =& $this->perm;
655         // get effective user and group
656         $s = '---------+';
657         if (isset($perm['view'][$owner]) or 
658             (isset($perm['view'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
659             $s[0] = 'r';
660         if (isset($perm['edit'][$owner]) or 
661             (isset($perm['edit'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
662             $s[1] = 'w';
663         if (isset($perm['change'][$owner]) or 
664             (isset($perm['change'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
665             $s[2] = 'x';
666         if (!empty($group)) {
667             if (isset($perm['view'][$group]) or 
668                 (isset($perm['view'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
669                 $s[3] = 'r';
670             if (isset($perm['edit'][$group]) or 
671                 (isset($perm['edit'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
672                 $s[4] = 'w';
673             if (isset($perm['change'][$group]) or 
674                 (isset($perm['change'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
675                 $s[5] = 'x';
676         }
677         if (isset($perm['view'][ACL_EVERY]) or 
678             (isset($perm['view'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
679             $s[6] = 'r';
680         if (isset($perm['edit'][ACL_EVERY]) or 
681             (isset($perm['edit'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
682             $s[7] = 'w';
683         if (isset($perm['change'][ACL_EVERY]) or 
684             (isset($perm['change'][ACL_AUTHENTICATED]) and $request->_user->isAuthenticated()))
685             $s[8] = 'x';
686         return $s;
687     }
688 }
689
690 // $Log: not supported by cvs2svn $
691 // Revision 1.19  2004/06/06 17:12:28  rurban
692 // fixed PagePerm non-object problem (mayAccessPage), also bug #967150
693 //
694 // Revision 1.18  2004/05/27 17:49:05  rurban
695 // renamed DB_Session to DbSession (in CVS also)
696 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
697 // remove leading slash in error message
698 // added force_unlock parameter to File_Passwd (no return on stale locks)
699 // fixed adodb session AffectedRows
700 // added FileFinder helpers to unify local filenames and DATA_PATH names
701 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
702 //
703 // Revision 1.17  2004/05/16 23:10:44  rurban
704 // update_locale wrongly resetted LANG, which broke japanese.
705 // japanese now correctly uses EUC_JP, not utf-8.
706 // more charset and lang headers to help the browser.
707 //
708 // Revision 1.16  2004/05/16 22:32:53  rurban
709 // setacl icons
710 //
711 // Revision 1.15  2004/05/16 22:07:35  rurban
712 // check more config-default and predefined constants
713 // various PagePerm fixes:
714 //   fix default PagePerms, esp. edit and view for Bogo and Password users
715 //   implemented Creator and Owner
716 //   BOGOUSERS renamed to BOGOUSER
717 // fixed syntax errors in signin.tmpl
718 //
719 // Revision 1.14  2004/05/15 22:54:49  rurban
720 // fixed important WikiDB bug with DEBUG > 0: wrong assertion
721 // improved SetAcl (works) and PagePerms, some WikiGroup helpers.
722 //
723 // Revision 1.13  2004/05/15 19:48:33  rurban
724 // fix some too loose PagePerms for signed, but not authenticated users
725 //  (admin, owner, creator)
726 // no double login page header, better login msg.
727 // moved action_pdf to lib/pdf.php
728 //
729 // Revision 1.12  2004/05/04 22:34:25  rurban
730 // more pdf support
731 //
732 // Revision 1.11  2004/05/02 21:26:38  rurban
733 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
734 //   because they will not survive db sessions, if too large.
735 // extended action=upgrade
736 // some WikiTranslation button work
737 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
738 // some temp. session debug statements
739 //
740 // Revision 1.10  2004/04/29 22:32:56  zorloc
741 // Slightly more elegant fix.  Instead of WIKIAUTH_FORBIDDEN, the current user's level + 1 is returned on a false.
742 //
743 // Revision 1.9  2004/04/29 17:18:19  zorloc
744 // Fixes permission failure issues.  With PagePermissions and Disabled Actions when user did not have permission WIKIAUTH_FORBIDDEN was returned.  In WikiUser this was ok because WIKIAUTH_FORBIDDEN had a value of 11 -- thus no user could perform that action.  But WikiUserNew has a WIKIAUTH_FORBIDDEN value of -1 -- thus a user without sufficent permission to do anything.  The solution is a new high value permission level (WIKIAUTH_UNOBTAINABLE) to be the default level for access failure.
745 //
746 // Revision 1.8  2004/03/14 16:24:35  rurban
747 // authenti(fi)cation spelling
748 //
749 // Revision 1.7  2004/02/28 22:25:07  rurban
750 // First PagePerm implementation:
751 //
752 // $Theme->setAnonEditUnknownLinks(false);
753 //
754 // Layout improvement with dangling links for mostly closed wiki's:
755 // If false, only users with edit permissions will be presented the
756 // special wikiunknown class with "?" and Tooltip.
757 // If true (default), any user will see the ?, but will be presented
758 // the PrintLoginForm on a click.
759 //
760 // Revision 1.6  2004/02/24 15:20:05  rurban
761 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
762 //
763 // Revision 1.5  2004/02/23 21:30:25  rurban
764 // more PagePerm stuff: (working against 1.4.0)
765 //   ACL editing and simplification of ACL's to simple rwx------ string
766 //   not yet working.
767 //
768 // Revision 1.4  2004/02/12 13:05:36  rurban
769 // Rename functional for PearDB backend
770 // some other minor changes
771 // SiteMap comes with a not yet functional feature request: includepages (tbd)
772 //
773 // Revision 1.3  2004/02/09 03:58:12  rurban
774 // for now default DB_SESSION to false
775 // PagePerm:
776 //   * not existing perms will now query the parent, and not
777 //     return the default perm
778 //   * added pagePermissions func which returns the object per page
779 //   * added getAccessDescription
780 // WikiUserNew:
781 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
782 //   * force init of authdbh in the 2 db classes
783 // main:
784 //   * fixed session handling (not triple auth request anymore)
785 //   * don't store cookie prefs with sessions
786 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
787 //
788 // Revision 1.2  2004/02/08 13:17:48  rurban
789 // This should be the functionality. Needs testing and some minor todos.
790 //
791 // Revision 1.1  2004/02/08 12:29:30  rurban
792 // initial version, not yet hooked into lib/main.php
793 //
794 //
795
796 // Local Variables:
797 // mode: php
798 // tab-width: 8
799 // c-basic-offset: 4
800 // c-hanging-comment-ender-p: nil
801 // indent-tabs-mode: nil
802 // End:
803 ?>