2 rcs_id('$Id: WikiAdminRename.php,v 1.11 2004-05-24 17:34:53 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.11 $");
53 function getDefaultArguments() {
55 /* Pages to exclude in listing */
57 /* Columns to include in listing */
58 'info' => 'pagename,mtime',
60 'sortby' => 'pagename',
67 function renameHelper($name, $from, $to) {
68 return str_replace($from,$to,$name);
71 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks=false) {
74 foreach ($pages as $name) {
75 if ( ($newname = $this->renameHelper($name,$from,$to)) and
77 if ($dbi->isWikiPage($newname))
78 $ul->pushContent(HTML::li(fmt("Page %s already exists. Ignored.",WikiLink($newname))));
79 elseif (!mayAccessPage('change',$name))
80 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.",WikiLink($name))));
81 elseif ( $dbi->renamePage($name,$newname,$updatelinks)) {
82 /* not yet implemented for all backends */
83 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.",$name,WikiLink($newname))));
86 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
89 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
94 return HTML($ul, HTML::p(fmt("%s pages have been permanently renamed.",$count)));
96 return HTML($ul, HTML::p(fmt("No pages renamed.")));
100 function run($dbi, $argstr, &$request, $basepage) {
101 if ($request->getArg('action') != 'browse')
102 return $this->disabled("(action != 'browse')");
104 $args = $this->getArgs($argstr, $request);
105 $this->_args = $args;
106 if (!empty($args['exclude']))
107 $exclude = explodePageList($args['exclude']);
111 $p = $request->getArg('p');
112 $post_args = $request->getArg('admin_rename');
113 $next_action = 'select';
115 if ($p && !$request->isPost())
117 if ($p && $request->isPost() &&
118 !empty($post_args['rename']) && empty($post_args['cancel'])) {
120 // FIXME: check individual PagePermissions
122 if (!$request->_user->isAdmin()) {
123 $request->_notAuthorized(WIKIAUTH_ADMIN);
124 $this->disabled("! user->isAdmin");
128 // FIXME: error message if not admin.
129 if ($post_args['action'] == 'verify') {
131 return $this->renamePages($dbi, $request, array_keys($p),
132 $post_args['from'], $post_args['to'], !empty($post_args['updatelinks']));
134 if ($post_args['action'] == 'select') {
135 if (!empty($post_args['from']))
136 $next_action = 'verify';
137 foreach ($p as $name => $c) {
142 if ($next_action == 'select' and empty($pages)) {
143 // List all pages to select from.
144 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
146 if ($next_action == 'verify') {
147 $args['info'] = "checkbox,pagename,renamed_pagename";
149 $pagelist = new PageList_Selectable
151 $args['info'], $exclude,
153 array('renamed_pagename'
154 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
156 $pagelist->addPageList($pages);
159 if ($next_action == 'verify') {
160 $button_label = _("Yes");
161 $header->pushContent(
162 HTML::p(HTML::strong(
163 _("Are you sure you want to permanently rename the selected files?"))));
164 $header = $this->renameForm($header, $post_args);
167 $button_label = _("Rename selected pages");
168 $header->pushContent(HTML::p(_("Select the pages to rename:")));
169 $header = $this->renameForm($header, $post_args);
173 $buttons = HTML::p(Button('submit:admin_rename[rename]', $button_label, 'wikiadmin'),
174 Button('submit:admin_rename[cancel]', _("Cancel"), 'button'));
176 return HTML::form(array('action' => $request->getPostURL(),
179 $pagelist->getContent(),
180 HiddenInputs($request->getArgs(),
182 array('admin_rename')),
183 HiddenInputs(array('admin_rename[action]' => $next_action,
184 /*'require_authority_for_post' => WIKIAUTH_ADMIN */)),
188 function renameForm(&$header, $post_args) {
189 $header->pushContent(_("Rename")." "._("from").': ');
190 $header->pushContent(HTML::input(array('name' => 'admin_rename[from]',
191 'value' => $post_args['from'])));
192 $header->pushContent(' '._("to").': ');
193 $header->pushContent(HTML::input(array('name' => 'admin_rename[to]',
194 'value' => $post_args['to'])));
195 $header->pushContent(' '._("(no regex, case-sensitive)"));
196 if (DEBUG) { // not yet tested
197 $header->pushContent(HTML::br());
198 $header->pushContent(_("Change pagename in all linked pages also?"));
199 $header->pushContent(HTML::em(_("Currently not working)")));
200 $checkbox = HTML::input(array('type' => 'checkbox',
201 'name' => 'admin_rename[updatelinks]',
203 if (!empty($post_args['updatelinks']))
204 $checkbox->setAttr('checked','checked');
205 $header->pushContent($checkbox);
207 $header->pushContent(HTML::p());
212 // moved from lib/PageList.php
213 class _PageList_Column_renamed_pagename extends _PageList_Column {
214 function _getValue ($page_handle, &$revision_handle) {
215 $post_args = $GLOBALS['request']->getArg('admin_rename');
216 $value = str_replace($post_args['from'], $post_args['to'],$page_handle->getName());
217 $div = HTML::div(" => ",HTML::input(array('type' => 'text',
218 'name' => 'rename[]',
219 'value' => $value)));
220 $new_page = $GLOBALS['request']->getPage($value);
221 if ($new_page->exists()) {
222 $div->setAttr('class','error');
223 $div->setAttr('title',_("This page already exists"));
229 // $Log: not supported by cvs2svn $
230 // Revision 1.10 2004/04/06 20:00:11 rurban
231 // Cleanup of special PageList column types
232 // Added support of plugin and theme specific Pagelist Types
233 // Added support for theme specific UserPreferences
234 // Added session support for ip-based throttling
235 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
236 // Enhanced postgres schema
237 // Added DB_Session_dba support
239 // Revision 1.9 2004/03/12 13:31:43 rurban
240 // enforce PagePermissions, errormsg if not Admin
242 // Revision 1.8 2004/03/01 13:48:46 rurban
244 // p[] consistency fix
246 // Revision 1.7 2004/02/22 23:20:33 rurban
247 // fixed DumpHtmlToDir,
248 // enhanced sortby handling in PageList
249 // new button_heading th style (enabled),
250 // added sortby and limit support to the db backends and plugins
251 // for paging support (<<prev, next>> links on long lists)
253 // Revision 1.6 2004/02/17 12:11:36 rurban
254 // 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, ...)
256 // Revision 1.5 2004/02/15 21:34:37 rurban
257 // PageList enhanced and improved.
258 // fixed new WikiAdmin... plugins
259 // editpage, Theme with exp. htmlarea framework
260 // (htmlarea yet committed, this is really questionable)
261 // WikiUser... code with better session handling for prefs
262 // enhanced UserPreferences (again)
263 // RecentChanges for show_deleted: how should pages be deleted then?
265 // Revision 1.4 2004/02/12 17:05:39 rurban
267 // added "Change pagename in all linked pages also"
269 // added javascript toggle for Select
270 // WikiAdminSearchReplace:
271 // fixed another typo
273 // Revision 1.3 2004/02/12 13:05:50 rurban
274 // Rename functional for PearDB backend
275 // some other minor changes
276 // SiteMap comes with a not yet functional feature request: includepages (tbd)
278 // Revision 1.2 2004/02/12 11:45:11 rurban
279 // only WikiDB method missing
281 // Revision 1.1 2004/02/11 20:00:16 rurban
282 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
289 // c-hanging-comment-ender-p: nil
290 // indent-tabs-mode: nil