]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChmod.php
Fix rss_icon, rss2_icon and pageLink arguments
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChmod.php
1 <?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     {
40         return _("WikiAdminChmod");
41     }
42
43     function getDescription()
44     {
45         return _("Set individual page permissions.");
46     }
47
48     function getDefaultArguments()
49     {
50         return array_merge
51         (
52             PageList::supportedArgs(),
53             array(
54                 's' => false,
55                 'perm' => false,
56                 /* Columns to include in listing */
57                 'info' => 'pagename,perm,mtime,author',
58             ));
59     }
60
61     // todo: change permstring to some kind of default ACL hash.
62     // See PagePermission class
63     function chmodHelper($permstring)
64     {
65         $perm = array();
66         return $perm;
67     }
68
69     function chmodPages(&$dbi, &$request, $pages, $permstring)
70     {
71         $ul = HTML::ul();
72         $count = 0;
73         $acl = chmodHelper($permstring);
74         if ($perm = new PagePermission($acl)) {
75             foreach ($pages as $name) {
76                 if ($perm->store($dbi->getPage($name))) {
77                     $ul->pushContent(HTML::li(fmt("chmod page “%s” to “%s”.", $name, $permstring)));
78                     $count++;
79                 } else {
80                     $ul->pushContent(HTML::li(fmt("Couldn't chmod page “%s” to “%s”.", $name, $permstring)));
81                 }
82             }
83         } else {
84             $ul->pushContent(HTML::li(_("Invalid chmod string")));
85         }
86         if ($count) {
87             $dbi->touch();
88             return HTML($ul,
89                 HTML::p(fmt("%d pages have been changed.", $count)));
90         } else {
91             return HTML($ul,
92                 HTML::p(_("No pages changed.")));
93         }
94     }
95
96     function run($dbi, $argstr, &$request, $basepage)
97     {
98         if (!DEBUG) {
99             return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
100         }
101
102         $args = $this->getArgs($argstr, $request);
103         $this->_args = $args;
104         $this->preSelectS($args, $request);
105
106         $p = $request->getArg('p');
107         if (!$p) $p = $this->_list;
108         $post_args = $request->getArg('admin_chmod');
109         $next_action = 'select';
110         $pages = array();
111         if ($p && !$request->isPost())
112             $pages = $p;
113         if ($p && $request->isPost() &&
114             !empty($post_args['chmod']) && empty($post_args['cancel'])
115         ) {
116             // without individual PagePermissions:
117             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
118                 $request->_notAuthorized(WIKIAUTH_ADMIN);
119                 $this->disabled("! user->isAdmin");
120             }
121
122             if ($post_args['action'] == 'verify') {
123                 // Real action
124                 return $this->chmodPages($dbi, $request, array_keys($p),
125                     $post_args['perm']);
126             }
127             if ($post_args['action'] == 'select') {
128                 if (!empty($post_args['perm']))
129                     $next_action = 'verify';
130                 foreach ($p as $name => $c) {
131                     $pages[$name] = 1;
132                 }
133             }
134         }
135         if ($next_action == 'select' and empty($pages)) {
136             // List all pages to select from.
137             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
138         }
139         if ($next_action == 'verify') {
140             $args['info'] = "checkbox,pagename,perm,author,mtime";
141         }
142         $args['types'] = array('perm' => new _PageList_Column_chmod_perm('perm', _("Permission")));
143         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
144         $pagelist->addPageList($pages);
145
146         $header = HTML::p();
147         if ($next_action == 'verify') {
148             $button_label = _("Yes");
149             $header = $this->chmodForm($header, $post_args);
150             $header->pushContent(
151                 HTML::p(HTML::strong(
152                     _("Are you sure you want to permanently change the selected files?"))));
153         } else {
154             $button_label = _("Chmod");
155             $header = $this->chmodForm($header, $post_args);
156             $header->pushContent(HTML::p(_("Select the pages to change:")));
157         }
158
159         $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
160             Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
161
162         return HTML::form(array('action' => $request->getPostURL(),
163                 'method' => 'post'),
164             $header,
165             $buttons,
166             $pagelist->getContent(),
167             HiddenInputs($request->getArgs(),
168                 false,
169                 array('admin_chmod')),
170             HiddenInputs(array('admin_chmod[action]' => $next_action)),
171             ENABLE_PAGEPERM
172                 ? ''
173                 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
174     }
175
176     function chmodForm(&$header, $post_args)
177     {
178         $header->pushContent(
179             HTML::p(HTML::em(
180                 _("This plugin is currently under development and does not work!"))));
181         $header->pushContent(_("Chmod to permission:"));
182         $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
183             'value' => $post_args['perm'])));
184         $header->pushContent(' ' . _("(ugo : rwx)"));
185         $header->pushContent(HTML::p());
186         $checkbox = HTML::input(array('type' => 'checkbox',
187             'name' => 'admin_chmod[updatechildren]',
188             'value' => 1));
189         if (!empty($post_args['updatechildren'])) $checkbox->setAttr('checked', 'checked');
190         $header->pushContent($checkbox, HTML::raw("&nbsp;"),
191             _("Propagate new permissions to all subpages?"),
192             HTML::raw("&nbsp;&nbsp;"),
193             HTML::em(_("(disable individual page permissions, enable inheritance)?")));
194         $header->pushContent(HTML::hr(), HTML::p());
195         return $header;
196     }
197 }
198
199 // Local Variables:
200 // mode: php
201 // tab-width: 8
202 // c-basic-offset: 4
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil
205 // End: