2 rcs_id('$Id: UserPreferences.php,v 1.21 2004-03-14 16:26:21 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 within the user's home page or in a cookie.
28 class WikiPlugin_UserPreferences
34 return _("UserPreferences");
37 function getVersion() {
38 return preg_replace("/[Revision: $]/", '',
39 "\$Revision: 1.21 $");
42 function getDefaultArguments() {
44 $pagename = $request->getArg('pagename');
45 $user = $request->getUser();
46 //we need a hash of pref => default_value
47 $pref = $user->getPreferences();
49 foreach ($pref->_prefs as $name => $obj) {
50 $prefs[$name] = $obj->default_value;
55 function run($dbi, $argstr, &$request, $basepage) {
56 $args = $this->getArgs($argstr, $request);
57 $user = &$request->getUser();
58 if (! $request->isActionPage($request->getArg('pagename'))) {
59 $no_args = $this->getDefaultArguments();
61 // foreach ($no_args as $key => $value) {
62 // $no_args[$value] = false;
64 $no_args['errmsg'] = HTML(HTML::h2(_("Error: The user HomePage must be a valid WikiWord. Sorry, UserPreferences cannot be saved."),HTML::hr()));
65 $no_args['isForm'] = false;
66 return Template('userprefs', $no_args);
68 $userid = $user->UserName();
69 if (((defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN && $user->isSignedIn())
70 || $user->isAuthenticated())
72 $pref = $user->getPreferences();
73 //trigger_error("DEBUG: reading prefs from getPreferences".print_r($pref));
75 if ($request->isPost()) {
77 if ($rp = $request->getArg('pref')) {
78 // replace only changed prefs in $pref with those from request
79 if (!empty($rp['passwd']) and ($rp['passwd2'] != $rp['passwd'])) {
80 $errmsg = _("Wrong password. Try again.");
82 //trigger_error("DEBUG: reading prefs from request".print_r($rp));
83 //trigger_error("DEBUG: writing prefs with setPreferences".print_r($pref));
84 if (empty($rp['passwd']))
86 $num = $user->setPreferences($rp);
87 if (!empty($rp['passwd'])) {
89 if ($user->mayChangePass()) {
90 if (method_exists($user, 'storePass')) {
91 $passchanged = $user->storePass($rp['passwd']);
93 if (method_exists($user, 'changePass')) {
94 $passchanged = $user->changePass($rp['passwd']);
97 $errmsg = _("Password updated.");
99 $errmsg = _("Password cannot be changed.");
102 $errmsg = _("Password cannot be changed.");
106 $errmsg .= " " ._("No changes.");
108 $pref = $user->_prefs;
109 $errmsg .= sprintf(_("%d UserPreferences fields successfully updated."), $num);
112 $args['errmsg'] = HTML(HTML::h2($errmsg), HTML::hr());
115 $available_themes = array();
116 $dir_root = 'themes/';
117 if (defined('PHPWIKI_DIR'))
118 $dir_root = PHPWIKI_DIR . "/$dir_root";
119 $dir = dir($dir_root);
121 while($entry = $dir->read()) {
122 if (is_dir($dir_root.$entry)
123 && (substr($entry,0,1) != '.')
124 && $entry != 'CVS') {
125 array_push($available_themes, $entry);
130 $args['available_themes'] = $available_themes;
132 $available_languages = array('en');
133 $dir_root = 'locale/';
134 if (defined('PHPWIKI_DIR'))
135 $dir_root = PHPWIKI_DIR . "/$dir_root";
136 $dir = dir($dir_root);
138 while($entry = $dir->read()) {
139 if (is_dir($dir_root.$entry)
140 && (substr($entry,0,1) != '.')
142 && $entry != 'CVS') {
143 array_push($available_languages, $entry);
148 $args['available_languages'] = $available_languages;
150 return Template('userprefs', $args);
153 // wrong or unauthenticated user
154 return $user->PrintLoginForm ($request, $args, false, false);
159 // $Log: not supported by cvs2svn $
160 // Revision 1.20 2004/03/12 23:20:58 rurban
161 // pref fixes (base64)
163 // Revision 1.19 2004/02/27 13:21:17 rurban
164 // several performance improvements, esp. with peardb
166 // storepass seperated from prefs if defined so
167 // stacked and strict still not working
169 // Revision 1.18 2004/02/24 15:20:06 rurban
170 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
172 // Revision 1.17 2004/02/17 12:11:36 rurban
173 // 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, ...)
175 // Revision 1.16 2004/02/15 21:34:37 rurban
176 // PageList enhanced and improved.
177 // fixed new WikiAdmin... plugins
178 // editpage, Theme with exp. htmlarea framework
179 // (htmlarea yet committed, this is really questionable)
180 // WikiUser... code with better session handling for prefs
181 // enhanced UserPreferences (again)
182 // RecentChanges for show_deleted: how should pages be deleted then?
184 // Revision 1.15 2004/01/27 22:37:50 rurban
185 // fixed default args: no objects
187 // Revision 1.14 2004/01/26 09:18:00 rurban
188 // * changed stored pref representation as before.
189 // the array of objects is 1) bigger and 2)
190 // less portable. If we would import packed pref
191 // objects and the object definition was changed, PHP would fail.
192 // This doesn't happen with an simple array of non-default values.
193 // * use $prefs->retrieve and $prefs->store methods, where retrieve
194 // understands the interim format of array of objects also.
195 // * simplified $prefs->get() and fixed $prefs->set()
196 // * added $user->_userid and class '_WikiUser' portability functions
197 // * fixed $user object ->_level upgrading, mostly using sessions.
198 // this fixes yesterdays problems with loosing authorization level.
199 // * fixed WikiUserNew::checkPass to return the _level
200 // * fixed WikiUserNew::isSignedIn
201 // * added explodePageList to class PageList, support sortby arg
202 // * fixed UserPreferences for WikiUserNew
203 // * fixed WikiPlugin for empty defaults array
204 // * UnfoldSubpages: added pagename arg, renamed pages arg,
205 // removed sort arg, support sortby arg
207 // Revision 1.13 2003/12/04 20:27:00 carstenklapp
210 // Revision 1.12 2003/12/01 22:21:33 carstenklapp
211 // Bugfix: UserPreferences are no longer clobbered when signing in after
212 // the previous session has ended (i.e. user closed browser then signed
213 // in again). This is still a bit of a mess, and the preferences do not
214 // take effect until the next page browse/link has been clicked.
216 // Revision 1.11 2003/09/19 22:01:19 carstenklapp
217 // BOGO users allowed preferences too when ALLOW_BOGO_LOGIN == true.
219 // Revision 1.10 2003/09/13 21:57:26 carstenklapp
220 // Reformatting only.
222 // Revision 1.9 2003/09/13 21:53:41 carstenklapp
223 // Added lang and theme arguments, getVersion(), copyright and cvs log.
231 // c-hanging-comment-ender-p: nil
232 // indent-tabs-mode: nil