4 Copyright 2004 $ThePhpWikiProgrammingTeam
5 Copyright 2008 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 _("Chown 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 if ( ($owner = $page->getOwner()) and
68 $newowner != $owner ) {
69 if (!mayAccessPage('change', $name)) {
70 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
73 $page->set('owner', $newowner);
74 if ($page->get('owner') === $newowner) {
75 $ul->pushContent(HTML::li(fmt("Chown page '%s' to '%s'.",
76 WikiLink($name), WikiLink($newowner))));
79 $ul->pushContent(HTML::li(fmt("Couldn't chown page '%s' to '%s'.",
80 WikiLink($name), $newowner)));
87 return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.",
90 return HTML($ul, HTML::p(fmt("No pages changed.")));
94 function run($dbi, $argstr, &$request, $basepage) {
95 if ($request->getArg('action') != 'browse')
96 if (!$request->getArg('action') == _("PhpWikiAdministration/Chown"))
97 return $this->disabled("(action != 'browse')");
99 $args = $this->getArgs($argstr, $request);
100 $this->_args = $args;
101 if (empty($args['user']))
102 $args['user'] = $request->_user->UserName();
103 /*if (!empty($args['exclude']))
104 $exclude = explodePageList($args['exclude']);
107 $this->preSelectS($args, $request);
109 $p = $request->getArg('p');
110 if (!$p) $p = $this->_list;
111 $post_args = $request->getArg('admin_chown');
112 if (!$request->isPost() and empty($post_args['user']))
113 $post_args['user'] = $args['user'];
114 $next_action = 'select';
116 if ($p && !$request->isPost())
118 if ($p && $request->isPost() &&
119 !empty($post_args['chown']) && empty($post_args['cancel'])) {
120 // without individual PagePermissions:
121 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
122 $request->_notAuthorized(WIKIAUTH_ADMIN);
123 $this->disabled("! user->isAdmin");
125 // DONE: error message if not allowed.
126 if ($post_args['action'] == 'verify') {
128 return $this->chownPages($dbi, $request, array_keys($p),
131 if ($post_args['action'] == 'select') {
132 if (!empty($post_args['user']))
133 $next_action = 'verify';
134 foreach ($p as $name => $c) {
139 if ($next_action == 'select' and empty($pages)) {
140 // List all pages to select from.
141 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'],
144 /* // let the user decide which info
145 if ($next_action == 'verify') {
146 $args['info'] = "checkbox,pagename,owner,mtime";
149 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], $args);
150 $pagelist->addPageList($pages);
152 $header = HTML::div();
153 if ($next_action == 'verify') {
154 $button_label = _("Yes");
155 $header->pushContent(
156 HTML::p(HTML::strong(
157 _("Are you sure you want to permanently chown the selected files?"))));
158 $header = $this->chownForm($header, $post_args);
161 $button_label = _("Chown selected pages");
162 $header->pushContent(HTML::p(_("Select the pages to change the owner:")));
163 $header = $this->chownForm($header, $post_args);
166 $buttons = HTML::p(Button('submit:admin_chown[chown]', $button_label, 'wikiadmin'),
167 Button('submit:admin_chown[cancel]', _("Cancel"), 'button'));
169 return HTML::form(array('action' => $request->getPostURL(),
173 $pagelist->getContent(),
174 HiddenInputs($request->getArgs(),
176 array('admin_chown')),
177 HiddenInputs(array('admin_chown[action]' => $next_action)),
180 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)));
183 function chownForm(&$header, $post_args) {
184 $header->pushContent(_("Chown")." ");
185 $header->pushContent(' '._("to").': ');
186 $header->pushContent(HTML::input(array('name' => 'admin_chown[user]',
187 'value' => $post_args['user'])));
188 $header->pushContent(HTML::p());
197 // c-hanging-comment-ender-p: nil
198 // indent-tabs-mode: nil