4 * Copyright 2004 $ThePhpWikiProgrammingTeam
5 * Copyright 2008 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Set individual PagePermissions, simplifying effective ACLs to
26 * unix-like rwxr--r--+ permissions. (as in cygwin)
28 * Usage: <<WikiAdminChmod >> or called via WikiAdminSelect
29 * Author: Reini Urban <rurban@x-ray.at>
32 require_once('lib/PageList.php');
33 require_once('lib/plugin/WikiAdminSelect.php');
35 class WikiPlugin_WikiAdminChmod
36 extends WikiPlugin_WikiAdminSelect
39 return _("WikiAdminChmod");
42 function getDescription() {
43 return _("Set individual page permissions.");
46 function getDefaultArguments() {
49 PageList::supportedArgs(),
53 /* Columns to include in listing */
54 'info' => 'pagename,perm,mtime,author',
58 // todo: change permstring to some kind of default ACL hash.
59 // See PagePermission class
60 function chmodHelper($permstring) {
65 function chmodPages(&$dbi, &$request, $pages, $permstring) {
68 $acl = chmodHelper($permstring);
69 if ($perm = new PagePermission($acl)) {
70 foreach ($pages as $name) {
71 if ( $perm->store($dbi->getPage($name)) ) {
72 $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $permstring)));
75 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
79 $ul->pushContent(HTML::li(_("Invalid chmod string")));
84 HTML::p(fmt("%d pages have been changed.", $count)));
87 HTML::p(_("No pages changed.")));
91 function run($dbi, $argstr, &$request, $basepage) {
93 return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
95 $args = $this->getArgs($argstr, $request);
97 $this->preSelectS($args, $request);
99 $p = $request->getArg('p');
100 if (!$p) $p = $this->_list;
101 $post_args = $request->getArg('admin_chmod');
102 $next_action = 'select';
104 if ($p && !$request->isPost())
106 if ($p && $request->isPost() &&
107 !empty($post_args['chmod']) && empty($post_args['cancel'])) {
108 // without individual PagePermissions:
109 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
110 $request->_notAuthorized(WIKIAUTH_ADMIN);
111 $this->disabled("! user->isAdmin");
114 if ($post_args['action'] == 'verify') {
116 return $this->chmodPages($dbi, $request, array_keys($p),
119 if ($post_args['action'] == 'select') {
120 if (!empty($post_args['perm']))
121 $next_action = 'verify';
122 foreach ($p as $name => $c) {
127 if ($next_action == 'select' and empty($pages)) {
128 // List all pages to select from.
129 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
131 if ($next_action == 'verify') {
132 $args['info'] = "checkbox,pagename,perm,author,mtime";
134 $args['types'] = array('perm' => new _PageList_Column_chmod_perm('perm', _("Permission")));
135 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
136 $pagelist->addPageList($pages);
139 if ($next_action == 'verify') {
140 $button_label = _("Yes");
141 $header = $this->chmodForm($header, $post_args);
142 $header->pushContent(
143 HTML::p(HTML::strong(
144 _("Are you sure you want to permanently change the selected files?"))));
147 $button_label = _("Chmod");
148 $header = $this->chmodForm($header, $post_args);
149 $header->pushContent(HTML::p(_("Select the pages to change:")));
152 $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
153 Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
155 return HTML::form(array('action' => $request->getPostURL(),
159 $pagelist->getContent(),
160 HiddenInputs($request->getArgs(),
162 array('admin_chmod')),
163 HiddenInputs(array('admin_chmod[action]' => $next_action)),
166 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
169 function chmodForm(&$header, $post_args) {
170 $header->pushContent(
172 _("This plugin is currently under development and does not work!"))));
173 $header->pushContent(_("Chmod to permission:"));
174 $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
175 'value' => $post_args['perm'])));
176 $header->pushContent(' '._("(ugo : rwx)"));
177 $header->pushContent(HTML::p());
178 $checkbox = HTML::input(array('type' => 'checkbox',
179 'name' => 'admin_chmod[updatechildren]',
181 if (!empty($post_args['updatechildren'])) $checkbox->setAttr('checked','checked');
182 $header->pushContent($checkbox, HTML::raw(" "),
183 _("Propagate new permissions to all subpages?"),
184 HTML::raw(" "),
185 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
186 $header->pushContent(HTML::hr(),HTML::p());
195 // c-hanging-comment-ender-p: nil
196 // indent-tabs-mode: nil