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 getVersion() {
46 return preg_replace("/[Revision: $]/", '',
50 function getDefaultArguments() {
53 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
56 /* Columns to include in listing */
57 'info' => 'pagename,owner,mtime',
61 function chownPages(&$dbi, &$request, $pages, $newowner) {
62 $result = HTML::div();
65 foreach ($pages as $name) {
66 $page = $dbi->getPage($name);
67 $current = $page->getCurrentRevision();
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 $version = $current->getVersion();
75 $meta = $current->_data;
76 $text = $current->getPackedContent();
77 $meta['summary'] = "Change page owner from '".$owner."' to '".$newowner."'";
78 $meta['is_minor_edit'] = 1;
79 $meta['author'] = $request->_user->UserName();
80 unset($meta['mtime']); // force new date
81 $page->set('owner', $newowner);
82 $page->save($text, $version + 1, $meta);
83 if ($page->get('owner') === $newowner) {
84 $ul->pushContent(HTML::li(fmt("Change owner of page '%s' to '%s'.",
85 WikiLink($name), WikiLink($newowner))));
88 $ul->pushContent(HTML::li(fmt("Could not change owner of page '%s' to '%s'.",
89 WikiLink($name), $newowner)));
96 $result->setAttr('class', 'feedback');
98 $result->pushContent(HTML::p("One page has been permanently changed:"));
100 $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
102 $result->pushContent($ul);
105 $result->setAttr('class', 'error');
106 $result->pushContent(HTML::p("No pages changed."));
111 function run($dbi, $argstr, &$request, $basepage) {
112 if ($request->getArg('action') != 'browse')
113 if (!$request->getArg('action') == _("PhpWikiAdministration/Chown"))
114 return $this->disabled("(action != 'browse')");
116 $args = $this->getArgs($argstr, $request);
117 $this->_args = $args;
118 if (empty($args['user']))
119 $args['user'] = $request->_user->UserName();
120 /*if (!empty($args['exclude']))
121 $exclude = explodePageList($args['exclude']);
124 $this->preSelectS($args, $request);
126 $p = $request->getArg('p');
127 if (!$p) $p = $this->_list;
128 $post_args = $request->getArg('admin_chown');
129 if (!$request->isPost() and empty($post_args['user']))
130 $post_args['user'] = $args['user'];
131 $next_action = 'select';
133 if ($p && !$request->isPost())
135 if ($p && $request->isPost() &&
136 !empty($post_args['chown']) && empty($post_args['cancel'])) {
137 // without individual PagePermissions:
138 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
139 $request->_notAuthorized(WIKIAUTH_ADMIN);
140 $this->disabled("! user->isAdmin");
142 // DONE: error message if not allowed.
143 if ($post_args['action'] == 'verify') {
145 return $this->chownPages($dbi, $request, array_keys($p),
146 trim($post_args['user']));
148 if ($post_args['action'] == 'select') {
149 if (!empty($post_args['user']))
150 $next_action = 'verify';
151 foreach ($p as $name => $c) {
156 if ($next_action == 'select' and empty($pages)) {
157 // List all pages to select from.
158 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
161 /* // let the user decide which info
162 if ($next_action == 'verify') {
163 $args['info'] = "checkbox,pagename,owner,mtime";
166 if ($next_action == 'select') {
167 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
169 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
171 $pagelist->addPageList($pages);
173 $header = HTML::fieldset();
174 if ($next_action == 'verify') {
175 $button_label = _("Yes");
176 $header->pushContent(
177 HTML::p(HTML::strong(
178 _("Are you sure you want to permanently change the owner of the selected pages?"))));
179 $header = $this->chownForm($header, $post_args);
182 $button_label = _("Change owner of selected pages");
183 $header->pushContent(HTML::legend(_("Select the pages to change the owner")));
184 $header = $this->chownForm($header, $post_args);
187 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
188 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
189 $header->pushContent($buttons);
191 return HTML::form(array('action' => $request->getPostURL(),
194 $pagelist->getContent(),
195 HiddenInputs($request->getArgs(),
197 array('admin_chown')),
198 HiddenInputs(array('admin_chown[action]' => $next_action)),
201 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
204 function chownForm(&$header, $post_args) {
205 $header->pushContent(_("Change owner")." ");
206 $header->pushContent(' '._("to").': ');
207 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
208 'value' => $post_args['user'],
218 // c-hanging-comment-ender-p: nil
219 // indent-tabs-mode: nil