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 getDefaultArguments() {
51 PageList::supportedArgs(),
55 /* Columns to include in listing */
56 'info' => 'pagename,perm,mtime,author',
60 // todo: change permstring to some kind of default ACL hash.
61 // See PagePermission class
62 function chmodHelper($permstring) {
67 function chmodPages(&$dbi, &$request, $pages, $permstring) {
70 $acl = chmodHelper($permstring);
71 if ($perm = new PagePermission($acl)) {
72 foreach ($pages as $name) {
73 if ( $perm->store($dbi->getPage($name)) ) {
74 $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $permstring)));
77 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
81 $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
86 HTML::p(fmt("%s pages have been changed.",$count)));
89 HTML::p(fmt("No pages changed.")));
93 function run($dbi, $argstr, &$request, $basepage) {
95 return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
97 $args = $this->getArgs($argstr, $request);
99 $this->preSelectS($args, $request);
101 $p = $request->getArg('p');
102 if (!$p) $p = $this->_list;
103 $post_args = $request->getArg('admin_chmod');
104 $next_action = 'select';
106 if ($p && !$request->isPost())
108 if ($p && $request->isPost() &&
109 !empty($post_args['chmod']) && empty($post_args['cancel'])) {
110 // without individual PagePermissions:
111 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
112 $request->_notAuthorized(WIKIAUTH_ADMIN);
113 $this->disabled("! user->isAdmin");
116 if ($post_args['action'] == 'verify') {
118 return $this->chmodPages($dbi, $request, array_keys($p),
121 if ($post_args['action'] == 'select') {
122 if (!empty($post_args['perm']))
123 $next_action = 'verify';
124 foreach ($p as $name => $c) {
129 if ($next_action == 'select' and empty($pages)) {
130 // List all pages to select from.
131 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
133 if ($next_action == 'verify') {
134 $args['info'] = "checkbox,pagename,perm,author,mtime";
136 $args['types'] = array('perm' => new _PageList_Column_chmod_perm('perm', _("Permission")));
137 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
138 $pagelist->addPageList($pages);
141 if ($next_action == 'verify') {
142 $button_label = _("Yes");
143 $header = $this->chmodForm($header, $post_args);
144 $header->pushContent(
145 HTML::p(HTML::strong(
146 _("Are you sure you want to permanently change the selected files?"))));
149 $button_label = _("Chmod");
150 $header = $this->chmodForm($header, $post_args);
151 $header->pushContent(HTML::p(_("Select the pages to change:")));
154 $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
155 Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
157 return HTML::form(array('action' => $request->getPostURL(),
161 $pagelist->getContent(),
162 HiddenInputs($request->getArgs(),
164 array('admin_chmod')),
165 HiddenInputs(array('admin_chmod[action]' => $next_action)),
168 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
171 function chmodForm(&$header, $post_args) {
172 $header->pushContent(
174 _("This plugin is currently under development and does not work!"))));
175 $header->pushContent(_("Chmod to permission:"));
176 $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
177 'value' => $post_args['perm'])));
178 $header->pushContent(' '._("(ugo : rwx)"));
179 $header->pushContent(HTML::p());
180 $checkbox = HTML::input(array('type' => 'checkbox',
181 'name' => 'admin_chmod[updatechildren]',
183 if (!empty($post_args['updatechildren'])) $checkbox->setAttr('checked','checked');
184 $header->pushContent($checkbox, HTML::raw(" "),
185 _("Propagate new permissions to all subpages?"),
186 HTML::raw(" "),
187 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
188 $header->pushContent(HTML::hr(),HTML::p());
193 // conflicts with WikiAdminSetAcl
194 class _PageList_Column_chmod_perm extends _PageList_Column {
195 function _getValue ($page_handle, &$revision_handle) {
196 $perm_array = pagePermissions($page_handle->_pagename);
197 return pagePermissionsSimpleFormat($perm_array,
198 $page_handle->get('author'),
199 $page_handle->get('group'));
207 // c-hanging-comment-ender-p: nil
208 // indent-tabs-mode: nil