2 rcs_id('$Id: WikiAdminUtils.php,v 1.8 2004-04-01 15:57:11 rurban Exp $');
4 Copyright 2003 $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
25 class WikiPlugin_WikiAdminUtils
29 return _("WikiAdminUtils");
32 function getDescription () {
33 return _("Miscellaneous utility functions of use to the administrator.");
36 function getVersion() {
37 return preg_replace("/[Revision: $]/", '',
41 function getDefaultArguments() {
42 return array('action' => '',
47 function run($dbi, $argstr, &$request, $basepage) {
48 $args = $this->getArgs($argstr, $request);
49 $args['action'] = strtolower($args['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')");
59 $posted = $request->getArg('wikiadminutils');
60 $request->setArg('wikiadminutils', false);
62 if ($request->isPost()) {
63 $user = $request->getUser();
64 if (!$user->isAdmin()) {
65 $request->_notAuthorized(WIKIAUTH_ADMIN);
66 return $this->error(_("You must be an administrator to use this plugin."));
68 return $this->do_action($request, $posted);
72 $label = $default_label;
74 return $this->_makeButton($request, $args, $label);
77 function _makeButton(&$request, $args, $label) {
78 $args['return_url'] = $request->getURLtoSelf();
79 return HTML::form(array('action' => $request->getPostURL(),
81 HTML::p(Button('submit:', $label, 'wikiadmin')),
82 HiddenInputs($args, 'wikiadminutils'),
83 HiddenInputs(array('require_authority_for_post' =>
85 HiddenInputs($request->getArgs()));
88 function do_action(&$request, $args) {
89 $method = strtolower('_do_' . str_replace('-', '_', $args['action']));
90 if (!method_exists($this, $method))
91 return $this->error("Bad action");
93 $message = call_user_func(array(&$this, $method), $request, $args);
95 // display as seperate page or as alert?
96 $alert = new Alert(_("WikiAdminUtils says:"),
98 array(_("Okay") => $args['return_url']));
99 $alert->show(); // noreturn
102 function _getLabel($action) {
103 $labels = array('purge-cache' => _("Purge Markup Cache"),
104 'purge-bad-pagenames' => _("Delete Pages With Invalid Names"));
105 return @$labels[$action];
108 function _do_purge_cache(&$request, $args) {
109 $dbi = $request->getDbh();
110 $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too?
111 while (($page = $pages->next())) {
112 $page->set('_cached_html', false);
114 return _("Markup cache purged!");
117 function _do_purge_bad_pagenames(&$request, $args) {
118 // FIXME: this should be moved into WikiDB::normalize() or something...
119 $dbi = $request->getDbh();
120 $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too?
122 while (($page = $pages->next())) {
123 $pagename = $page->getName();
124 $wpn = new WikiPageName($pagename);
125 if (! $wpn->isValid())
126 $badpages[] = $pagename;
130 return _("No pages with bad names were found.");
133 foreach ($badpages as $pagename) {
134 $dbi->deletePage($pagename);
135 $list->pushContent(HTML::li($pagename));
138 return HTML(fmt("Deleted %s pages with invalid names:",
144 function _do_access_restrictions(&$request, &$args) {
145 return _("Sorry. Access Restrictions not yet implemented");
148 // pagelist with enable/disable button
149 function _do_email_verification(&$request, &$args) {
150 $dbi = $request->getDbh();
151 $pagelist = new PageList('pagename',0,$args);
152 //$args['return_url'] = 'action=email-verification-verified';
153 $email = new _PageList_Column_email('email',_("E-Mail"),'left');
154 $emailVerified = new _PageList_Column_emailVerified('emailVerified',_("Verification Status"),'center');
155 $pagelist->_columns[] = $email;
156 $pagelist->_columns[] = $emailVerified;
157 //This is the best method to find all users (Db and PersonalPage)
158 $group = WikiGroup::getGroup($request);
159 foreach ($group->_allUsers() as $username) {
161 $user = WikiUser($username);
163 $user = new WikiUser(&$request,$username);
164 $prefs = $user->getPreferences();
165 if ($prefs->get('email')) {
166 $group = (int)(count($pagelist->_rows) / $pagelist->_group_rows);
167 $class = ($group % 2) ? 'oddrow' : 'evenrow';
168 $row = HTML::tr(array('class' => $class));
169 $page_handle = $dbi->getPage($username);
170 $row->pushContent($pagelist->_columns[0]->format($pagelist, $page_handle, $page_handle));
171 $row->pushContent($email->format($pagelist, &$prefs, $page_handle));
172 if (!empty($args['verified'])) {
173 $prefs->set('emailVerified',empty($args['user'][$username]) ? 0 : 2);
175 $row->pushContent($emailVerified->format($pagelist, &$prefs, $args['verified']));
176 $pagelist->_rows[] = $row;
179 if (!empty($args['verified'])) {
180 return HTML($pagelist->_generateTable(false));
182 $args['verified'] = 1;
183 $args['return_url'] = $request->getURLtoSelf();
184 return HTML::form(array('action' => $request->getPostURL(),
186 HiddenInputs($args, 'wikiadminutils'),
187 HiddenInputs(array('require_authority_for_post' =>
189 HiddenInputs($request->getArgs()),
190 $pagelist->_generateTable(false),
191 HTML::p(Button('submit:', _("Change Verification Status"), 'wikiadmin'))
197 require_once("lib/PageList.php");
199 class _PageList_Column_email
200 extends _PageList_Column {
201 function _getValue ($prefs, $dummy) {
202 return $prefs->get('email');
206 class _PageList_Column_emailVerified
207 extends _PageList_Column {
208 function _getValue ($prefs, $status) {
209 $name = $prefs->get('userid');
210 $input = HTML::input(array('type' => 'checkbox',
211 'name' => 'wikiadminutils[user]['.$name.']',
213 if ($prefs->get('emailVerified'))
214 $input->setAttr('checked','1');
216 $input->setAttr('disabled','1');
227 // c-hanging-comment-ender-p: nil
228 // indent-tabs-mode: nil