]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChmod.php
avoid nameclash with SetAcl
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChmod.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminChmod.php,v 1.14 2004-12-13 14:36:35 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  * Requires PHP 4.2 so far.
32  */
33 require_once('lib/PageList.php');
34 require_once('lib/plugin/WikiAdminSelect.php');
35
36 class WikiPlugin_WikiAdminChmod
37 extends WikiPlugin_WikiAdminSelect
38 {
39     function getName() {
40         return _("WikiAdminChmod");
41     }
42
43     function getDescription() {
44         return _("Set individual page permissions.");
45     }
46
47     function getVersion() {
48         return preg_replace("/[Revision: $]/", '',
49                             "\$Revision: 1.14 $");
50     }
51
52     function getDefaultArguments() {
53         return array_merge
54             (
55              PageList::supportedArgs(),
56              array(
57                    's'          => false,
58                    'perm'       => false,
59                    /* Columns to include in listing */
60                    'info'     => 'pagename,perm,mtime,author',
61                    ));
62     }
63
64     // todo: change permstring to some kind of default ACL hash. 
65     // See PagePermission class
66     function chmodHelper($permstring) {
67         $perm = array();
68         return $perm;
69     }
70
71     function chmodPages(&$dbi, &$request, $pages, $permstring) {
72         $ul = HTML::ul();
73         $count = 0;
74         $acl = chmodHelper($permstring);
75         if ($perm = new PagePermission($acl)) {
76             foreach ($pages as $name) {
77                 if ( $perm->store($dbi->getPage($name)) ) {
78                     $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $permstring)));
79                     $count++;
80                 } else {
81                     $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
82                 }
83             }
84         } else {
85             $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
86         }
87         if ($count) {
88             $dbi->touch();
89             return HTML($ul,
90                         HTML::p(fmt("%s pages have been changed.",$count)));
91         } else {
92             return HTML($ul,
93                         HTML::p(fmt("No pages changed.")));
94         }
95     }
96     
97     function run($dbi, $argstr, &$request, $basepage) {
98         if (!DEBUG)
99             return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
100         
101         $args = $this->getArgs($argstr, $request);
102         $this->_args = $args;
103         $this->preSelectS($args, $request);
104
105         $p = $request->getArg('p');
106         if (!$p) $p = $this->_list;
107         $post_args = $request->getArg('admin_chmod');
108         $next_action = 'select';
109         $pages = array();
110         if ($p && !$request->isPost())
111             $pages = $p;
112         if ($p && $request->isPost() &&
113             !empty($post_args['chmod']) && empty($post_args['cancel'])) {
114             // without individual PagePermissions:
115             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
116                 $request->_notAuthorized(WIKIAUTH_ADMIN);
117                 $this->disabled("! user->isAdmin");
118             }
119
120             if ($post_args['action'] == 'verify') {
121                 // Real action
122                 return $this->chmodPages($dbi, $request, array_keys($p), 
123                                           $post_args['perm']);
124             }
125             if ($post_args['action'] == 'select') {
126                 if (!empty($post_args['perm']))
127                     $next_action = 'verify';
128                 foreach ($p as $name => $c) {
129                     $pages[$name] = 1;
130                 }
131             }
132         }
133         if ($next_action == 'select' and empty($pages)) {
134             // List all pages to select from.
135             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
136         }
137         if ($next_action == 'verify') {
138             $args['info'] = "checkbox,pagename,perm,author,mtime";
139         }
140         $args['types'] = array('perm' => new _PageList_Column_chmod_perm('perm', _("Permission")));
141         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
142         $pagelist->addPageList($pages);
143
144         $header = HTML::p();
145         if ($next_action == 'verify') {
146             $button_label = _("Yes");
147             $header = $this->chmodForm($header, $post_args);
148             $header->pushContent(
149               HTML::p(HTML::strong(
150                 _("Are you sure you want to permanently change the selected files?"))));
151         }
152         else {
153             $button_label = _("Chmod");
154             $header = $this->chmodForm($header, $post_args);
155             $header->pushContent(HTML::p(_("Select the pages to change:")));
156         }
157
158         $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
159                            Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
160
161         return HTML::form(array('action' => $request->getPostURL(),
162                                 'method' => 'post'),
163                           $header,
164                           $pagelist->getContent(),
165                           HiddenInputs($request->getArgs(),
166                                         false,
167                                         array('admin_chmod')),
168                           HiddenInputs(array('admin_chmod[action]' => $next_action)),
169                           ENABLE_PAGEPERM
170                           ? ''
171                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
172                           $buttons);
173     }
174
175     function chmodForm(&$header, $post_args) {
176         $header->pushContent(
177             HTML::p(HTML::em(
178                _("This plugin is currently under development and does not work!"))));
179         $header->pushContent(_("Chmod to permission:"));
180         $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
181                                                'value' => $post_args['perm'])));
182         $header->pushContent(' '._("(ugo : rwx)"));
183         $header->pushContent(HTML::p());
184         $checkbox = HTML::input(array('type' => 'checkbox',
185                                       'name' => 'admin_chmod[updatechildren]',
186                                       'value' => 1));
187         if (!empty($post_args['updatechildren']))  $checkbox->setAttr('checked','checked');
188         $header->pushContent($checkbox, HTML::raw("&nbsp;"),
189                 _("Propagate new permissions to all subpages?"),
190                 HTML::raw("&nbsp;&nbsp;"),
191                 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
192         $header->pushContent(HTML::hr(),HTML::p());
193         return $header;
194     }
195 }
196
197 // conflicts with WikiAdminSetAcl
198 class _PageList_Column_chmod_perm extends _PageList_Column {
199     function _getValue ($page_handle, &$revision_handle) {
200         $perm_array = pagePermissions($page_handle->_pagename);
201         return pagePermissionsSimpleFormat($perm_array,
202                                            $page_handle->get('author'),
203                                            $page_handle->get('group'));
204     }
205 };
206
207 // $Log: not supported by cvs2svn $
208 // Revision 1.13  2004/12/06 19:50:05  rurban
209 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
210 // renamed delete_page to purge_page.
211 // enable action=edit&version=-1 to force creation of a new version.
212 // added BABYCART_PATH config
213 // fixed magiqc in adodb.inc.php
214 // and some more docs
215 //
216 // Revision 1.12  2004/11/23 15:17:19  rurban
217 // better support for case_exact search (not caseexact for consistency),
218 // plugin args simplification:
219 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
220 //     and exclude in advance (at the sql level if possible)
221 //   handle sortby and limit from request override in WikiPlugin::getArgs
222 // ListSubpages: renamed pages to maxpages
223 //
224 // Revision 1.11  2004/06/16 10:38:59  rurban
225 // Disallow refernces in calls if the declaration is a reference
226 // ("allow_call_time_pass_reference clean").
227 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
228 //   but several external libraries may not.
229 //   In detail these libs look to be affected (not tested):
230 //   * Pear_DB odbc
231 //   * adodb oracle
232 //
233 // Revision 1.10  2004/06/14 11:31:39  rurban
234 // renamed global $Theme to $WikiTheme (gforge nameclash)
235 // inherit PageList default options from PageList
236 //   default sortby=pagename
237 // use options in PageList_Selectable (limit, sortby, ...)
238 // added action revert, with button at action=diff
239 // added option regex to WikiAdminSearchReplace
240 //
241 // Revision 1.9  2004/06/13 15:33:20  rurban
242 // new support for arguments owner, author, creator in most relevant
243 // PageList plugins. in WikiAdmin* via preSelectS()
244 //
245 // Revision 1.8  2004/06/04 20:32:54  rurban
246 // Several locale related improvements suggested by Pierrick Meignen
247 // LDAP fix by John Cole
248 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
249 //
250 // Revision 1.7  2004/06/03 22:24:42  rurban
251 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
252 //
253 // Revision 1.6  2004/03/17 20:23:44  rurban
254 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
255 //
256 // Revision 1.5  2004/03/12 13:31:43  rurban
257 // enforce PagePermissions, errormsg if not Admin
258 //
259 // Revision 1.4  2004/02/24 15:20:06  rurban
260 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
261 //
262 // Revision 1.3  2004/02/24 04:02:06  rurban
263 // Better warning messages
264 //
265 // Revision 1.2  2004/02/24 03:21:40  rurban
266 // enabled require_all check in WikiPoll
267 // better handling of <20 min visiting client: display results so far
268 //
269 // Revision 1.1  2004/02/23 21:30:25  rurban
270 // more PagePerm stuff: (working against 1.4.0)
271 //   ACL editing and simplification of ACL's to simple rwx------ string
272 //   not yet working.
273 //
274 //
275
276 // Local Variables:
277 // mode: php
278 // tab-width: 8
279 // c-basic-offset: 4
280 // c-hanging-comment-ender-p: nil
281 // indent-tabs-mode: nil
282 // End:
283 ?>