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 along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Usage: <<WikiAdminChown s||=* >> or called via WikiAdminSelect
26 * @author: Reini Urban <rurban@x-ray.at>
29 require_once 'lib/PageList.php';
30 require_once 'lib/plugin/WikiAdminSelect.php';
32 class WikiPlugin_WikiAdminChown
33 extends WikiPlugin_WikiAdminSelect
37 return _("WikiAdminChown");
40 function getDescription()
42 return _("Change owner of selected pages.");
45 function getDefaultArguments()
49 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
52 /* Columns to include in listing */
53 'info' => 'pagename,owner,mtime',
57 function chownPages(&$dbi, &$request, $pages, $newowner)
59 $result = HTML::div();
62 foreach ($pages as $name) {
63 $page = $dbi->getPage($name);
64 $current = $page->getCurrentRevision();
65 if (($owner = $page->getOwner()) and
68 if (!mayAccessPage('change', $name)) {
69 $ul->pushContent(HTML::li(fmt("Access denied to change page “%s”.",
72 $version = $current->getVersion();
73 $meta = $current->_data;
74 $text = $current->getPackedContent();
75 $meta['summary'] = "Change page owner from '" . $owner . "' to '" . $newowner . "'";
76 $meta['is_minor_edit'] = 1;
77 $meta['author'] = $request->_user->UserName();
78 unset($meta['mtime']); // force new date
79 $page->set('owner', $newowner);
80 $page->save($text, $version + 1, $meta);
81 if ($page->get('owner') === $newowner) {
82 $ul->pushContent(HTML::li(fmt("Change owner of page “%s” to “%s”.",
83 WikiLink($name), WikiLink($newowner))));
86 $ul->pushContent(HTML::li(fmt("Could not change owner of page “%s” to “%s”.",
87 WikiLink($name), $newowner)));
94 $result->setAttr('class', 'feedback');
96 $result->pushContent(HTML::p(_("One page has been changed:")));
98 $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count)));
100 $result->pushContent($ul);
103 $result->setAttr('class', 'error');
104 $result->pushContent(HTML::p(_("No pages changed.")));
109 function run($dbi, $argstr, &$request, $basepage)
111 if ($request->getArg('action') != 'browse') {
112 if (!$request->getArg('action') == _("PhpWikiAdministration/Chown")) {
113 return $this->disabled(_("Plugin not run: not in browse mode"));
117 $args = $this->getArgs($argstr, $request);
118 $this->_args = $args;
119 if (empty($args['user']))
120 $args['user'] = $request->_user->UserName();
121 /*if (!empty($args['exclude']))
122 $exclude = explodePageList($args['exclude']);
125 $this->preSelectS($args, $request);
127 $p = $request->getArg('p');
128 if (!$p) $p = $this->_list;
129 $post_args = $request->getArg('admin_chown');
130 if (!$request->isPost() and empty($post_args['user']))
131 $post_args['user'] = $args['user'];
132 $next_action = 'select';
134 if ($p && !$request->isPost())
136 if ($p && $request->isPost() &&
137 !empty($post_args['chown']) && empty($post_args['cancel'])
139 // without individual PagePermissions:
140 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
141 $request->_notAuthorized(WIKIAUTH_ADMIN);
142 $this->disabled("! user->isAdmin");
144 // DONE: error message if not allowed.
145 if ($post_args['action'] == 'verify') {
147 return $this->chownPages($dbi, $request, array_keys($p),
148 trim($post_args['user']));
150 if ($post_args['action'] == 'select') {
151 if (!empty($post_args['user']))
152 $next_action = 'verify';
153 foreach ($p as $name => $c) {
158 if ($next_action == 'select' and empty($pages)) {
159 // List all pages to select from.
160 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
163 /* // let the user decide which info
164 if ($next_action == 'verify') {
165 $args['info'] = "checkbox,pagename,owner,mtime";
168 if ($next_action == 'select') {
169 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
171 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
173 $pagelist->addPageList($pages);
175 $header = HTML::fieldset();
176 if ($next_action == 'verify') {
177 $button_label = _("Yes");
178 $header->pushContent(HTML::legend(_("Confirm ownership change")));
179 $header->pushContent(
180 HTML::p(HTML::strong(
181 _("Are you sure you want to change the owner of the selected pages?"))));
182 $header = $this->chownForm($header, $post_args);
184 $button_label = _("Change owner of selected pages.");
185 $header->pushContent(HTML::legend(_("Select the pages to change the owner")));
186 $header = $this->chownForm($header, $post_args);
189 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
190 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
191 $header->pushContent($buttons);
193 return HTML::form(array('action' => $request->getPostURL(),
196 $pagelist->getContent(),
197 HiddenInputs($request->getArgs(),
199 array('admin_chown')),
200 HiddenInputs(array('admin_chown[action]' => $next_action)),
203 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
206 function chownForm(&$header, $post_args)
208 $header->pushContent(_("Change owner to: "));
209 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
210 'value' => $post_args['user'],
220 // c-hanging-comment-ender-p: nil
221 // indent-tabs-mode: nil