2 rcs_id('$Id: WikiAdminSetAcl.php,v 1.7 2004-05-16 22:07:35 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is not yet part of PhpWiki. It does not work yet.
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 * Currently we must be Admin. Later we use PagePermissions authorization.
31 * (require_authority_for_post' => WIKIAUTH_ADMIN)
32 * Requires PHP 4.2 so far.
34 require_once('lib/PageList.php');
35 require_once('lib/plugin/WikiAdminSelect.php');
37 class WikiPlugin_WikiAdminSetAcl
38 extends WikiPlugin_WikiAdminSelect
41 return _("WikiAdminSetAcl");
44 function getDescription() {
45 return _("Set individual page permissions.");
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
53 function getDefaultArguments() {
56 /* Pages to exclude in listing */
58 /* Columns to include in listing */
59 'info' => 'pagename,perm,mtime,owner,author',
61 'sortby' => 'pagename',
66 function setaclPages(&$request, $pages, $acl) {
69 $dbi =& $request->_dbi;
70 // check new_group and new_perm
71 if (isset($acl['_add_group'])) {
72 //add groups with perm
73 foreach ($acl['_add_group'] as $access => $dummy) {
74 $group = $acl['_new_group'][$access];
75 $acl[$access][$group] = isset($acl['_new_perm'][$access]) ? 1 : 0;
77 unset($acl['_add_group']); unset($acl['_new_group']); unset($acl['_new_perm']);
79 if (isset($acl['_del_group'])) {
80 //del groups with perm
81 foreach ($acl['_del_group'] as $access => $del) {
82 while (list($group,$dummy) = each($del))
83 unset($acl[$access][$group]);
85 unset($acl['_del_group']);
87 if ($perm = new PagePermission($acl)) {
89 foreach ($pages as $pagename) {
90 // check if unchanged? we need a deep array_equal
91 $page = $dbi->getPage($pagename);
92 $oldperm = getPagePermissions($page);
94 if ($perm->equal($oldperm->perm)) // (serialize($oldperm->perm) == serialize($perm->perm))
95 $ul->pushContent(HTML::li(fmt("ACL not changed for page '%s'.",$pagename)));
96 elseif (mayAccessPage('change',$pagename)) {
97 setPagePermissions ($page,$perm);
98 $ul->pushContent(HTML::li(fmt("ACL changed for page '%s'.",$pagename)));
101 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",$pagename)));
105 $ul->pushContent(HTML::li(fmt("Invalid ACL")));
110 HTML::p(fmt("%s pages have been changed.",$count)));
113 HTML::p(fmt("No pages changed.")));
117 function run($dbi, $argstr, &$request, $basepage) {
119 // return $this->disabled("WikiAdminSetAcl not yet enabled. Set DEBUG to try it.");
121 $args = $this->getArgs($argstr, $request);
122 $this->_args = $args;
123 if (!empty($args['exclude']))
124 $exclude = explodePageList($args['exclude']);
128 $p = $request->getArg('p');
129 $post_args = $request->getArg('admin_setacl');
130 $next_action = 'select';
132 if ($p && !$request->isPost())
135 if ($p && $request->isPost() &&
136 !empty($post_args['acl']) && empty($post_args['cancel'])) {
138 // DONE: check individual PagePermissions
140 if (!$request->_user->isAdmin()) {
141 $request->_notAuthorized(WIKIAUTH_ADMIN);
142 $this->disabled("! user->isAdmin");
145 if ($post_args['action'] == 'verify') {
147 $header->pushContent(
148 $this->setaclPages($request, array_keys($p),
149 $request->getArg('acl')));
151 if ($post_args['action'] == 'select') {
152 if (!empty($post_args['acl']))
153 $next_action = 'verify';
154 foreach ($p as $name => $c) {
159 if ($next_action == 'select' and empty($pages)) {
160 // List all pages to select from.
161 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
163 if ($next_action == 'verify') {
164 $args['info'] = "checkbox,pagename,perm,mtime,owner,author";
166 $pagelist = new PageList_Selectable($args['info'],
168 array('types' => array(
170 => new _PageList_Column_perm('perm', _("Permission")),
172 => new _PageList_Column_acl('acl', _("ACL")))));
174 $pagelist->addPageList($pages);
175 if ($next_action == 'verify') {
176 $button_label = _("Yes");
177 $header = $this->setaclForm($header, $post_args, $pages);
178 $header->pushContent(
179 HTML::p(HTML::strong(
180 _("Are you sure you want to permanently change the selected files?"))));
183 $button_label = _("SetAcl");
184 $header = $this->setaclForm($header, $post_args, $pages);
185 $header->pushContent(HTML::p(_("Select the pages to change:")));
188 $buttons = HTML::p(Button('submit:admin_setacl[acl]', $button_label, 'wikiadmin'),
189 Button('submit:admin_setacl[cancel]', _("Cancel"), 'button'));
191 return HTML::form(array('action' => $request->getPostURL(),
194 $pagelist->getContent(),
195 HiddenInputs($request->getArgs(),
197 array('admin_setacl')),
198 HiddenInputs(array('admin_setacl[action]' => $next_action,
199 'require_authority_for_post' => WIKIAUTH_ADMIN)),
203 function setaclForm(&$header, $post_args, $pagehash) {
204 $acl = $post_args['acl'];
205 //$header->pushContent(HTML::p(HTML::em(_("This plugin is currently under development and does not work!"))));
206 //todo: find intersection of all page perms
208 foreach ($pagehash as $name => $checked) {
209 if ($checked) $pages[] = $name;
211 $perm_tree = pagePermissions($name);
212 $table = pagePermissionsAclFormat($perm_tree,!empty($pages));
213 $header->pushContent(HTML::p(fmt("Selected Pages: %s",join(', ',$pages))));
215 ;//$header->pushContent(HTML::pre("Permission tree for $name:\n",print_r($perm_tree,true)));
217 $type = $perm_tree[0];
218 if ($type == 'inherited')
219 $type = sprintf(_("page permission inherited from %s"),$perm_tree[1][0]);
220 elseif ($type == 'page')
221 $type = _("invidual page permission");
222 elseif ($type == 'default')
223 $type = _("default page permission");
224 $header->pushContent(HTML::p(_("Type: "),$type));
225 $header->pushContent(HTML::p(
226 _("Description: Selected Grant checkboxes allow access, unselected checkboxes deny access."),
227 _("To ignore delete the line."),
228 _("To add check 'Add' near the dropdown list.")
230 $header->pushContent(HTML::blockquote($table));
232 // display array of checkboxes for existing perms
233 // and a dropdown for user/group to add perms.
234 // disabled if inherited,
235 // checkbox to disable inheritance,
236 // another checkbox to progate new permissions to all childs (if there exist some)
238 // warn if more pages are selected and they have different perms
239 //$header->pushContent(HTML::input(array('name' => 'admin_setacl[acl]',
240 // 'value' => $post_args['acl'])));
241 $header->pushContent(HTML::br());
242 if (!empty($pages)) {
243 $checkbox = HTML::input(array('type' => 'checkbox',
244 'name' => 'admin_setacl[updatechildren]',
246 if (!empty($post_args['updatechildren'])) $checkbox->setAttr('checked','checked');
247 $header->pushContent($checkbox,
248 _("Propagate new permissions to all subpages?"),
249 HTML::raw(" "),
250 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
252 $header->pushContent(HTML::hr(),HTML::p());
257 class _PageList_Column_acl extends _PageList_Column {
258 function _getValue ($page_handle, &$revision_handle) {
259 $perm_tree = pagePermissions($page_handle->_pagename);
260 return pagePermissionsAclFormat($perm_tree);
263 var_dump($perm_array);
264 $xml = ob_get_contents();
271 class _PageList_Column_perm extends _PageList_Column {
272 function _getValue ($page_handle, &$revision_handle) {
273 $perm_array = pagePermissions($page_handle->_pagename);
274 return pagePermissionsSimpleFormat($perm_array,
275 $page_handle->get('author'),
276 $page_handle->get('group'));
279 var_dump($perm_array);
280 $xml = ob_get_contents();
287 // $Log: not supported by cvs2svn $
288 // Revision 1.5 2004/04/07 23:13:19 rurban
289 // fixed pear/File_Passwd for Windows
290 // fixed FilePassUser sessions (filehandle revive) and password update
292 // Revision 1.4 2004/03/17 20:23:44 rurban
293 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
295 // Revision 1.3 2004/03/12 13:31:43 rurban
296 // enforce PagePermissions, errormsg if not Admin
298 // Revision 1.2 2004/02/24 04:02:07 rurban
299 // Better warning messages
301 // Revision 1.1 2004/02/23 21:30:25 rurban
302 // more PagePerm stuff: (working against 1.4.0)
303 // ACL editing and simplification of ACL's to simple rwx------ string
312 // c-hanging-comment-ender-p: nil
313 // indent-tabs-mode: nil