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: <?plugin WikiAdminChmod ?> or called via WikiAdminSelect
29 * Author: Reini Urban <rurban@x-ray.at>
32 * Requires PHP 4.2 so far.
34 require_once('lib/PageList.php');
35 require_once('lib/plugin/WikiAdminSelect.php');
37 class WikiPlugin_WikiAdminChmod
38 extends WikiPlugin_WikiAdminSelect
41 return _("WikiAdminChmod");
44 function getDescription() {
45 return _("Set individual page permissions.");
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
53 function getDefaultArguments() {
56 PageList::supportedArgs(),
60 /* Columns to include in listing */
61 'info' => 'pagename,perm,mtime,author',
65 // todo: change permstring to some kind of default ACL hash.
66 // See PagePermission class
67 function chmodHelper($permstring) {
72 function chmodPages(&$dbi, &$request, $pages, $permstring) {
75 $acl = chmodHelper($permstring);
76 if ($perm = new PagePermission($acl)) {
77 foreach ($pages as $name) {
78 if ( $perm->store($dbi->getPage($name)) ) {
79 $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $permstring)));
82 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
86 $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
91 HTML::p(fmt("%s pages have been changed.",$count)));
94 HTML::p(fmt("No pages changed.")));
98 function run($dbi, $argstr, &$request, $basepage) {
100 return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
102 $args = $this->getArgs($argstr, $request);
103 $this->_args = $args;
104 $this->preSelectS($args, $request);
106 $p = $request->getArg('p');
107 if (!$p) $p = $this->_list;
108 $post_args = $request->getArg('admin_chmod');
109 $next_action = 'select';
111 if ($p && !$request->isPost())
113 if ($p && $request->isPost() &&
114 !empty($post_args['chmod']) && empty($post_args['cancel'])) {
115 // without individual PagePermissions:
116 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
117 $request->_notAuthorized(WIKIAUTH_ADMIN);
118 $this->disabled("! user->isAdmin");
121 if ($post_args['action'] == 'verify') {
123 return $this->chmodPages($dbi, $request, array_keys($p),
126 if ($post_args['action'] == 'select') {
127 if (!empty($post_args['perm']))
128 $next_action = 'verify';
129 foreach ($p as $name => $c) {
134 if ($next_action == 'select' and empty($pages)) {
135 // List all pages to select from.
136 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
138 if ($next_action == 'verify') {
139 $args['info'] = "checkbox,pagename,perm,author,mtime";
141 $args['types'] = array('perm' => new _PageList_Column_chmod_perm('perm', _("Permission")));
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(),
166 $pagelist->getContent(),
167 HiddenInputs($request->getArgs(),
169 array('admin_chmod')),
170 HiddenInputs(array('admin_chmod[action]' => $next_action)),
173 : 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, HTML::raw(" "),
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());
198 // conflicts with WikiAdminSetAcl
199 class _PageList_Column_chmod_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'));
212 // c-hanging-comment-ender-p: nil
213 // indent-tabs-mode: nil