]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSetAcl.php
more PagePerm stuff: (working against 1.4.0)
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSetAcl.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSetAcl.php,v 1.1 2004-02-23 21:30:25 rurban Exp $');
3 /*
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is not yet part of PhpWiki. It does not work yet.
7
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.
12
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.
17
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
21  */
22
23 /**
24  * Set individual PagePermissions
25  *
26  * Usage:   <?plugin WikiAdminSetAcl ?> or called via WikiAdminSelect
27  * Author:  Reini Urban <rurban@x-ray.at>
28  *
29  * KNOWN ISSUES:
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.
33  */
34 require_once('lib/PageList.php');
35 require_once('lib/plugin/WikiAdminSelect.php');
36
37 class WikiPlugin_WikiAdminSetAcl
38 extends WikiPlugin_WikiAdminSelect
39 {
40     function getName() {
41         return _("WikiAdminSetAcl");
42     }
43
44     function getDescription() {
45         return _("Set individual page permissions.");
46     }
47
48     function getVersion() {
49         return preg_replace("/[Revision: $]/", '',
50                             "\$Revision: 1.1 $");
51     }
52
53     function getDefaultArguments() {
54         return array(
55                      'p'        => "[]",
56                      'acl'      => false,
57                      /* Pages to exclude in listing */
58                      'exclude'  => '',
59                      /* Columns to include in listing */
60                      'info'     => 'pagename,perm,owner,group,mtime,author',
61                      /* How to sort */
62                      'sortby'   => 'pagename',
63                      'limit'    => 0,
64                      );
65     }
66
67     function setaclPages(&$dbi, &$request, $pages, $acl) {
68         $ul = HTML::ul();
69         $count = 0;
70         if ($perm = new PagePermission($acl)) {
71           foreach ($pages as $name) {
72             if ( $perm->store($dbi->getPage($name)) ) {
73                 /* not yet implemented for all backends */
74                 $ul->pushContent(HTML::li(fmt("set acl for page '%s'.",$name)));
75                 $count++;
76             } else {
77                 $ul->pushContent(HTML::li(fmt("Couldn't setacl page '%s'.", $name)));
78             }
79           }
80         } else {
81             $ul->pushContent(HTML::li(fmt("Invalid acl")));
82         }
83         if ($count) {
84             $dbi->touch();
85             return HTML($ul,
86                         HTML::p(fmt("%s pages have been changed.",$count)));
87         } else {
88             return HTML($ul,
89                         HTML::p(fmt("No pages changed.")));
90         }
91     }
92     
93     function run($dbi, $argstr, &$request, $basepage) {
94         if (!DEBUG)
95             return $this->disabled("setacl not yet implemented");
96         
97         $args = $this->getArgs($argstr, $request);
98         $this->_args = $args;
99         if (!empty($args['exclude']))
100             $exclude = explodePageList($args['exclude']);
101         else
102             $exclude = false;
103
104         $p = $request->getArg('p');
105         $post_args = $request->getArg('admin_setacl');
106         $next_action = 'select';
107         $pages = array();
108         if ($p && !$request->isPost())
109             $pages = $p;
110         if ($p && $request->isPost() && $request->_user->isAdmin()
111             && !empty($post_args['acl']) && empty($post_args['cancel'])) {
112             // FIXME: error message if not admin.
113             if ($post_args['action'] == 'verify') {
114                 // Real action
115                 return $this->setaclPages($dbi, $request, $p, 
116                                           $post_args['acl']);
117             }
118             if ($post_args['action'] == 'select') {
119                 if (!empty($post_args['acl']))
120                     $next_action = 'verify';
121                 foreach ($p as $name) {
122                     $pages[$name] = 1;
123                 }
124             }
125         }
126         if ($next_action == 'select' and empty($pages)) {
127             // List all pages to select from.
128             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
129         }
130         if ($next_action == 'verify') {
131             $args['info'] = "checkbox,pagename,perm,owner,group,mtime,author";
132         }
133         $pagelist = new PageList_Selectable($args['info'], $exclude);
134         $pagelist->addPageList($pages);
135
136         $header = HTML::p();
137         if ($next_action == 'verify') {
138             $button_label = _("Yes");
139             $header = $this->setaclForm($header, $post_args, $pages);
140             $header->pushContent(
141               HTML::p(HTML::strong(
142                                    _("Are you sure you want to permanently change the selected files?"))));
143         }
144         else {
145             $button_label = _("SetAcl");
146             $header = $this->setaclForm($header, $post_args, $pages);
147             $header->pushContent(HTML::p(_("Select the pages to change:")));
148         }
149
150         $buttons = HTML::p(Button('submit:admin_setacl[acl]', $button_label, 'wikiadmin'),
151                            Button('submit:admin_setacl[cancel]', _("Cancel"), 'button'));
152
153         return HTML::form(array('action' => $request->getPostURL(),
154                                 'method' => 'post'),
155                           $header,
156                           $pagelist->getContent(),
157                           HiddenInputs($request->getArgs(),
158                                         false,
159                                         array('admin_setacl')),
160                           HiddenInputs(array('admin_setacl[action]' => $next_action,
161                                              'require_authority_for_post' => WIKIAUTH_ADMIN)),
162                           $buttons);
163     }
164
165     function setaclForm(&$header, $post_args, $pagehash) {
166         $acl = $post_args['acl'];
167         $header->pushContent(HTML::p(HTML::em(_("This plugin is currently under development and does not work!"))));
168         //todo: find intersection of all page perms
169         $pages = array();
170         foreach ($pagehash as $name => $checked) {
171            if ($checked) $pages[] = $name;
172         }
173         $perm_tree = pagePermissions($pagename);
174         $table = pagePermissionsAclFormat($perm_tree,true);
175         $header->pushContent(HTML::p(fmt("Pages: %s",join(',',$pages))));
176         $type = $perm_tree[0];
177         if ($type == 'inherited')
178             $type = sprintf(_("page permission inherited from %s"),$perm_tree[1][0]);
179         elseif ($type == 'page')
180             $type = _("invidual page permission");
181         elseif ($type == 'default')
182             $type = _("default page permission");
183         $header->pushContent(HTML::p(_("Type: "),$type));
184         $header->pushContent(HTML::blockquote($table));
185         //todo:
186         // display array of checkboxes for existing perms
187         // and a dropdown for user/group to add perms.
188         // disabled if inherited, 
189         // checkbox to disable inheritance, 
190         // another checkbox to progate new permissions to all childs (if there exist some)
191         // warn if more pages are selected and they have different perms
192         //$header->pushContent(HTML::input(array('name' => 'admin_setacl[acl]',
193         //                                       'value' => $post_args['acl'])));
194         $header->pushContent(HTML::br());
195         $checkbox = HTML::input(array('type' => 'checkbox',
196                                       'name' => 'admin_setacl[updatechildren]',
197                                       'value' => 1));
198         if ($post_args['updatechildren'])  $checkbox->setAttr('checked','checked');
199         $header->pushContent($checkbox,
200                 _("Propagate new permissions to all subpages?"),
201                 HTML::raw("&nbsp;&nbsp;"),
202                 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
203         $header->pushContent(HTML::hr(),HTML::p());
204         return $header;
205     }
206
207 }
208
209 // $Log: not supported by cvs2svn $
210 //
211
212 // Local Variables:
213 // mode: php
214 // tab-width: 8
215 // c-basic-offset: 4
216 // c-hanging-comment-ender-p: nil
217 // indent-tabs-mode: nil
218 // End:
219 ?>