'', 'label' => '', ); } function run($dbi, $argstr, $request) { $args = $this->getArgs($argstr, $request); $args['action'] = strtolower($args['action']); extract($args); if (!$action) $this->error("No action specified"); if (!($default_label = $this->_getLabel($action))) $this->error("Bad action"); if ($request->getArg('action') != 'browse') return $this->disabled("(action != 'browse')"); $posted = $request->getArg('wikiadminutils'); $request->setArg('wikiadminutils', false); if ($request->isPost()) { $user = $request->getUser(); if (!$user->isAdmin()) return $this->error(_("You must be an administrator to use this plugin.")); return $this->do_action($request, $posted); } if (empty($label)) $label = $default_label; return $this->_makeButton($request, $args, $label); } function _makeButton(&$request, $args, $label) { $args['return_url'] = $request->getURLtoSelf(); return HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), HTML::p(Button('submit:', $label, 'wikiadmin')), HiddenInputs($args, 'wikiadminutils'), HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)), HiddenInputs($request->getArgs())); } function do_action(&$request, $args) { $method = '_do_' . str_replace('-', '_', $args['action']); if (!method_exists($this, $method)) return $this->error("Bad action"); $message = call_user_func(array(&$this, $method), $request, $args); $alert = new Alert(_("WikiAdminUtils says:"), $message, array(_("Okay") => $args['return_url'])); $alert->show(); // noreturn } function _getLabel($action) { $labels = array('purge-cache' => _("Purge Markup Cache"), 'purge-bad-pagenames' => _("Delete Pages With Invalid Names")); return @$labels[$action]; } function _do_purge_cache(&$request, $args) { $dbi = $request->getDbh(); $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too? while (($page = $pages->next())) { $page->set('_cached_html', false); } return _("Markup cache purged!"); } function _do_purge_bad_pagenames(&$request, $args) { // FIXME: this should be moved into WikiDB::normalize() or something... $dbi = $request->getDbh(); $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too? $count = 0; $list = HTML::ul(); while (($page = $pages->next())) { $pagename = $page->getName(); if ($pagename[0] == SUBPAGE_SEPARATOR) { $dbi->deletePage($pagename); $list->pushContent(HTML::li($pagename)); $count++; } } return HTML(fmt("Deleted %s pages with invalid names:", $count), $list); } }; // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>