2 rcs_id('$Id: UserPreferences.php,v 1.25 2004-04-07 23:13:19 rurban Exp $');
4 Copyright (C) 2001, 2002, 2003, 2004 $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
24 * Plugin to allow any user to adjust his own preferences.
25 * This must be used in the page "UserPreferences".
26 * Prefs are stored in metadata in the current session,
27 * within the user's home page or in a database.
30 * Certain themes should be able to extend the predefined list
33 class WikiPlugin_UserPreferences
39 return _("UserPreferences");
42 function getVersion() {
43 return preg_replace("/[Revision: $]/", '',
44 "\$Revision: 1.25 $");
47 function getDefaultArguments() {
49 $pagename = $request->getArg('pagename');
50 $user = $request->getUser();
51 if ( isset($user->_prefs) and
52 isset($user->_prefs->_prefs) and
53 isset($user->_prefs->_method) ) {
54 $pref =& $user->_prefs;
56 $pref = $user->getPreferences();
59 //we need a hash of pref => default_value
60 foreach ($pref->_prefs as $name => $obj) {
61 $prefs[$name] = $obj->default_value;
66 function run($dbi, $argstr, &$request, $basepage) {
67 $args = $this->getArgs($argstr, $request);
68 $user = &$request->getUser();
69 if (! $request->isActionPage($request->getArg('pagename'))) {
70 $no_args = $this->getDefaultArguments();
72 // foreach ($no_args as $key => $value) {
73 // $no_args[$value] = false;
75 $no_args['errmsg'] = HTML(HTML::h2(_("Error: The user HomePage must be a valid WikiWord. Sorry, UserPreferences cannot be saved."),HTML::hr()));
76 $no_args['isForm'] = false;
77 return Template('userprefs', $no_args);
79 $userid = $user->UserName();
80 if (// ((defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN && $user->isSignedIn()) ||
81 $user->isAuthenticated() and !empty($userid))
83 $pref = $user->getPreferences();
84 //trigger_error("DEBUG: reading prefs from getPreferences".print_r($pref));
86 if ($request->isPost()) {
88 if ($rp = $request->getArg('pref')) {
89 // replace only changed prefs in $pref with those from request
90 if (!empty($rp['passwd']) and ($rp['passwd2'] != $rp['passwd'])) {
91 $errmsg = _("Wrong password. Try again.");
93 //trigger_error("DEBUG: reading prefs from request".print_r($rp));
94 //trigger_error("DEBUG: writing prefs with setPreferences".print_r($pref));
95 if (empty($rp['passwd'])) unset($rp['passwd']);
96 // fix to set system pulldown's. empty values don't get posted
97 if (empty($rp['theme'])) $rp['theme'] = '';
98 if (empty($rp['lang'])) $rp['lang'] = '';
99 $num = $user->setPreferences($rp);
100 if (!empty($rp['passwd'])) {
101 $passchanged = false;
102 if ($user->mayChangePass()) {
103 if (method_exists($user, 'storePass')) {
104 $passchanged = $user->storePass($rp['passwd']);
106 if (!$passchanged and method_exists($user, 'changePass')) {
107 $passchanged = $user->changePass($rp['passwd']);
110 $errmsg = _("Password updated.");
112 $errmsg = _("Password cannot be changed.");
115 $errmsg = _("Password cannot be changed.");
119 $errmsg .= " " ._("No changes.");
121 $request->_setUser($user);
122 $pref = $user->_prefs;
123 $errmsg .= sprintf(_("%d UserPreferences fields successfully updated."), $num);
126 $args['errmsg'] = HTML(HTML::h2($errmsg), HTML::hr());
129 $available_themes = array();
130 $dir_root = 'themes/';
131 if (defined('PHPWIKI_DIR'))
132 $dir_root = PHPWIKI_DIR . "/$dir_root";
133 $dir = dir($dir_root);
135 while($entry = $dir->read()) {
136 if (is_dir($dir_root.$entry)
137 && (substr($entry,0,1) != '.')
138 && $entry != 'CVS') {
139 array_push($available_themes, $entry);
144 $args['available_themes'] = $available_themes;
146 $available_languages = array('en');
147 $dir_root = 'locale/';
148 if (defined('PHPWIKI_DIR'))
149 $dir_root = PHPWIKI_DIR . "/$dir_root";
150 $dir = dir($dir_root);
152 while($entry = $dir->read()) {
153 if (is_dir($dir_root.$entry)
154 && (substr($entry,0,1) != '.')
156 && $entry != 'CVS') {
157 array_push($available_languages, $entry);
162 $args['available_languages'] = $available_languages;
164 return Template('userprefs', $args);
167 // wrong or unauthenticated user
168 return $request->_notAuthorized(WIKIAUTH_BOGO);
169 //return $user->PrintLoginForm ($request, $args, false, false);
174 // $Log: not supported by cvs2svn $
175 // Revision 1.24 2004/04/06 20:00:11 rurban
176 // Cleanup of special PageList column types
177 // Added support of plugin and theme specific Pagelist Types
178 // Added support for theme specific UserPreferences
179 // Added session support for ip-based throttling
180 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
181 // Enhanced postgres schema
182 // Added DB_Session_dba support
184 // Revision 1.23 2004/04/02 15:06:56 rurban
185 // fixed a nasty ADODB_mysql session update bug
186 // improved UserPreferences layout (tabled hints)
187 // fixed UserPreferences auth handling
188 // improved auth stability
189 // improved old cookie handling: fixed deletion of old cookies with paths
191 // Revision 1.22 2004/03/24 19:39:03 rurban
192 // php5 workaround code (plus some interim debugging code in XmlElement)
193 // php5 doesn't work yet with the current XmlElement class constructors,
194 // WikiUserNew does work better than php4.
195 // rewrote WikiUserNew user upgrading to ease php5 update
196 // fixed pref handling in WikiUserNew
197 // added Email Notification
198 // added simple Email verification
199 // removed emailVerify userpref subclass: just a email property
200 // changed pref binary storage layout: numarray => hash of non default values
201 // print optimize message only if really done.
202 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
203 // prefs should be stored in db or homepage, besides the current session.
205 // Revision 1.21 2004/03/14 16:26:21 rurban
208 // Revision 1.20 2004/03/12 23:20:58 rurban
209 // pref fixes (base64)
211 // Revision 1.19 2004/02/27 13:21:17 rurban
212 // several performance improvements, esp. with peardb
214 // storepass seperated from prefs if defined so
215 // stacked and strict still not working
217 // Revision 1.18 2004/02/24 15:20:06 rurban
218 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
220 // Revision 1.17 2004/02/17 12:11:36 rurban
221 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
223 // Revision 1.16 2004/02/15 21:34:37 rurban
224 // PageList enhanced and improved.
225 // fixed new WikiAdmin... plugins
226 // editpage, Theme with exp. htmlarea framework
227 // (htmlarea yet committed, this is really questionable)
228 // WikiUser... code with better session handling for prefs
229 // enhanced UserPreferences (again)
230 // RecentChanges for show_deleted: how should pages be deleted then?
232 // Revision 1.15 2004/01/27 22:37:50 rurban
233 // fixed default args: no objects
235 // Revision 1.14 2004/01/26 09:18:00 rurban
236 // * changed stored pref representation as before.
237 // the array of objects is 1) bigger and 2)
238 // less portable. If we would import packed pref
239 // objects and the object definition was changed, PHP would fail.
240 // This doesn't happen with an simple array of non-default values.
241 // * use $prefs->retrieve and $prefs->store methods, where retrieve
242 // understands the interim format of array of objects also.
243 // * simplified $prefs->get() and fixed $prefs->set()
244 // * added $user->_userid and class '_WikiUser' portability functions
245 // * fixed $user object ->_level upgrading, mostly using sessions.
246 // this fixes yesterdays problems with loosing authorization level.
247 // * fixed WikiUserNew::checkPass to return the _level
248 // * fixed WikiUserNew::isSignedIn
249 // * added explodePageList to class PageList, support sortby arg
250 // * fixed UserPreferences for WikiUserNew
251 // * fixed WikiPlugin for empty defaults array
252 // * UnfoldSubpages: added pagename arg, renamed pages arg,
253 // removed sort arg, support sortby arg
255 // Revision 1.13 2003/12/04 20:27:00 carstenklapp
258 // Revision 1.12 2003/12/01 22:21:33 carstenklapp
259 // Bugfix: UserPreferences are no longer clobbered when signing in after
260 // the previous session has ended (i.e. user closed browser then signed
261 // in again). This is still a bit of a mess, and the preferences do not
262 // take effect until the next page browse/link has been clicked.
264 // Revision 1.11 2003/09/19 22:01:19 carstenklapp
265 // BOGO users allowed preferences too when ALLOW_BOGO_LOGIN == true.
267 // Revision 1.10 2003/09/13 21:57:26 carstenklapp
268 // Reformatting only.
270 // Revision 1.9 2003/09/13 21:53:41 carstenklapp
271 // Added lang and theme arguments, getVersion(), copyright and cvs log.
279 // c-hanging-comment-ender-p: nil
280 // indent-tabs-mode: nil