Update of /cvsroot/phpwiki/phpwiki/lib In directory usw-pr-cvs1:/tmp/cvs-serv7202/lib Modified Files: WikiUser.php Log Message: Minor cleanup of preference setting code for theme and language preferences. Index: WikiUser.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiUser.php,v retrieving revision 1.24 retrieving revision 1.25 diff -u -2 -b -p -d -r1.24 -r1.25 --- WikiUser.php 12 Sep 2002 20:56:29 -0000 1.24 +++ WikiUser.php 18 Sep 2002 18:35:24 -0000 1.25 @@ -29,6 +29,6 @@ $UserPreferences = array( 'emailVerified' => new _UserPreference_bool(), 'notifyPages' => new _UserPreference(''), - 'theme' => new _UserPreference(THEME), - 'lang' => new _UserPreference($LANG), + 'theme' => new _UserPreference_theme(THEME), + 'lang' => new _UserPreference_language(DEFAULT_LANGUAGE), 'editWidth' => new _UserPreference_int(80, 30, 150), 'editHeight' => new _UserPreference_int(22, 5, 80), @@ -120,5 +120,4 @@ class WikiUser { } - function AuthCheck ($postargs) { // Normalize args, and extract. @@ -446,4 +445,7 @@ class _UserPreference return (string) $value; } + + function update ($value) { + } } @@ -503,4 +505,41 @@ class _UserPreference_bool extends _User } + +class _UserPreference_language extends _UserPreference +{ + function _UserPreference_language ($default = 'en') { + $this->_UserPreference($default); + } + + function sanify ($value) { + // FIXME: check for valid locale + } + + function update ($newvalue) { + update_locale ($newvalue); + } +} + +class _UserPreference_theme extends _UserPreference +{ + function _UserPreference_theme ($default = 'default') { + $this->_UserPreference($default); + } + + function sanify ($value) { + if (file_exists($this->_themefile($value))) + return $value; + return $this->default; + } + + function update ($newvalue) { + include($this->_themefile($value)); + } + + function _themefile ($theme) { + return "themes/$theme/themeinfo.php"; + } +} + // don't save default preferences for efficiency. class UserPreferences { @@ -538,23 +577,17 @@ class UserPreferences { if (!($pref = $this->_getPref($name))) return false; + + $newvalue = $pref->sanify($value); + $oldvalue = $this->get($name); + + // update on changes + if ($newvalue != $oldvalue) + $pref->update($newvalue); + // don't set default values to save space (in cookies, db and sesssion) if ($value == $pref->default_value) unset($this->_prefs[$name]); - else { - // update on changes - $newvalue = $pref->sanify($value); - if (!empty($this->_prefs[$name]) and $this->_prefs[$name] != $newvalue) { - // check updates (theme, lang, ...) - switch ($name) { - case 'theme': - include_once("themes/$newvalue/themeinfo.php"); - break; - case 'lang': - update_locale ($newvalue); - break; - } - } - $this->_prefs[$name] = $pref->sanify($value); - } + else + $this->_prefs[$name] = $newvalue; } }