2 rcs_id('$Id: WikiAdminRename.php,v 1.14 2004-06-03 22:24:48 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
31 * Enabled now PagePermissions.
32 * Requires PHP 4.2 so far.
34 require_once('lib/PageList.php');
35 require_once('lib/plugin/WikiAdminSelect.php');
37 class WikiPlugin_WikiAdminRename
38 extends WikiPlugin_WikiAdminSelect
41 return _("WikiAdminRename");
44 function getDescription() {
45 return _("Rename selected pages.");
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
50 "\$Revision: 1.14 $");
53 function getDefaultArguments() {
56 /* Pages to exclude in listing */
58 /* Columns to include in listing */
59 'info' => 'pagename,mtime',
61 'sortby' => 'pagename',
68 function renameHelper($name, $from, $to) {
69 return str_replace($from,$to,$name);
72 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks=false) {
75 foreach ($pages as $name) {
76 if ( ($newname = $this->renameHelper($name,$from,$to)) and
78 if ($dbi->isWikiPage($newname))
79 $ul->pushContent(HTML::li(fmt("Page %s already exists. Ignored.",WikiLink($newname))));
80 elseif (!mayAccessPage('change',$name))
81 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",WikiLink($name))));
82 elseif ( $dbi->renamePage($name,$newname,$updatelinks)) {
83 /* not yet implemented for all backends */
84 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.",$name,WikiLink($newname))));
87 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
90 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
95 return HTML($ul, HTML::p(fmt("%s pages have been permanently renamed.",$count)));
97 return HTML($ul, HTML::p(fmt("No pages renamed.")));
101 function run($dbi, $argstr, &$request, $basepage) {
102 if ($request->getArg('action') != 'browse')
103 return $this->disabled("(action != 'browse')");
105 $args = $this->getArgs($argstr, $request);
106 $this->_args = $args;
107 if (!empty($args['exclude']))
108 $exclude = explodePageList($args['exclude']);
111 $this->preSelectS(&$args, &$request);
113 $p = $request->getArg('p');
114 if (!$p) $p = $this->_list;
115 $post_args = $request->getArg('admin_rename');
116 $next_action = 'select';
118 if ($p && !$request->isPost())
120 if ($p && $request->isPost() &&
121 !empty($post_args['rename']) && empty($post_args['cancel'])) {
122 // DONE: check individual PagePermissions
123 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
124 $request->_notAuthorized(WIKIAUTH_ADMIN);
125 $this->disabled("! user->isAdmin");
127 // DONE: error message if not allowed.
128 if ($post_args['action'] == 'verify') {
130 return $this->renamePages($dbi, $request, array_keys($p),
131 $post_args['from'], $post_args['to'], !empty($post_args['updatelinks']));
133 if ($post_args['action'] == 'select') {
134 if (!empty($post_args['from']))
135 $next_action = 'verify';
136 foreach ($p as $name => $c) {
141 if ($next_action == 'select' and empty($pages)) {
142 // List all pages to select from.
143 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
145 if ($next_action == 'verify') {
146 $args['info'] = "checkbox,pagename,renamed_pagename";
148 $pagelist = new PageList_Selectable
150 $args['info'], $exclude,
152 array('renamed_pagename'
153 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
155 $pagelist->addPageList($pages);
158 if ($next_action == 'verify') {
159 $button_label = _("Yes");
160 $header->pushContent(
161 HTML::p(HTML::strong(
162 _("Are you sure you want to permanently rename the selected files?"))));
163 $header = $this->renameForm($header, $post_args);
166 $button_label = _("Rename selected pages");
167 $header->pushContent(HTML::p(_("Select the pages to rename:")));
168 $header = $this->renameForm($header, $post_args);
172 $buttons = HTML::p(Button('submit:admin_rename[rename]', $button_label, 'wikiadmin'),
173 Button('submit:admin_rename[cancel]', _("Cancel"), 'button'));
175 return HTML::form(array('action' => $request->getPostURL(),
178 $pagelist->getContent(),
179 HiddenInputs($request->getArgs(),
181 array('admin_rename')),
182 HiddenInputs(array('admin_rename[action]' => $next_action,
183 /*'require_authority_for_post' => WIKIAUTH_ADMIN */)),
187 function renameForm(&$header, $post_args) {
188 $header->pushContent(_("Rename")." "._("from").': ');
189 $header->pushContent(HTML::input(array('name' => 'admin_rename[from]',
190 'value' => $post_args['from'])));
191 $header->pushContent(' '._("to").': ');
192 $header->pushContent(HTML::input(array('name' => 'admin_rename[to]',
193 'value' => $post_args['to'])));
194 $header->pushContent(' '._("(no regex, case-sensitive)"));
195 if (DEBUG) { // not yet tested
196 $header->pushContent(HTML::br());
197 $header->pushContent(_("Change pagename in all linked pages also?"));
198 $header->pushContent(HTML::em(_("(Currently not working)")));
199 $checkbox = HTML::input(array('type' => 'checkbox',
200 'name' => 'admin_rename[updatelinks]',
202 if (!empty($post_args['updatelinks']))
203 $checkbox->setAttr('checked','checked');
204 $header->pushContent($checkbox);
206 $header->pushContent(HTML::p());
211 // moved from lib/PageList.php
212 class _PageList_Column_renamed_pagename extends _PageList_Column {
213 function _getValue ($page_handle, &$revision_handle) {
214 $post_args = $GLOBALS['request']->getArg('admin_rename');
215 $value = str_replace($post_args['from'], $post_args['to'],$page_handle->getName());
216 $div = HTML::div(" => ",HTML::input(array('type' => 'text',
217 'name' => 'rename[]',
218 'value' => $value)));
219 $new_page = $GLOBALS['request']->getPage($value);
220 if ($new_page->exists()) {
221 $div->setAttr('class','error');
222 $div->setAttr('title',_("This page already exists"));
228 // $Log: not supported by cvs2svn $
229 // Revision 1.13 2004/06/03 12:59:41 rurban
230 // simplify translation
231 // NS4 wrap=virtual only
233 // Revision 1.12 2004/06/01 15:28:01 rurban
234 // AdminUser only ADMIN_USER not member of Administrators
235 // some RateIt improvements by dfrankow
236 // edit_toolbar buttons
238 // Revision 1.11 2004/05/24 17:34:53 rurban
241 // Revision 1.10 2004/04/06 20:00:11 rurban
242 // Cleanup of special PageList column types
243 // Added support of plugin and theme specific Pagelist Types
244 // Added support for theme specific UserPreferences
245 // Added session support for ip-based throttling
246 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
247 // Enhanced postgres schema
248 // Added DB_Session_dba support
250 // Revision 1.9 2004/03/12 13:31:43 rurban
251 // enforce PagePermissions, errormsg if not Admin
253 // Revision 1.8 2004/03/01 13:48:46 rurban
255 // p[] consistency fix
257 // Revision 1.7 2004/02/22 23:20:33 rurban
258 // fixed DumpHtmlToDir,
259 // enhanced sortby handling in PageList
260 // new button_heading th style (enabled),
261 // added sortby and limit support to the db backends and plugins
262 // for paging support (<<prev, next>> links on long lists)
264 // Revision 1.6 2004/02/17 12:11:36 rurban
265 // 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, ...)
267 // Revision 1.5 2004/02/15 21:34:37 rurban
268 // PageList enhanced and improved.
269 // fixed new WikiAdmin... plugins
270 // editpage, Theme with exp. htmlarea framework
271 // (htmlarea yet committed, this is really questionable)
272 // WikiUser... code with better session handling for prefs
273 // enhanced UserPreferences (again)
274 // RecentChanges for show_deleted: how should pages be deleted then?
276 // Revision 1.4 2004/02/12 17:05:39 rurban
278 // added "Change pagename in all linked pages also"
280 // added javascript toggle for Select
281 // WikiAdminSearchReplace:
282 // fixed another typo
284 // Revision 1.3 2004/02/12 13:05:50 rurban
285 // Rename functional for PearDB backend
286 // some other minor changes
287 // SiteMap comes with a not yet functional feature request: includepages (tbd)
289 // Revision 1.2 2004/02/12 11:45:11 rurban
290 // only WikiDB method missing
292 // Revision 1.1 2004/02/11 20:00:16 rurban
293 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
300 // c-hanging-comment-ender-p: nil
301 // indent-tabs-mode: nil