diff --git a/error_report.php b/error_report.php
index 3176744bac..722277a1d5 100644
--- a/error_report.php
+++ b/error_report.php
@@ -6,9 +6,10 @@
* @package PhpMyAdmin
*/
use PhpMyAdmin\Response;
+use PhpMyAdmin\UserPreferences;
+
require_once 'libraries/common.inc.php';
require_once 'libraries/error_report.lib.php';
-require_once 'libraries/user_preferences.lib.php';
if (!isset($_REQUEST['exception_type'])
||!in_array($_REQUEST['exception_type'], array('js', 'php'))
@@ -114,7 +115,7 @@ if (isset($_REQUEST['send_error_report'])
if (isset($_REQUEST['always_send'])
&& $_REQUEST['always_send'] === "true"
) {
- PMA_persistOption("SendErrorReports", "always", "ask");
+ UserPreferences::persistOption("SendErrorReports", "always", "ask");
}
}
} elseif (! empty($_REQUEST['get_settings'])) {
diff --git a/libraries/classes/Config.php b/libraries/classes/Config.php
index 8dd17e2587..649a4a49f5 100644
--- a/libraries/classes/Config.php
+++ b/libraries/classes/Config.php
@@ -13,6 +13,7 @@ use PhpMyAdmin\Error;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\ThemeManager;
use PhpMyAdmin\Url;
+use PhpMyAdmin\UserPreferences;
use PhpMyAdmin\Util;
/**
@@ -907,11 +908,9 @@ class Config
if (! isset($_SESSION['cache'][$cache_key]['userprefs'])
|| $_SESSION['cache'][$cache_key]['config_mtime'] < $config_mtime
) {
- // load required libraries
- include_once './libraries/user_preferences.lib.php';
- $prefs = PMA_loadUserprefs();
+ $prefs = UserPreferences::load();
$_SESSION['cache'][$cache_key]['userprefs']
- = PMA_applyUserprefs($prefs['config_data']);
+ = UserPreferences::apply($prefs['config_data']);
$_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime'];
$_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type'];
$_SESSION['cache'][$cache_key]['config_mtime'] = $config_mtime;
@@ -1032,11 +1031,10 @@ class Config
// use permanent user preferences if possible
$prefs_type = $this->get('user_preferences');
if ($prefs_type) {
- include_once './libraries/user_preferences.lib.php';
if ($default_value === null) {
$default_value = Core::arrayRead($cfg_path, $this->default);
}
- PMA_persistOption($cfg_path, $new_cfg_value, $default_value);
+ UserPreferences::persistOption($cfg_path, $new_cfg_value, $default_value);
}
if ($prefs_type != 'db' && $cookie_name) {
// fall back to cookies
diff --git a/libraries/classes/Config/PageSettings.php b/libraries/classes/Config/PageSettings.php
index c1be5d6585..5caf758166 100644
--- a/libraries/classes/Config/PageSettings.php
+++ b/libraries/classes/Config/PageSettings.php
@@ -13,8 +13,7 @@ use PhpMyAdmin\Config\Forms\Page\PageFormList;
use PhpMyAdmin\Core;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
-
-require_once 'libraries/user_preferences.lib.php';
+use PhpMyAdmin\UserPreferences;
/**
* Page-related settings
@@ -71,7 +70,7 @@ class PageSettings
$this->_groupName = $formGroupName;
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
- PMA_userprefsPageInit($cf);
+ UserPreferences::pageInit($cf);
$form_display = new $form_class($cf);
@@ -100,7 +99,7 @@ class PageSettings
{
if ($form_display->process(false) && !$form_display->hasErrors()) {
// save settings
- $result = PMA_saveUserprefs($cf->getConfigArray());
+ $result = UserPreferences::save($cf->getConfigArray());
if ($result === true) {
// reload page
$response = Response::getInstance();
diff --git a/libraries/classes/Header.php b/libraries/classes/Header.php
index eb38f8ddc8..8dc0c6556b 100644
--- a/libraries/classes/Header.php
+++ b/libraries/classes/Header.php
@@ -17,6 +17,7 @@ use PhpMyAdmin\RecentFavoriteTable;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Scripts;
use PhpMyAdmin\Url;
+use PhpMyAdmin\UserPreferences;
use PhpMyAdmin\Util;
/**
@@ -436,8 +437,7 @@ class Header
$retval .= Config::renderHeader();
// offer to load user preferences from localStorage
if ($this->_userprefsOfferImport) {
- include_once './libraries/user_preferences.lib.php';
- $retval .= PMA_userprefsAutoloadGetHeader();
+ $retval .= UserPreferences::autoloadGetHeader();
}
// pass configuration for hint tooltip display
// (to be used by PMA_tooltip() in js/functions.js)
diff --git a/libraries/classes/UserPreferences.php b/libraries/classes/UserPreferences.php
new file mode 100644
index 0000000000..bcab88abb3
--- /dev/null
+++ b/libraries/classes/UserPreferences.php
@@ -0,0 +1,262 @@
+resetConfigData(); // start with a clean instance
+ $cf->setAllowedKeys($forms_all_keys);
+ $cf->setCfgUpdateReadMapping(
+ array(
+ 'Server/hide_db' => 'Servers/1/hide_db',
+ 'Server/only_db' => 'Servers/1/only_db'
+ )
+ );
+ $cf->updateWithGlobalConfig($GLOBALS['cfg']);
+ }
+
+ /**
+ * Loads user preferences
+ *
+ * Returns an array:
+ * * config_data - path => value pairs
+ * * mtime - last modification time
+ * * type - 'db' (config read from pmadb) or 'session' (read from user session)
+ *
+ * @return array
+ */
+ public static function load()
+ {
+ $cfgRelation = Relation::getRelationsParam();
+ if (! $cfgRelation['userconfigwork']) {
+ // no pmadb table, use session storage
+ if (! isset($_SESSION['userconfig'])) {
+ $_SESSION['userconfig'] = array(
+ 'db' => array(),
+ 'ts' => time());
+ }
+ return array(
+ 'config_data' => $_SESSION['userconfig']['db'],
+ 'mtime' => $_SESSION['userconfig']['ts'],
+ 'type' => 'session');
+ }
+ // load configuration from pmadb
+ $query_table = Util::backquote($cfgRelation['db']) . '.'
+ . Util::backquote($cfgRelation['userconfig']);
+ $query = 'SELECT `config_data`, UNIX_TIMESTAMP(`timevalue`) ts'
+ . ' FROM ' . $query_table
+ . ' WHERE `username` = \''
+ . $GLOBALS['dbi']->escapeString($cfgRelation['user'])
+ . '\'';
+ $row = $GLOBALS['dbi']->fetchSingleRow($query, 'ASSOC', $GLOBALS['controllink']);
+
+ return array(
+ 'config_data' => $row ? (array)json_decode($row['config_data']) : array(),
+ 'mtime' => $row ? $row['ts'] : time(),
+ 'type' => 'db');
+ }
+
+ /**
+ * Saves user preferences
+ *
+ * @param array $config_array configuration array
+ *
+ * @return true|PhpMyAdmin\Message
+ */
+ public static function save(array $config_array)
+ {
+ $cfgRelation = Relation::getRelationsParam();
+ $server = isset($GLOBALS['server'])
+ ? $GLOBALS['server']
+ : $GLOBALS['cfg']['ServerDefault'];
+ $cache_key = 'server_' . $server;
+ if (! $cfgRelation['userconfigwork']) {
+ // no pmadb table, use session storage
+ $_SESSION['userconfig'] = array(
+ 'db' => $config_array,
+ 'ts' => time());
+ if (isset($_SESSION['cache'][$cache_key]['userprefs'])) {
+ unset($_SESSION['cache'][$cache_key]['userprefs']);
+ }
+ return true;
+ }
+
+ // save configuration to pmadb
+ $query_table = Util::backquote($cfgRelation['db']) . '.'
+ . Util::backquote($cfgRelation['userconfig']);
+ $query = 'SELECT `username` FROM ' . $query_table
+ . ' WHERE `username` = \''
+ . $GLOBALS['dbi']->escapeString($cfgRelation['user'])
+ . '\'';
+
+ $has_config = $GLOBALS['dbi']->fetchValue(
+ $query, 0, 0, $GLOBALS['controllink']
+ );
+ $config_data = json_encode($config_array);
+ if ($has_config) {
+ $query = 'UPDATE ' . $query_table
+ . ' SET `timevalue` = NOW(), `config_data` = \''
+ . $GLOBALS['dbi']->escapeString($config_data)
+ . '\''
+ . ' WHERE `username` = \''
+ . $GLOBALS['dbi']->escapeString($cfgRelation['user'])
+ . '\'';
+ } else {
+ $query = 'INSERT INTO ' . $query_table
+ . ' (`username`, `timevalue`,`config_data`) '
+ . 'VALUES (\''
+ . $GLOBALS['dbi']->escapeString($cfgRelation['user']) . '\', NOW(), '
+ . '\'' . $GLOBALS['dbi']->escapeString($config_data) . '\')';
+ }
+ if (isset($_SESSION['cache'][$cache_key]['userprefs'])) {
+ unset($_SESSION['cache'][$cache_key]['userprefs']);
+ }
+ if (!$GLOBALS['dbi']->tryQuery($query, $GLOBALS['controllink'])) {
+ $message = Message::error(__('Could not save configuration'));
+ $message->addMessage(
+ Message::rawError(
+ $GLOBALS['dbi']->getError($GLOBALS['controllink'])
+ ),
+ '
'
+ );
+ return $message;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a user preferences array filtered by $cfg['UserprefsDisallow']
+ * (blacklist) and keys from user preferences form (whitelist)
+ *
+ * @param array $config_data path => value pairs
+ *
+ * @return array
+ */
+ public static function apply(array $config_data)
+ {
+ $cfg = array();
+ $blacklist = array_flip($GLOBALS['cfg']['UserprefsDisallow']);
+ $whitelist = array_flip(UserFormList::getFields());
+ // whitelist some additional fields which are custom handled
+ $whitelist['ThemeDefault'] = true;
+ $whitelist['fontsize'] = true;
+ $whitelist['lang'] = true;
+ $whitelist['collation_connection'] = true;
+ $whitelist['Server/hide_db'] = true;
+ $whitelist['Server/only_db'] = true;
+ foreach ($config_data as $path => $value) {
+ if (! isset($whitelist[$path]) || isset($blacklist[$path])) {
+ continue;
+ }
+ Core::arrayWrite($path, $cfg, $value);
+ }
+ return $cfg;
+ }
+
+ /**
+ * Updates one user preferences option (loads and saves to database).
+ *
+ * No validation is done!
+ *
+ * @param string $path configuration
+ * @param mixed $value value
+ * @param mixed $default_value default value
+ *
+ * @return void
+ */
+ public static function persistOption($path, $value, $default_value)
+ {
+ $prefs = self::load();
+ if ($value === $default_value) {
+ if (isset($prefs['config_data'][$path])) {
+ unset($prefs['config_data'][$path]);
+ } else {
+ return;
+ }
+ } else {
+ $prefs['config_data'][$path] = $value;
+ }
+ self::save($prefs['config_data']);
+ }
+
+ /**
+ * Redirects after saving new user preferences
+ *
+ * @param string $file_name Filename
+ * @param array $params URL parameters
+ * @param string $hash Hash value
+ *
+ * @return void
+ */
+ public static function redirect($file_name,
+ $params = null, $hash = null
+ ) {
+ // redirect
+ $url_params = array('saved' => 1);
+ if (is_array($params)) {
+ $url_params = array_merge($params, $url_params);
+ }
+ if ($hash) {
+ $hash = '#' . urlencode($hash);
+ }
+ Core::sendHeaderLocation('./' . $file_name
+ . Url::getCommonRaw($url_params) . $hash
+ );
+ }
+
+ /**
+ * Shows form which allows to quickly load
+ * settings stored in browser's local storage
+ *
+ * @return string
+ */
+ public static function autoloadGetHeader()
+ {
+ if (isset($_REQUEST['prefs_autoload'])
+ && $_REQUEST['prefs_autoload'] == 'hide'
+ ) {
+ $_SESSION['userprefs_autoload'] = true;
+ return '';
+ }
+
+ $script_name = basename(basename($GLOBALS['PMA_PHP_SELF']));
+ $return_url = $script_name . '?' . http_build_query($_GET, '', '&');
+
+ return Template::get('prefs_autoload')
+ ->render(
+ array(
+ 'hidden_inputs' => Url::getHiddenInputs(),
+ 'return_url' => $return_url,
+ )
+ );
+ }
+}
diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php
deleted file mode 100644
index 5c2209dea1..0000000000
--- a/libraries/user_preferences.lib.php
+++ /dev/null
@@ -1,254 +0,0 @@
-resetConfigData(); // start with a clean instance
- $cf->setAllowedKeys($forms_all_keys);
- $cf->setCfgUpdateReadMapping(
- array(
- 'Server/hide_db' => 'Servers/1/hide_db',
- 'Server/only_db' => 'Servers/1/only_db'
- )
- );
- $cf->updateWithGlobalConfig($GLOBALS['cfg']);
-}
-
-/**
- * Loads user preferences
- *
- * Returns an array:
- * * config_data - path => value pairs
- * * mtime - last modification time
- * * type - 'db' (config read from pmadb) or 'session' (read from user session)
- *
- * @return array
- */
-function PMA_loadUserprefs()
-{
- $cfgRelation = Relation::getRelationsParam();
- if (! $cfgRelation['userconfigwork']) {
- // no pmadb table, use session storage
- if (! isset($_SESSION['userconfig'])) {
- $_SESSION['userconfig'] = array(
- 'db' => array(),
- 'ts' => time());
- }
- return array(
- 'config_data' => $_SESSION['userconfig']['db'],
- 'mtime' => $_SESSION['userconfig']['ts'],
- 'type' => 'session');
- }
- // load configuration from pmadb
- $query_table = PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.'
- . PhpMyAdmin\Util::backquote($cfgRelation['userconfig']);
- $query = 'SELECT `config_data`, UNIX_TIMESTAMP(`timevalue`) ts'
- . ' FROM ' . $query_table
- . ' WHERE `username` = \''
- . $GLOBALS['dbi']->escapeString($cfgRelation['user'])
- . '\'';
- $row = $GLOBALS['dbi']->fetchSingleRow($query, 'ASSOC', $GLOBALS['controllink']);
-
- return array(
- 'config_data' => $row ? (array)json_decode($row['config_data']) : array(),
- 'mtime' => $row ? $row['ts'] : time(),
- 'type' => 'db');
-}
-
-/**
- * Saves user preferences
- *
- * @param array $config_array configuration array
- *
- * @return true|PhpMyAdmin\Message
- */
-function PMA_saveUserprefs(array $config_array)
-{
- $cfgRelation = Relation::getRelationsParam();
- $server = isset($GLOBALS['server'])
- ? $GLOBALS['server']
- : $GLOBALS['cfg']['ServerDefault'];
- $cache_key = 'server_' . $server;
- if (! $cfgRelation['userconfigwork']) {
- // no pmadb table, use session storage
- $_SESSION['userconfig'] = array(
- 'db' => $config_array,
- 'ts' => time());
- if (isset($_SESSION['cache'][$cache_key]['userprefs'])) {
- unset($_SESSION['cache'][$cache_key]['userprefs']);
- }
- return true;
- }
-
- // save configuration to pmadb
- $query_table = PhpMyAdmin\Util::backquote($cfgRelation['db']) . '.'
- . PhpMyAdmin\Util::backquote($cfgRelation['userconfig']);
- $query = 'SELECT `username` FROM ' . $query_table
- . ' WHERE `username` = \''
- . $GLOBALS['dbi']->escapeString($cfgRelation['user'])
- . '\'';
-
- $has_config = $GLOBALS['dbi']->fetchValue(
- $query, 0, 0, $GLOBALS['controllink']
- );
- $config_data = json_encode($config_array);
- if ($has_config) {
- $query = 'UPDATE ' . $query_table
- . ' SET `timevalue` = NOW(), `config_data` = \''
- . $GLOBALS['dbi']->escapeString($config_data)
- . '\''
- . ' WHERE `username` = \''
- . $GLOBALS['dbi']->escapeString($cfgRelation['user'])
- . '\'';
- } else {
- $query = 'INSERT INTO ' . $query_table
- . ' (`username`, `timevalue`,`config_data`) '
- . 'VALUES (\''
- . $GLOBALS['dbi']->escapeString($cfgRelation['user']) . '\', NOW(), '
- . '\'' . $GLOBALS['dbi']->escapeString($config_data) . '\')';
- }
- if (isset($_SESSION['cache'][$cache_key]['userprefs'])) {
- unset($_SESSION['cache'][$cache_key]['userprefs']);
- }
- if (!$GLOBALS['dbi']->tryQuery($query, $GLOBALS['controllink'])) {
- $message = Message::error(__('Could not save configuration'));
- $message->addMessage(
- Message::rawError(
- $GLOBALS['dbi']->getError($GLOBALS['controllink'])
- ),
- '
'
- );
- return $message;
- }
- return true;
-}
-
-/**
- * Returns a user preferences array filtered by $cfg['UserprefsDisallow']
- * (blacklist) and keys from user preferences form (whitelist)
- *
- * @param array $config_data path => value pairs
- *
- * @return array
- */
-function PMA_applyUserprefs(array $config_data)
-{
- $cfg = array();
- $blacklist = array_flip($GLOBALS['cfg']['UserprefsDisallow']);
- $whitelist = array_flip(UserFormList::getFields());
- // whitelist some additional fields which are custom handled
- $whitelist['ThemeDefault'] = true;
- $whitelist['fontsize'] = true;
- $whitelist['lang'] = true;
- $whitelist['collation_connection'] = true;
- $whitelist['Server/hide_db'] = true;
- $whitelist['Server/only_db'] = true;
- foreach ($config_data as $path => $value) {
- if (! isset($whitelist[$path]) || isset($blacklist[$path])) {
- continue;
- }
- Core::arrayWrite($path, $cfg, $value);
- }
- return $cfg;
-}
-
-/**
- * Updates one user preferences option (loads and saves to database).
- *
- * No validation is done!
- *
- * @param string $path configuration
- * @param mixed $value value
- * @param mixed $default_value default value
- *
- * @return void
- */
-function PMA_persistOption($path, $value, $default_value)
-{
- $prefs = PMA_loadUserprefs();
- if ($value === $default_value) {
- if (isset($prefs['config_data'][$path])) {
- unset($prefs['config_data'][$path]);
- } else {
- return;
- }
- } else {
- $prefs['config_data'][$path] = $value;
- }
- PMA_saveUserprefs($prefs['config_data']);
-}
-
-/**
- * Redirects after saving new user preferences
- *
- * @param string $file_name Filename
- * @param array $params URL parameters
- * @param string $hash Hash value
- *
- * @return void
- */
-function PMA_userprefsRedirect($file_name,
- $params = null, $hash = null
-) {
- // redirect
- $url_params = array('saved' => 1);
- if (is_array($params)) {
- $url_params = array_merge($params, $url_params);
- }
- if ($hash) {
- $hash = '#' . urlencode($hash);
- }
- Core::sendHeaderLocation('./' . $file_name
- . Url::getCommonRaw($url_params) . $hash
- );
-}
-
-/**
- * Shows form which allows to quickly load
- * settings stored in browser's local storage
- *
- * @return string
- */
-function PMA_userprefsAutoloadGetHeader()
-{
- if (isset($_REQUEST['prefs_autoload'])
- && $_REQUEST['prefs_autoload'] == 'hide'
- ) {
- $_SESSION['userprefs_autoload'] = true;
- return '';
- }
-
- $script_name = basename(basename($GLOBALS['PMA_PHP_SELF']));
- $return_url = $script_name . '?' . http_build_query($_GET, '', '&');
-
- return PhpMyAdmin\Template::get('prefs_autoload')
- ->render(
- array(
- 'hidden_inputs' => Url::getHiddenInputs(),
- 'return_url' => $return_url,
- )
- );
-}
diff --git a/prefs_forms.php b/prefs_forms.php
index 0bc0160fb6..d596c999e1 100644
--- a/prefs_forms.php
+++ b/prefs_forms.php
@@ -10,15 +10,15 @@ use PhpMyAdmin\Config\Forms\User\UserFormList;
use PhpMyAdmin\Core;
use PhpMyAdmin\Response;
use PhpMyAdmin\Url;
+use PhpMyAdmin\UserPreferences;
/**
* Gets some core libraries and displays a top message if required
*/
require_once 'libraries/common.inc.php';
-require_once 'libraries/user_preferences.lib.php';
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
-PMA_userprefsPageInit($cf);
+UserPreferences::pageInit($cf);
// handle form processing
@@ -45,13 +45,13 @@ if (isset($_POST['revert'])) {
$error = null;
if ($form_display->process(false) && !$form_display->hasErrors()) {
// save settings
- $result = PMA_saveUserprefs($cf->getConfigArray());
+ $result = UserPreferences::save($cf->getConfigArray());
if ($result === true) {
// reload config
$GLOBALS['PMA_Config']->loadUserPreferences();
$tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null;
$hash = ltrim($tabHash, '#');
- PMA_userprefsRedirect(
+ UserPreferences::redirect(
'prefs_forms.php',
array('form' => $form_param),
$hash
diff --git a/prefs_manage.php b/prefs_manage.php
index b6b27a5ce9..fa76b0baf7 100644
--- a/prefs_manage.php
+++ b/prefs_manage.php
@@ -11,19 +11,19 @@ use PhpMyAdmin\Core;
use PhpMyAdmin\File;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
-use PhpMyAdmin\Util;
-use PhpMyAdmin\Url;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\ThemeManager;
+use PhpMyAdmin\Url;
+use PhpMyAdmin\UserPreferences;
+use PhpMyAdmin\Util;
/**
* Gets some core libraries and displays a top message if required
*/
require_once 'libraries/common.inc.php';
-require_once 'libraries/user_preferences.lib.php';
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
-PMA_userprefsPageInit($cf);
+UserPreferences::pageInit($cf);
$response = Response::getInstance();
$error = '';
@@ -35,7 +35,7 @@ if (isset($_POST['submit_export'])
$response->disable();
$filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.json';
Core::downloadHeader($filename, 'application/json');
- $settings = PMA_loadUserprefs();
+ $settings = UserPreferences::load();
echo json_encode($settings['config_data'], JSON_PRETTY_PRINT);
exit;
} elseif (isset($_POST['submit_export'])
@@ -46,7 +46,7 @@ if (isset($_POST['submit_export'])
$response->disable();
$filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.php';
Core::downloadHeader($filename, 'application/php');
- $settings = PMA_loadUserprefs();
+ $settings = UserPreferences::load();
echo '/* ' . _('phpMyAdmin configuration snippet') . " */\n\n";
echo '/* ' . _('Paste it to your config.inc.php') . " */\n\n";
foreach ($settings['config_data'] as $key => $val) {
@@ -55,7 +55,7 @@ if (isset($_POST['submit_export'])
}
exit;
} else if (isset($_POST['submit_get_json'])) {
- $settings = PMA_loadUserprefs();
+ $settings = UserPreferences::load();
$response->addJSON('prefs', json_encode($settings['config_data']));
$response->addJSON('mtime', $settings['mtime']);
exit;
@@ -172,7 +172,7 @@ if (isset($_POST['submit_export'])
}
// save settings
- $result = PMA_saveUserprefs($cf->getConfigArray());
+ $result = UserPreferences::save($cf->getConfigArray());
if ($result === true) {
if ($return_url) {
$query = PhpMyAdmin\Util::splitURLQuery($return_url);
@@ -191,14 +191,14 @@ if (isset($_POST['submit_export'])
}
// reload config
$GLOBALS['PMA_Config']->loadUserPreferences();
- PMA_userprefsRedirect($return_url, $params);
+ UserPreferences::redirect($return_url, $params);
exit;
} else {
$error = $result;
}
}
} else if (isset($_POST['submit_clear'])) {
- $result = PMA_saveUserprefs(array());
+ $result = UserPreferences::save(array());
if ($result === true) {
$params = array();
if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
@@ -206,7 +206,7 @@ if (isset($_POST['submit_export'])
}
$GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
$GLOBALS['PMA_Config']->removeCookie('pma_lang');
- PMA_userprefsRedirect('prefs_manage.php', $params);
+ UserPreferences::redirect('prefs_manage.php', $params);
exit;
} else {
$error = $result;
diff --git a/setup/lib/common.inc.php b/setup/lib/common.inc.php
index 45fe35d9a9..f790f21be2 100644
--- a/setup/lib/common.inc.php
+++ b/setup/lib/common.inc.php
@@ -19,7 +19,6 @@ if (!file_exists('./libraries/common.inc.php')) {
}
require_once './libraries/common.inc.php';
-require_once './libraries/user_preferences.lib.php';
require_once './setup/lib/ConfigGenerator.php';
// use default error handler
@@ -48,4 +47,3 @@ $GLOBALS['ConfigFile']->setPersistKeys(
// allows for redirection even after sending some data
ob_start();
-
diff --git a/test/libraries/PMA_user_preferences_test.php b/test/classes/UserPreferencesTest.php
similarity index 88%
rename from test/libraries/PMA_user_preferences_test.php
rename to test/classes/UserPreferencesTest.php
index e1b0960d7e..213aa6bd33 100644
--- a/test/libraries/PMA_user_preferences_test.php
+++ b/test/classes/UserPreferencesTest.php
@@ -1,26 +1,22 @@
assertEquals(
array(
@@ -63,7 +59,7 @@ class PMA_User_Preferences_Test extends PMATestCase
}
/**
- * Test for PMA_loadUserprefs
+ * Test for UserPreferences::load
*
* @return void
*/
@@ -74,7 +70,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$_SESSION['relation'][$GLOBALS['server']]['userconfigwork'] = null;
unset($_SESSION['userconfig']);
- $result = PMA_loadUserprefs();
+ $result = UserPreferences::load();
$this->assertCount(
3,
@@ -129,7 +125,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$GLOBALS['dbi'] = $dbi;
- $result = PMA_loadUserprefs();
+ $result = UserPreferences::load();
$this->assertEquals(
array(
@@ -142,7 +138,7 @@ class PMA_User_Preferences_Test extends PMATestCase
}
/**
- * Test for PMA_saveUserprefs
+ * Test for UserPreferences::save
*
* @return void
*/
@@ -153,7 +149,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$_SESSION['relation'][2]['userconfigwork'] = null;
unset($_SESSION['userconfig']);
- $result = PMA_saveUserprefs(array(1));
+ $result = UserPreferences::save(array(1));
$this->assertTrue(
$result
@@ -220,7 +216,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$GLOBALS['dbi'] = $dbi;
$this->assertTrue(
- PMA_saveUserprefs(array(1))
+ UserPreferences::save(array(1))
);
// case 3
@@ -255,7 +251,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$GLOBALS['dbi'] = $dbi;
- $result = PMA_saveUserprefs(array(1));
+ $result = UserPreferences::save(array(1));
$this->assertEquals(
'Could not save configuration
err1',
@@ -264,7 +260,7 @@ class PMA_User_Preferences_Test extends PMATestCase
}
/**
- * Test for PMA_applyUserprefs
+ * Test for UserPreferences::apply
*
* @return void
*/
@@ -275,7 +271,7 @@ class PMA_User_Preferences_Test extends PMATestCase
'foo' => 'bar'
);
$GLOBALS['cfg']['UserprefsDeveloperTab'] = null;
- $result = PMA_applyUserprefs(
+ $result = UserPreferences::apply(
array(
'DBG/sql' => true,
'ErrorHandler/display' => true,
@@ -296,14 +292,14 @@ class PMA_User_Preferences_Test extends PMATestCase
}
/**
- * Test for PMA_applyUserprefs
+ * Test for UserPreferences::apply
*
* @return void
*/
public function testApplyDevelUserprefs()
{
$GLOBALS['cfg']['UserprefsDeveloperTab'] = true;
- $result = PMA_applyUserprefs(
+ $result = UserPreferences::apply(
array(
'DBG/sql' => true,
)
@@ -318,7 +314,7 @@ class PMA_User_Preferences_Test extends PMATestCase
}
/**
- * Test for PMA_persistOption
+ * Test for UserPreferences::persistOption
*
* @return void
*/
@@ -337,20 +333,20 @@ class PMA_User_Preferences_Test extends PMATestCase
$_SESSION['relation'][2]['userconfigwork'] = null;
$this->assertNull(
- PMA_persistOption('Server/hide_db', 'val', 'val')
+ UserPreferences::persistOption('Server/hide_db', 'val', 'val')
);
$this->assertNull(
- PMA_persistOption('Server/hide_db', 'val2', 'val')
+ UserPreferences::persistOption('Server/hide_db', 'val2', 'val')
);
$this->assertNull(
- PMA_persistOption('Server/hide_db2', 'val', 'val')
+ UserPreferences::persistOption('Server/hide_db2', 'val', 'val')
);
}
/**
- * Test for PMA_userprefsRedirect
+ * Test for UserPreferences::redirect
*
* @return void
*/
@@ -363,7 +359,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$GLOBALS['PMA_Config']->set('PmaAbsoluteUri', '');
$GLOBALS['PMA_Config']->set('PMA_IS_IIS', false);
- PMA_userprefsRedirect(
+ UserPreferences::redirect(
'file.html',
array('a' => 'b'),
'h ash'
@@ -371,7 +367,7 @@ class PMA_User_Preferences_Test extends PMATestCase
}
/**
- * Test for PMA_userprefsAutoloadGetHeader
+ * Test for UserPreferences::autoloadGetHeader
*
* @return void
*/
@@ -382,7 +378,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$this->assertEquals(
'',
- PMA_userprefsAutoloadGetHeader()
+ UserPreferences::autoloadGetHeader()
);
$this->assertTrue(
@@ -392,7 +388,7 @@ class PMA_User_Preferences_Test extends PMATestCase
$_REQUEST['prefs_autoload'] = 'nohide';
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['PMA_PHP_SELF'] = 'phpunit';
- $result = PMA_userprefsAutoloadGetHeader();
+ $result = UserPreferences::autoloadGetHeader();
$this->assertContains(
'