2 rcs_id('$Id: WikiAdminChmod.php,v 1.12 2004-11-23 15:17:19 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: $]/", '',
51 "\$Revision: 1.12 $");
54 function getDefaultArguments() {
57 PageList::supportedArgs(),
61 /* Columns to include in listing */
62 'info' => 'pagename,perm,mtime,author',
66 // todo: change permstring to some kind of default ACL hash.
67 // See PagePermission class
68 function chmodHelper($permstring) {
73 function chmodPages(&$dbi, &$request, $pages, $permstring) {
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)));
83 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
87 $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
92 HTML::p(fmt("%s pages have been changed.",$count)));
95 HTML::p(fmt("No pages changed.")));
99 function run($dbi, $argstr, &$request, $basepage) {
101 return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
103 $args = $this->getArgs($argstr, $request);
104 $this->_args = $args;
105 $this->preSelectS($args, $request);
107 $p = $request->getArg('p');
108 if (!$p) $p = $this->_list;
109 $post_args = $request->getArg('admin_chmod');
110 $next_action = 'select';
112 if ($p && !$request->isPost())
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");
122 if ($post_args['action'] == 'verify') {
124 return $this->chmodPages($dbi, $request, array_keys($p),
127 if ($post_args['action'] == 'select') {
128 if (!empty($post_args['perm']))
129 $next_action = 'verify';
130 foreach ($p as $name => $c) {
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']);
139 if ($next_action == 'verify') {
140 $args['info'] = "checkbox,pagename,perm,author,mtime";
142 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
143 $pagelist->addPageList($pages);
146 if ($next_action == 'verify') {
147 $button_label = _("Yes");
148 $header = $this->chmodForm($header, $post_args);
149 $header->pushContent(
150 HTML::p(HTML::strong(
151 _("Are you sure you want to permanently change the selected files?"))));
154 $button_label = _("Chmod");
155 $header = $this->chmodForm($header, $post_args);
156 $header->pushContent(HTML::p(_("Select the pages to change:")));
159 $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
160 Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
162 return HTML::form(array('action' => $request->getPostURL(),
165 $pagelist->getContent(),
166 HiddenInputs($request->getArgs(),
168 array('admin_chmod')),
169 HiddenInputs(array('admin_chmod[action]' => $next_action)),
172 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
176 function chmodForm(&$header, $post_args) {
177 $header->pushContent(
179 _("This plugin is currently under development and does not work!"))));
180 $header->pushContent(_("Chmod to permission:"));
181 $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
182 'value' => $post_args['perm'])));
183 $header->pushContent(' '._("(ugo : rwx)"));
184 $header->pushContent(HTML::p());
185 $checkbox = HTML::input(array('type' => 'checkbox',
186 'name' => 'admin_chmod[updatechildren]',
188 if (!empty($post_args['updatechildren'])) $checkbox->setAttr('checked','checked');
189 $header->pushContent($checkbox,
190 _("Propagate new permissions to all subpages?"),
191 HTML::raw(" "),
192 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
193 $header->pushContent(HTML::hr(),HTML::p());
199 // $Log: not supported by cvs2svn $
200 // Revision 1.11 2004/06/16 10:38:59 rurban
201 // Disallow refernces in calls if the declaration is a reference
202 // ("allow_call_time_pass_reference clean").
203 // PhpWiki is now allow_call_time_pass_reference = Off clean,
204 // but several external libraries may not.
205 // In detail these libs look to be affected (not tested):
209 // Revision 1.10 2004/06/14 11:31:39 rurban
210 // renamed global $Theme to $WikiTheme (gforge nameclash)
211 // inherit PageList default options from PageList
212 // default sortby=pagename
213 // use options in PageList_Selectable (limit, sortby, ...)
214 // added action revert, with button at action=diff
215 // added option regex to WikiAdminSearchReplace
217 // Revision 1.9 2004/06/13 15:33:20 rurban
218 // new support for arguments owner, author, creator in most relevant
219 // PageList plugins. in WikiAdmin* via preSelectS()
221 // Revision 1.8 2004/06/04 20:32:54 rurban
222 // Several locale related improvements suggested by Pierrick Meignen
223 // LDAP fix by John Cole
224 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
226 // Revision 1.7 2004/06/03 22:24:42 rurban
227 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
229 // Revision 1.6 2004/03/17 20:23:44 rurban
230 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
232 // Revision 1.5 2004/03/12 13:31:43 rurban
233 // enforce PagePermissions, errormsg if not Admin
235 // Revision 1.4 2004/02/24 15:20:06 rurban
236 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
238 // Revision 1.3 2004/02/24 04:02:06 rurban
239 // Better warning messages
241 // Revision 1.2 2004/02/24 03:21:40 rurban
242 // enabled require_all check in WikiPoll
243 // better handling of <20 min visiting client: display results so far
245 // Revision 1.1 2004/02/23 21:30:25 rurban
246 // more PagePerm stuff: (working against 1.4.0)
247 // ACL editing and simplification of ACL's to simple rwx------ string
256 // c-hanging-comment-ender-p: nil
257 // indent-tabs-mode: nil