2 rcs_id('$Id: WikiAdminRename.php,v 1.1 2004-02-11 20:00:16 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Usage: <?plugin WikiAdminRename ?> or called via WikiAdminSelect
25 * Author: Reini Urban <rurban@x-ray.at>
28 * Currently we must be Admin.
29 * Future versions will support PagePermissions.
30 * requires PHP 4.2 so far.
32 require_once('lib/PageList.php');
33 require_once('lib/plugin/WikiAdminSelect.php');
35 class WikiPlugin_WikiAdminRename
36 extends WikiPlugin_WikiAdminSelect
39 return _("WikiAdminRename");
42 function getDescription() {
43 return _("Rename selected pages.");
46 function getVersion() {
47 return preg_replace("/[Revision: $]/", '',
51 function getDefaultArguments() {
53 /* Pages to exclude */
55 /* Columns to include in listing */
56 'info' => 'pagename,mtime',
58 'sortby' => 'pagename',
62 function renameHelper($name, $from, $to) {
63 return str_replace($from,$to,$name);
66 function renamePages(&$request, $pages, $from, $to) {
68 $dbi = $request->getDbh();
70 foreach ($pages as $name) {
71 if (($newname = $this->renameHelper($name,$from,$to)) and $newname != $name) {
72 $dbi->renamePage($name,$newname); /* not yet implemented */
73 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.", $name, $newname)));
75 } elseif (! $newname) {
76 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
81 HTML::p(fmt("%s pages have been permanently renamed.",$count)));
84 function run($dbi, $argstr, $request) {
85 if ($request->getArg('action') != 'browse')
86 return $this->disabled("(action != 'browse')");
88 $args = $this->getArgs($argstr, $request);
90 if (!empty($args['exclude']))
91 $exclude = explodePageList($args['exclude']);
96 $p = $request->getArg('p');
97 $post_args = $request->getArg('admin_rename');
98 $next_action = 'select';
101 if ($p && $request->isPost() && $request->_user->isAdmin()
102 && !empty($post_args['rename']) && empty($post_args['cancel'])) {
103 // FIXME: error message if not admin.
104 if ($post_args['action'] == 'verify') {
106 return $this->renamePages($request, $p, $post_args['from'], $post_args['to']);
109 if ($post_args['action'] == 'select') {
110 if (!empty($post_args['from']))
111 $next_action = 'verify';
112 foreach ($p as $name) {
117 if ($next_action == 'select') {
118 // List all pages to select from.
119 $list = $this->collectPages($pages, $dbi, $args['sortby']);
125 $info .= "," . $args['info'];
126 if ($next_action == 'verify') {
127 $info = "checkbox,pagename,renamed_pagename";
129 $pagelist = new PageList_Selectable($info, $exclude);
130 $pagelist->addPageList($pages);
133 if ($next_action == 'verify') {
134 $button_label = _("Yes");
135 $header->pushContent(
136 HTML::p(HTML::strong(
137 _("Are you sure you want to permanently rename the selected files?"))));
138 $header->pushContent(_("Rename")." "._("from").': ');
139 $header->pushContent(HTML::input(array('name' => 'admin_rename[from]',
140 'value' => $post_args['from'])));
141 $header->pushContent(' '._("to").': ');
142 $header->pushContent(HTML::input(array('name' => 'admin_rename[to]',
143 'value' => $post_args['to'])));
144 $header->pushContent(' '._("(no regex, case-sensitive)"));
145 $header->pushContent(HTML::p());
148 $button_label = _("Rename selected pages");
149 $header->pushContent(HTML::p(_("Select the pages to rename:")));
150 $header->pushContent(_("Rename")." "._("from").': ');
151 $header->pushContent(HTML::input(array('name' => 'admin_rename[from]')));
152 $header->pushContent(' '._("to").': ');
153 $header->pushContent(HTML::input(array('name' => 'admin_rename[to]')));
154 $header->pushContent(' '._("(no regex, case-sensitive)"));
155 $header->pushContent(HTML::p());
159 $buttons = HTML::p(Button('submit:admin_rename[rename]', $button_label, 'wikiadmin'),
160 Button('submit:admin_rename[cancel]', _("Cancel"), 'button'));
162 return HTML::form(array('action' => $request->getPostURL(),
165 $pagelist->getContent(),
166 HiddenInputs($request->getArgs(),
168 array('admin_rename')),
169 HiddenInputs(array('admin_rename[action]' => $next_action,
170 'require_authority_for_post' => WIKIAUTH_ADMIN)),
175 // $Log: not supported by cvs2svn $
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil