]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminChown.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminChown.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
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  * Usage:   <?plugin WikiAdminChown s||=* ?> or called via WikiAdminSelect
25  * @author:  Reini Urban <rurban@x-ray.at>
26  *
27  * KNOWN ISSUES:
28  * Requires PHP 4.2 so far.
29  */
30 require_once('lib/PageList.php');
31 require_once('lib/plugin/WikiAdminSelect.php');
32
33 class WikiPlugin_WikiAdminChown
34 extends WikiPlugin_WikiAdminSelect
35 {
36     function getName() {
37         return _("WikiAdminChown");
38     }
39
40     function getDescription() {
41         return _("Chown selected pages.");
42     }
43
44     function getVersion() {
45         return preg_replace("/[Revision: $]/", '',
46                             "\$Revision$");
47     }
48
49     function getDefaultArguments() {
50         return array_merge 
51             (
52              PageList::supportedArgs(),
53              array(
54                    's'          => false,
55                    'user'       => false,
56                    /* Columns to include in listing */
57                    'info'     => 'pagename,owner,mtime',
58                    ));
59     }
60
61     function chownPages(&$dbi, &$request, $pages, $newowner) {
62         $ul = HTML::ul();
63         $count = 0;
64         foreach ($pages as $name) {
65             $page = $dbi->getPage($name);
66             if ( ($owner = $page->getOwner()) and 
67                  $newowner != $owner ) {
68                 if (!mayAccessPage('change', $name)) {
69                     $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
70                                                   WikiLink($name))));
71                 } else {
72                     $page->set('owner', $newowner);
73                     if ($page->get('owner') === $newowner) {
74                         $ul->pushContent(HTML::li(fmt("Chown page '%s' to '%s'.",
75                                                       WikiLink($name), WikiLink($newowner))));
76                         $count++;
77                     } else {
78                         $ul->pushContent(HTML::li(fmt("Couldn't chown page '%s' to '%s'.", 
79                                                       WikiLink($name), $newowner)));
80                     }
81                 }
82             }
83         }
84         if ($count) {
85             $dbi->touch();
86             return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
87                                          $count)));
88         } else {
89             return HTML($ul, HTML::p(fmt("No pages changed.")));
90         }
91     }
92     
93     function run($dbi, $argstr, &$request, $basepage) {
94         if ($request->getArg('action') != 'browse')
95             if (!$request->getArg('action') == _("PhpWikiAdministration/Chown"))
96                 return $this->disabled("(action != 'browse')");
97         
98         $args = $this->getArgs($argstr, $request);
99         $this->_args = $args;
100         if (empty($args['user']))
101             $args['user'] = $request->_user->UserName();
102         /*if (!empty($args['exclude']))
103             $exclude = explodePageList($args['exclude']);
104         else
105         $exclude = false;*/
106         $this->preSelectS($args, $request);
107
108         $p = $request->getArg('p');
109         if (!$p) $p = $this->_list;
110         $post_args = $request->getArg('admin_chown');
111         if (!$request->isPost() and empty($post_args['user']))
112             $post_args['user'] = $args['user'];
113         $next_action = 'select';
114         $pages = array();
115         if ($p && !$request->isPost())
116             $pages = $p;
117         if ($p && $request->isPost() &&
118             !empty($post_args['chown']) && empty($post_args['cancel'])) {
119             // without individual PagePermissions:
120             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
121                 $request->_notAuthorized(WIKIAUTH_ADMIN);
122                 $this->disabled("! user->isAdmin");
123             }
124             // DONE: error message if not allowed.
125             if ($post_args['action'] == 'verify') {
126                 // Real action
127                 return $this->chownPages($dbi, $request, array_keys($p), 
128                                           $post_args['user']);
129             }
130             if ($post_args['action'] == 'select') {
131                 if (!empty($post_args['user']))
132                     $next_action = 'verify';
133                 foreach ($p as $name => $c) {
134                     $pages[$name] = 1;
135                 }
136             }
137         }
138         if ($next_action == 'select' and empty($pages)) {
139             // List all pages to select from.
140             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], 
141                                          $args['exclude']);
142         }
143         /* // let the user decide which info
144          if ($next_action == 'verify') {
145             $args['info'] = "checkbox,pagename,owner,mtime";
146         }
147         */
148         $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
149         $pagelist->addPageList($pages);
150
151         $header = HTML::div();
152         if ($next_action == 'verify') {
153             $button_label = _("Yes");
154             $header->pushContent(
155               HTML::p(HTML::strong(
156                 _("Are you sure you want to permanently chown the selected files?"))));
157             $header = $this->chownForm($header, $post_args);
158         }
159         else {
160             $button_label = _("Chown selected pages");
161             $header->pushContent(HTML::p(_("Select the pages to change the owner:")));
162             $header = $this->chownForm($header, $post_args);
163         }
164
165         $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
166                            Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
167
168         return HTML::form(array('action' => $request->getPostURL(),
169                                 'method' => 'post'),
170                           $header,
171                           $pagelist->getContent(),
172                           HiddenInputs($request->getArgs(),
173                                         false,
174                                         array('admin_chown')),
175                           HiddenInputs(array('admin_chown[action]' => $next_action)),
176                           ENABLE_PAGEPERM
177                           ? ''
178                           : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
179                           $buttons);
180     }
181
182     function chownForm(&$header, $post_args) {
183         $header->pushContent(_("Chown")." ");
184         $header->pushContent(' '._("to").': ');
185         $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
186                                                'value' => $post_args['user'])));
187         $header->pushContent(HTML::p());
188         return $header;
189     }
190 }
191
192 // $Log: not supported by cvs2svn $
193 // Revision 1.8  2005/01/29 19:48:14  rurban
194 // reformatting
195 //
196 // Revision 1.7  2004/11/23 15:17:19  rurban
197 // better support for case_exact search (not caseexact for consistency),
198 // plugin args simplification:
199 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
200 //     and exclude in advance (at the sql level if possible)
201 //   handle sortby and limit from request override in WikiPlugin::getArgs
202 // ListSubpages: renamed pages to maxpages
203 //
204 // Revision 1.6  2004/06/16 10:38:59  rurban
205 // Disallow refernces in calls if the declaration is a reference
206 // ("allow_call_time_pass_reference clean").
207 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
208 //   but several external libraries may not.
209 //   In detail these libs look to be affected (not tested):
210 //   * Pear_DB odbc
211 //   * adodb oracle
212 //
213 // Revision 1.5  2004/06/14 11:31:39  rurban
214 // renamed global $Theme to $WikiTheme (gforge nameclash)
215 // inherit PageList default options from PageList
216 //   default sortby=pagename
217 // use options in PageList_Selectable (limit, sortby, ...)
218 // added action revert, with button at action=diff
219 // added option regex to WikiAdminSearchReplace
220 //
221 // Revision 1.4  2004/06/13 15:33:20  rurban
222 // new support for arguments owner, author, creator in most relevant
223 // PageList plugins. in WikiAdmin* via preSelectS()
224 //
225 // Revision 1.3  2004/06/08 10:05:11  rurban
226 // simplified admin action shortcuts
227 //
228 // Revision 1.2  2004/06/07 18:59:42  rurban
229 // added Chown link to Owner in statusbar
230 //
231 // Revision 1.1  2004/06/07 17:58:58  rurban
232 // new chown plugin
233 //
234 //
235
236 // Local Variables:
237 // mode: php
238 // tab-width: 8
239 // c-basic-offset: 4
240 // c-hanging-comment-ender-p: nil
241 // indent-tabs-mode: nil
242 // End:
243 ?>