2 rcs_id('$Id: WikiAdminChmod.php,v 1.14 2004-12-13 14:36:35 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is not yet part of PhpWiki. It doesn't work yet.
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.
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.
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
24 * Set individual PagePermissions, simplifying effective ACLs to
25 * unix-like rwxr--r--+ permissions. (as in cygwin)
27 * Usage: <?plugin WikiAdminChmod ?> or called via WikiAdminSelect
28 * Author: Reini Urban <rurban@x-ray.at>
31 * Requires PHP 4.2 so far.
33 require_once('lib/PageList.php');
34 require_once('lib/plugin/WikiAdminSelect.php');
36 class WikiPlugin_WikiAdminChmod
37 extends WikiPlugin_WikiAdminSelect
40 return _("WikiAdminChmod");
43 function getDescription() {
44 return _("Set individual page permissions.");
47 function getVersion() {
48 return preg_replace("/[Revision: $]/", '',
49 "\$Revision: 1.14 $");
52 function getDefaultArguments() {
55 PageList::supportedArgs(),
59 /* Columns to include in listing */
60 'info' => 'pagename,perm,mtime,author',
64 // todo: change permstring to some kind of default ACL hash.
65 // See PagePermission class
66 function chmodHelper($permstring) {
71 function chmodPages(&$dbi, &$request, $pages, $permstring) {
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)));
81 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
85 $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
90 HTML::p(fmt("%s pages have been changed.",$count)));
93 HTML::p(fmt("No pages changed.")));
97 function run($dbi, $argstr, &$request, $basepage) {
99 return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
101 $args = $this->getArgs($argstr, $request);
102 $this->_args = $args;
103 $this->preSelectS($args, $request);
105 $p = $request->getArg('p');
106 if (!$p) $p = $this->_list;
107 $post_args = $request->getArg('admin_chmod');
108 $next_action = 'select';
110 if ($p && !$request->isPost())
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");
120 if ($post_args['action'] == 'verify') {
122 return $this->chmodPages($dbi, $request, array_keys($p),
125 if ($post_args['action'] == 'select') {
126 if (!empty($post_args['perm']))
127 $next_action = 'verify';
128 foreach ($p as $name => $c) {
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']);
137 if ($next_action == 'verify') {
138 $args['info'] = "checkbox,pagename,perm,author,mtime";
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);
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?"))));
153 $button_label = _("Chmod");
154 $header = $this->chmodForm($header, $post_args);
155 $header->pushContent(HTML::p(_("Select the pages to change:")));
158 $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
159 Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
161 return HTML::form(array('action' => $request->getPostURL(),
164 $pagelist->getContent(),
165 HiddenInputs($request->getArgs(),
167 array('admin_chmod')),
168 HiddenInputs(array('admin_chmod[action]' => $next_action)),
171 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
175 function chmodForm(&$header, $post_args) {
176 $header->pushContent(
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]',
187 if (!empty($post_args['updatechildren'])) $checkbox->setAttr('checked','checked');
188 $header->pushContent($checkbox, HTML::raw(" "),
189 _("Propagate new permissions to all subpages?"),
190 HTML::raw(" "),
191 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
192 $header->pushContent(HTML::hr(),HTML::p());
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'));
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
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
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):
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
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()
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
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
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
256 // Revision 1.5 2004/03/12 13:31:43 rurban
257 // enforce PagePermissions, errormsg if not Admin
259 // Revision 1.4 2004/02/24 15:20:06 rurban
260 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
262 // Revision 1.3 2004/02/24 04:02:06 rurban
263 // Better warning messages
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
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
280 // c-hanging-comment-ender-p: nil
281 // indent-tabs-mode: nil