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