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