]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminUtils.php
List the invalid pagenames which were deleted.
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminUtils.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminUtils.php,v 1.2 2003-02-21 20:56:12 carstenklapp Exp $');
3 /**
4  Copyright 2003 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 /**
24  */
25 class WikiPlugin_WikiAdminUtils
26 extends WikiPlugin
27 {
28     function getName () {
29         return _("WikiAdminUtils");
30     }
31
32     function getDescription () {
33         return _("Miscellaneous utility functions of use to the administrator.");
34     }
35
36     function getVersion() {
37         return preg_replace("/[Revision: $]/", '',
38                             "\$Revision: 1.2 $");
39     }
40
41     function getDefaultArguments() {
42         return array('action'           => '',
43                      'label'            => '',
44                      );
45     }
46
47     function run($dbi, $argstr, $request) {
48         $args = $this->getArgs($argstr, $request);
49         $args['action'] = strtolower($args['action']);
50         extract($args);
51         
52         if (!$action)
53             $this->error("No action specified");
54         if (!($default_label = $this->_getLabel($action)))
55             $this->error("Bad action");
56         if ($request->getArg('action') != 'browse')
57             return $this->disabled("(action != 'browse')");
58         
59         $posted = $request->getArg('wikiadminutils');
60         $request->setArg('wikiadminutils', false);
61
62         if ($request->isPost()) {
63             $user = $request->getUser();
64             if (!$user->isAdmin())
65                 return $this->error(_("You must be an administrator to use this plugin."));
66             return $this->do_action($request, $posted);
67         }
68
69         if (empty($label))
70             $label = $default_label;
71         
72         return $this->_makeButton($request, $args, $label);
73     }
74
75     function _makeButton(&$request, $args, $label) {
76         $args['return_url'] = $request->getURLtoSelf();
77         return HTML::form(array('action' => $request->getPostURL(),
78                                 'method' => 'post'),
79                           HTML::p(Button('submit:', $label, 'wikiadmin')),
80                           HiddenInputs($args, 'wikiadminutils'),
81                           HiddenInputs(array('require_authority_for_post' =>
82                                              WIKIAUTH_ADMIN)),
83                           HiddenInputs($request->getArgs()));
84     }
85     
86     function do_action(&$request, $args) {
87         $method = '_do_' . str_replace('-', '_', $args['action']);
88         if (!method_exists($this, $method))
89             return $this->error("Bad action");
90
91         $message = call_user_func(array(&$this, $method), $request, $args);
92
93         $alert = new Alert(_("WikiAdminUtils says:"),
94                            $message,
95                            array(_("Okay") => $args['return_url']));
96
97         $alert->show();         // noreturn
98     }
99
100     function _getLabel($action) {
101         $labels = array('purge-cache' => _("Purge Markup Cache"),
102                         'purge-bad-pagenames' => _("Delete Pages With Invalid Names"));
103         return @$labels[$action];
104     }
105
106     function _do_purge_cache(&$request, $args) {
107         $dbi = $request->getDbh();
108         $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too?
109         while (($page = $pages->next())) {
110             $page->set('_cached_html', false);
111         }
112         return _("Markup cache purged!");
113     }
114
115     function _do_purge_bad_pagenames(&$request, $args) {
116         // FIXME: this should be moved into WikiDB::normalize() or something...
117         $dbi = $request->getDbh();
118         $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too?
119         $count = 0;
120         $list = HTML::ul();
121         while (($page = $pages->next())) {
122             $pagename = $page->getName();
123             if ($pagename[0] == SUBPAGE_SEPARATOR) {
124                 $dbi->deletePage($pagename);
125                 $list->pushContent(HTML::li($pagename));
126                 $count++;
127             }
128         }
129         return HTML(fmt("Deleted %s pages with invalid names:", $count), $list);
130     }
131 };
132
133 // For emacs users
134 // Local Variables:
135 // mode: php
136 // tab-width: 8
137 // c-basic-offset: 4
138 // c-hanging-comment-ender-p: nil
139 // indent-tabs-mode: nil
140 // End:
141 ?>