2 rcs_id('$Id: WikiAdminChown.php,v 1.4 2004-06-13 15:33:20 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
24 * Usage: <?plugin WikiAdminChown s||=* ?> or called via WikiAdminSelect
25 * @author: Reini Urban <rurban@x-ray.at>
28 * Requires PHP 4.2 so far.
30 require_once('lib/PageList.php');
31 require_once('lib/plugin/WikiAdminSelect.php');
33 class WikiPlugin_WikiAdminChown
34 extends WikiPlugin_WikiAdminSelect
37 return _("WikiAdminChown");
40 function getDescription() {
41 return _("Chown selected pages.");
44 function getVersion() {
45 return preg_replace("/[Revision: $]/", '',
49 function getDefaultArguments() {
53 /* select pages by meta-data: */
57 /* Pages to exclude in listing */
59 /* Columns to include in listing */
60 'info' => 'pagename,owner,mtime',
62 'sortby' => 'pagename',
67 function chownPages(&$dbi, &$request, $pages, $newowner) {
70 foreach ($pages as $name) {
71 $page = $dbi->getPage($name);
72 if ( ($owner = $page->getOwner()) and
73 $newowner != $owner ) {
74 if (!mayAccessPage('change', $name)) {
75 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
78 $page->set('owner', $newowner);
79 if ($page->get('owner') === $newowner) {
80 $ul->pushContent(HTML::li(fmt("Chown page '%s' to '%s'.",
81 WikiLink($name), WikiLink($newowner))));
84 $ul->pushContent(HTML::li(fmt("Couldn't chown page '%s' to '%s'.",
85 WikiLink($name), $newowner)));
92 return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
95 return HTML($ul, HTML::p(fmt("No pages changed.")));
99 function run($dbi, $argstr, &$request, $basepage) {
100 if ($request->getArg('action') != 'browse')
101 if (!$request->getArg('action') == _("PhpWikiAdministration/Chown"))
102 return $this->disabled("(action != 'browse')");
104 $args = $this->getArgs($argstr, $request);
105 $this->_args = $args;
106 if (empty($args['user']))
107 $args['user'] = $request->_user->UserName();
108 if (!empty($args['exclude']))
109 $exclude = explodePageList($args['exclude']);
112 $this->preSelectS(&$args, &$request);
114 $p = $request->getArg('p');
115 if (!$p) $p = $this->_list;
116 $post_args = $request->getArg('admin_chown');
117 if (!$request->isPost() and empty($post_args['user']))
118 $post_args['user'] = $args['user'];
119 $next_action = 'select';
121 if ($p && !$request->isPost())
123 if ($p && $request->isPost() &&
124 !empty($post_args['chown']) && empty($post_args['cancel'])) {
125 // without individual PagePermissions:
126 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
127 $request->_notAuthorized(WIKIAUTH_ADMIN);
128 $this->disabled("! user->isAdmin");
130 // DONE: error message if not allowed.
131 if ($post_args['action'] == 'verify') {
133 return $this->chownPages($dbi, $request, array_keys($p),
136 if ($post_args['action'] == 'select') {
137 if (!empty($post_args['user']))
138 $next_action = 'verify';
139 foreach ($p as $name => $c) {
144 if ($next_action == 'select' and empty($pages)) {
145 // List all pages to select from.
146 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
148 /* // let the user decide which info
149 if ($next_action == 'verify') {
150 $args['info'] = "checkbox,pagename,owner,mtime";
153 $pagelist = new PageList_Selectable($args['info'], $exclude);
154 $pagelist->addPageList($pages);
157 if ($next_action == 'verify') {
158 $button_label = _("Yes");
159 $header->pushContent(
160 HTML::p(HTML::strong(
161 _("Are you sure you want to permanently chown the selected files?"))));
162 $header = $this->chownForm($header, $post_args);
165 $button_label = _("Chown selected pages");
166 $header->pushContent(HTML::p(_("Select the pages to change the owner:")));
167 $header = $this->chownForm($header, $post_args);
170 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
171 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
173 return HTML::form(array('action' => $request->getPostURL(),
176 $pagelist->getContent(),
177 HiddenInputs($request->getArgs(),
179 array('admin_chown')),
180 HiddenInputs(array('admin_chown[action]' => $next_action)),
183 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
187 function chownForm(&$header, $post_args) {
188 $header->pushContent(_("Chown")." ");
189 $header->pushContent(' '._("to").': ');
190 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
191 'value' => $post_args['user'])));
192 $header->pushContent(HTML::p());
197 // $Log: not supported by cvs2svn $
198 // Revision 1.3 2004/06/08 10:05:11 rurban
199 // simplified admin action shortcuts
201 // Revision 1.2 2004/06/07 18:59:42 rurban
202 // added Chown link to Owner in statusbar
204 // Revision 1.1 2004/06/07 17:58:58 rurban
213 // c-hanging-comment-ender-p: nil
214 // indent-tabs-mode: nil