4 * Copyright 2004 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Usage: <?plugin WikiAdminChown s||=* ?> or called via WikiAdminSelect
26 * @author: Reini Urban <rurban@x-ray.at>
29 * Requires PHP 4.2 so far.
31 require_once('lib/PageList.php');
32 require_once('lib/plugin/WikiAdminSelect.php');
34 class WikiPlugin_WikiAdminChown
35 extends WikiPlugin_WikiAdminSelect
38 return _("WikiAdminChown");
41 function getDescription() {
42 return _("Change owner of selected pages.");
45 function getDefaultArguments() {
48 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
51 /* Columns to include in listing */
52 'info' => 'pagename,owner,mtime',
56 function chownPages(&$dbi, &$request, $pages, $newowner) {
57 $result = HTML::div();
60 foreach ($pages as $name) {
61 $page = $dbi->getPage($name);
62 $current = $page->getCurrentRevision();
63 if ( ($owner = $page->getOwner()) and
64 $newowner != $owner ) {
65 if (!mayAccessPage('change', $name)) {
66 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
69 $version = $current->getVersion();
70 $meta = $current->_data;
71 $text = $current->getPackedContent();
72 $meta['summary'] = "Change page owner from '".$owner."' to '".$newowner."'";
73 $meta['is_minor_edit'] = 1;
74 $meta['author'] = $request->_user->UserName();
75 unset($meta['mtime']); // force new date
76 $page->set('owner', $newowner);
77 $page->save($text, $version + 1, $meta);
78 if ($page->get('owner') === $newowner) {
79 $ul->pushContent(HTML::li(fmt("Change owner of page '%s' to '%s'.",
80 WikiLink($name), WikiLink($newowner))));
83 $ul->pushContent(HTML::li(fmt("Could not change owner of page '%s' to '%s'.",
84 WikiLink($name), $newowner)));
91 $result->setAttr('class', 'feedback');
93 $result->pushContent(HTML::p("One page has been permanently changed:"));
95 $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
97 $result->pushContent($ul);
100 $result->setAttr('class', 'error');
101 $result->pushContent(HTML::p("No pages changed."));
106 function run($dbi, $argstr, &$request, $basepage) {
107 if ($request->getArg('action') != 'browse')
108 if (!$request->getArg('action') == _("PhpWikiAdministration/Chown"))
109 return $this->disabled("(action != 'browse')");
111 $args = $this->getArgs($argstr, $request);
112 $this->_args = $args;
113 if (empty($args['user']))
114 $args['user'] = $request->_user->UserName();
115 /*if (!empty($args['exclude']))
116 $exclude = explodePageList($args['exclude']);
119 $this->preSelectS($args, $request);
121 $p = $request->getArg('p');
122 if (!$p) $p = $this->_list;
123 $post_args = $request->getArg('admin_chown');
124 if (!$request->isPost() and empty($post_args['user']))
125 $post_args['user'] = $args['user'];
126 $next_action = 'select';
128 if ($p && !$request->isPost())
130 if ($p && $request->isPost() &&
131 !empty($post_args['chown']) && empty($post_args['cancel'])) {
132 // without individual PagePermissions:
133 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
134 $request->_notAuthorized(WIKIAUTH_ADMIN);
135 $this->disabled("! user->isAdmin");
137 // DONE: error message if not allowed.
138 if ($post_args['action'] == 'verify') {
140 return $this->chownPages($dbi, $request, array_keys($p),
141 trim($post_args['user']));
143 if ($post_args['action'] == 'select') {
144 if (!empty($post_args['user']))
145 $next_action = 'verify';
146 foreach ($p as $name => $c) {
151 if ($next_action == 'select' and empty($pages)) {
152 // List all pages to select from.
153 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
156 /* // let the user decide which info
157 if ($next_action == 'verify') {
158 $args['info'] = "checkbox,pagename,owner,mtime";
161 if ($next_action == 'select') {
162 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
164 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
166 $pagelist->addPageList($pages);
168 $header = HTML::fieldset();
169 if ($next_action == 'verify') {
170 $button_label = _("Yes");
171 $header->pushContent(
172 HTML::p(HTML::strong(
173 _("Are you sure you want to permanently change the owner of the selected pages?"))));
174 $header = $this->chownForm($header, $post_args);
177 $button_label = _("Change owner of selected pages");
178 $header->pushContent(HTML::legend(_("Select the pages to change the owner")));
179 $header = $this->chownForm($header, $post_args);
182 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
183 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
184 $header->pushContent($buttons);
186 return HTML::form(array('action' => $request->getPostURL(),
189 $pagelist->getContent(),
190 HiddenInputs($request->getArgs(),
192 array('admin_chown')),
193 HiddenInputs(array('admin_chown[action]' => $next_action)),
196 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
199 function chownForm(&$header, $post_args) {
200 $header->pushContent(_("Change owner")." ");
201 $header->pushContent(' '._("to").': ');
202 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
203 'value' => $post_args['user'],
213 // c-hanging-comment-ender-p: nil
214 // indent-tabs-mode: nil