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
35 function getDescription()
37 return _("Change owner of selected pages.");
40 function getDefaultArguments()
44 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
47 /* Columns to include in listing */
48 'info' => 'pagename,owner,mtime',
52 function chownPages(&$dbi, &$request, $pages, $newowner)
54 $result = HTML::div();
57 foreach ($pages as $name) {
58 $page = $dbi->getPage($name);
59 $current = $page->getCurrentRevision();
60 if (($owner = $page->getOwner()) and
63 if (!mayAccessPage('change', $name)) {
64 $ul->pushContent(HTML::li(fmt("Access denied to change page “%s”.",
67 $version = $current->getVersion();
68 $meta = $current->_data;
69 $text = $current->getPackedContent();
70 $meta['summary'] = "Change page owner from '" . $owner . "' to '" . $newowner . "'";
71 $meta['is_minor_edit'] = 1;
72 $meta['author'] = $request->_user->UserName();
73 unset($meta['mtime']); // force new date
74 $page->set('owner', $newowner);
75 $page->save($text, $version + 1, $meta);
76 if ($page->get('owner') === $newowner) {
77 $ul->pushContent(HTML::li(fmt("Change owner of page “%s” to “%s”.",
78 WikiLink($name), WikiLink($newowner))));
81 $ul->pushContent(HTML::li(fmt("Could not change owner of page “%s” to “%s”.",
82 WikiLink($name), $newowner)));
89 $result->setAttr('class', 'feedback');
91 $result->pushContent(HTML::p(_("One page has been changed:")));
93 $result->pushContent(HTML::p(fmt("%d pages have been changed:", $count)));
95 $result->pushContent($ul);
98 $result->setAttr('class', 'error');
99 $result->pushContent(HTML::p(_("No pages changed.")));
104 function run($dbi, $argstr, &$request, $basepage)
106 if ($request->getArg('action') != 'browse') {
107 if (!$request->getArg('action') == __("PhpWikiAdministration")."/".__("Chown")) {
108 return $this->disabled(_("Plugin not run: not in browse mode"));
112 $args = $this->getArgs($argstr, $request);
113 $this->_args = $args;
114 if (empty($args['user']))
115 $args['user'] = $request->_user->UserName();
116 /*if (!empty($args['exclude']))
117 $exclude = explodePageList($args['exclude']);
120 $this->preSelectS($args, $request);
122 $p = $request->getArg('p');
123 if (!$p) $p = $this->_list;
124 $post_args = $request->getArg('admin_chown');
125 if (!$request->isPost() and empty($post_args['user']))
126 $post_args['user'] = $args['user'];
127 $next_action = 'select';
129 if ($p && !$request->isPost())
131 if ($p && $request->isPost() &&
132 !empty($post_args['chown']) && empty($post_args['cancel'])
134 // without individual PagePermissions:
135 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
136 $request->_notAuthorized(WIKIAUTH_ADMIN);
137 $this->disabled("! user->isAdmin");
139 // DONE: error message if not allowed.
140 if ($post_args['action'] == 'verify') {
142 return $this->chownPages($dbi, $request, array_keys($p),
143 trim($post_args['user']));
145 if ($post_args['action'] == 'select') {
146 if (!empty($post_args['user']))
147 $next_action = 'verify';
148 foreach ($p as $name => $c) {
153 if ($next_action == 'select' and empty($pages)) {
154 // List all pages to select from.
155 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
158 /* // let the user decide which info
159 if ($next_action == 'verify') {
160 $args['info'] = "checkbox,pagename,owner,mtime";
163 if ($next_action == 'select') {
164 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
166 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
168 $pagelist->addPageList($pages);
170 $header = HTML::fieldset();
171 if ($next_action == 'verify') {
172 $button_label = _("Yes");
173 $header->pushContent(HTML::legend(_("Confirm ownership change")));
174 $header->pushContent(
175 HTML::p(HTML::strong(
176 _("Are you sure you want to change the owner of the selected pages?"))));
177 $header = $this->chownForm($header, $post_args);
179 $button_label = _("Change owner of selected pages.");
180 $header->pushContent(HTML::legend(_("Select the pages to change the owner")));
181 $header = $this->chownForm($header, $post_args);
184 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
185 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
186 $header->pushContent($buttons);
188 return HTML::form(array('action' => $request->getPostURL(),
191 $pagelist->getContent(),
192 HiddenInputs($request->getArgs(),
194 array('admin_chown')),
195 HiddenInputs(array('admin_chown[action]' => $next_action)),
198 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
201 function chownForm(&$header, $post_args)
203 $header->pushContent(_("Change owner to: "));
204 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
205 'value' => $post_args['user'],
215 // c-hanging-comment-ender-p: nil
216 // indent-tabs-mode: nil