]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChmod.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChmod.php
1 <?php // -*-php-*-
2
3 /*
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
5  * Copyright 2008 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
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.
13  *
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.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 /**
25  * Set individual PagePermissions, simplifying effective ACLs to
26  * unix-like rwxr--r--+ permissions. (as in cygwin)
27  *
28  * Usage:   <<WikiAdminChmod >> or called via WikiAdminSelect
29  * Author:  Reini Urban <rurban@x-ray.at>
30  *
31  */
32 require_once 'lib/PageList.php';
33 require_once 'lib/plugin/WikiAdminSelect.php';
34
35 class WikiPlugin_WikiAdminChmod
36 extends WikiPlugin_WikiAdminSelect
37 {
38     function getName() {
39         return _("WikiAdminChmod");
40     }
41
42     function getDescription() {
43         return _("Set individual page permissions.");
44     }
45
46     function getDefaultArguments() {
47         return array_merge
48             (
49              PageList::supportedArgs(),
50              array(
51                    's'                 => false,
52                    'perm'         => false,
53                    /* Columns to include in listing */
54                    'info'     => 'pagename,perm,mtime,author',
55                    ));
56     }
57
58     // todo: change permstring to some kind of default ACL hash.
59     // See PagePermission class
60     function chmodHelper($permstring) {
61         $perm = array();
62         return $perm;
63     }
64
65     function chmodPages(&$dbi, &$request, $pages, $permstring) {
66         $ul = HTML::ul();
67         $count = 0;
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)));
73                     $count++;
74                 } else {
75                     $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
76                 }
77             }
78         } else {
79             $ul->pushContent(HTML::li(_("Invalid chmod string")));
80         }
81         if ($count) {
82             $dbi->touch();
83             return HTML($ul,
84                         HTML::p(fmt("%d pages have been changed.", $count)));
85         } else {
86             return HTML($ul,
87                         HTML::p(_("No pages changed.")));
88         }
89     }
90
91     function run($dbi, $argstr, &$request, $basepage) {
92         if (!DEBUG) {
93             return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
94         }
95
96         $args = $this->getArgs($argstr, $request);
97         $this->_args = $args;
98         $this->preSelectS($args, $request);
99
100         $p = $request->getArg('p');
101         if (!$p) $p = $this->_list;
102         $post_args = $request->getArg('admin_chmod');
103         $next_action = 'select';
104         $pages = array();
105         if ($p && !$request->isPost())
106             $pages = $p;
107         if ($p && $request->isPost() &&
108             !empty($post_args['chmod']) && empty($post_args['cancel'])) {
109             // without individual PagePermissions:
110             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
111                 $request->_notAuthorized(WIKIAUTH_ADMIN);
112                 $this->disabled("! user->isAdmin");
113             }
114
115             if ($post_args['action'] == 'verify') {
116                 // Real action
117                 return $this->chmodPages($dbi, $request, array_keys($p),
118                                           $post_args['perm']);
119             }
120             if ($post_args['action'] == 'select') {
121                 if (!empty($post_args['perm']))
122                     $next_action = 'verify';
123                 foreach ($p as $name => $c) {
124                     $pages[$name] = 1;
125                 }
126             }
127         }
128         if ($next_action == 'select' and empty($pages)) {
129             // List all pages to select from.
130             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
131         }
132         if ($next_action == 'verify') {
133             $args['info'] = "checkbox,pagename,perm,author,mtime";
134         }
135         $args['types'] = array('perm' => new _PageList_Column_chmod_perm('perm', _("Permission")));
136         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
137         $pagelist->addPageList($pages);
138
139         $header = HTML::p();
140         if ($next_action == 'verify') {
141             $button_label = _("Yes");
142             $header = $this->chmodForm($header, $post_args);
143             $header->pushContent(
144               HTML::p(HTML::strong(
145                 _("Are you sure you want to permanently change the selected files?"))));
146         }
147         else {
148             $button_label = _("Chmod");
149             $header = $this->chmodForm($header, $post_args);
150             $header->pushContent(HTML::p(_("Select the pages to change:")));
151         }
152
153         $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
154                            Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
155
156         return HTML::form(array('action' => $request->getPostURL(),
157                                 'method' => 'post'),
158                           $header,
159                           $buttons,
160                           $pagelist->getContent(),
161                           HiddenInputs($request->getArgs(),
162                                         false,
163                                         array('admin_chmod')),
164                           HiddenInputs(array('admin_chmod[action]' => $next_action)),
165                           ENABLE_PAGEPERM
166                           ? ''
167                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
168     }
169
170     function chmodForm(&$header, $post_args) {
171         $header->pushContent(
172             HTML::p(HTML::em(
173                _("This plugin is currently under development and does not work!"))));
174         $header->pushContent(_("Chmod to permission:"));
175         $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
176                                                'value' => $post_args['perm'])));
177         $header->pushContent(' '._("(ugo : rwx)"));
178         $header->pushContent(HTML::p());
179         $checkbox = HTML::input(array('type' => 'checkbox',
180                                       'name' => 'admin_chmod[updatechildren]',
181                                       'value' => 1));
182         if (!empty($post_args['updatechildren']))  $checkbox->setAttr('checked','checked');
183         $header->pushContent($checkbox, HTML::raw("&nbsp;"),
184                 _("Propagate new permissions to all subpages?"),
185                 HTML::raw("&nbsp;&nbsp;"),
186                 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
187         $header->pushContent(HTML::hr(),HTML::p());
188         return $header;
189     }
190 }
191
192 // Local Variables:
193 // mode: php
194 // tab-width: 8
195 // c-basic-offset: 4
196 // c-hanging-comment-ender-p: nil
197 // indent-tabs-mode: nil
198 // End: