2 rcs_id('$Id: WikiAdminChown.php,v 1.1 2004-06-07 17:58:58 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 /* Pages to exclude in listing */
55 /* Columns to include in listing */
56 'info' => 'pagename,owner,mtime',
58 'sortby' => 'pagename',
63 function chownPages(&$dbi, &$request, $pages, $newowner) {
66 foreach ($pages as $name) {
67 $page = $dbi->getPage($name);
68 if ( ($owner = $page->getOwner()) and
69 $newowner != $owner ) {
70 if (!mayAccessPage('change', $name)) {
71 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
74 $page->set('owner', $newowner);
75 if ($page->get('owner') === $newowner) {
76 $ul->pushContent(HTML::li(fmt("Chown page '%s' to '%s'.",
77 WikiLink($name), WikiLink($newowner))));
80 $ul->pushContent(HTML::li(fmt("Couldn't chown page '%s' to '%s'.",
81 WikiLink($name), $newowner)));
88 return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
91 return HTML($ul, HTML::p(fmt("No pages changed.")));
95 function run($dbi, $argstr, &$request, $basepage) {
96 if ($request->getArg('action') != 'browse')
97 return $this->disabled("(action != 'browse')");
99 $args = $this->getArgs($argstr, $request);
100 $this->_args = $args;
101 if (empty($args['user']))
102 $args['user'] = $request->_user->UserName();
103 if (!empty($args['exclude']))
104 $exclude = explodePageList($args['exclude']);
107 $this->preSelectS(&$args, &$request);
109 $p = $request->getArg('p');
110 if (!$p) $p = $this->_list;
111 $post_args = $request->getArg('admin_chown');
112 if (!$request->isPost() and empty($post_args['user']))
113 $post_args['user'] = $args['user'];
114 $next_action = 'select';
116 if ($p && !$request->isPost())
118 if ($p && $request->isPost() &&
119 !empty($post_args['chown']) && empty($post_args['cancel'])) {
120 // without individual PagePermissions:
121 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
122 $request->_notAuthorized(WIKIAUTH_ADMIN);
123 $this->disabled("! user->isAdmin");
125 // DONE: error message if not allowed.
126 if ($post_args['action'] == 'verify') {
128 return $this->chownPages($dbi, $request, array_keys($p),
131 if ($post_args['action'] == 'select') {
132 if (!empty($post_args['user']))
133 $next_action = 'verify';
134 foreach ($p as $name => $c) {
139 if ($next_action == 'select' and empty($pages)) {
140 // List all pages to select from.
141 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
143 /* // let the user decide which info
144 if ($next_action == 'verify') {
145 $args['info'] = "checkbox,pagename,owner,mtime";
148 $pagelist = new PageList_Selectable($args['info'], $exclude);
149 $pagelist->addPageList($pages);
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);
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);
165 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
166 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
168 return HTML::form(array('action' => $request->getPostURL(),
171 $pagelist->getContent(),
172 HiddenInputs($request->getArgs(),
174 array('admin_chown')),
175 HiddenInputs(array('admin_chown[action]' => $next_action)),
178 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
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());
192 // $Log: not supported by cvs2svn $
199 // c-hanging-comment-ender-p: nil
200 // indent-tabs-mode: nil