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 PageList::supportedArgs(),
57 /* Columns to include in listing */
58 'info' => 'pagename,owner,mtime',
62 function chownPages(&$dbi, &$request, $pages, $newowner) {
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'] = sprintf(_("Change page owner from %s to %s"), $owner, $newowner);
78 $meta['is_minor_edit'] = 0;
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 return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
99 return HTML($ul, HTML::p(fmt("No pages changed.")));
103 function run($dbi, $argstr, &$request, $basepage) {
104 if ($request->getArg('action') != 'browse')
105 if (!$request->getArg('action') == _("PhpWikiAdministration/Chown"))
106 return $this->disabled("(action != 'browse')");
108 $args = $this->getArgs($argstr, $request);
109 $this->_args = $args;
110 if (empty($args['user']))
111 $args['user'] = $request->_user->UserName();
112 /*if (!empty($args['exclude']))
113 $exclude = explodePageList($args['exclude']);
116 $this->preSelectS($args, $request);
118 $p = $request->getArg('p');
119 if (!$p) $p = $this->_list;
120 $post_args = $request->getArg('admin_chown');
121 if (!$request->isPost() and empty($post_args['user']))
122 $post_args['user'] = $args['user'];
123 $next_action = 'select';
125 if ($p && !$request->isPost())
127 if ($p && $request->isPost() &&
128 !empty($post_args['chown']) && empty($post_args['cancel'])) {
129 // without individual PagePermissions:
130 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
131 $request->_notAuthorized(WIKIAUTH_ADMIN);
132 $this->disabled("! user->isAdmin");
134 // DONE: error message if not allowed.
135 if ($post_args['action'] == 'verify') {
137 return $this->chownPages($dbi, $request, array_keys($p),
138 trim($post_args['user']));
140 if ($post_args['action'] == 'select') {
141 if (!empty($post_args['user']))
142 $next_action = 'verify';
143 foreach ($p as $name => $c) {
148 if ($next_action == 'select' and empty($pages)) {
149 // List all pages to select from.
150 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
153 /* // let the user decide which info
154 if ($next_action == 'verify') {
155 $args['info'] = "checkbox,pagename,owner,mtime";
158 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
159 $pagelist->addPageList($pages);
161 $header = HTML::div();
162 if ($next_action == 'verify') {
163 $button_label = _("Yes");
164 $header->pushContent(
165 HTML::p(HTML::strong(
166 _("Are you sure you want to permanently change the owner of the selected pages?"))));
167 $header = $this->chownForm($header, $post_args);
170 $button_label = _("Change owner of selected pages");
171 $header->pushContent(HTML::p(_("Select the pages to change the owner:")));
172 $header = $this->chownForm($header, $post_args);
175 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
176 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
178 return HTML::form(array('action' => $request->getPostURL(),
182 $pagelist->getContent(),
183 HiddenInputs($request->getArgs(),
185 array('admin_chown')),
186 HiddenInputs(array('admin_chown[action]' => $next_action)),
189 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
192 function chownForm(&$header, $post_args) {
193 $header->pushContent(_("Change owner")." ");
194 $header->pushContent(' '._("to").': ');
195 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
196 'value' => $post_args['user'])));
205 // c-hanging-comment-ender-p: nil
206 // indent-tabs-mode: nil