]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminUtils.php
Disallow refernces in calls if the declaration is a reference
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminUtils.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminUtils.php,v 1.12 2004-06-16 10:38:59 rurban 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.12 $");
39     }
40
41     function getDefaultArguments() {
42         return array('action'           => '',
43                      'label'            => '',
44                      );
45     }
46
47     function run($dbi, $argstr, &$request, $basepage) {
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                 $request->_notAuthorized(WIKIAUTH_ADMIN);
66                 return $this->error(_("You must be an administrator to use this plugin."));
67             }
68             return $this->do_action($request, $posted);
69         }
70
71         if (empty($label))
72             $label = $default_label;
73         
74         return $this->_makeButton($request, $args, $label);
75     }
76
77     function _makeButton(&$request, $args, $label) {
78         $args['return_url'] = $request->getURLtoSelf();
79         return HTML::form(array('action' => $request->getPostURL(),
80                                 'method' => 'post'),
81                           HTML::p(Button('submit:', $label, 'wikiadmin')),
82                           HiddenInputs($args, 'wikiadminutils'),
83                           HiddenInputs(array('require_authority_for_post' =>
84                                              WIKIAUTH_ADMIN)),
85                           HiddenInputs($request->getArgs()));
86     }
87     
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");
92
93         $message = call_user_func(array(&$this, $method), $request, $args);
94
95         // display as seperate page or as alert?
96         $alert = new Alert(_("WikiAdminUtils says:"),
97                            $message,
98                            array(_("Okay") => $args['return_url']));
99         $alert->show();         // noreturn
100     }
101
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];
106     }
107
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);
113         }
114         return _("Markup cache purged!");
115     }
116
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?
121         $badpages = array();
122         while (($page = $pages->next())) {
123             $pagename = $page->getName();
124             $wpn = new WikiPageName($pagename);
125             if (! $wpn->isValid())
126                 $badpages[] = $pagename;
127         }
128
129         if (!$badpages)
130             return _("No pages with bad names were found.");
131         
132         $list = HTML::ul();
133         foreach ($badpages as $pagename) {
134             $dbi->deletePage($pagename);
135             $list->pushContent(HTML::li($pagename));
136         }
137         
138         return HTML(fmt("Deleted %s pages with invalid names:",
139                         count($badpages)),
140                     $list);
141     }
142
143     //TODO: We need a seperate plugin for this.
144     //      Too many options.
145     function _do_access_restrictions(&$request, &$args) {
146         return _("Sorry. Access Restrictions not yet implemented");
147     }
148     
149     // pagelist with enable/disable button
150     function _do_email_verification(&$request, &$args) {
151         $dbi = $request->getDbh();
152         $pagelist = new PageList('pagename',0,$args);
153         //$args['return_url'] = 'action=email-verification-verified';
154         $email = new _PageList_Column_email('email',_("E-Mail"),'left');
155         $emailVerified = new _PageList_Column_emailVerified('emailVerified',
156                                                             _("Verification Status"),'center');
157         $pagelist->_columns[] = $email;
158         $pagelist->_columns[] = $emailVerified;
159         //This is the best method to find all users (Db and PersonalPage)
160         $current_user = $request->_user;
161         if (empty($args['verify'])) {
162             $group = WikiGroup::getGroup();
163             $allusers = $group->_allUsers();
164         } else {
165             $allusers = array_keys($args['user']);
166         }
167         foreach ($allusers as $username) {
168             if (ENABLE_USER_NEW)
169                 $user = WikiUser($username);
170             else 
171                 $user = new WikiUser($request, $username);
172             $prefs = $user->getPreferences();
173             if ($prefs->get('email')) {
174                 if (!$prefs->get('userid'))
175                     $prefs->set('userid',$username);
176                 $group = (int)(count($pagelist->_rows) / $pagelist->_group_rows);
177                 $class = ($group % 2) ? 'oddrow' : 'evenrow';
178                 $row = HTML::tr(array('class' => $class));
179                 $page_handle = $dbi->getPage($username);
180                 $row->pushContent($pagelist->_columns[0]->format($pagelist, 
181                                                                  $page_handle, $page_handle));
182                 $row->pushContent($email->format($pagelist, $prefs, $page_handle));
183                 if (!empty($args['verify'])) {
184                     $prefs->_prefs['email']->set('emailVerified', 
185                                                  empty($args['verified'][$username]) ? 0 : 2);
186                     $user->setPreferences($prefs);
187                 }
188                 $row->pushContent($emailVerified->format($pagelist, $prefs, $args['verify']));
189                 $pagelist->_rows[] = $row;
190             }
191         }
192         $request->_user = $current_user;
193         if (!empty($args['verify'])) {
194             return HTML($pagelist->_generateTable(false));
195         } else {
196             $args['verify'] = 1;
197             $args['return_url'] = $request->getURLtoSelf();
198             return HTML::form(array('action' => $request->getPostURL(),
199                                     'method' => 'post'),
200                           HiddenInputs($args, 'wikiadminutils'),
201                           HiddenInputs(array('require_authority_for_post' =>
202                                              WIKIAUTH_ADMIN)),
203                           HiddenInputs($request->getArgs()),
204                           $pagelist->_generateTable(false),                   
205                           HTML::p(Button('submit:', _("Change Verification Status"), 
206                                          'wikiadmin'),
207                                   HTML::Raw('&nbsp;'),
208                                   Button('cancel', _("Cancel")))
209                                  );
210         }
211     }
212 };
213
214 require_once("lib/PageList.php");
215
216 class _PageList_Column_email 
217 extends _PageList_Column {
218     function _getValue (&$prefs, $dummy) {
219         return $prefs->get('email');
220     }
221 }
222
223 class _PageList_Column_emailVerified
224 extends _PageList_Column {
225     function _getValue (&$prefs, $status) {
226         $name = $prefs->get('userid');
227         $input = HTML::input(array('type' => 'checkbox',
228                                    'name' => 'wikiadminutils[verified]['.$name.']',
229                                    'value' => 1));
230         if ($prefs->get('emailVerified'))
231             $input->setAttr('checked','1');
232         if ($status)
233             $input->setAttr('disabled','1');
234         return HTML($input, HTML::input
235                     (array('type' => 'hidden',
236                            'name' => 'wikiadminutils[user]['.$name.']',
237                            'value' => $name)));
238     }
239 }
240
241
242 // For emacs users
243 // Local Variables:
244 // mode: php
245 // tab-width: 8
246 // c-basic-offset: 4
247 // c-hanging-comment-ender-p: nil
248 // indent-tabs-mode: nil
249 // End:
250 ?>