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 parent::getDefaultArguments(),
47 /* Columns to include in listing */
48 'info' => 'pagename,owner,mtime',
52 private 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)));
96 $result->setAttr('class', 'error');
97 $result->pushContent(HTML::p(_("No pages changed.")));
99 $result->pushContent($ul);
105 * @param string $argstr
106 * @param WikiRequest $request
107 * @param string $basepage
110 function run($dbi, $argstr, &$request, $basepage)
112 if ($request->getArg('action') != 'browse') {
113 if ($request->getArg('action') != __("PhpWikiAdministration")."/".__("Chown")) {
114 return $this->disabled(_("Plugin not run: not in browse mode"));
118 $args = $this->getArgs($argstr, $request);
119 $this->_args = $args;
120 if (empty($args['user']))
121 $args['user'] = $request->_user->UserName();
122 $this->preSelectS($args, $request);
124 $p = $request->getArg('p');
125 if (!$p) $p = $this->_list;
126 $post_args = $request->getArg('admin_chown');
127 if (!$request->isPost() and empty($post_args['user']))
128 $post_args['user'] = $args['user'];
129 $next_action = 'select';
131 if ($p && !$request->isPost())
133 if ($p && $request->isPost() &&
134 !empty($post_args['chown']) && empty($post_args['cancel'])
136 // without individual PagePermissions:
137 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
138 $request->_notAuthorized(WIKIAUTH_ADMIN);
139 $this->disabled("! user->isAdmin");
141 if ($post_args['action'] == 'verify') {
143 return $this->chownPages($dbi, $request, array_keys($p),
144 trim($post_args['user']));
146 if ($post_args['action'] == 'select') {
147 if (!empty($post_args['user']))
148 $next_action = 'verify';
149 foreach ($p as $name => $c) {
154 if ($next_action == 'select' and empty($pages)) {
155 // List all pages to select from.
156 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
159 $header = HTML::fieldset();
160 if ($next_action == 'verify') {
161 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
162 $pagelist->addPageList($pages);
163 $button_label = _("Yes");
164 $header->pushContent(HTML::legend(_("Confirm ownership change")));
165 $header->pushContent(HTML::p(HTML::strong(
166 _("Are you sure you want to change the owner of the selected pages?"))));
168 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
169 $pagelist->addPageList($pages);
170 $button_label = _("Change owner of selected pages.");
171 $header->pushContent(HTML::legend(_("Select the pages to change the owner")));
174 $header->pushContent(_("Change owner to: "));
175 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
176 'value' => $post_args['user'],
179 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
180 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
181 $header->pushContent($buttons);
183 return HTML::form(array('action' => $request->getPostURL(),
186 $pagelist->getContent(),
187 HiddenInputs($request->getArgs(),
189 array('admin_chown')),
190 HiddenInputs(array('admin_chown[action]' => $next_action)),
193 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
201 // c-hanging-comment-ender-p: nil
202 // indent-tabs-mode: nil