2 rcs_id('$Id: WikiAdminChmod.php,v 1.7 2004-06-03 22:24:42 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 * Currently we must be Admin. Later we use PagePermissions authorization.
32 * (require_authority_for_post' => WIKIAUTH_ADMIN)
33 * Requires PHP 4.2 so far.
35 require_once('lib/PageList.php');
36 require_once('lib/plugin/WikiAdminSelect.php');
38 class WikiPlugin_WikiAdminChmod
39 extends WikiPlugin_WikiAdminSelect
42 return _("WikiAdminChmod");
45 function getDescription() {
46 return _("Set individual page permissions.");
49 function getVersion() {
50 return preg_replace("/[Revision: $]/", '',
54 function getDefaultArguments() {
57 /* Pages to exclude in listing */
59 /* Columns to include in listing */
60 'info' => 'pagename,perm,mtime,author',
62 'sortby' => 'pagename',
67 // todo: change permstring to some kind of default ACL hash.
68 // See PagePermission class
69 function chmodHelper($permstring) {
74 function chmodPages(&$dbi, &$request, $pages, $permstring) {
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)));
84 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
88 $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
93 HTML::p(fmt("%s pages have been changed.",$count)));
96 HTML::p(fmt("No pages changed.")));
100 function run($dbi, $argstr, &$request, $basepage) {
102 return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
104 $args = $this->getArgs($argstr, $request);
105 $this->_args = $args;
106 if (!empty($args['exclude']))
107 $exclude = explodePageList($args['exclude']);
110 $this->preSelectS(&$args, &$request);
112 $p = $request->getArg('p');
113 if (!$p) $p = $this->_list;
114 $post_args = $request->getArg('admin_chmod');
115 $next_action = 'select';
117 if ($p && !$request->isPost())
119 if ($p && $request->isPost() &&
120 !empty($post_args['chmod']) && empty($post_args['cancel'])) {
122 // check individual PagePermissions
123 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
124 $request->_notAuthorized(WIKIAUTH_ADMIN);
125 $this->disabled("! user->isAdmin");
128 if ($post_args['action'] == 'verify') {
130 return $this->chmodPages($dbi, $request, array_keys($p),
133 if ($post_args['action'] == 'select') {
134 if (!empty($post_args['perm']))
135 $next_action = 'verify';
136 foreach ($p as $name => $c) {
141 if ($next_action == 'select' and empty($pages)) {
142 // List all pages to select from.
143 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
145 if ($next_action == 'verify') {
146 $args['info'] = "checkbox,pagename,perm,author,mtime";
148 $pagelist = new PageList_Selectable($args['info'], $exclude);
149 $pagelist->addPageList($pages);
152 if ($next_action == 'verify') {
153 $button_label = _("Yes");
154 $header = $this->chmodForm($header, $post_args);
155 $header->pushContent(
156 HTML::p(HTML::strong(
157 _("Are you sure you want to permanently change the selected files?"))));
160 $button_label = _("Chmod");
161 $header = $this->chmodForm($header, $post_args);
162 $header->pushContent(HTML::p(_("Select the pages to change:")));
165 $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
166 Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
168 return HTML::form(array('action' => $request->getPostURL(),
171 $pagelist->getContent(),
172 HiddenInputs($request->getArgs(),
174 array('admin_chmod')),
175 HiddenInputs(array('admin_chmod[action]' => $next_action,
176 'require_authority_for_post' => WIKIAUTH_ADMIN)),
180 function chmodForm(&$header, $post_args) {
181 $header->pushContent(
183 _("This plugin is currently under development and does not work!"))));
184 $header->pushContent(_("Chmod to permission:"));
185 $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
186 'value' => $post_args['perm'])));
187 $header->pushContent(' '._("(ugo : rwx)"));
188 $header->pushContent(HTML::p());
189 $checkbox = HTML::input(array('type' => 'checkbox',
190 'name' => 'admin_chmod[updatechildren]',
192 if ($post_args['updatechildren']) $checkbox->setAttr('checked','checked');
193 $header->pushContent($checkbox,
194 _("Propagate new permissions to all subpages?"),
195 HTML::raw(" "),
196 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
197 $header->pushContent(HTML::hr(),HTML::p());
203 // $Log: not supported by cvs2svn $
204 // Revision 1.6 2004/03/17 20:23:44 rurban
205 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
207 // Revision 1.5 2004/03/12 13:31:43 rurban
208 // enforce PagePermissions, errormsg if not Admin
210 // Revision 1.4 2004/02/24 15:20:06 rurban
211 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
213 // Revision 1.3 2004/02/24 04:02:06 rurban
214 // Better warning messages
216 // Revision 1.2 2004/02/24 03:21:40 rurban
217 // enabled require_all check in WikiPoll
218 // better handling of <20 min visiting client: display results so far
220 // Revision 1.1 2004/02/23 21:30:25 rurban
221 // more PagePerm stuff: (working against 1.4.0)
222 // ACL editing and simplification of ACL's to simple rwx------ string
231 // c-hanging-comment-ender-p: nil
232 // indent-tabs-mode: nil