]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSetAclSimple.php
Update lib/nusoap/nusoap.php to version 0.9.5
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSetAclSimple.php
1 <?php
2
3 /*
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
5  * Copyright 2009-2010 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 /**
25  * Set simple individual PagePermissions
26  *
27  * Usage:   <<WikiAdminSetAclSimple >> or called via WikiAdminSelect
28  * Author:  Marc-Etienne Vargenau, Alcatel-Lucent
29  *
30  */
31
32 require_once 'lib/plugin/WikiAdminSetAcl.php';
33
34 class WikiPlugin_WikiAdminSetAclSimple
35     extends WikiPlugin_WikiAdminSetAcl
36 {
37     function getName()
38     {
39         return _("WikiAdminSetAclSimple");
40     }
41
42     function getDescription()
43     {
44         return _("Set simple individual page permissions.");
45     }
46
47     function run($dbi, $argstr, &$request, $basepage)
48     {
49         if ($request->getArg('action') != 'browse') {
50             if ($request->getArg('action') != _("PhpWikiAdministration/SetAclSimple")) {
51                 return $this->disabled(_("Plugin not run: not in browse mode"));
52             }
53         }
54         if (!ENABLE_PAGEPERM) {
55             return $this->disabled("ENABLE_PAGEPERM = false");
56         }
57
58         $args = $this->getArgs($argstr, $request);
59         $this->_args = $args;
60         $this->preSelectS($args, $request);
61
62         $p = $request->getArg('p');
63         $post_args = $request->getArg('admin_setacl');
64         $pages = array();
65         if ($p && !$request->isPost())
66             $pages = $p;
67         elseif ($this->_list)
68             $pages = $this->_list;
69         $header = HTML::fieldset();
70         if ($p && $request->isPost() &&
71             (!empty($post_args['aclliberal']) || !empty($post_args['aclrestricted']))
72         ) {
73             // without individual PagePermissions:
74             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
75                 $request->_notAuthorized(WIKIAUTH_ADMIN);
76                 $this->disabled("! user->isAdmin");
77             }
78             if (!empty($post_args['aclliberal'])) {
79                 return $this->setaclPages($request, array_keys($p), $this->liberalPerms());
80             } elseif (!empty($post_args['aclrestricted'])) {
81                 return $this->setaclPages($request, array_keys($p), $this->restrictedPerms());
82             }
83         }
84         if (empty($pages)) {
85             // List all pages to select from.
86             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
87         }
88         $pagelist = new PageList_Selectable($args['info'],
89             $args['exclude'],
90             array('types' => array(
91                 'acl'
92                 => new _PageList_Column_acl('acl', _("ACL")))));
93
94         $pagelist->addPageList($pages);
95         $button_label_liberal = _("Set Liberal Access Rights");
96         $button_label_restrictive = _("Set Restrictive Access Rights");
97         $header = $this->setaclForm($header, $pages);
98         $header->pushContent(HTML::legend(_("Select the pages where to change access rights")));
99
100         $buttons = HTML::p(Button('submit:admin_setacl[aclliberal]', $button_label_liberal, 'wikiadmin'),
101             Button('submit:admin_setacl[aclrestricted]', $button_label_restrictive, 'wikiadmin'));
102         $header->pushContent($buttons);
103
104         return HTML::form(array('action' => $request->getPostURL(),
105                 'method' => 'post'),
106             $header,
107             $pagelist->getContent(),
108             HiddenInputs($request->getArgs(),
109                 false,
110                 array('admin_setacl')),
111             ENABLE_PAGEPERM
112                 ? ''
113                 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
114     }
115
116     /*
117      * acces rights where everyone can edit
118      * _EVERY: view edit list create;
119      * _ADMIN: remove purge dump change;
120      * _OWNER: remove purge dump change;
121      */
122
123     function liberalPerms()
124     {
125
126         $perm = array('view' => array(ACL_EVERY => true),
127             'edit' => array(ACL_EVERY => true),
128             'create' => array(ACL_EVERY => true),
129             'list' => array(ACL_EVERY => true),
130             'remove' => array(ACL_ADMIN => true,
131                 ACL_OWNER => true),
132             'purge' => array(ACL_ADMIN => true,
133                 ACL_OWNER => true),
134             'dump' => array(ACL_ADMIN => true,
135                 ACL_OWNER => true),
136             'change' => array(ACL_ADMIN => true,
137                 ACL_OWNER => true));
138         return $perm;
139     }
140
141     /*
142      * acces rights where only authenticated users can see pages
143      * _AUTHENTICATED: view edit list create;
144      * _ADMIN: remove purge dump change;
145      * _OWNER: remove purge dump change;
146      * _EVERY: -view -edit -list -create;
147      */
148
149     function restrictedPerms()
150     {
151
152         $perm = array('view' => array(ACL_AUTHENTICATED => true,
153             ACL_EVERY => false),
154             'edit' => array(ACL_AUTHENTICATED => true,
155                 ACL_EVERY => false),
156             'create' => array(ACL_AUTHENTICATED => true,
157                 ACL_EVERY => false),
158             'list' => array(ACL_AUTHENTICATED => true,
159                 ACL_EVERY => false),
160             'remove' => array(ACL_ADMIN => true,
161                 ACL_OWNER => true),
162             'purge' => array(ACL_ADMIN => true,
163                 ACL_OWNER => true),
164             'dump' => array(ACL_ADMIN => true,
165                 ACL_OWNER => true),
166             'change' => array(ACL_ADMIN => true,
167                 ACL_OWNER => true));
168         return $perm;
169     }
170
171     function setaclForm(&$header, $pagehash)
172     {
173
174         $pages = array();
175         foreach ($pagehash as $name => $checked) {
176             if ($checked) $pages[] = $name;
177         }
178
179         $header->pushContent(HTML::strong(_("Selected Pages: ")), HTML::tt(join(', ', $pages)), HTML::br());
180         return $header;
181     }
182 }
183
184 // Local Variables:
185 // mode: php
186 // tab-width: 8
187 // c-basic-offset: 4
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil
190 // End: