]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSetAclSimple.php
elseif
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSetAclSimple.php
1 <?php // -*-php-*-
2 // $Id$
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         return _("WikiAdminSetAclSimple");
39     }
40
41     function getDescription() {
42         return _("Set simple individual page permissions.");
43     }
44
45     function run($dbi, $argstr, &$request, $basepage) {
46         if ($request->getArg('action') != 'browse') {
47             if ($request->getArg('action') != _("PhpWikiAdministration/SetAclSimple")) {
48                 return $this->disabled(_("Plugin not run: not in browse mode"));
49             }
50         }
51         if (!ENABLE_PAGEPERM) {
52             return $this->disabled("ENABLE_PAGEPERM = false");
53         }
54
55         $args = $this->getArgs($argstr, $request);
56         $this->_args = $args;
57         $this->preSelectS($args, $request);
58
59         $p = $request->getArg('p');
60         $post_args = $request->getArg('admin_setacl');
61         $pages = array();
62         if ($p && !$request->isPost())
63             $pages = $p;
64         elseif ($this->_list)
65             $pages = $this->_list;
66         $header = HTML::fieldset();
67         if ($p && $request->isPost() &&
68             (!empty($post_args['aclliberal']) || !empty($post_args['aclrestricted']))) {
69             // without individual PagePermissions:
70             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
71                 $request->_notAuthorized(WIKIAUTH_ADMIN);
72                 $this->disabled("! user->isAdmin");
73             }
74             if (!empty($post_args['aclliberal'])) {
75                 return $this->setaclPages($request, array_keys($p), $this->liberalPerms());
76             } elseif (!empty($post_args['aclrestricted'])) {
77                 return $this->setaclPages($request, array_keys($p), $this->restrictedPerms());
78             }
79         }
80         if (empty($pages)) {
81             // List all pages to select from.
82             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
83         }
84         $pagelist = new PageList_Selectable($args['info'],
85                                             $args['exclude'],
86                                             array('types' => array(
87                                                   'acl'
88                                                   => new _PageList_Column_acl('acl', _("ACL")))));
89
90         $pagelist->addPageList($pages);
91         $button_label_liberal = _("Set Liberal Access Rights");
92         $button_label_restrictive = _("Set Restrictive Access Rights");
93         $header = $this->setaclForm($header, $pages);
94         $header->pushContent(HTML::legend(_("Select the pages where to change access rights")));
95
96         $buttons = HTML::p(Button('submit:admin_setacl[aclliberal]', $button_label_liberal, 'wikiadmin'),
97                            Button('submit:admin_setacl[aclrestricted]', $button_label_restrictive, 'wikiadmin'));
98         $header->pushContent($buttons);
99
100         return HTML::form(array('action' => $request->getPostURL(),
101                                 'method' => 'post'),
102                           $header,
103                           $pagelist->getContent(),
104                           HiddenInputs($request->getArgs(),
105                                         false,
106                                         array('admin_setacl')),
107                           ENABLE_PAGEPERM
108                           ? ''
109                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
110     }
111
112     /*
113      * acces rights where everyone can edit
114      * _EVERY: view edit list create;
115      * _ADMIN: remove purge dump change;
116      * _OWNER: remove purge dump change;
117      */
118
119     function liberalPerms() {
120
121         $perm = array('view'   => array(ACL_EVERY => true),
122                       'edit'   => array(ACL_EVERY => true),
123                       'create' => array(ACL_EVERY => true),
124                       'list'   => array(ACL_EVERY => true),
125                       'remove' => array(ACL_ADMIN => true,
126                                         ACL_OWNER => true),
127                       'purge'  => array(ACL_ADMIN => true,
128                                         ACL_OWNER => true),
129                       'dump'   => array(ACL_ADMIN => true,
130                                         ACL_OWNER => true),
131                       'change' => array(ACL_ADMIN => true,
132                                         ACL_OWNER => true));
133         return $perm;
134     }
135
136     /*
137      * acces rights where only authenticated users can see pages
138      * _AUTHENTICATED: view edit list create;
139      * _ADMIN: remove purge dump change;
140      * _OWNER: remove purge dump change;
141      * _EVERY: -view -edit -list -create;
142      */
143
144     function restrictedPerms() {
145
146         $perm = array('view'   => array(ACL_AUTHENTICATED => true,
147                                         ACL_EVERY => false),
148                       'edit'   => array(ACL_AUTHENTICATED => true,
149                                         ACL_EVERY => false),
150                       'create' => array(ACL_AUTHENTICATED => true,
151                                         ACL_EVERY => false),
152                       'list'   => array(ACL_AUTHENTICATED => true,
153                                         ACL_EVERY => false),
154                       'remove' => array(ACL_ADMIN => true,
155                                         ACL_OWNER => true),
156                       'purge'  => array(ACL_ADMIN => true,
157                                         ACL_OWNER => true),
158                       'dump'   => array(ACL_ADMIN => true,
159                                         ACL_OWNER => true),
160                       'change' => array(ACL_ADMIN => true,
161                                         ACL_OWNER => true));
162         return $perm;
163     }
164
165     function setaclForm(&$header, $pagehash) {
166
167         $pages = array();
168         foreach ($pagehash as $name => $checked) {
169            if ($checked) $pages[] = $name;
170         }
171
172         $header->pushContent(HTML::strong(_("Selected Pages: ")), HTML::tt(join(', ',$pages)), HTML::br());
173         return $header;
174     }
175 };
176
177 // Local Variables:
178 // mode: php
179 // tab-width: 8
180 // c-basic-offset: 4
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil
183 // End:
184 ?>