2 rcs_id('$Id: WikiAdminChmod.php,v 1.1 2004-02-23 21:30:25 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
26 * Usage: <?plugin WikiAdminChmod ?> or called via WikiAdminSelect
27 * Author: Reini Urban <rurban@x-ray.at>
30 * Currently we must be Admin. Later we use PagePermissions authorization.
31 * (require_authority_for_post' => WIKIAUTH_ADMIN)
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() {
55 /* Pages to exclude in listing */
57 /* Columns to include in listing */
58 'info' => 'pagename,perm,mtime,author',
60 'sortby' => 'pagename',
65 // todo: change permstring to some kind default ACL hash. See PagePermission class
66 function chmodHelper($permstring) {
71 function chmodPages(&$dbi, &$request, $pages, $permstring) {
74 $acl = chmodHelper($permstring);
75 if ($perm = new PagePermission($acl)) {
76 foreach ($pages as $name) {
77 if ( $perm->store($dbi->getPage($name)) ) {
78 $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $perm)));
81 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $perm)));
85 $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
90 HTML::p(fmt("%s pages have been changed.",$count)));
93 HTML::p(fmt("No pages changed.")));
97 function run($dbi, $argstr, &$request, $basepage) {
99 return $this->disabled("chmod not yet implemented");
101 $args = $this->getArgs($argstr, $request);
102 $this->_args = $args;
103 if (!empty($args['exclude']))
104 $exclude = explodePageList($args['exclude']);
108 $p = $request->getArg('p');
109 $post_args = $request->getArg('admin_chmod');
110 $next_action = 'select';
112 if ($p && !$request->isPost())
114 if ($p && $request->isPost() && $request->_user->isAdmin()
115 && !empty($post_args['chmod']) && empty($post_args['cancel'])) {
116 // FIXME: error message if not admin.
117 if ($post_args['action'] == 'verify') {
119 return $this->chmodPages($dbi, $request, $p,
122 if ($post_args['action'] == 'select') {
123 if (!empty($post_args['perm']))
124 $next_action = 'verify';
125 foreach ($p as $name) {
130 if ($next_action == 'select' and empty($pages)) {
131 // List all pages to select from.
132 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
134 if ($next_action == 'verify') {
135 $args['info'] = "checkbox,pagename,perm,author,mtime";
137 $pagelist = new PageList_Selectable($args['info'], $exclude);
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(),
160 $pagelist->getContent(),
161 HiddenInputs($request->getArgs(),
163 array('admin_chmod')),
164 HiddenInputs(array('admin_chmod[action]' => $next_action,
165 'require_authority_for_post' => WIKIAUTH_ADMIN)),
169 function chmodForm(&$header, $post_args) {
170 $header->pushContent(HTML::p(HTML::em(_("This plugin is currently under development and does not work!"))));
171 $header->pushContent(_("Chmod to permission:"));
172 $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
173 'value' => $post_args['perm'])));
174 $header->pushContent(' '._("(ugo : rwx)"));
175 $header->pushContent(HTML::p());
176 $checkbox = HTML::input(array('type' => 'checkbox',
177 'name' => 'admin_chmod[updatechildren]',
179 if ($post_args['updatechildren']) $checkbox->setAttr('checked','checked');
180 $header->pushContent($checkbox,
181 _("Propagate new permissions to all subpages?"),
182 HTML::raw(" "),
183 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
184 $header->pushContent(HTML::hr(),HTML::p());
190 // $Log: not supported by cvs2svn $
197 // c-hanging-comment-ender-p: nil
198 // indent-tabs-mode: nil