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) {
63 $result = HTML::div();
66 foreach ($pages as $name) {
67 $page = $dbi->getPage($name);
68 $current = $page->getCurrentRevision();
69 if ( ($owner = $page->getOwner()) and
70 $newowner != $owner ) {
71 if (!mayAccessPage('change', $name)) {
72 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
75 $version = $current->getVersion();
76 $meta = $current->_data;
77 $text = $current->getPackedContent();
78 $meta['summary'] = "Change page owner from '".$owner."' to '".$newowner."'";
79 $meta['is_minor_edit'] = 0;
80 $meta['author'] = $request->_user->UserName();
81 unset($meta['mtime']); // force new date
82 $page->set('owner', $newowner);
83 $page->save($text, $version + 1, $meta);
84 if ($page->get('owner') === $newowner) {
85 $ul->pushContent(HTML::li(fmt("Change owner of page '%s' to '%s'.",
86 WikiLink($name), WikiLink($newowner))));
89 $ul->pushContent(HTML::li(fmt("Could not change owner of page '%s' to '%s'.",
90 WikiLink($name), $newowner)));
97 $result->setAttr('class', 'feedback');
99 $result->pushContent(HTML::p("One page has been permanently changed:"));
101 $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
103 $result->pushContent($ul);
106 $result->setAttr('class', 'error');
107 $result->pushContent(HTML::p("No pages changed."));
112 function run($dbi, $argstr, &$request, $basepage) {
113 if ($request->getArg('action') != 'browse')
114 if (!$request->getArg('action') == _("PhpWikiAdministration/Chown"))
115 return $this->disabled("(action != 'browse')");
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'])) {
138 // without individual PagePermissions:
139 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
140 $request->_notAuthorized(WIKIAUTH_ADMIN);
141 $this->disabled("! user->isAdmin");
143 // DONE: error message if not allowed.
144 if ($post_args['action'] == 'verify') {
146 return $this->chownPages($dbi, $request, array_keys($p),
147 trim($post_args['user']));
149 if ($post_args['action'] == 'select') {
150 if (!empty($post_args['user']))
151 $next_action = 'verify';
152 foreach ($p as $name => $c) {
157 if ($next_action == 'select' and empty($pages)) {
158 // List all pages to select from.
159 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
162 /* // let the user decide which info
163 if ($next_action == 'verify') {
164 $args['info'] = "checkbox,pagename,owner,mtime";
167 if ($next_action == 'select') {
168 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
170 $pagelist = new PageList_Unselectable($args['info'], $args['exclude'], $args);
172 $pagelist->addPageList($pages);
174 $header = HTML::fieldset();
175 if ($next_action == 'verify') {
176 $button_label = _("Yes");
177 $header->pushContent(
178 HTML::p(HTML::strong(
179 _("Are you sure you want to permanently change the owner of the selected pages?"))));
180 $header = $this->chownForm($header, $post_args);
183 $button_label = _("Change owner of selected pages");
184 $header->pushContent(HTML::legend(_("Select the pages to change the owner")));
185 $header = $this->chownForm($header, $post_args);
188 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
189 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
190 $header->pushContent($buttons);
192 return HTML::form(array('action' => $request->getPostURL(),
195 $pagelist->getContent(),
196 HiddenInputs($request->getArgs(),
198 array('admin_chown')),
199 HiddenInputs(array('admin_chown[action]' => $next_action)),
202 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
205 function chownForm(&$header, $post_args) {
206 $header->pushContent(_("Change owner")." ");
207 $header->pushContent(' '._("to").': ');
208 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
209 'value' => $post_args['user'],
219 // c-hanging-comment-ender-p: nil
220 // indent-tabs-mode: nil