2 rcs_id('$Id: WikiAdminRename.php,v 1.6 2004-02-17 12:11:36 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 in listing */
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(&$dbi, &$request, $pages, $from, $to, $updatelinks=false) {
69 foreach ($pages as $name) {
70 if ( ($newname = $this->renameHelper($name,$from,$to)) and
72 $dbi->renamePage($name,$newname,$updatelinks) ) {
73 /* not yet implemented for all backends */
74 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.",$name,WikiLink($newname))));
77 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
83 HTML::p(fmt("%s pages have been permanently renamed.",$count)));
86 HTML::p(fmt("No pages renamed.")));
90 function run($dbi, $argstr, &$request, $basepage) {
91 if ($request->getArg('action') != 'browse')
92 return $this->disabled("(action != 'browse')");
94 $args = $this->getArgs($argstr, $request);
96 if (!empty($args['exclude']))
97 $exclude = explodePageList($args['exclude']);
101 $p = $request->getArg('p');
102 $post_args = $request->getArg('admin_rename');
103 $next_action = 'select';
105 if ($p && !$request->isPost())
107 if ($p && $request->isPost() && $request->_user->isAdmin()
108 && !empty($post_args['rename']) && empty($post_args['cancel'])) {
109 // FIXME: error message if not admin.
110 if ($post_args['action'] == 'verify') {
112 return $this->renamePages($dbi, $request, $p,
113 $post_args['from'], $post_args['to'], $post_args['updatelinks']);
115 if ($post_args['action'] == 'select') {
116 if (!empty($post_args['from']))
117 $next_action = 'verify';
118 foreach ($p as $name) {
123 if ($next_action == 'select' and empty($pages)) {
124 // List all pages to select from.
125 $pages = $this->collectPages($pages, $dbi, $args['sortby']);
127 if ($next_action == 'verify') {
128 $args['info'] = "checkbox,pagename,renamed_pagename";
130 $pagelist = new PageList_Selectable($args['info'], $exclude);
131 $pagelist->addPageList($pages);
134 if ($next_action == 'verify') {
135 $button_label = _("Yes");
136 $header->pushContent(
137 HTML::p(HTML::strong(
138 _("Are you sure you want to permanently rename the selected files?"))));
139 $header = $this->renameForm($header, $post_args);
142 $button_label = _("Rename selected pages");
143 $header->pushContent(HTML::p(_("Select the pages to rename:")));
144 $header = $this->renameForm($header, $post_args);
148 $buttons = HTML::p(Button('submit:admin_rename[rename]', $button_label, 'wikiadmin'),
149 Button('submit:admin_rename[cancel]', _("Cancel"), 'button'));
151 return HTML::form(array('action' => $request->getPostURL(),
154 $pagelist->getContent(),
155 HiddenInputs($request->getArgs(),
157 array('admin_rename')),
158 HiddenInputs(array('admin_rename[action]' => $next_action,
159 'require_authority_for_post' => WIKIAUTH_ADMIN)),
163 function renameForm(&$header, $post_args) {
164 $header->pushContent(_("Rename")." "._("from").': ');
165 $header->pushContent(HTML::input(array('name' => 'admin_rename[from]',
166 'value' => $post_args['from'])));
167 $header->pushContent(' '._("to").': ');
168 $header->pushContent(HTML::input(array('name' => 'admin_rename[to]',
169 'value' => $post_args['to'])));
170 $header->pushContent(' '._("(no regex, case-sensitive)"));
171 if (0) { // not yet tested
172 $header->pushContent(HTML::br());
173 $header->pushContent(_("Change pagename in all linked pages also?"));
174 $checkbox = HTML::input(array('type' => 'checkbox',
175 'name' => 'admin_rename[updatelinks]',
177 if ($post_args['updatelinks'])
178 $checkbox->setAttr('checked','checked');
179 $header->pushContent($checkbox);
181 $header->pushContent(HTML::p());
187 // $Log: not supported by cvs2svn $
188 // Revision 1.5 2004/02/15 21:34:37 rurban
189 // PageList enhanced and improved.
190 // fixed new WikiAdmin... plugins
191 // editpage, Theme with exp. htmlarea framework
192 // (htmlarea yet committed, this is really questionable)
193 // WikiUser... code with better session handling for prefs
194 // enhanced UserPreferences (again)
195 // RecentChanges for show_deleted: how should pages be deleted then?
197 // Revision 1.4 2004/02/12 17:05:39 rurban
199 // added "Change pagename in all linked pages also"
201 // added javascript toggle for Select
202 // WikiAdminSearchReplace:
203 // fixed another typo
205 // Revision 1.3 2004/02/12 13:05:50 rurban
206 // Rename functional for PearDB backend
207 // some other minor changes
208 // SiteMap comes with a not yet functional feature request: includepages (tbd)
210 // Revision 1.2 2004/02/12 11:45:11 rurban
211 // only WikiDB method missing
213 // Revision 1.1 2004/02/11 20:00:16 rurban
214 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
221 // c-hanging-comment-ender-p: nil
222 // indent-tabs-mode: nil