From ce48abf47d7bedc9dc6604f2a4cddefc1df90856 Mon Sep 17 00:00:00 2001 From: rurban Date: Wed, 11 Feb 2004 20:00:16 +0000 Subject: [PATCH] WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@2992 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/plugin/WikiAdminRemove.php | 20 ++-- lib/plugin/WikiAdminRename.php | 184 +++++++++++++++++++++++++++++++++ lib/plugin/WikiAdminSelect.php | 35 +++++-- 3 files changed, 218 insertions(+), 21 deletions(-) create mode 100644 lib/plugin/WikiAdminRename.php diff --git a/lib/plugin/WikiAdminRemove.php b/lib/plugin/WikiAdminRemove.php index 10ab03cbb..ba4542c23 100644 --- a/lib/plugin/WikiAdminRemove.php +++ b/lib/plugin/WikiAdminRemove.php @@ -1,7 +1,7 @@ 31, - /* Pages to exclude */ + /* Pages or regex to exclude */ 'exclude' => '', /* Columns to include in listing */ - 'info' => '', + 'info' => 'most', /* How to sort */ - 'sortby' => '' + 'sortby' => 'pagename' ); } - function collectPages(&$list, &$dbi) { + function collectPages(&$list, &$dbi, $sortby) { extract($this->_args); $now = time(); - $allPages = $dbi->getAllPages('include_deleted'); + $allPages = $dbi->getAllPages('include_deleted',$sortby); while ($pagehandle = $allPages->next()) { $pagename = $pagehandle->getName(); $current = $pagehandle->getCurrentRevision(); @@ -157,7 +157,7 @@ extends WikiPlugin } if ($next_action == 'select') { // List all pages to select from. - $list = $this->collectPages($pages, $dbi); + $list = $this->collectPages($pages, $dbi, $args['sortby']); } @@ -169,7 +169,7 @@ extends WikiPlugin $header = HTML::p(); if ($next_action == 'verify') { - $button_label = _("Permanently remove selected pages"); + $button_label = _("Yes"); $header->pushContent(HTML::strong( _("Are you sure you want to permanently remove the selected files?"))); } diff --git a/lib/plugin/WikiAdminRename.php b/lib/plugin/WikiAdminRename.php new file mode 100644 index 000000000..f2f665556 --- /dev/null +++ b/lib/plugin/WikiAdminRename.php @@ -0,0 +1,184 @@ + or called via WikiAdminSelect + * Author: Reini Urban + * + * KNOWN ISSUES: + * Currently we must be Admin. + * Future versions will support PagePermissions. + * requires PHP 4.2 so far. + */ +require_once('lib/PageList.php'); +require_once('lib/plugin/WikiAdminSelect.php'); + +class WikiPlugin_WikiAdminRename +extends WikiPlugin_WikiAdminSelect +{ + function getName() { + return _("WikiAdminRename"); + } + + function getDescription() { + return _("Rename selected pages."); + } + + function getVersion() { + return preg_replace("/[Revision: $]/", '', + "\$Revision: 1.1 $"); + } + + function getDefaultArguments() { + return array( + /* Pages to exclude */ + 'exclude' => '', + /* Columns to include in listing */ + 'info' => 'pagename,mtime', + /* How to sort */ + 'sortby' => 'pagename', + ); + } + + function renameHelper($name, $from, $to) { + return str_replace($from,$to,$name); + } + + function renamePages(&$request, $pages, $from, $to) { + $ul = HTML::ul(); + $dbi = $request->getDbh(); + $count = 0; + foreach ($pages as $name) { + if (($newname = $this->renameHelper($name,$from,$to)) and $newname != $name) { + $dbi->renamePage($name,$newname); /* not yet implemented */ + $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.", $name, $newname))); + $count++; + } elseif (! $newname) { + $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname))); + } + } + $dbi->touch(); + return HTML($ul, + HTML::p(fmt("%s pages have been permanently renamed.",$count))); + } + + function run($dbi, $argstr, $request) { + if ($request->getArg('action') != 'browse') + return $this->disabled("(action != 'browse')"); + + $args = $this->getArgs($argstr, $request); + $this->_args = $args; + if (!empty($args['exclude'])) + $exclude = explodePageList($args['exclude']); + else + $exclude = false; + + + $p = $request->getArg('p'); + $post_args = $request->getArg('admin_rename'); + $next_action = 'select'; + $pages = array(); + + if ($p && $request->isPost() && $request->_user->isAdmin() + && !empty($post_args['rename']) && empty($post_args['cancel'])) { + // FIXME: error message if not admin. + if ($post_args['action'] == 'verify') { + // Real action + return $this->renamePages($request, $p, $post_args['from'], $post_args['to']); + } + + if ($post_args['action'] == 'select') { + if (!empty($post_args['from'])) + $next_action = 'verify'; + foreach ($p as $name) { + $pages[$name] = 1; + } + } + } + if ($next_action == 'select') { + // List all pages to select from. + $list = $this->collectPages($pages, $dbi, $args['sortby']); + } + + + $info = 'checkbox'; + if ($args['info']) + $info .= "," . $args['info']; + if ($next_action == 'verify') { + $info = "checkbox,pagename,renamed_pagename"; + } + $pagelist = new PageList_Selectable($info, $exclude); + $pagelist->addPageList($pages); + + $header = HTML::p(); + if ($next_action == 'verify') { + $button_label = _("Yes"); + $header->pushContent( + HTML::p(HTML::strong( + _("Are you sure you want to permanently rename the selected files?")))); + $header->pushContent(_("Rename")." "._("from").': '); + $header->pushContent(HTML::input(array('name' => 'admin_rename[from]', + 'value' => $post_args['from']))); + $header->pushContent(' '._("to").': '); + $header->pushContent(HTML::input(array('name' => 'admin_rename[to]', + 'value' => $post_args['to']))); + $header->pushContent(' '._("(no regex, case-sensitive)")); + $header->pushContent(HTML::p()); + } + else { + $button_label = _("Rename selected pages"); + $header->pushContent(HTML::p(_("Select the pages to rename:"))); + $header->pushContent(_("Rename")." "._("from").': '); + $header->pushContent(HTML::input(array('name' => 'admin_rename[from]'))); + $header->pushContent(' '._("to").': '); + $header->pushContent(HTML::input(array('name' => 'admin_rename[to]'))); + $header->pushContent(' '._("(no regex, case-sensitive)")); + $header->pushContent(HTML::p()); + } + + + $buttons = HTML::p(Button('submit:admin_rename[rename]', $button_label, 'wikiadmin'), + Button('submit:admin_rename[cancel]', _("Cancel"), 'button')); + + return HTML::form(array('action' => $request->getPostURL(), + 'method' => 'post'), + $header, + $pagelist->getContent(), + HiddenInputs($request->getArgs(), + false, + array('admin_rename')), + HiddenInputs(array('admin_rename[action]' => $next_action, + 'require_authority_for_post' => WIKIAUTH_ADMIN)), + $buttons); + } +} + +// $Log: not supported by cvs2svn $ + +// Local Variables: +// mode: php +// tab-width: 8 +// c-basic-offset: 4 +// c-hanging-comment-ender-p: nil +// indent-tabs-mode: nil +// End: +?> diff --git a/lib/plugin/WikiAdminSelect.php b/lib/plugin/WikiAdminSelect.php index 6b8c44e79..8dfee8617 100644 --- a/lib/plugin/WikiAdminSelect.php +++ b/lib/plugin/WikiAdminSelect.php @@ -1,5 +1,5 @@ '*', 'only' => '', 'exclude' => '', - 'info' => 'all', + 'info' => 'most', + 'sortby' => 'pagename', 'debug' => false); } - function collectPages(&$list, &$dbi) { - $allPages = $dbi->getAllPages(); + function collectPages(&$list, &$dbi, $sortby) { + $allPages = $dbi->getAllPages(0,$sortby); while ($pagehandle = $allPages->next()) { $pagename = $pagehandle->getName(); if (empty($list[$pagename])) @@ -68,6 +69,8 @@ extends WikiPlugin } function run($dbi, $argstr, $request) { + if ($request->getArg('action') != 'browse') + return $this->disabled("(action != 'browse')"); $args = $this->getArgs($argstr, $request); if (!empty($args['only'])) $only = explodePageList($args['only']); @@ -102,7 +105,7 @@ extends WikiPlugin //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better. $uri = $request->getURLtoSelf(false, array('verify')); $form = HTML::form(array('action' => $uri, 'method' => 'POST')); - if ($request->getArg('submit') == 'WikiAdminSelect') + if ($request->getArg('WikiAdminSelect') == _("Go")) $p = false; else $p = $request->getArg('p'); @@ -139,13 +142,17 @@ extends WikiPlugin } } elseif (empty($args['s'])) { // List all pages to select from. - $this->collectPages($this->_list, $dbi); + $this->collectPages($this->_list, $dbi, $sortby); } $pagelist = new PageList_Selectable($info ? 'checkbox,' . $info : 'checkbox', $exclude); $pagelist->addPageList($this->_list); $form->pushContent($pagelist->getContent()); + foreach ($args as $k => $v) { + if (!in_array($k,array('s','WikiAdminSelect','action'))) + $form->pushContent(HiddenInputs(array($k => $v))); // plugin params + } foreach ($_GET as $k => $v) { if (!in_array($k,array('s','WikiAdminSelect','action'))) $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ... @@ -172,10 +179,10 @@ extends WikiPlugin foreach ($actions as $f) { $f = preg_replace('/.php$/','', $f); $s = preg_replace('/^WikiAdmin/','', $f); -// if ($s != "Select") { - $form->pushContent(Button("submit:$f", _($s), "wikiadmin")); - $form->pushContent($Theme->getButtonSeparator()); -// } + if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils + $form->pushContent(Button("submit:$f", _($s), "wikiadmin")); + $form->pushContent($Theme->getButtonSeparator()); + } } $form->pushContent(Button('submit:cancel', _("Cancel"), 'button')); } @@ -188,6 +195,12 @@ extends WikiPlugin } // $Log: not supported by cvs2svn $ +// Revision 1.7 2004/01/27 23:23:39 rurban +// renamed ->Username => _userid for consistency +// renamed mayCheckPassword => mayCheckPass +// fixed recursion problem in WikiUserNew +// fixed bogo login (but not quite 100% ready yet, password storage) +// // Revision 1.6 2004/01/26 19:15:29 rurban // Interim fix // -- 2.45.0