2 rcs_id('$Id: WikiAdminRename.php,v 1.22 2004-11-23 15:17:20 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>
27 * TODO: support case-insensitive checkbox
28 * support regex checkbox and renaming
32 * Enabled now PagePermissions.
33 * Requires PHP 4.2 so far.
35 require_once('lib/PageList.php');
36 require_once('lib/plugin/WikiAdminSelect.php');
38 class WikiPlugin_WikiAdminRename
39 extends WikiPlugin_WikiAdminSelect
42 return _("WikiAdminRename");
45 function getDescription() {
46 return _("Rename selected pages.");
49 function getVersion() {
50 return preg_replace("/[Revision: $]/", '',
51 "\$Revision: 1.22 $");
54 function getDefaultArguments() {
57 PageList::supportedArgs(),
60 /* Columns to include in listing */
61 'info' => 'pagename,mtime',
66 //TODO: regex and case-inexact option
67 function renameHelper($name, $from, $to, $options=false) {
68 return str_replace($from, $to, $name);
71 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks=false) {
74 foreach ($pages as $name) {
75 if (0 and $updatelinks) { // do it in the backend
76 $oldpage = $dbi->getPage($from);
77 require_once('lib/plugin/WikiAdminSearchReplace.php');
78 //$newpage = $dbi->getPage($to);
79 $links = $oldpage->getBackLinks();
80 while ($linked_page = $links->next()) {
81 if (WikiPlugin_WikiAdminSearchReplace::replaceHelper($dbi,$linked_page->getName(),$from,$to))
82 $ul->pushContent(HTML::li(fmt("Replaced link in %s.",
83 WikiLink($linked_page->getName()))));
85 $links = $oldpage->getPageLinks();
86 while ($linked_page = $links->next()) {
87 WikiPlugin_WikiAdminSearchReplace::replaceHelper($dbi,$linked_page->getName(),$from,$to);
88 $ul->pushContent(HTML::li(fmt("Replaced link in %s.",
89 WikiLink($linked_page->getName()))));
92 if ( ($newname = $this->renameHelper($name, $from, $to))
93 and $newname != $name )
95 if ($dbi->isWikiPage($newname))
96 $ul->pushContent(HTML::li(fmt("Page %s already exists. Ignored.",
97 WikiLink($newname))));
98 elseif (! mayAccessPage('change', $name))
99 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",
101 elseif ( $dbi->renamePage($name, $newname, $updatelinks)) {
102 /* not yet implemented for all backends */
103 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.",
104 $name, WikiLink($newname))));
107 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.",
111 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.",
117 return HTML($ul, HTML::p(fmt("%s pages have been permanently renamed.",
120 return HTML($ul, HTML::p(fmt("No pages renamed.")));
124 function run($dbi, $argstr, &$request, $basepage) {
125 if ($request->getArg('action') != 'browse')
126 if ($request->getArg('action') != _("PhpWikiAdministration/Rename"))
127 return $this->disabled("(action != 'browse')");
129 $args = $this->getArgs($argstr, $request);
130 $this->_args = $args;
131 $this->preSelectS($args, $request);
133 $p = $request->getArg('p');
134 if (!$p) $p = $this->_list;
135 $post_args = $request->getArg('admin_rename');
136 $next_action = 'select';
138 if ($p && !$request->isPost())
140 if ($p && $request->isPost() &&
141 !empty($post_args['rename']) && empty($post_args['cancel'])) {
142 // without individual PagePermissions:
143 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
144 $request->_notAuthorized(WIKIAUTH_ADMIN);
145 $this->disabled("! user->isAdmin");
147 // DONE: error message if not allowed.
148 if ($post_args['action'] == 'verify') {
150 return $this->renamePages($dbi, $request, array_keys($p),
151 trim($post_args['from']), trim($post_args['to']),
152 !empty($post_args['updatelinks']));
154 if ($post_args['action'] == 'select') {
155 if (!empty($post_args['from']))
156 $next_action = 'verify';
157 foreach ($p as $name => $c) {
162 if ($next_action == 'select' and empty($pages)) {
163 // List all pages to select from.
164 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
166 if ($next_action == 'verify') {
167 $args['info'] = "checkbox,pagename,renamed_pagename";
169 $pagelist = new PageList_Selectable
171 $args['info'], $args['exclude'],
173 array('renamed_pagename'
174 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
176 $pagelist->addPageList($pages);
179 if ($next_action == 'verify') {
180 $button_label = _("Yes");
181 $header->pushContent(
182 HTML::p(HTML::strong(
183 _("Are you sure you want to permanently rename the selected files?"))));
184 $header = $this->renameForm($header, $post_args);
187 $button_label = _("Rename selected pages");
188 $header->pushContent(HTML::p(_("Select the pages to rename:")));
189 $header = $this->renameForm($header, $post_args);
192 $buttons = HTML::p(Button('submit:admin_rename[rename]', $button_label, 'wikiadmin'),
193 Button('submit:admin_rename[cancel]', _("Cancel"), 'button'));
195 return HTML::form(array('action' => $request->getPostURL(),
198 $pagelist->getContent(),
199 HiddenInputs($request->getArgs(),
201 array('admin_rename')),
202 HiddenInputs(array('admin_rename[action]' => $next_action)),
205 : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)),
209 function checkBox (&$post_args, $name, $msg) {
211 $checkbox = HTML::input(array('type' => 'checkbox',
212 'name' => 'admin_rename['.$name.']',
214 if (!empty($post_args[$name]))
215 $checkbox->setAttr('checked', 'checked');
216 //$html->pushContent($checkbox);
217 //$html->pushContent($msg);
218 return HTML::div($checkbox, HTML::span($msg));
221 function renameForm(&$header, $post_args) {
222 $header->pushContent(_("Rename")." "._("from").': ');
223 $header->pushContent(HTML::input(array('name' => 'admin_rename[from]',
224 'value' => trim($post_args['from']))));
225 $header->pushContent(' '._("to").': ');
226 $header->pushContent(HTML::input(array('name' => 'admin_rename[to]',
227 'value' => trim($post_args['to']))));
229 $header->pushContent($this->checkBox($post_args, 'regex', _("Regex?")));
230 $header->pushContent($this->checkBox($post_args, 'case-sensitive', _("Case sensitive?")));
232 $header->pushContent(' '._("(no regex, case-sensitive)"));
234 if (DEBUG) { // not yet tested
235 $header->pushContent($this->checkBox($post_args, 'updatelinks', _("Change pagename in all linked pages also?")));
237 $header->pushContent(HTML::br());
238 $checkbox = HTML::input(array('type' => 'checkbox',
239 'name' => 'admin_rename[updatelinks]',
241 if (!empty($post_args['updatelinks']))
242 $checkbox->setAttr('checked','checked');
243 $header->pushContent($checkbox);
244 $header->pushContent(_("Change pagename in all linked pages also?"));
246 //$header->pushContent(HTML::em(_("(Currently not working)")));
248 $header->pushContent(HTML::p());
253 // TODO: grey out unrenamable pages, even in the initial list also?
254 // TODO: autoselect by matching name javascript in admin_rename[from]
255 // TODO: update rename[] fields when case-sensitive and regex is changed
257 // moved from lib/PageList.php
258 class _PageList_Column_renamed_pagename extends _PageList_Column {
259 function _getValue ($page_handle, &$revision_handle) {
261 $post_args = $request->getArg('admin_rename');
262 $value = WikiPlugin_WikiAdminRename::renameHelper($page_handle->getName(), $post_args['from'], $post_args['to']);
264 $div = HTML::div(" => ",HTML::input(array('type' => 'text',
265 'name' => 'rename[]',
266 'value' => $value)));
267 $new_page = $request->getPage($value);
268 if ($new_page->exists()) {
269 $div->setAttr('class','error');
270 $div->setAttr('title',_("This page already exists"));
276 // $Log: not supported by cvs2svn $
277 // Revision 1.21 2004/11/01 10:43:59 rurban
278 // seperate PassUser methods into seperate dir (memory usage)
279 // fix WikiUser (old) overlarge data session
280 // remove wikidb arg from various page class methods, use global ->_dbi instead
283 // Revision 1.20 2004/06/16 10:38:59 rurban
284 // Disallow refernces in calls if the declaration is a reference
285 // ("allow_call_time_pass_reference clean").
286 // PhpWiki is now allow_call_time_pass_reference = Off clean,
287 // but several external libraries may not.
288 // In detail these libs look to be affected (not tested):
292 // Revision 1.19 2004/06/14 11:31:39 rurban
293 // renamed global $Theme to $WikiTheme (gforge nameclash)
294 // inherit PageList default options from PageList
295 // default sortby=pagename
296 // use options in PageList_Selectable (limit, sortby, ...)
297 // added action revert, with button at action=diff
298 // added option regex to WikiAdminSearchReplace
300 // Revision 1.18 2004/06/13 15:33:20 rurban
301 // new support for arguments owner, author, creator in most relevant
302 // PageList plugins. in WikiAdmin* via preSelectS()
304 // Revision 1.17 2004/06/08 10:05:12 rurban
305 // simplified admin action shortcuts
307 // Revision 1.16 2004/06/07 18:57:31 rurban
308 // fix rename: Change pagename in all linked pages
310 // Revision 1.15 2004/06/04 20:32:54 rurban
311 // Several locale related improvements suggested by Pierrick Meignen
312 // LDAP fix by John Cole
313 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
315 // Revision 1.14 2004/06/03 22:24:48 rurban
316 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
318 // Revision 1.13 2004/06/03 12:59:41 rurban
319 // simplify translation
320 // NS4 wrap=virtual only
322 // Revision 1.12 2004/06/01 15:28:01 rurban
323 // AdminUser only ADMIN_USER not member of Administrators
324 // some RateIt improvements by dfrankow
325 // edit_toolbar buttons
327 // Revision 1.11 2004/05/24 17:34:53 rurban
330 // Revision 1.10 2004/04/06 20:00:11 rurban
331 // Cleanup of special PageList column types
332 // Added support of plugin and theme specific Pagelist Types
333 // Added support for theme specific UserPreferences
334 // Added session support for ip-based throttling
335 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
336 // Enhanced postgres schema
337 // Added DB_Session_dba support
339 // Revision 1.9 2004/03/12 13:31:43 rurban
340 // enforce PagePermissions, errormsg if not Admin
342 // Revision 1.8 2004/03/01 13:48:46 rurban
344 // p[] consistency fix
346 // Revision 1.7 2004/02/22 23:20:33 rurban
347 // fixed DumpHtmlToDir,
348 // enhanced sortby handling in PageList
349 // new button_heading th style (enabled),
350 // added sortby and limit support to the db backends and plugins
351 // for paging support (<<prev, next>> links on long lists)
353 // Revision 1.6 2004/02/17 12:11:36 rurban
354 // 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, ...)
356 // Revision 1.5 2004/02/15 21:34:37 rurban
357 // PageList enhanced and improved.
358 // fixed new WikiAdmin... plugins
359 // editpage, Theme with exp. htmlarea framework
360 // (htmlarea yet committed, this is really questionable)
361 // WikiUser... code with better session handling for prefs
362 // enhanced UserPreferences (again)
363 // RecentChanges for show_deleted: how should pages be deleted then?
365 // Revision 1.4 2004/02/12 17:05:39 rurban
367 // added "Change pagename in all linked pages also"
369 // added javascript toggle for Select
370 // WikiAdminSearchReplace:
371 // fixed another typo
373 // Revision 1.3 2004/02/12 13:05:50 rurban
374 // Rename functional for PearDB backend
375 // some other minor changes
376 // SiteMap comes with a not yet functional feature request: includepages (tbd)
378 // Revision 1.2 2004/02/12 11:45:11 rurban
379 // only WikiDB method missing
381 // Revision 1.1 2004/02/11 20:00:16 rurban
382 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
389 // c-hanging-comment-ender-p: nil
390 // indent-tabs-mode: nil