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