]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChmod.php
Better warning messages
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChmod.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminChmod.php,v 1.3 2004-02-24 04:02:06 rurban Exp $');
3 /*
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is not yet part of PhpWiki. It doesn't 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, simplifying effective ACLs to 
25  * unix-like rwxr--r--+ permissions. (as in cygwin)
26  *
27  * Usage:   <?plugin WikiAdminChmod ?> or called via WikiAdminSelect
28  * Author:  Reini Urban <rurban@x-ray.at>
29  *
30  * KNOWN ISSUES:
31  * Currently we must be Admin. Later we use PagePermissions authorization.
32  *   (require_authority_for_post' => WIKIAUTH_ADMIN)
33  * Requires PHP 4.2 so far.
34  */
35 require_once('lib/PageList.php');
36 require_once('lib/plugin/WikiAdminSelect.php');
37
38 class WikiPlugin_WikiAdminChmod
39 extends WikiPlugin_WikiAdminSelect
40 {
41     function getName() {
42         return _("WikiAdminChmod");
43     }
44
45     function getDescription() {
46         return _("Set individual page permissions.");
47     }
48
49     function getVersion() {
50         return preg_replace("/[Revision: $]/", '',
51                             "\$Revision: 1.3 $");
52     }
53
54     function getDefaultArguments() {
55         return array(
56                      /* Pages to exclude in listing */
57                      'exclude'  => '',
58                      /* Columns to include in listing */
59                      'info'     => 'pagename,perm,mtime,author',
60                      /* How to sort */
61                      'sortby'   => 'pagename',
62                      'limit'    => 0,
63                      );
64     }
65
66     // todo: change permstring to some kind default ACL hash. See PagePermission class
67     function chmodHelper($permstring) {
68         $perm = array();
69         return $perm;
70     }
71
72     function chmodPages(&$dbi, &$request, $pages, $permstring) {
73         $ul = HTML::ul();
74         $count = 0;
75         $acl = chmodHelper($permstring);
76         if ($perm = new PagePermission($acl)) {
77             foreach ($pages as $name) {
78                 if ( $perm->store($dbi->getPage($name)) ) {
79                     $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $perm)));
80                     $count++;
81                 } else {
82                     $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $perm)));
83                 }
84             }
85         } else {
86             $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
87         }
88         if ($count) {
89             $dbi->touch();
90             return HTML($ul,
91                         HTML::p(fmt("%s pages have been changed.",$count)));
92         } else {
93             return HTML($ul,
94                         HTML::p(fmt("No pages changed.")));
95         }
96     }
97     
98     function run($dbi, $argstr, &$request, $basepage) {
99         if (!DEBUG)
100             return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
101         
102         $args = $this->getArgs($argstr, $request);
103         $this->_args = $args;
104         if (!empty($args['exclude']))
105             $exclude = explodePageList($args['exclude']);
106         else
107             $exclude = false;
108
109         $p = $request->getArg('p');
110         $post_args = $request->getArg('admin_chmod');
111         $next_action = 'select';
112         $pages = array();
113         if ($p && !$request->isPost())
114             $pages = $p;
115         if ($p && $request->isPost() && $request->_user->isAdmin()
116             && !empty($post_args['chmod']) && empty($post_args['cancel'])) {
117             // FIXME: error message if not admin.
118             if ($post_args['action'] == 'verify') {
119                 // Real action
120                 return $this->chmodPages($dbi, $request, $p, 
121                                           $post_args['perm']);
122             }
123             if ($post_args['action'] == 'select') {
124                 if (!empty($post_args['perm']))
125                     $next_action = 'verify';
126                 foreach ($p as $name) {
127                     $pages[$name] = 1;
128                 }
129             }
130         }
131         if ($next_action == 'select' and empty($pages)) {
132             // List all pages to select from.
133             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
134         }
135         if ($next_action == 'verify') {
136             $args['info'] = "checkbox,pagename,perm,author,mtime";
137         }
138         $pagelist = new PageList_Selectable($args['info'], $exclude);
139         $pagelist->addPageList($pages);
140
141         $header = HTML::p();
142         if ($next_action == 'verify') {
143             $button_label = _("Yes");
144             $header = $this->chmodForm($header, $post_args);
145             $header->pushContent(
146               HTML::p(HTML::strong(
147                                    _("Are you sure you want to permanently change the selected files?"))));
148         }
149         else {
150             $button_label = _("Chmod");
151             $header = $this->chmodForm($header, $post_args);
152             $header->pushContent(HTML::p(_("Select the pages to change:")));
153         }
154
155         $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
156                            Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
157
158         return HTML::form(array('action' => $request->getPostURL(),
159                                 'method' => 'post'),
160                           $header,
161                           $pagelist->getContent(),
162                           HiddenInputs($request->getArgs(),
163                                         false,
164                                         array('admin_chmod')),
165                           HiddenInputs(array('admin_chmod[action]' => $next_action,
166                                              'require_authority_for_post' => WIKIAUTH_ADMIN)),
167                           $buttons);
168     }
169
170     function chmodForm(&$header, $post_args) {
171         $header->pushContent(
172             HTML::p(HTML::em(_("This plugin is currently under development and does not work!"))));
173         $header->pushContent(_("Chmod to permission:"));
174         $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
175                                                'value' => $post_args['perm'])));
176         $header->pushContent(' '._("(ugo : rwx)"));
177         $header->pushContent(HTML::p());
178         $checkbox = HTML::input(array('type' => 'checkbox',
179                                       'name' => 'admin_chmod[updatechildren]',
180                                       'value' => 1));
181         if ($post_args['updatechildren'])  $checkbox->setAttr('checked','checked');
182         $header->pushContent($checkbox,
183                 _("Propagate new permissions to all subpages?"),
184                 HTML::raw("&nbsp;&nbsp;"),
185                 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
186         $header->pushContent(HTML::hr(),HTML::p());
187         return $header;
188     }
189
190 }
191
192 // $Log: not supported by cvs2svn $
193 // Revision 1.2  2004/02/24 03:21:40  rurban
194 // enabled require_all check in WikiPoll
195 // better handling of <20 min visiting client: display results so far
196 //
197 // Revision 1.1  2004/02/23 21:30:25  rurban
198 // more PagePerm stuff: (working against 1.4.0)
199 //   ACL editing and simplification of ACL's to simple rwx------ string
200 //   not yet working.
201 //
202 //
203
204 // Local Variables:
205 // mode: php
206 // tab-width: 8
207 // c-basic-offset: 4
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil
210 // End:
211 ?>