]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChmod.php
new support for arguments owner, author, creator in most relevant
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChmod.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminChmod.php,v 1.9 2004-06-13 15:33:20 rurban Exp $');
3 /*
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is not yet part of PhpWiki. It doesn't work yet.
7
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.
12
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.
17
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
21  */
22
23 /**
24  * Set individual PagePermissions, simplifying effective ACLs to 
25  * unix-like rwxr--r--+ permissions. (as in cygwin)
26  *
27  * Usage:   <?plugin WikiAdminChmod ?> or called via WikiAdminSelect
28  * Author:  Reini Urban <rurban@x-ray.at>
29  *
30  * KNOWN ISSUES:
31  * Currently we must be Admin. Later we use PagePermissions authorization.
32  *   (require_authority_for_post' => WIKIAUTH_ADMIN)
33  * Requires PHP 4.2 so far.
34  */
35 require_once('lib/PageList.php');
36 require_once('lib/plugin/WikiAdminSelect.php');
37
38 class WikiPlugin_WikiAdminChmod
39 extends WikiPlugin_WikiAdminSelect
40 {
41     function getName() {
42         return _("WikiAdminChmod");
43     }
44
45     function getDescription() {
46         return _("Set individual page permissions.");
47     }
48
49     function getVersion() {
50         return preg_replace("/[Revision: $]/", '',
51                             "\$Revision: 1.9 $");
52     }
53
54     function getDefaultArguments() {
55         return array(
56                      's'        => false,
57                      'perm'     => false,
58                      /* select pages by meta-data: */
59                      'author'   => false,
60                      'owner'    => false,
61                      'creator'  => false,
62                      /* Pages to exclude in listing */
63                      'exclude'  => '',
64                      /* Columns to include in listing */
65                      'info'     => 'pagename,perm,mtime,author',
66                      /* How to sort */
67                      'sortby'   => 'pagename',
68                      'limit'    => 0,
69                      );
70     }
71
72     // todo: change permstring to some kind of default ACL hash. 
73     // See PagePermission class
74     function chmodHelper($permstring) {
75         $perm = array();
76         return $perm;
77     }
78
79     function chmodPages(&$dbi, &$request, $pages, $permstring) {
80         $ul = HTML::ul();
81         $count = 0;
82         $acl = chmodHelper($permstring);
83         if ($perm = new PagePermission($acl)) {
84             foreach ($pages as $name) {
85                 if ( $perm->store($dbi->getPage($name)) ) {
86                     $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.",$name, $permstring)));
87                     $count++;
88                 } else {
89                     $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
90                 }
91             }
92         } else {
93             $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
94         }
95         if ($count) {
96             $dbi->touch();
97             return HTML($ul,
98                         HTML::p(fmt("%s pages have been changed.",$count)));
99         } else {
100             return HTML($ul,
101                         HTML::p(fmt("No pages changed.")));
102         }
103     }
104     
105     function run($dbi, $argstr, &$request, $basepage) {
106         if (!DEBUG)
107             return $this->disabled("WikiAdminChmod not yet enabled. Set DEBUG to try it.");
108         
109         $args = $this->getArgs($argstr, $request);
110         $this->_args = $args;
111         if (!empty($args['exclude']))
112             $exclude = explodePageList($args['exclude']);
113         else
114             $exclude = false;
115         $this->preSelectS(&$args, &$request);
116
117         $p = $request->getArg('p');
118         if (!$p) $p = $this->_list;
119         $post_args = $request->getArg('admin_chmod');
120         $next_action = 'select';
121         $pages = array();
122         if ($p && !$request->isPost())
123             $pages = $p;
124         if ($p && $request->isPost() &&
125             !empty($post_args['chmod']) && empty($post_args['cancel'])) {
126             // without individual PagePermissions:
127             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
128                 $request->_notAuthorized(WIKIAUTH_ADMIN);
129                 $this->disabled("! user->isAdmin");
130             }
131
132             if ($post_args['action'] == 'verify') {
133                 // Real action
134                 return $this->chmodPages($dbi, $request, array_keys($p), 
135                                           $post_args['perm']);
136             }
137             if ($post_args['action'] == 'select') {
138                 if (!empty($post_args['perm']))
139                     $next_action = 'verify';
140                 foreach ($p as $name => $c) {
141                     $pages[$name] = 1;
142                 }
143             }
144         }
145         if ($next_action == 'select' and empty($pages)) {
146             // List all pages to select from.
147             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
148         }
149         if ($next_action == 'verify') {
150             $args['info'] = "checkbox,pagename,perm,author,mtime";
151         }
152         $pagelist = new PageList_Selectable($args['info'], $exclude);
153         $pagelist->addPageList($pages);
154
155         $header = HTML::p();
156         if ($next_action == 'verify') {
157             $button_label = _("Yes");
158             $header = $this->chmodForm($header, $post_args);
159             $header->pushContent(
160               HTML::p(HTML::strong(
161                 _("Are you sure you want to permanently change the selected files?"))));
162         }
163         else {
164             $button_label = _("Chmod");
165             $header = $this->chmodForm($header, $post_args);
166             $header->pushContent(HTML::p(_("Select the pages to change:")));
167         }
168
169         $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
170                            Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
171
172         return HTML::form(array('action' => $request->getPostURL(),
173                                 'method' => 'post'),
174                           $header,
175                           $pagelist->getContent(),
176                           HiddenInputs($request->getArgs(),
177                                         false,
178                                         array('admin_chmod')),
179                           HiddenInputs(array('admin_chmod[action]' => $next_action)),
180                           ENABLE_PAGEPERM
181                           ? ''
182                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
183                           $buttons);
184     }
185
186     function chmodForm(&$header, $post_args) {
187         $header->pushContent(
188             HTML::p(HTML::em(
189                _("This plugin is currently under development and does not work!"))));
190         $header->pushContent(_("Chmod to permission:"));
191         $header->pushContent(HTML::input(array('name' => 'admin_chmod[perm]',
192                                                'value' => $post_args['perm'])));
193         $header->pushContent(' '._("(ugo : rwx)"));
194         $header->pushContent(HTML::p());
195         $checkbox = HTML::input(array('type' => 'checkbox',
196                                       'name' => 'admin_chmod[updatechildren]',
197                                       'value' => 1));
198         if ($post_args['updatechildren'])  $checkbox->setAttr('checked','checked');
199         $header->pushContent($checkbox,
200                 _("Propagate new permissions to all subpages?"),
201                 HTML::raw("&nbsp;&nbsp;"),
202                 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
203         $header->pushContent(HTML::hr(),HTML::p());
204         return $header;
205     }
206
207 }
208
209 // $Log: not supported by cvs2svn $
210 // Revision 1.8  2004/06/04 20:32:54  rurban
211 // Several locale related improvements suggested by Pierrick Meignen
212 // LDAP fix by John Cole
213 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
214 //
215 // Revision 1.7  2004/06/03 22:24:42  rurban
216 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
217 //
218 // Revision 1.6  2004/03/17 20:23:44  rurban
219 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
220 //
221 // Revision 1.5  2004/03/12 13:31:43  rurban
222 // enforce PagePermissions, errormsg if not Admin
223 //
224 // Revision 1.4  2004/02/24 15:20:06  rurban
225 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
226 //
227 // Revision 1.3  2004/02/24 04:02:06  rurban
228 // Better warning messages
229 //
230 // Revision 1.2  2004/02/24 03:21:40  rurban
231 // enabled require_all check in WikiPoll
232 // better handling of <20 min visiting client: display results so far
233 //
234 // Revision 1.1  2004/02/23 21:30:25  rurban
235 // more PagePerm stuff: (working against 1.4.0)
236 //   ACL editing and simplification of ACL's to simple rwx------ string
237 //   not yet working.
238 //
239 //
240
241 // Local Variables:
242 // mode: php
243 // tab-width: 8
244 // c-basic-offset: 4
245 // c-hanging-comment-ender-p: nil
246 // indent-tabs-mode: nil
247 // End:
248 ?>