2 rcs_id('$Id: WikiAdminSetAcl.php,v 1.11 2004-06-01 15:28:02 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
24 * Set individual PagePermissions
26 * Usage: <?plugin WikiAdminSetAcl ?> or called via WikiAdminSelect
27 * Author: Reini Urban <rurban@x-ray.at>
30 * Doesn't accept yet s=wildcard preselection
31 * Requires PHP 4.2 so far.
33 require_once('lib/PageList.php');
34 require_once('lib/plugin/WikiAdminSelect.php');
36 class WikiPlugin_WikiAdminSetAcl
37 extends WikiPlugin_WikiAdminSelect
40 return _("WikiAdminSetAcl");
43 function getDescription() {
44 return _("Set individual page permissions.");
47 function getVersion() {
48 return preg_replace("/[Revision: $]/", '',
49 "\$Revision: 1.11 $");
52 function getDefaultArguments() {
55 /* Pages to exclude in listing */
57 /* Columns to include in listing */
58 'info' => 'pagename,perm,mtime,owner,author',
60 'sortby' => 'pagename',
65 function setaclPages(&$request, $pages, $acl) {
68 $dbi =& $request->_dbi;
69 // check new_group and new_perm
70 if (isset($acl['_add_group'])) {
71 //add groups with perm
72 foreach ($acl['_add_group'] as $access => $dummy) {
73 $group = $acl['_new_group'][$access];
74 $acl[$access][$group] = isset($acl['_new_perm'][$access]) ? 1 : 0;
76 unset($acl['_add_group']); unset($acl['_new_group']); unset($acl['_new_perm']);
78 if (isset($acl['_del_group'])) {
79 //del groups with perm
80 foreach ($acl['_del_group'] as $access => $del) {
81 while (list($group,$dummy) = each($del))
82 unset($acl[$access][$group]);
84 unset($acl['_del_group']);
86 if ($perm = new PagePermission($acl)) {
88 foreach ($pages as $pagename) {
89 // check if unchanged? we need a deep array_equal
90 $page = $dbi->getPage($pagename);
91 $oldperm = getPagePermissions($page);
93 if ($perm->equal($oldperm->perm)) // (serialize($oldperm->perm) == serialize($perm->perm))
94 $ul->pushContent(HTML::li(fmt("ACL not changed for page '%s'.",$pagename)));
95 elseif (mayAccessPage('change',$pagename)) {
96 setPagePermissions ($page,$perm);
97 $ul->pushContent(HTML::li(fmt("ACL changed for page '%s'.",$pagename)));
100 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",$pagename)));
104 $ul->pushContent(HTML::li(fmt("Invalid ACL")));
109 HTML::p(fmt("%s pages have been changed.",$count)));
112 HTML::p(fmt("No pages changed.")));
116 function run($dbi, $argstr, &$request, $basepage) {
118 // return $this->disabled("WikiAdminSetAcl not yet enabled. Set DEBUG to try it.");
120 $args = $this->getArgs($argstr, $request);
121 $this->_args = $args;
122 if (!empty($args['exclude']))
123 $exclude = explodePageList($args['exclude']);
126 $this->preSelectS(&$args, &$request);
128 $p = $request->getArg('p');
129 $post_args = $request->getArg('admin_setacl');
130 $next_action = 'select';
132 if ($p && !$request->isPost())
134 elseif ($this->_list)
135 $pages = $this->_list;
137 if ($p && $request->isPost() &&
138 !empty($post_args['acl']) && empty($post_args['cancel'])) {
140 // DONE: check individual PagePermissions
142 if (!$request->_user->isAdmin()) {
143 $request->_notAuthorized(WIKIAUTH_ADMIN);
144 $this->disabled("! user->isAdmin");
147 if ($post_args['action'] == 'verify') {
149 $header->pushContent(
150 $this->setaclPages($request, array_keys($p),
151 $request->getArg('acl')));
153 if ($post_args['action'] == 'select') {
154 if (!empty($post_args['acl']))
155 $next_action = 'verify';
156 foreach ($p as $name => $c) {
161 if ($next_action == 'select' and empty($pages)) {
162 // List all pages to select from.
163 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
165 if ($next_action == 'verify') {
166 $args['info'] = "checkbox,pagename,perm,mtime,owner,author";
168 $pagelist = new PageList_Selectable($args['info'],
170 array('types' => array(
172 => new _PageList_Column_perm('perm', _("Permission")),
174 => new _PageList_Column_acl('acl', _("ACL")))));
176 $pagelist->addPageList($pages);
177 if ($next_action == 'verify') {
178 $button_label = _("Yes");
179 $header = $this->setaclForm($header, $post_args, $pages);
180 $header->pushContent(
181 HTML::p(HTML::strong(
182 _("Are you sure you want to permanently change access to the selected files?"))));
185 $button_label = _("SetAcl");
186 $header = $this->setaclForm($header, $post_args, $pages);
187 $header->pushContent(HTML::p(_("Select the pages to change:")));
190 $buttons = HTML::p(Button('submit:admin_setacl[acl]', $button_label, 'wikiadmin'),
191 Button('submit:admin_setacl[cancel]', _("Cancel"), 'button'));
193 return HTML::form(array('action' => $request->getPostURL(),
196 $pagelist->getContent(),
197 HiddenInputs($request->getArgs(),
199 array('admin_setacl')),
200 HiddenInputs(array('admin_setacl[action]' => $next_action)),
204 function setaclForm(&$header, $post_args, $pagehash) {
205 $acl = $post_args['acl'];
206 //$header->pushContent(HTML::p(HTML::em(_("This plugin is currently under development and does not work!"))));
207 //todo: find intersection of all page perms
209 foreach ($pagehash as $name => $checked) {
210 if ($checked) $pages[] = $name;
212 $perm_tree = pagePermissions($name);
213 $table = pagePermissionsAclFormat($perm_tree,!empty($pages));
214 $header->pushContent(HTML::p(fmt("Selected Pages: %s",join(', ',$pages))));
216 ;//$header->pushContent(HTML::pre("Permission tree for $name:\n",print_r($perm_tree,true)));
218 $type = $perm_tree[0];
219 if ($type == 'inherited')
220 $type = sprintf(_("page permission inherited from %s"),$perm_tree[1][0]);
221 elseif ($type == 'page')
222 $type = _("invidual page permission");
223 elseif ($type == 'default')
224 $type = _("default page permission");
225 $header->pushContent(HTML::p(_("Type: "),$type));
226 $header->pushContent(HTML::p(
227 _("Description: Selected Grant checkboxes allow access, unselected checkboxes deny access."),
228 _("To ignore delete the line."),
229 _("To add check 'Add' near the dropdown list.")
231 $header->pushContent(HTML::blockquote($table));
233 // display array of checkboxes for existing perms
234 // and a dropdown for user/group to add perms.
235 // disabled if inherited,
236 // checkbox to disable inheritance,
237 // another checkbox to progate new permissions to all childs (if there exist some)
239 // warn if more pages are selected and they have different perms
240 //$header->pushContent(HTML::input(array('name' => 'admin_setacl[acl]',
241 // 'value' => $post_args['acl'])));
242 $header->pushContent(HTML::br());
243 if (!empty($pages) and DEBUG) {
244 $checkbox = HTML::input(array('type' => 'checkbox',
245 'name' => 'admin_setacl[updatechildren]',
247 if (!empty($post_args['updatechildren'])) $checkbox->setAttr('checked','checked');
248 $header->pushContent($checkbox,
249 _("Propagate new permissions to all subpages?"),
250 HTML::raw(" "),
251 HTML::em(_("(disable individual page permissions, enable inheritance)?")),
252 HTML::em(_("(Currently not working)"))
255 $header->pushContent(HTML::hr(),HTML::p());
260 class _PageList_Column_acl extends _PageList_Column {
261 function _getValue ($page_handle, &$revision_handle) {
262 $perm_tree = pagePermissions($page_handle->_pagename);
263 return pagePermissionsAclFormat($perm_tree);
266 var_dump($perm_array);
267 $xml = ob_get_contents();
274 class _PageList_Column_perm extends _PageList_Column {
275 function _getValue ($page_handle, &$revision_handle) {
276 $perm_array = pagePermissions($page_handle->_pagename);
277 return pagePermissionsSimpleFormat($perm_array,
278 $page_handle->get('author'),
279 $page_handle->get('group'));
282 var_dump($perm_array);
283 $xml = ob_get_contents();
290 // $Log: not supported by cvs2svn $
291 // Revision 1.10 2004/05/27 17:49:06 rurban
292 // renamed DB_Session to DbSession (in CVS also)
293 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
294 // remove leading slash in error message
295 // added force_unlock parameter to File_Passwd (no return on stale locks)
296 // fixed adodb session AffectedRows
297 // added FileFinder helpers to unify local filenames and DATA_PATH names
298 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
300 // Revision 1.9 2004/05/24 17:34:53 rurban
303 // Revision 1.8 2004/05/16 22:32:54 rurban
306 // Revision 1.7 2004/05/16 22:07:35 rurban
307 // check more config-default and predefined constants
308 // various PagePerm fixes:
309 // fix default PagePerms, esp. edit and view for Bogo and Password users
310 // implemented Creator and Owner
311 // BOGOUSERS renamed to BOGOUSER
312 // fixed syntax errors in signin.tmpl
314 // Revision 1.5 2004/04/07 23:13:19 rurban
315 // fixed pear/File_Passwd for Windows
316 // fixed FilePassUser sessions (filehandle revive) and password update
318 // Revision 1.4 2004/03/17 20:23:44 rurban
319 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
321 // Revision 1.3 2004/03/12 13:31:43 rurban
322 // enforce PagePermissions, errormsg if not Admin
324 // Revision 1.2 2004/02/24 04:02:07 rurban
325 // Better warning messages
327 // Revision 1.1 2004/02/23 21:30:25 rurban
328 // more PagePerm stuff: (working against 1.4.0)
329 // ACL editing and simplification of ACL's to simple rwx------ string
338 // c-hanging-comment-ender-p: nil
339 // indent-tabs-mode: nil