]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChmod.php
Several locale related improvements suggested by Pierrick Meignen
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChmod.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminChmod.php,v 1.8 2004-06-04 20:32:54 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.8 $");
52     }
53
54     function getDefaultArguments() {
55         return array(
56                      's'        => false,
57                      /* Pages to exclude in listing */
58                      'exclude'  => '',
59                      /* Columns to include in listing */
60                      'info'     => 'pagename,perm,mtime,author',
61                      /* How to sort */
62                      'sortby'   => 'pagename',
63                      'limit'    => 0,
64                      );
65     }
66
67     // todo: change permstring to some kind of default ACL hash. 
68     // See PagePermission class
69     function chmodHelper($permstring) {
70         $perm = array();
71         return $perm;
72     }
73
74     function chmodPages(&$dbi, &$request, $pages, $permstring) {
75         $ul = HTML::ul();
76         $count = 0;
77         $acl = chmodHelper($permstring);
78         if ($perm = new PagePermission($acl)) {
79             foreach ($pages as $name) {
80                 if ( $perm->store($dbi->getPage($name)) ) {
81                     $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $permstring)));
82                     $count++;
83                 } else {
84                     $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
85                 }
86             }
87         } else {
88             $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
89         }
90         if ($count) {
91             $dbi->touch();
92             return HTML($ul,
93                         HTML::p(fmt("%s pages have been changed.",$count)));
94         } else {
95             return HTML($ul,
96                         HTML::p(fmt("No pages changed.")));
97         }
98     }
99     
100     function run($dbi, $argstr, &$request, $basepage) {
101         if (!DEBUG)
102             return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
103         
104         $args = $this->getArgs($argstr, $request);
105         $this->_args = $args;
106         if (!empty($args['exclude']))
107             $exclude = explodePageList($args['exclude']);
108         else
109             $exclude = false;
110         $this->preSelectS(&$args, &$request);
111
112         $p = $request->getArg('p');
113         if (!$p) $p = $this->_list;
114         $post_args = $request->getArg('admin_chmod');
115         $next_action = 'select';
116         $pages = array();
117         if ($p && !$request->isPost())
118             $pages = $p;
119         if ($p && $request->isPost() &&
120             !empty($post_args['chmod']) && empty($post_args['cancel'])) {
121             // without individual PagePermissions:
122             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
123                 $request->_notAuthorized(WIKIAUTH_ADMIN);
124                 $this->disabled("! user->isAdmin");
125             }
126
127             if ($post_args['action'] == 'verify') {
128                 // Real action
129                 return $this->chmodPages($dbi, $request, array_keys($p), 
130                                           $post_args['perm']);
131             }
132             if ($post_args['action'] == 'select') {
133                 if (!empty($post_args['perm']))
134                     $next_action = 'verify';
135                 foreach ($p as $name => $c) {
136                     $pages[$name] = 1;
137                 }
138             }
139         }
140         if ($next_action == 'select' and empty($pages)) {
141             // List all pages to select from.
142             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
143         }
144         if ($next_action == 'verify') {
145             $args['info'] = "checkbox,pagename,perm,author,mtime";
146         }
147         $pagelist = new PageList_Selectable($args['info'], $exclude);
148         $pagelist->addPageList($pages);
149
150         $header = HTML::p();
151         if ($next_action == 'verify') {
152             $button_label = _("Yes");
153             $header = $this->chmodForm($header, $post_args);
154             $header->pushContent(
155               HTML::p(HTML::strong(
156                 _("Are you sure you want to permanently change the selected files?"))));
157         }
158         else {
159             $button_label = _("Chmod");
160             $header = $this->chmodForm($header, $post_args);
161             $header->pushContent(HTML::p(_("Select the pages to change:")));
162         }
163
164         $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
165                            Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
166
167         return HTML::form(array('action' => $request->getPostURL(),
168                                 'method' => 'post'),
169                           $header,
170                           $pagelist->getContent(),
171                           HiddenInputs($request->getArgs(),
172                                         false,
173                                         array('admin_chmod')),
174                           HiddenInputs(array('admin_chmod[action]' => $next_action)),
175                           ENABLE_PAGEPERM
176                           ? ''
177                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
178                           $buttons);
179     }
180
181     function chmodForm(&$header, $post_args) {
182         $header->pushContent(
183             HTML::p(HTML::em(
184                _("This plugin is currently under development and does not work!"))));
185         $header->pushContent(_("Chmod to permission:"));
186         $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
187                                                'value' => $post_args['perm'])));
188         $header->pushContent(' '._("(ugo : rwx)"));
189         $header->pushContent(HTML::p());
190         $checkbox = HTML::input(array('type' => 'checkbox',
191                                       'name' => 'admin_chmod[updatechildren]',
192                                       'value' => 1));
193         if ($post_args['updatechildren'])  $checkbox->setAttr('checked','checked');
194         $header->pushContent($checkbox,
195                 _("Propagate new permissions to all subpages?"),
196                 HTML::raw("&nbsp;&nbsp;"),
197                 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
198         $header->pushContent(HTML::hr(),HTML::p());
199         return $header;
200     }
201
202 }
203
204 // $Log: not supported by cvs2svn $
205 // Revision 1.7  2004/06/03 22:24:42  rurban
206 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
207 //
208 // Revision 1.6  2004/03/17 20:23:44  rurban
209 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
210 //
211 // Revision 1.5  2004/03/12 13:31:43  rurban
212 // enforce PagePermissions, errormsg if not Admin
213 //
214 // Revision 1.4  2004/02/24 15:20:06  rurban
215 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
216 //
217 // Revision 1.3  2004/02/24 04:02:06  rurban
218 // Better warning messages
219 //
220 // Revision 1.2  2004/02/24 03:21:40  rurban
221 // enabled require_all check in WikiPoll
222 // better handling of <20 min visiting client: display results so far
223 //
224 // Revision 1.1  2004/02/23 21:30:25  rurban
225 // more PagePerm stuff: (working against 1.4.0)
226 //   ACL editing and simplification of ACL's to simple rwx------ string
227 //   not yet working.
228 //
229 //
230
231 // Local Variables:
232 // mode: php
233 // tab-width: 8
234 // c-basic-offset: 4
235 // c-hanging-comment-ender-p: nil
236 // indent-tabs-mode: nil
237 // End:
238 ?>