]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChmod.php
more PagePerm stuff: (working against 1.4.0)
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChmod.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminChmod.php,v 1.1 2004-02-23 21:30:25 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
25  *
26  * Usage:   <?plugin WikiAdminChmod ?> or called via WikiAdminSelect
27  * Author:  Reini Urban <rurban@x-ray.at>
28  *
29  * KNOWN ISSUES:
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.
33  */
34 require_once('lib/PageList.php');
35 require_once('lib/plugin/WikiAdminSelect.php');
36
37 class WikiPlugin_WikiAdminChmod
38 extends WikiPlugin_WikiAdminSelect
39 {
40     function getName() {
41         return _("WikiAdminChmod");
42     }
43
44     function getDescription() {
45         return _("Set individual page permissions.");
46     }
47
48     function getVersion() {
49         return preg_replace("/[Revision: $]/", '',
50                             "\$Revision: 1.1 $");
51     }
52
53     function getDefaultArguments() {
54         return array(
55                      /* Pages to exclude in listing */
56                      'exclude'  => '',
57                      /* Columns to include in listing */
58                      'info'     => 'pagename,perm,mtime,author',
59                      /* How to sort */
60                      'sortby'   => 'pagename',
61                      'limit'    => 0,
62                      );
63     }
64
65     // todo: change permstring to some kind default ACL hash. See PagePermission class
66     function chmodHelper($permstring) {
67         $perm = array();
68         return $perm;
69     }
70
71     function chmodPages(&$dbi, &$request, $pages, $permstring) {
72         $ul = HTML::ul();
73         $count = 0;
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)));
79                     $count++;
80                 } else {
81                     $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $perm)));
82                 }
83             }
84         } else {
85             $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
86         }
87         if ($count) {
88             $dbi->touch();
89             return HTML($ul,
90                         HTML::p(fmt("%s pages have been changed.",$count)));
91         } else {
92             return HTML($ul,
93                         HTML::p(fmt("No pages changed.")));
94         }
95     }
96     
97     function run($dbi, $argstr, &$request, $basepage) {
98         if (!DEBUG)
99             return $this->disabled("chmod not yet implemented");
100         
101         $args = $this->getArgs($argstr, $request);
102         $this->_args = $args;
103         if (!empty($args['exclude']))
104             $exclude = explodePageList($args['exclude']);
105         else
106             $exclude = false;
107
108         $p = $request->getArg('p');
109         $post_args = $request->getArg('admin_chmod');
110         $next_action = 'select';
111         $pages = array();
112         if ($p && !$request->isPost())
113             $pages = $p;
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') {
118                 // Real action
119                 return $this->chmodPages($dbi, $request, $p, 
120                                           $post_args['perm']);
121             }
122             if ($post_args['action'] == 'select') {
123                 if (!empty($post_args['perm']))
124                     $next_action = 'verify';
125                 foreach ($p as $name) {
126                     $pages[$name] = 1;
127                 }
128             }
129         }
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']);
133         }
134         if ($next_action == 'verify') {
135             $args['info'] = "checkbox,pagename,perm,author,mtime";
136         }
137         $pagelist = new PageList_Selectable($args['info'], $exclude);
138         $pagelist->addPageList($pages);
139
140         $header = HTML::p();
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?"))));
147         }
148         else {
149             $button_label = _("Chmod");
150             $header = $this->chmodForm($header, $post_args);
151             $header->pushContent(HTML::p(_("Select the pages to change:")));
152         }
153
154         $buttons = HTML::p(Button('submit:admin_chmod[chmod]', $button_label, 'wikiadmin'),
155                            Button('submit:admin_chmod[cancel]', _("Cancel"), 'button'));
156
157         return HTML::form(array('action' => $request->getPostURL(),
158                                 'method' => 'post'),
159                           $header,
160                           $pagelist->getContent(),
161                           HiddenInputs($request->getArgs(),
162                                         false,
163                                         array('admin_chmod')),
164                           HiddenInputs(array('admin_chmod[action]' => $next_action,
165                                              'require_authority_for_post' => WIKIAUTH_ADMIN)),
166                           $buttons);
167     }
168
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]',
178                                       'value' => 1));
179         if ($post_args['updatechildren'])  $checkbox->setAttr('checked','checked');
180         $header->pushContent($checkbox,
181                 _("Propagate new permissions to all subpages?"),
182                 HTML::raw("&nbsp;&nbsp;"),
183                 HTML::em(_("(disable individual page permissions, enable inheritance)?")));
184         $header->pushContent(HTML::hr(),HTML::p());
185         return $header;
186     }
187
188 }
189
190 // $Log: not supported by cvs2svn $
191 //
192
193 // Local Variables:
194 // mode: php
195 // tab-width: 8
196 // c-basic-offset: 4
197 // c-hanging-comment-ender-p: nil
198 // indent-tabs-mode: nil
199 // End:
200 ?>