2 rcs_id('$Id: WikiAdminRename.php,v 1.10 2004-04-06 20:00:11 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: $]/", '',
48 "\$Revision: 1.10 $");
51 function getDefaultArguments() {
53 /* Pages to exclude in listing */
55 /* Columns to include in listing */
56 'info' => 'pagename,mtime',
58 'sortby' => 'pagename',
64 function renameHelper($name, $from, $to) {
65 return str_replace($from,$to,$name);
68 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks=false) {
71 foreach ($pages as $name) {
72 if ( ($newname = $this->renameHelper($name,$from,$to)) and
74 $dbi->renamePage($name,$newname,$updatelinks) ) {
75 /* not yet implemented for all backends */
76 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.",$name,WikiLink($newname))));
79 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
85 HTML::p(fmt("%s pages have been permanently renamed.",$count)));
88 HTML::p(fmt("No pages renamed.")));
92 function run($dbi, $argstr, &$request, $basepage) {
93 if ($request->getArg('action') != 'browse')
94 return $this->disabled("(action != 'browse')");
96 $args = $this->getArgs($argstr, $request);
98 if (!empty($args['exclude']))
99 $exclude = explodePageList($args['exclude']);
103 $p = $request->getArg('p');
104 $post_args = $request->getArg('admin_rename');
105 $next_action = 'select';
107 if ($p && !$request->isPost())
109 if ($p && $request->isPost() &&
110 !empty($post_args['rename']) && empty($post_args['cancel'])) {
112 // FIXME: check individual PagePermissions
113 if (!$request->_user->isAdmin()) {
114 $request->_notAuthorized(WIKIAUTH_ADMIN);
115 $this->disabled("! user->isAdmin");
118 // FIXME: error message if not admin.
119 if ($post_args['action'] == 'verify') {
121 return $this->renamePages($dbi, $request, array_keys($p),
122 $post_args['from'], $post_args['to'], !empty($post_args['updatelinks']));
124 if ($post_args['action'] == 'select') {
125 if (!empty($post_args['from']))
126 $next_action = 'verify';
127 foreach ($p as $name => $c) {
132 if ($next_action == 'select' and empty($pages)) {
133 // List all pages to select from.
134 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
136 if ($next_action == 'verify') {
137 $args['info'] = "checkbox,pagename,renamed_pagename";
139 $pagelist = new PageList_Selectable
141 $args['info'], $exclude,
143 array('renamed_pagename'
144 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
146 $pagelist->addPageList($pages);
149 if ($next_action == 'verify') {
150 $button_label = _("Yes");
151 $header->pushContent(
152 HTML::p(HTML::strong(
153 _("Are you sure you want to permanently rename the selected files?"))));
154 $header = $this->renameForm($header, $post_args);
157 $button_label = _("Rename selected pages");
158 $header->pushContent(HTML::p(_("Select the pages to rename:")));
159 $header = $this->renameForm($header, $post_args);
163 $buttons = HTML::p(Button('submit:admin_rename[rename]', $button_label, 'wikiadmin'),
164 Button('submit:admin_rename[cancel]', _("Cancel"), 'button'));
166 return HTML::form(array('action' => $request->getPostURL(),
169 $pagelist->getContent(),
170 HiddenInputs($request->getArgs(),
172 array('admin_rename')),
173 HiddenInputs(array('admin_rename[action]' => $next_action,
174 'require_authority_for_post' => WIKIAUTH_ADMIN)),
178 function renameForm(&$header, $post_args) {
179 $header->pushContent(_("Rename")." "._("from").': ');
180 $header->pushContent(HTML::input(array('name' => 'admin_rename[from]',
181 'value' => $post_args['from'])));
182 $header->pushContent(' '._("to").': ');
183 $header->pushContent(HTML::input(array('name' => 'admin_rename[to]',
184 'value' => $post_args['to'])));
185 $header->pushContent(' '._("(no regex, case-sensitive)"));
186 if (1) { // not yet tested
187 $header->pushContent(HTML::br());
188 $header->pushContent(_("Change pagename in all linked pages also?"));
189 $checkbox = HTML::input(array('type' => 'checkbox',
190 'name' => 'admin_rename[updatelinks]',
192 if (!empty($post_args['updatelinks']))
193 $checkbox->setAttr('checked','checked');
194 $header->pushContent($checkbox);
196 $header->pushContent(HTML::p());
201 // moved from lib/PageList.php
202 class _PageList_Column_renamed_pagename extends _PageList_Column {
203 function _getValue ($page_handle, &$revision_handle) {
204 $post_args = $GLOBALS['request']->getArg('admin_rename');
205 $value = str_replace($post_args['from'], $post_args['to'],$page_handle->getName());
206 $div = HTML::div(" => ",HTML::input(array('type' => 'text',
207 'name' => 'rename[]',
208 'value' => $value)));
209 $new_page = $GLOBALS['request']->getPage($value);
210 if ($new_page->exists()) {
211 $div->setAttr('class','error');
212 $div->setAttr('title',_("This page already exists"));
218 // $Log: not supported by cvs2svn $
219 // Revision 1.9 2004/03/12 13:31:43 rurban
220 // enforce PagePermissions, errormsg if not Admin
222 // Revision 1.8 2004/03/01 13:48:46 rurban
224 // p[] consistency fix
226 // Revision 1.7 2004/02/22 23:20:33 rurban
227 // fixed DumpHtmlToDir,
228 // enhanced sortby handling in PageList
229 // new button_heading th style (enabled),
230 // added sortby and limit support to the db backends and plugins
231 // for paging support (<<prev, next>> links on long lists)
233 // Revision 1.6 2004/02/17 12:11:36 rurban
234 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
236 // Revision 1.5 2004/02/15 21:34:37 rurban
237 // PageList enhanced and improved.
238 // fixed new WikiAdmin... plugins
239 // editpage, Theme with exp. htmlarea framework
240 // (htmlarea yet committed, this is really questionable)
241 // WikiUser... code with better session handling for prefs
242 // enhanced UserPreferences (again)
243 // RecentChanges for show_deleted: how should pages be deleted then?
245 // Revision 1.4 2004/02/12 17:05:39 rurban
247 // added "Change pagename in all linked pages also"
249 // added javascript toggle for Select
250 // WikiAdminSearchReplace:
251 // fixed another typo
253 // Revision 1.3 2004/02/12 13:05:50 rurban
254 // Rename functional for PearDB backend
255 // some other minor changes
256 // SiteMap comes with a not yet functional feature request: includepages (tbd)
258 // Revision 1.2 2004/02/12 11:45:11 rurban
259 // only WikiDB method missing
261 // Revision 1.1 2004/02/11 20:00:16 rurban
262 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
269 // c-hanging-comment-ender-p: nil
270 // indent-tabs-mode: nil