From: <var...@us...> - 2009-02-11 23:01:23
|
Revision: 6489 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=6489&view=rev Author: vargenau Date: 2009-02-11 21:46:59 +0000 (Wed, 11 Feb 2009) Log Message: ----------- WikiAdminPurge Added Paths: ----------- trunk/lib/plugin/WikiAdminPurge.php Added: trunk/lib/plugin/WikiAdminPurge.php =================================================================== --- trunk/lib/plugin/WikiAdminPurge.php (rev 0) +++ trunk/lib/plugin/WikiAdminPurge.php 2009-02-11 21:46:59 UTC (rev 6489) @@ -0,0 +1,164 @@ +<?php // -*-php-*- +rcs_id('$Id: WikiAdminPurge.php 6286 2008-10-02 10:01:29Z vargenau $'); +/* + Copyright 2002,2004 $ThePhpWikiProgrammingTeam + Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent + + This file is part of PhpWiki. + + PhpWiki is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PhpWiki is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PhpWiki; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** + * Usage: <?plugin WikiAdminPurge?> + */ +require_once('lib/PageList.php'); +require_once('lib/plugin/WikiAdminSelect.php'); + +class WikiPlugin_WikiAdminPurge +extends WikiPlugin_WikiAdminSelect +{ + function getName() { + return _("WikiAdminPurge"); + } + + function getDescription() { + return _("Permanently purge all selected pages."); + } + + function getVersion() { + return preg_replace("/[Revision: $]/", '', + "\$Revision: 6286 $"); + } + + function getDefaultArguments() { + return array_merge + ( + PageList::supportedArgs(), + array( + 's' => false, + /* Columns to include in listing */ + 'info' => 'most', + )); + } + + function collectPages(&$list, &$dbi, $sortby, $limit=0) { + return $list; + } + + function purgePages(&$request, $pages) { + $ul = HTML::ul(); + $dbi = $request->getDbh(); $count = 0; + foreach ($pages as $name) { + $name = str_replace(array('%5B','%5D'),array('[',']'),$name); + if (mayAccessPage('purge',$name)) { + $dbi->purgePage($name); + $ul->pushContent(HTML::li(fmt("Purged page '%s' successfully.", $name))); + $count++; + } else { + $ul->pushContent(HTML::li(fmt("Didn't purge page '%s'. Access denied.", $name))); + } + } + if ($count) $dbi->touch(); + return HTML($ul, + HTML::p(fmt("%d pages have been permanently purged.",$count))); + } + + function run($dbi, $argstr, &$request, $basepage) { + if ($request->getArg('action') != 'browse') + if ($request->getArg('action') != _("PhpWikiAdministration/Purge")) + return $this->disabled("(action != 'browse')"); + + $args = $this->getArgs($argstr, $request); + $this->_args =& $args; + $this->preSelectS($args, $request); + + $p = $request->getArg('p'); + if (!$p) $p = $this->_list; + $post_args = $request->getArg('admin_purge'); + + $next_action = 'select'; + $pages = array(); + if ($p && $request->isPost() && + !empty($post_args['purge']) && empty($post_args['cancel'])) { + + // check individual PagePermissions + if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) { + $request->_notAuthorized(WIKIAUTH_ADMIN); + $this->disabled("! user->isAdmin"); + } + if ($post_args['action'] == 'verify') { + // Real purge. + return $this->purgePages($request, array_keys($p)); + } + + if ($post_args['action'] == 'select') { + $next_action = 'verify'; + foreach ($p as $name => $c) { + $name = str_replace(array('%5B','%5D'),array('[',']'),$name); + $pages[$name] = $c; + } + } + } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect + $next_action = 'verify'; + foreach ($p as $name => $c) { + $name = str_replace(array('%5B','%5D'),array('[',']'),$name); + $pages[$name] = $c; + } + $request->setArg('p',false); + } + if ($next_action == 'select') { + // List all pages to select from. + $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']); + } + $pagelist = new PageList_UnSelectable($args['info'], $args['exclude'], array()); + $pagelist->addPageList($pages); + + $header = HTML::p(); + if ($next_action == 'verify') { + $button_label = _("Yes"); + $header->pushContent(HTML::strong( + _("Are you sure you want to permanently purge the following files?"))); + } + else { + $button_label = _("Purge selected pages"); + $header->pushContent(_("Permanently purge the selected files:"),HTML::br()); + } + + $buttons = HTML::p(Button('submit:admin_purge[purge]', $button_label, 'wikiadmin'), + Button('submit:admin_purge[cancel]', _("Cancel"), 'button')); + + // TODO: quick select by regex javascript? + return HTML::form(array('action' => $request->getPostURL(), + 'method' => 'post'), + $header, + $buttons, + $pagelist->getContent(), + HiddenInputs($request->getArgs(), + false, + array('admin_purge')), + HiddenInputs(array('admin_purge[action]' => $next_action, + 'require_authority_for_post' => WIKIAUTH_ADMIN))); + } +} + +// Local Variables: +// mode: php +// tab-width: 8 +// c-basic-offset: 4 +// c-hanging-comment-ender-p: nil +// indent-tabs-mode: nil +// End: +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |