4 Copyright 2003,2004,2006 $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
34 class WikiPlugin_WikiAdminUtils
38 return _("WikiAdminUtils");
41 function getDescription () {
42 return _("Miscellaneous utility functions for the Administrator.");
45 function getVersion() {
46 return preg_replace("/[Revision: $]/", '',
50 function getDefaultArguments() {
51 return array('action' => '',
56 function run($dbi, $argstr, &$request, $basepage) {
57 $args = $this->getArgs($argstr, $request);
58 $args['action'] = strtolower($args['action']);
62 $this->error("No action specified");
63 if (!($default_label = $this->_getLabel($action)))
64 $this->error("Bad action");
65 if ($request->getArg('action') != 'browse')
66 return $this->disabled("(action != 'browse')");
68 $posted = $request->getArg('wikiadminutils');
70 if ($request->isPost() and $posted['action'] == $action) { // a different form. we might have multiple
71 $user = $request->getUser();
72 if (!$user->isAdmin()) {
73 $request->_notAuthorized(WIKIAUTH_ADMIN);
74 return $this->error(_("You must be an administrator to use this plugin."));
76 return $this->do_action($request, $posted);
79 $label = $default_label;
81 return $this->_makeButton($request, $args, $label);
84 function _makeButton(&$request, $args, $label) {
85 $args['return_url'] = $request->getURLtoSelf();
86 return HTML::form(array('action' => $request->getPostURL(),
88 HTML::p(Button('submit:', $label, 'wikiadmin')),
89 HiddenInputs($args, 'wikiadminutils'),
90 HiddenInputs(array('require_authority_for_post' =>
92 HiddenInputs($request->getArgs(),false,array('action')));
95 function do_action(&$request, $args) {
96 $method = strtolower('_do_' . str_replace('-', '_', $args['action']));
97 if (!method_exists($this, $method))
98 return $this->error("Bad action $method");
100 $message = call_user_func(array(&$this, $method), $request, $args);
102 // display as seperate page or as alert?
103 $alert = new Alert(fmt("WikiAdminUtils %s returned:", $args['action']),
105 array(_("Back") => $args['return_url']));
106 $alert->show(); // noreturn
109 function _getLabel($action) {
110 $labels = array('purge-cache' => _("Purge Markup Cache"),
111 'purge-bad-pagenames' => _("Purge all Pages With Invalid Names"),
112 'purge-empty-pages' => _("Purge all empty, unreferenced Pages"),
113 'access-restrictions' => _("Access Restrictions"),
114 'email-verification' => _("Email Verification"),
115 'convert-cached-html' => _("Convert cached_html"),
116 'db-check' => _("DB Check"),
117 'db-rebuild' => _("Db Rebuild")
119 return @$labels[$action];
122 function _do_purge_cache(&$request, $args) {
123 $dbi = $request->getDbh();
124 $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too?
125 while (($page = $pages->next())) {
126 $page->set('_cached_html', false);
128 return _("Markup cache purged!");
131 function _do_purge_bad_pagenames(&$request, $args) {
132 // FIXME: this should be moved into WikiDB::normalize() or something...
133 $dbi = $request->getDbh();
135 $list = HTML::ol(array('align'=>'left'));
136 $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too?
137 while (($page = $pages->next())) {
138 $pagename = $page->getName();
139 $wpn = new WikiPageName($pagename);
140 if (! $wpn->isValid() ) {
141 $dbi->purgePage($pagename);
142 $list->pushContent(HTML::li($pagename));
148 return _("No pages with bad names had to be deleted.");
150 return HTML(fmt("Deleted %s pages with invalid names:", $count),
151 HTML::div(array('align'=>'left'), $list));
156 * Purge all non-referenced empty pages. Mainly those created by bad link extraction.
158 function _do_purge_empty_pages(&$request, $args) {
159 $dbi = $request->getDbh();
160 $count = 0; $notpurgable = 0;
161 $list = HTML::ol(array('align'=>'left'));
162 $pages = $dbi->getAllPages('include_empty');
163 while (($page = $pages->next())) {
165 and ($links = $page->getBackLinks('include_empty'))
168 $pagename = $page->getName();
169 if ($pagename == 'global_data' or $pagename == '.') continue;
170 if ($dbi->purgePage($pagename))
171 $list->pushContent(HTML::li($pagename.' '._("[purged]")));
173 $list->pushContent(HTML::li($pagename.' '._("[not purgable]")));
181 return _("No empty, unreferenced pages were found.");
183 return HTML(fmt("Deleted %s unreferenced pages:", $count),
184 HTML::div(array('align'=>'left'), $list),
186 fmt("The %d not-purgable pages/links are links in some page(s). You might want to edit them.",
192 function _do_convert_cached_html(&$request, $args) {
194 require_once("lib/upgrade.php");
195 $dbh = $request->_dbi;
196 _upgrade_db_init($dbh);
198 $count = _upgrade_cached_html($dbh, false);
201 return _("No old _cached_html pagedata found.");
203 return HTML(fmt("Converted successfully %d pages", $count),
204 HTML::div(array('align'=>'left'), $list));
208 function _do_db_check(&$request, $args) {
210 $dbh = $request->getDbh();
211 //FIXME: display result.
212 return $dbh->_backend->check($args);
215 function _do_db_rebuild(&$request, $args) {
217 $dbh = $request->getDbh();
218 //FIXME: display result.
219 return $dbh->_backend->rebuild($args);
222 //TODO: We need a seperate plugin for this.
224 function _do_access_restrictions(&$request, &$args) {
225 return _("Sorry. Access Restrictions not yet implemented");
228 // pagelist with enable/disable button
229 function _do_email_verification(&$request, &$args) {
230 $dbi = $request->getDbh();
231 $pagelist = new PageList('pagename',0,$args);
232 //$args['return_url'] = 'action=email-verification-verified';
233 $email = new _PageList_Column_email('email',_("E-Mail"),'left');
234 $emailVerified = new _PageList_Column_emailVerified('emailVerified',
235 _("Verification Status"),'center');
236 $pagelist->_columns[0]->_heading = _("Username");
237 $pagelist->_columns[] = $email;
238 $pagelist->_columns[] = $emailVerified;
239 //This is the best method to find all users (Db and PersonalPage)
240 $current_user = $request->_user;
241 if (empty($args['verify'])) {
242 $group = $request->getGroup();
243 $allusers = $group->_allUsers();
245 if (!empty($args['user']))
246 $allusers = array_keys($args['user']);
250 foreach ($allusers as $username) {
252 $user = WikiUser($username);
254 $user = new WikiUser($request, $username);
255 $prefs = $user->getPreferences();
256 if ($prefs->get('email')) {
257 if (!$prefs->get('userid'))
258 $prefs->set('userid',$username);
259 if (!empty($pagelist->_rows))
260 $group = (int)(count($pagelist->_rows) / $pagelist->_group_rows);
263 $class = ($group % 2) ? 'oddrow' : 'evenrow';
264 $row = HTML::tr(array('class' => $class));
265 $page_handle = $dbi->getPage($username);
266 $row->pushContent($pagelist->_columns[0]->format($pagelist,
267 $page_handle, $page_handle));
268 $row->pushContent($email->format($pagelist, $prefs, $page_handle));
269 if (!empty($args['verify'])) {
270 $prefs->_prefs['email']->set('emailVerified',
271 empty($args['verified'][$username]) ? 0 : true);
272 $user->setPreferences($prefs);
274 $row->pushContent($emailVerified->format($pagelist, $prefs, $args['verify']));
275 $pagelist->_rows[] = $row;
278 $request->_user = $current_user;
279 if (!empty($args['verify']) or empty($pagelist->_rows)) {
280 return HTML($pagelist->_generateTable(false));
281 } elseif (!empty($pagelist->_rows)) {
283 $args['return_url'] = $request->getURLtoSelf();
284 return HTML::form(array('action' => $request->getPostURL(),
286 HiddenInputs($args, 'wikiadminutils'),
287 HiddenInputs(array('require_authority_for_post' =>
289 HiddenInputs($request->getArgs()),
290 $pagelist->_generateTable(false),
291 HTML::p(Button('submit:', _("Change Verification Status"),
294 Button('cancel', _("Cancel")))
300 require_once("lib/PageList.php");
302 class _PageList_Column_email
303 extends _PageList_Column {
304 function _getValue (&$prefs, $dummy) {
305 return $prefs->get('email');
309 class _PageList_Column_emailVerified
310 extends _PageList_Column {
311 function _getValue (&$prefs, $status) {
312 $name = $prefs->get('userid');
313 $input = HTML::input(array('type' => 'checkbox',
314 'name' => 'wikiadminutils[verified]['.$name.']',
316 if ($prefs->get('emailVerified'))
317 $input->setAttr('checked','1');
319 $input->setAttr('disabled','1');
320 return HTML($input, HTML::input
321 (array('type' => 'hidden',
322 'name' => 'wikiadminutils[user]['.$name.']',
333 // c-hanging-comment-ender-p: nil
334 // indent-tabs-mode: nil