diff options
author | MaurĂcio Meneghini Fauth <mauriciofauth@gmail.com> | 2017-09-13 14:09:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-13 14:09:14 +0300 |
commit | 653f685b9acf889a7217d4fed86d0a2d3b89b309 (patch) | |
tree | 17bade993fc58d1accfe458d3d9bfef04a418e4a | |
parent | 3c2fd6a50537dd30b3c9494b69c099993e0381a9 (diff) | |
parent | 99642bf6e2c94d7f2fbe8fe3b3af933f671c9a2e (diff) |
Merge pull request #13677 from mauriciofauth/functions
Refactor some function calls to static method calls
66 files changed, 2649 insertions, 2653 deletions
diff --git a/db_designer.php b/db_designer.php index d199fdf1a1..ceb4f89ed6 100644 --- a/db_designer.php +++ b/db_designer.php @@ -22,7 +22,6 @@ if (isset($_REQUEST['dialog'])) { } else if ($_REQUEST['dialog'] == 'save_as') { $html = Designer::getHtmlForPageSaveAs($GLOBALS['db']); } else if ($_REQUEST['dialog'] == 'export') { - include_once 'libraries/plugin_interface.lib.php'; $html = Designer::getHtmlForSchemaExport( $GLOBALS['db'], $_REQUEST['selected_page'] ); diff --git a/db_multi_table_query.php b/db_multi_table_query.php index 0832462107..0df0ef445e 100644 --- a/db_multi_table_query.php +++ b/db_multi_table_query.php @@ -5,8 +5,9 @@ * * @package PhpMyAdmin */ -use PhpMyAdmin\Response; use PhpMyAdmin\DbMultiTableQuery; +use PhpMyAdmin\ParseAnalyze; +use PhpMyAdmin\Response; use PhpMyAdmin\Sql; require_once 'libraries/common.inc.php'; @@ -14,12 +15,11 @@ require_once 'libraries/common.inc.php'; if (isset($_REQUEST['sql_query'])) { $sql_query = $_REQUEST['sql_query']; $db = $_REQUEST['db']; - include_once 'libraries/parse_analyze.lib.php'; list( $analyzed_sql_results, $db, $table_from_sql - ) = PMA_parseAnalyze($sql_query, $db); + ) = ParseAnalyze::sqlQuery($sql_query, $db); extract($analyzed_sql_results); $goto = 'db_multi_table_query.php'; diff --git a/db_operations.php b/db_operations.php index 63d0123bbf..7ba8b094e1 100644 --- a/db_operations.php +++ b/db_operations.php @@ -15,8 +15,10 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Message; use PhpMyAdmin\Operations; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\Export\ExportSql; use PhpMyAdmin\Relation; +use PhpMyAdmin\RelationCleanup; use PhpMyAdmin\Response; use PhpMyAdmin\Util; @@ -75,10 +77,9 @@ if (strlen($GLOBALS['db']) > 0 $tables_full = $GLOBALS['dbi']->getTablesFull($GLOBALS['db']); - include_once "libraries/plugin_interface.lib.php"; // remove all foreign key constraints, otherwise we can get errors /* @var $export_sql_plugin ExportSql */ - $export_sql_plugin = PMA_getPlugin( + $export_sql_plugin = Plugins::getPlugin( "export", "sql", 'libraries/classes/Plugins/Export/', @@ -133,8 +134,7 @@ if (strlen($GLOBALS['db']) > 0 /** * cleanup pmadb stuff for this db */ - include_once 'libraries/relation_cleanup.lib.php'; - PMA_relationsCleanupDatabase($GLOBALS['db']); + RelationCleanup::database($GLOBALS['db']); // if someday the RENAME DATABASE reappears, do not DROP $local_query = 'DROP DATABASE ' 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/export.php b/export.php index 88b481989b..1c2fb68f84 100644 --- a/export.php +++ b/export.php @@ -9,6 +9,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; use PhpMyAdmin\Export; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Relation; use PhpMyAdmin\Sanitize; @@ -26,7 +27,6 @@ if (isset($_POST['output_format']) && $_POST['output_format'] == 'sendit') { define('PMA_BYPASS_GET_INSTANCE', 1); } include_once 'libraries/common.inc.php'; -include_once 'libraries/plugin_interface.lib.php'; //check if it's the GET request to check export time out if (isset($_GET['check_time_out'])) { @@ -181,7 +181,7 @@ $what = Core::securePath($_POST['what']); // export class instance, not array of properties, as before /* @var $export_plugin ExportPlugin */ -$export_plugin = PMA_getPlugin( +$export_plugin = Plugins::getPlugin( "export", $what, 'libraries/classes/Plugins/Export/', diff --git a/import.php b/import.php index 65780c1d34..1e00db8e1b 100644 --- a/import.php +++ b/import.php @@ -11,6 +11,8 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; use PhpMyAdmin\File; use PhpMyAdmin\Import; +use PhpMyAdmin\ParseAnalyze; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\ImportPlugin; use PhpMyAdmin\Response; use PhpMyAdmin\Sql; @@ -514,10 +516,8 @@ if (! $error && isset($_POST['skip'])) { $sql_data = array('valid_sql' => array(), 'valid_queries' => 0); if (! $error) { - // Check for file existence - include_once "libraries/plugin_interface.lib.php"; /* @var $import_plugin ImportPlugin */ - $import_plugin = PMA_getPlugin( + $import_plugin = Plugins::getPlugin( "import", $format, 'libraries/classes/Plugins/Import/', @@ -637,13 +637,11 @@ if (isset($message)) { // can choke on it so avoid parsing) $sqlLength = mb_strlen($sql_query); if ($sqlLength <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) { - include_once 'libraries/parse_analyze.lib.php'; - list( $analyzed_sql_results, $db, $table_from_sql - ) = PMA_parseAnalyze($sql_query, $db); + ) = ParseAnalyze::sqlQuery($sql_query, $db); // @todo: possibly refactor extract($analyzed_sql_results); @@ -675,12 +673,11 @@ if ($go_sql) { foreach ($sql_queries as $sql_query) { // parse sql query - include_once 'libraries/parse_analyze.lib.php'; list( $analyzed_sql_results, $db, $table_from_sql - ) = PMA_parseAnalyze($sql_query, $db); + ) = ParseAnalyze::sqlQuery($sql_query, $db); // @todo: possibly refactor extract($analyzed_sql_results); @@ -5,8 +5,8 @@ * * @package PhpMyAdmin */ - use PhpMyAdmin\Charsets; +use PhpMyAdmin\Config; use PhpMyAdmin\Core; use PhpMyAdmin\Display\GitRevision; use PhpMyAdmin\LanguageManager; @@ -15,8 +15,10 @@ use PhpMyAdmin\RecentFavoriteTable; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Sanitize; +use PhpMyAdmin\Server\Select; use PhpMyAdmin\ThemeManager; use PhpMyAdmin\Url; +use PhpMyAdmin\Util; /** * Gets some core libraries and displays a top message if required @@ -68,11 +70,11 @@ if (isset($_REQUEST['ajax_request']) && ! empty($_REQUEST['access_time'])) { if (! empty($_REQUEST['db'])) { $page = null; if (! empty($_REQUEST['table'])) { - $page = PhpMyAdmin\Util::getScriptNameForOption( + $page = Util::getScriptNameForOption( $GLOBALS['cfg']['DefaultTabTable'], 'table' ); } else { - $page = PhpMyAdmin\Util::getScriptNameForOption( + $page = Util::getScriptNameForOption( $GLOBALS['cfg']['DefaultTabDatabase'], 'database' ); } @@ -107,7 +109,7 @@ $show_query = '1'; // Any message to display? if (! empty($message)) { - echo PhpMyAdmin\Util::getMessage($message); + echo Util::getMessage($message); unset($message); } if (isset($_SESSION['partial_logout'])) { @@ -182,9 +184,8 @@ if ($server > 0 || count($cfg['Servers']) > 1 || ($server == 0 && count($cfg['Servers']) == 1))) ) { echo '<li id="li_select_server" class="no_bullets" >'; - include_once 'libraries/select_server.lib.php'; - echo PhpMyAdmin\Util::getImage('s_host.png') , " " - , PMA_selectServer(true, true); + echo Util::getImage('s_host.png') , " " + , Select::render(true, true); echo '</li>'; } @@ -198,8 +199,8 @@ if ($server > 0 || count($cfg['Servers']) > 1 if ($cfg['Server']['auth_type'] != 'config') { if ($cfg['ShowChgPassword']) { $conditional_class = 'ajax'; - PMA_printListItem( - PhpMyAdmin\Util::getImage('s_passwd.png') . " " . __( + Core::printListItem( + Util::getImage('s_passwd.png') . " " . __( 'Change password' ), 'li_change_password', @@ -216,10 +217,10 @@ if ($server > 0 || count($cfg['Servers']) > 1 echo ' <form method="post" action="index.php">' , "\n" . Url::getHiddenInputs(null, null, 4, 'collation_connection') . ' <label for="select_collation_connection">' . "\n" - . ' ' . PhpMyAdmin\Util::getImage('s_asci.png') + . ' ' . Util::getImage('s_asci.png') . " " . __('Server connection collation') . "\n" // put the doc link in the form so that it appears on the same line - . PhpMyAdmin\Util::showMySQLDocu('Charset-connection') + . Util::showMySQLDocu('Charset-connection') . ': ' . "\n" . ' </label>' . "\n" @@ -246,7 +247,7 @@ $language_manager = LanguageManager::getInstance(); if (empty($cfg['Lang']) && $language_manager->hasChoice()) { echo '<li id="li_select_lang" class="no_bullets">'; - echo PhpMyAdmin\Util::getImage('s_lang.png') , " " + echo Util::getImage('s_lang.png') , " " , $language_manager->getSelectorDisplay(); echo '</li>'; } @@ -255,12 +256,12 @@ if (empty($cfg['Lang']) && $language_manager->hasChoice()) { if ($GLOBALS['cfg']['ThemeManager']) { echo '<li id="li_select_theme" class="no_bullets">'; - echo PhpMyAdmin\Util::getImage('s_theme.png') , " " + echo Util::getImage('s_theme.png') , " " , ThemeManager::getInstance()->getHtmlSelectBox(); echo '</li>'; } echo '<li id="li_select_fontsize">'; -echo PhpMyAdmin\Config::getFontsizeForm(); +echo Config::getFontsizeForm(); echo '</li>'; echo '</ul>'; @@ -269,8 +270,8 @@ echo '</ul>'; if ($server > 0) { echo '<ul>'; - PMA_printListItem( - PhpMyAdmin\Util::getImage('b_tblops.png') . " " . __( + Core::printListItem( + Util::getImage('b_tblops.png') . " " . __( 'More settings' ), 'li_user_preferences', @@ -295,29 +296,29 @@ if ($server > 0 && $GLOBALS['cfg']['ShowServerInfo']) { echo '<div class="group">'; echo '<h2>' , __('Database server') , '</h2>'; echo '<ul>' , "\n"; - PMA_printListItem( + Core::printListItem( __('Server:') . ' ' . $server_info, 'li_server_info' ); - PMA_printListItem( - __('Server type:') . ' ' . PhpMyAdmin\Util::getServerType(), + Core::printListItem( + __('Server type:') . ' ' . Util::getServerType(), 'li_server_type' ); - PMA_printListItem( - __('Server connection:') . ' ' . PhpMyAdmin\Util::getServerSSL(), + Core::printListItem( + __('Server connection:') . ' ' . Util::getServerSSL(), 'li_server_type' ); - PMA_printListItem( + Core::printListItem( __('Server version:') . ' ' . $GLOBALS['dbi']->getVersionString() . ' - ' . $GLOBALS['dbi']->getVersionComment(), 'li_server_version' ); - PMA_printListItem( + Core::printListItem( __('Protocol version:') . ' ' . $GLOBALS['dbi']->getProtoInfo(), 'li_mysql_proto' ); - PMA_printListItem( + Core::printListItem( __('User:') . ' ' . htmlspecialchars($mysql_cur_user_and_host), 'li_user_info' ); @@ -339,35 +340,35 @@ if ($GLOBALS['cfg']['ShowServerInfo'] || $GLOBALS['cfg']['ShowPhpInfo']) { echo '<h2>' , __('Web server') , '</h2>'; echo '<ul>'; if ($GLOBALS['cfg']['ShowServerInfo']) { - PMA_printListItem($_SERVER['SERVER_SOFTWARE'], 'li_web_server_software'); + Core::printListItem($_SERVER['SERVER_SOFTWARE'], 'li_web_server_software'); if ($server > 0) { $client_version_str = $GLOBALS['dbi']->getClientInfo(); if (preg_match('#\d+\.\d+\.\d+#', $client_version_str)) { $client_version_str = 'libmysql - ' . $client_version_str; } - PMA_printListItem( + Core::printListItem( __('Database client version:') . ' ' . $client_version_str, 'li_mysql_client_version' ); $php_ext_string = __('PHP extension:') . ' '; - $extensions = PhpMyAdmin\Util::listPHPExtensions(); + $extensions = Util::listPHPExtensions(); foreach ($extensions as $extension) { $php_ext_string .= ' ' . $extension - . PhpMyAdmin\Util::showPHPDocu('book.' . $extension . '.php'); + . Util::showPHPDocu('book.' . $extension . '.php'); } - PMA_printListItem( + Core::printListItem( $php_ext_string, 'li_used_php_extension' ); $php_version_string = __('PHP version:') . ' ' . phpversion(); - PMA_printListItem( + Core::printListItem( $php_version_string, 'li_used_php_version' ); @@ -375,7 +376,7 @@ if ($GLOBALS['cfg']['ShowServerInfo'] || $GLOBALS['cfg']['ShowPhpInfo']) { } if ($cfg['ShowPhpInfo']) { - PMA_printListItem( + Core::printListItem( __('Show PHP information'), 'li_phpinfo', 'phpinfo.php' . $common_url_query, @@ -394,7 +395,7 @@ $class = null; if ($GLOBALS['cfg']['VersionCheck']) { $class = 'jsversioncheck'; } -PMA_printListItem( +Core::printListItem( __('Version information:') . ' <span class="version">' . PMA_VERSION . '</span>', 'li_pma_version', null, @@ -403,44 +404,44 @@ PMA_printListItem( null, $class ); -PMA_printListItem( +Core::printListItem( __('Documentation'), 'li_pma_docs', - PhpMyAdmin\Util::getDocuLink('index'), + Util::getDocuLink('index'), null, '_blank' ); // does not work if no target specified, don't know why -PMA_printListItem( +Core::printListItem( __('Official Homepage'), 'li_pma_homepage', Core::linkURL('https://www.phpmyadmin.net/'), null, '_blank' ); -PMA_printListItem( +Core::printListItem( __('Contribute'), 'li_pma_contribute', Core::linkURL('https://www.phpmyadmin.net/contribute/'), null, '_blank' ); -PMA_printListItem( +Core::printListItem( __('Get support'), 'li_pma_support', Core::linkURL('https://www.phpmyadmin.net/support/'), null, '_blank' ); -PMA_printListItem( +Core::printListItem( __('List of changes'), 'li_pma_changes', 'changelog.php' . Url::getCommon(), null, '_blank' ); -PMA_printListItem( +Core::printListItem( __('License'), 'li_pma_license', 'license.php' . Url::getCommon(), @@ -573,7 +574,7 @@ if ($server > 0) { . 'to set it up there.' ); } - $msg = PhpMyAdmin\Message::notice($msg_text); + $msg = Message::notice($msg_text); $msg->addParamHtml('<a href="./chk_rel.php' . $common_url_query . '">'); $msg->addParamHtml('</a>'); /* Show error if user has configured something, notice elsewhere */ @@ -638,39 +639,3 @@ if (@file_exists('libraries/language_stats.inc.php')) { ); } } - -/** - * prints list item for main page - * - * @param string $name displayed text - * @param string $listId id, used for css styles - * @param string $url make item as link with $url as target - * @param string $mysql_help_page display a link to MySQL's manual - * @param string $target special target for $url - * @param string $a_id id for the anchor, - * used for jQuery to hook in functions - * @param string $class class for the li element - * @param string $a_class class for the anchor element - * - * @return void - */ -function PMA_printListItem($name, $listId = null, $url = null, - $mysql_help_page = null, $target = null, $a_id = null, $class = null, - $a_class = null -) { - echo PhpMyAdmin\Template::get('list/item') - ->render( - array( - 'content' => $name, - 'id' => $listId, - 'class' => $class, - 'url' => array( - 'href' => $url, - 'target' => $target, - 'id' => $a_id, - 'class' => $a_class, - ), - 'mysql_help_page' => $mysql_help_page, - ) - ); -} 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/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index 3f85a95791..1a8fa69b75 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -14,6 +14,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\CreateAddField; use PhpMyAdmin\Index; use PhpMyAdmin\Message; +use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\Relation; use PhpMyAdmin\Sql; use PhpMyAdmin\SqlParser\Context; @@ -793,11 +794,10 @@ class TableStructureController extends TableController // Parse and analyze the query $db = &$this->db; - include_once 'libraries/parse_analyze.lib.php'; list( $analyzed_sql_results, $db, - ) = PMA_parseAnalyze($sql_query, $db); + ) = ParseAnalyze::sqlQuery($sql_query, $db); // @todo: possibly refactor extract($analyzed_sql_results); diff --git a/libraries/classes/Core.php b/libraries/classes/Core.php index b198c616b2..bbac3e353d 100644 --- a/libraries/classes/Core.php +++ b/libraries/classes/Core.php @@ -1179,4 +1179,40 @@ class Core ); } } + + /** + * prints list item for main page + * + * @param string $name displayed text + * @param string $listId id, used for css styles + * @param string $url make item as link with $url as target + * @param string $mysql_help_page display a link to MySQL's manual + * @param string $target special target for $url + * @param string $a_id id for the anchor, + * used for jQuery to hook in functions + * @param string $class class for the li element + * @param string $a_class class for the anchor element + * + * @return void + */ + public static function printListItem($name, $listId = null, $url = null, + $mysql_help_page = null, $target = null, $a_id = null, $class = null, + $a_class = null + ) { + echo Template::get('list/item') + ->render( + array( + 'content' => $name, + 'id' => $listId, + 'class' => $class, + 'url' => array( + 'href' => $url, + 'target' => $target, + 'id' => $a_id, + 'class' => $a_class, + ), + 'mysql_help_page' => $mysql_help_page, + ) + ); + } } diff --git a/libraries/classes/Database/Designer.php b/libraries/classes/Database/Designer.php index e290c95d56..763ae5ae3c 100644 --- a/libraries/classes/Database/Designer.php +++ b/libraries/classes/Database/Designer.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Database; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Message; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\SchemaPlugin; use PhpMyAdmin\Relation; use PhpMyAdmin\Template; @@ -114,7 +115,7 @@ class Designer { /* Scan for schema plugins */ /* @var $export_list SchemaPlugin[] */ - $export_list = PMA_getPlugins( + $export_list = Plugins::getPlugins( "schema", 'libraries/classes/Plugins/Schema/', null diff --git a/libraries/classes/Display/Export.php b/libraries/classes/Display/Export.php index 48414bb696..6bef98947b 100644 --- a/libraries/classes/Display/Export.php +++ b/libraries/classes/Display/Export.php @@ -10,6 +10,7 @@ namespace PhpMyAdmin\Display; use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; use PhpMyAdmin\Message; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -371,7 +372,7 @@ class Export { $html = '<div class="exportoptions" id="format">'; $html .= '<h3>' . __('Format:') . '</h3>'; - $html .= PMA_pluginGetChoice('Export', 'what', $export_list, 'format'); + $html .= Plugins::getChoice('Export', 'what', $export_list, 'format'); $html .= '</div>'; return $html; } @@ -393,7 +394,7 @@ class Export . 'and ignore the options for other formats.' ); $html .= '</p>'; - $html .= PMA_pluginGetOptions('Export', $export_list); + $html .= Plugins::getOptions('Export', $export_list); $html .= '</div>'; if (Encoding::canConvertKanji()) { @@ -1002,11 +1003,9 @@ class Export $GLOBALS['single_table'] = $_REQUEST['single_table']; } - include_once './libraries/plugin_interface.lib.php'; - /* Scan for plugins */ /* @var $export_list ExportPlugin[] */ - $export_list = PMA_getPlugins( + $export_list = Plugins::getPlugins( "export", 'libraries/classes/Plugins/Export/', array( diff --git a/libraries/classes/Display/GitRevision.php b/libraries/classes/Display/GitRevision.php index ece20a3821..3de8c4e1f9 100644 --- a/libraries/classes/Display/GitRevision.php +++ b/libraries/classes/Display/GitRevision.php @@ -69,7 +69,7 @@ class GitRevision $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER'); $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR'); - PMA_printListItem( + Core::printListItem( __('Git revision:') . ' ' . $branch . ',<br /> ' . sprintf( diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 17afb49e53..3fcbf21890 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Display\ImportAjax; use PhpMyAdmin\Encoding; use PhpMyAdmin\Message; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\ImportPlugin; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Url; @@ -308,7 +309,7 @@ class Import $html .= ' <div class="formelementrow">'; $html .= ' <input type="checkbox" name="allow_interrupt" value="yes"'; $html .= ' id="checkbox_allow_interrupt" ' - . PMA_pluginCheckboxCheck('Import', 'allow_interrupt') . '/>'; + . Plugins::checkboxCheck('Import', 'allow_interrupt') . '/>'; $html .= ' <label for="checkbox_allow_interrupt">' . __( 'Allow the interruption of an import in case the script detects ' @@ -325,7 +326,7 @@ class Import ) . '</label>'; $html .= ' <input type="number" name="skip_queries" value="' - . PMA_pluginGetDefault('Import', 'skip_queries') + . Plugins::getDefault('Import', 'skip_queries') . '" id="text_skip_queries" min="0" />'; $html .= ' </div>'; @@ -334,7 +335,7 @@ class Import // do not show the Skip dialog to avoid the risk of someone // entering a value here that would interfere with "skip" $html .= ' <input type="hidden" name="skip_queries" value="' - . PMA_pluginGetDefault('Import', 'skip_queries') + . Plugins::getDefault('Import', 'skip_queries') . '" id="text_skip_queries" />'; } @@ -371,7 +372,7 @@ class Import { $html = ' <div class="importoptions">'; $html .= ' <h3>' . __('Format:') . '</h3>'; - $html .= PMA_pluginGetChoice('Import', 'format', $import_list); + $html .= Plugins::getChoice('Import', 'format', $import_list); $html .= ' <div id="import_notification"></div>'; $html .= ' </div>'; @@ -380,7 +381,7 @@ class Import $html .= ' <p class="no_js_msg" id="scroll_to_options_msg">' . 'Scroll down to fill in the options for the selected format ' . 'and ignore the options for other formats.</p>'; - $html .= PMA_pluginGetOptions('Import', $import_list); + $html .= Plugins::getOptions('Import', $import_list); $html .= ' </div>'; $html .= ' <div class="clearfloat"></div>'; @@ -650,7 +651,6 @@ class Import public static function getImportDisplay($import_type, $db, $table, $max_upload_size) { global $SESSION_KEY; - include_once './libraries/plugin_interface.lib.php'; list( $SESSION_KEY, @@ -659,7 +659,7 @@ class Import /* Scan for plugins */ /* @var $import_list ImportPlugin[] */ - $import_list = PMA_getPlugins( + $import_list = Plugins::getPlugins( "import", 'libraries/classes/Plugins/Import/', $import_type diff --git a/libraries/classes/File.php b/libraries/classes/File.php index a7ca8a195d..9624a09317 100644 --- a/libraries/classes/File.php +++ b/libraries/classes/File.php @@ -547,18 +547,6 @@ class File return false; } - /** - * @todo - * get registered plugins for file compression - - foreach (PMA_getPlugins($type = 'compression') as $plugin) { - if ($plugin['classname']::canHandle($this->getName())) { - $this->setCompressionPlugin($plugin); - break; - } - } - */ - $this->_compression = Util::getCompressionMimeType($file); return $this->_compression; } 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/IpAllowDeny.php b/libraries/classes/IpAllowDeny.php new file mode 100644 index 0000000000..790db16e0c --- /dev/null +++ b/libraries/classes/IpAllowDeny.php @@ -0,0 +1,310 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * This library is used with the server IP allow/deny host authentication + * feature + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin; + +use PhpMyAdmin\Core; + +require_once './libraries/hash.lib.php'; + +/** + * PhpMyAdmin\IpAllowDeny class + * + * @package PhpMyAdmin + */ +class IpAllowDeny +{ + /** + * Matches for IPv4 or IPv6 addresses + * + * @param string $testRange string of IP range to match + * @param string $ipToTest string of IP to test against range + * + * @return boolean whether the IP mask matches + * + * @access public + */ + public static function ipMaskTest($testRange, $ipToTest) + { + if (mb_strpos($testRange, ':') > -1 + || mb_strpos($ipToTest, ':') > -1 + ) { + // assume IPv6 + $result = self::ipv6MaskTest($testRange, $ipToTest); + } else { + $result = self::ipv4MaskTest($testRange, $ipToTest); + } + + return $result; + } // end of the "self::ipMaskTest()" function + + /** + * Based on IP Pattern Matcher + * Originally by J.Adams <jna@retina.net> + * Found on <https://secure.php.net/manual/en/function.ip2long.php> + * Modified for phpMyAdmin + * + * Matches: + * xxx.xxx.xxx.xxx (exact) + * xxx.xxx.xxx.[yyy-zzz] (range) + * xxx.xxx.xxx.xxx/nn (CIDR) + * + * Does not match: + * xxx.xxx.xxx.xx[yyy-zzz] (range, partial octets not supported) + * + * @param string $testRange string of IP range to match + * @param string $ipToTest string of IP to test against range + * + * @return boolean whether the IP mask matches + * + * @access public + */ + public static function ipv4MaskTest($testRange, $ipToTest) + { + $result = true; + $match = preg_match( + '|([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/([0-9]+)|', + $testRange, + $regs + ); + if ($match) { + // performs a mask match + $ipl = ip2long($ipToTest); + $rangel = ip2long( + $regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4] + ); + + $maskl = 0; + + for ($i = 0; $i < 31; $i++) { + if ($i < $regs[5] - 1) { + $maskl = $maskl + pow(2, (30 - $i)); + } // end if + } // end for + + if (($maskl & $rangel) == ($maskl & $ipl)) { + return true; + } + + return false; + } + + // range based + $maskocts = explode('.', $testRange); + $ipocts = explode('.', $ipToTest); + + // perform a range match + for ($i = 0; $i < 4; $i++) { + if (preg_match('|\[([0-9]+)\-([0-9]+)\]|', $maskocts[$i], $regs)) { + if (($ipocts[$i] > $regs[2]) || ($ipocts[$i] < $regs[1])) { + $result = false; + } // end if + } else { + if ($maskocts[$i] <> $ipocts[$i]) { + $result = false; + } // end if + } // end if/else + } //end for + + return $result; + } // end of the "self::ipv4MaskTest()" function + + /** + * IPv6 matcher + * CIDR section taken from https://stackoverflow.com/a/10086404 + * Modified for phpMyAdmin + * + * Matches: + * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx + * (exact) + * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:[yyyy-zzzz] + * (range, only at end of IP - no subnets) + * xxxx:xxxx:xxxx:xxxx/nn + * (CIDR) + * + * Does not match: + * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xx[yyy-zzz] + * (range, partial octets not supported) + * + * @param string $test_range string of IP range to match + * @param string $ip_to_test string of IP to test against range + * + * @return boolean whether the IP mask matches + * + * @access public + */ + public static function ipv6MaskTest($test_range, $ip_to_test) + { + $result = true; + + // convert to lowercase for easier comparison + $test_range = mb_strtolower($test_range); + $ip_to_test = mb_strtolower($ip_to_test); + + $is_cidr = mb_strpos($test_range, '/') > -1; + $is_range = mb_strpos($test_range, '[') > -1; + $is_single = ! $is_cidr && ! $is_range; + + $ip_hex = bin2hex(inet_pton($ip_to_test)); + + if ($is_single) { + $range_hex = bin2hex(inet_pton($test_range)); + $result = hash_equals($ip_hex, $range_hex); + return $result; + } + + if ($is_range) { + // what range do we operate on? + $range_match = array(); + $match = preg_match( + '/\[([0-9a-f]+)\-([0-9a-f]+)\]/', $test_range, $range_match + ); + if ($match) { + $range_start = $range_match[1]; + $range_end = $range_match[2]; + + // get the first and last allowed IPs + $first_ip = str_replace($range_match[0], $range_start, $test_range); + $first_hex = bin2hex(inet_pton($first_ip)); + $last_ip = str_replace($range_match[0], $range_end, $test_range); + $last_hex = bin2hex(inet_pton($last_ip)); + + // check if the IP to test is within the range + $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex); + } + return $result; + } + + if ($is_cidr) { + // Split in address and prefix length + list($first_ip, $subnet) = explode('/', $test_range); + + // Parse the address into a binary string + $first_bin = inet_pton($first_ip); + $first_hex = bin2hex($first_bin); + + $flexbits = 128 - $subnet; + + // Build the hexadecimal string of the last address + $last_hex = $first_hex; + + $pos = 31; + while ($flexbits > 0) { + // Get the character at this position + $orig = mb_substr($last_hex, $pos, 1); + + // Convert it to an integer + $origval = hexdec($orig); + + // OR it with (2^flexbits)-1, with flexbits limited to 4 at a time + $newval = $origval | (pow(2, min(4, $flexbits)) - 1); + + // Convert it back to a hexadecimal character + $new = dechex($newval); + + // And put that character back in the string + $last_hex = substr_replace($last_hex, $new, $pos, 1); + + // We processed one nibble, move to previous position + $flexbits -= 4; + --$pos; + } + + // check if the IP to test is within the range + $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex); + } + + return $result; + } // end of the "self::ipv6MaskTest()" function + + /** + * Runs through IP Allow/Deny rules the use of it below for more information + * + * @param string $type 'allow' | 'deny' type of rule to match + * + * @return bool Whether rule has matched + * + * @access public + * + * @see Core::getIp() + */ + public static function allowDeny($type) + { + global $cfg; + + // Grabs true IP of the user and returns if it can't be found + $remote_ip = Core::getIp(); + if (empty($remote_ip)) { + return false; + } + + // copy username + $username = $cfg['Server']['user']; + + // copy rule database + if (isset($cfg['Server']['AllowDeny']['rules'])) { + $rules = $cfg['Server']['AllowDeny']['rules']; + if (! is_array($rules)) { + $rules = array(); + } + } else { + $rules = array(); + } + + // lookup table for some name shortcuts + $shortcuts = array( + 'all' => '0.0.0.0/0', + 'localhost' => '127.0.0.1/8' + ); + + // Provide some useful shortcuts if server gives us address: + if (Core::getenv('SERVER_ADDR')) { + $shortcuts['localnetA'] = Core::getenv('SERVER_ADDR') . '/8'; + $shortcuts['localnetB'] = Core::getenv('SERVER_ADDR') . '/16'; + $shortcuts['localnetC'] = Core::getenv('SERVER_ADDR') . '/24'; + } + + foreach ($rules as $rule) { + // extract rule data + $rule_data = explode(' ', $rule); + + // check for rule type + if ($rule_data[0] != $type) { + continue; + } + + // check for username + if (($rule_data[1] != '%') //wildcarded first + && (! hash_equals($rule_data[1], $username)) + ) { + continue; + } + + // check if the config file has the full string with an extra + // 'from' in it and if it does, just discard it + if ($rule_data[2] == 'from') { + $rule_data[2] = $rule_data[3]; + } + + // Handle shortcuts with above array + if (isset($shortcuts[$rule_data[2]])) { + $rule_data[2] = $shortcuts[$rule_data[2]]; + } + + // Add code for host lookups here + // Excluded for the moment + + // Do the actual matching now + if (self::ipMaskTest($rule_data[2], $remote_ip)) { + return true; + } + } // end while + + return false; + } // end of the "self::allowDeny()" function +} diff --git a/libraries/classes/Mime.php b/libraries/classes/Mime.php new file mode 100644 index 0000000000..c42293e397 --- /dev/null +++ b/libraries/classes/Mime.php @@ -0,0 +1,39 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * MIME detection code. + * + * @package PhpMyAdmin + * @todo Maybe we could try to use fileinfo module if loaded + */ +namespace PhpMyAdmin; + +/** + * PhpMyAdmin\Mime class; + * + * @package PhpMyAdmin + */ +class Mime +{ + /** + * Tries to detect MIME type of content. + * + * @param string &$test First few bytes of content to use for detection + * + * @return string + */ + public static function detect(&$test) + { + $len = mb_strlen($test); + if ($len >= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) { + return 'image/jpeg'; + } + if ($len >= 3 && substr($test, 0, 3) == 'GIF') { + return 'image/gif'; + } + if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") { + return 'image/png'; + } + return 'application/octet-stream'; + } +} diff --git a/libraries/classes/MultSubmits.php b/libraries/classes/MultSubmits.php new file mode 100644 index 0000000000..10ba65e940 --- /dev/null +++ b/libraries/classes/MultSubmits.php @@ -0,0 +1,587 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * functions for multi submit forms + * + * @usedby mult_submits.inc.php + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin; + +use PhpMyAdmin\Operations; +use PhpMyAdmin\RelationCleanup; +use PhpMyAdmin\Sql; +use PhpMyAdmin\Table; +use PhpMyAdmin\Transformations; +use PhpMyAdmin\Url; +use PhpMyAdmin\Util; + +/** + * PhpMyAdmin\MultSubmits class + * + * @package PhpMyAdmin + */ +class MultSubmits +{ + /** + * Gets url params + * + * @param string $what mult submit type + * @param bool $reload is reload + * @param string $action action type + * @param string $db database name + * @param string $table table name + * @param array $selected selected rows(table,db) + * @param array $views table views + * @param string $original_sql_query original sql query + * @param string $original_url_query original url query + * + * @return array + */ + public static function getUrlParams( + $what, $reload, $action, $db, $table, $selected, $views, + $original_sql_query, $original_url_query + ) { + $_url_params = array( + 'query_type' => $what, + 'reload' => (! empty($reload) ? 1 : 0), + ); + if (mb_strpos(' ' . $action, 'db_') == 1) { + $_url_params['db']= $db; + } elseif (mb_strpos(' ' . $action, 'tbl_') == 1 + || $what == 'row_delete' + ) { + $_url_params['db']= $db; + $_url_params['table']= $table; + } + foreach ($selected as $sval) { + if ($what == 'row_delete') { + $_url_params['selected'][] = 'DELETE FROM ' + . Util::backquote($table) + . ' WHERE ' . $sval . ' LIMIT 1;'; + } else { + $_url_params['selected'][] = $sval; + } + } + if ($what == 'drop_tbl' && !empty($views)) { + foreach ($views as $current) { + $_url_params['views'][] = $current; + } + } + if ($what == 'row_delete') { + $_url_params['original_sql_query'] = $original_sql_query; + if (! empty($original_url_query)) { + $_url_params['original_url_query'] = $original_url_query; + } + } + + return $_url_params; + } + + /** + * Builds or execute queries for multiple elements, depending on $query_type + * + * @param string $query_type query type + * @param array $selected selected tables + * @param string $db db name + * @param string $table table name + * @param array $views table views + * @param string $primary table primary + * @param string $from_prefix from prefix original + * @param string $to_prefix to prefix original + * + * @return array + */ + public static function buildOrExecuteQueryForMulti( + $query_type, $selected, $db, $table, $views, $primary, + $from_prefix, $to_prefix + ) { + $rebuild_database_list = false; + $reload = null; + $a_query = null; + $sql_query = ''; + $sql_query_views = null; + // whether to run query after each pass + $run_parts = false; + // whether to execute the query at the end (to display results) + $execute_query_later = false; + $result = null; + + if ($query_type == 'drop_tbl') { + $sql_query_views = ''; + } + + $selected_cnt = count($selected); + $deletes = false; + $copy_tbl =false; + + for ($i = 0; $i < $selected_cnt; $i++) { + switch ($query_type) { + case 'row_delete': + $deletes = true; + $a_query = $selected[$i]; + $run_parts = true; + break; + + case 'drop_db': + RelationCleanup::database($selected[$i]); + $a_query = 'DROP DATABASE ' + . Util::backquote($selected[$i]); + $reload = 1; + $run_parts = true; + $rebuild_database_list = true; + break; + + case 'drop_tbl': + RelationCleanup::table($db, $selected[$i]); + $current = $selected[$i]; + if (!empty($views) && in_array($current, $views)) { + $sql_query_views .= (empty($sql_query_views) ? 'DROP VIEW ' : ', ') + . Util::backquote($current); + } else { + $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ') + . Util::backquote($current); + } + $reload = 1; + break; + + case 'check_tbl': + $sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ') + . Util::backquote($selected[$i]); + $execute_query_later = true; + break; + + case 'optimize_tbl': + $sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ') + . Util::backquote($selected[$i]); + $execute_query_later = true; + break; + + case 'analyze_tbl': + $sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ') + . Util::backquote($selected[$i]); + $execute_query_later = true; + break; + + case 'checksum_tbl': + $sql_query .= (empty($sql_query) ? 'CHECKSUM TABLE ' : ', ') + . Util::backquote($selected[$i]); + $execute_query_later = true; + break; + + case 'repair_tbl': + $sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ') + . Util::backquote($selected[$i]); + $execute_query_later = true; + break; + + case 'empty_tbl': + $deletes = true; + $a_query = 'TRUNCATE '; + $a_query .= Util::backquote($selected[$i]); + $run_parts = true; + break; + + case 'drop_fld': + RelationCleanup::column($db, $table, $selected[$i]); + $sql_query .= (empty($sql_query) + ? 'ALTER TABLE ' . Util::backquote($table) + : ',') + . ' DROP ' . Util::backquote($selected[$i]) + . (($i == $selected_cnt-1) ? ';' : ''); + break; + + case 'primary_fld': + $sql_query .= (empty($sql_query) + ? 'ALTER TABLE ' . Util::backquote($table) + . (empty($primary) + ? '' + : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' + : ', ') + . Util::backquote($selected[$i]) + . (($i == $selected_cnt-1) ? ');' : ''); + break; + + case 'index_fld': + $sql_query .= (empty($sql_query) + ? 'ALTER TABLE ' . Util::backquote($table) + . ' ADD INDEX( ' + : ', ') + . Util::backquote($selected[$i]) + . (($i == $selected_cnt-1) ? ');' : ''); + break; + + case 'unique_fld': + $sql_query .= (empty($sql_query) + ? 'ALTER TABLE ' . Util::backquote($table) + . ' ADD UNIQUE( ' + : ', ') + . Util::backquote($selected[$i]) + . (($i == $selected_cnt-1) ? ');' : ''); + break; + + case 'spatial_fld': + $sql_query .= (empty($sql_query) + ? 'ALTER TABLE ' . Util::backquote($table) + . ' ADD SPATIAL( ' + : ', ') + . Util::backquote($selected[$i]) + . (($i == $selected_cnt-1) ? ');' : ''); + break; + + case 'fulltext_fld': + $sql_query .= (empty($sql_query) + ? 'ALTER TABLE ' . Util::backquote($table) + . ' ADD FULLTEXT( ' + : ', ') + . Util::backquote($selected[$i]) + . (($i == $selected_cnt-1) ? ');' : ''); + break; + + case 'add_prefix_tbl': + $newtablename = $_POST['add_prefix'] . $selected[$i]; + // ADD PREFIX TO TABLE NAME + $a_query = 'ALTER TABLE ' + . Util::backquote($selected[$i]) + . ' RENAME ' + . Util::backquote($newtablename); + $run_parts = true; + break; + + case 'replace_prefix_tbl': + $current = $selected[$i]; + $subFromPrefix = mb_substr( + $current, + 0, + mb_strlen($from_prefix) + ); + if ($subFromPrefix == $from_prefix) { + $newtablename = $to_prefix + . mb_substr( + $current, + mb_strlen($from_prefix) + ); + } else { + $newtablename = $current; + } + // CHANGE PREFIX PATTERN + $a_query = 'ALTER TABLE ' + . Util::backquote($selected[$i]) + . ' RENAME ' + . Util::backquote($newtablename); + $run_parts = true; + break; + + case 'copy_tbl_change_prefix': + $run_parts = true; + $copy_tbl = true; + + $current = $selected[$i]; + $newtablename = $to_prefix . + mb_substr($current, mb_strlen($from_prefix)); + + // COPY TABLE AND CHANGE PREFIX PATTERN + Table::moveCopy( + $db, $current, $db, $newtablename, + 'data', false, 'one_table' + ); + break; + + case 'copy_tbl': + $run_parts = true; + $copy_tbl = true; + Table::moveCopy($db, $selected[$i], $_POST['target_db'], $selected[$i], $_POST['what'], false, 'one_table'); + if (isset($_POST['adjust_privileges']) && !empty($_POST['adjust_privileges'])) { + Operations::adjustPrivilegesCopyTable($db, $selected[$i], $_POST['target_db'], $selected[$i]); + } + break; + } // end switch + + // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE" + // statements will be run at once below + if ($run_parts && !$copy_tbl) { + $sql_query .= $a_query . ';' . "\n"; + if ($query_type != 'drop_db') { + $GLOBALS['dbi']->selectDb($db); + } + $result = $GLOBALS['dbi']->query($a_query); + + if ($query_type == 'drop_db') { + Transformations::clear($selected[$i]); + } elseif ($query_type == 'drop_tbl') { + Transformations::clear($db, $selected[$i]); + } else if ($query_type == 'drop_fld') { + Transformations::clear($db, $table, $selected[$i]); + } + } // end if + } // end for + + if ($deletes && ! empty($_REQUEST['pos'])) { + $_REQUEST['pos'] = Sql::calculatePosForLastPage( + $db, $table, isset($_REQUEST['pos']) ? $_REQUEST['pos'] : null + ); + } + + return array( + $result, $rebuild_database_list, $reload, + $run_parts, $execute_query_later, $sql_query, $sql_query_views + ); + } + + /** + * Gets HTML for copy tables form + * + * @param string $action action type + * @param array $_url_params URL params + * + * @return string + */ + public static function getHtmlForCopyMultipleTables($action, $_url_params) + { + $html = '<form id="ajax_form" action="' . $action . '" method="post">'; + $html .= Url::getHiddenInputs($_url_params); + $html .= '<fieldset class = "input">'; + $databases_list = $GLOBALS['dblist']->databases; + foreach ($databases_list as $key => $db_name) + if ($db_name == $GLOBALS['db']){ + $databases_list->offsetUnset($key); + break; + } + $html .= '<strong><label for="db_name_dropdown">' . __('Database') . ':</label></strong>'; + $html .= '<select id="db_name_dropdown" class="halfWidth" name="target_db" >' + . $databases_list->getHtmlOptions(true, false) + . '</select>'; + $html .= '<br><br>'; + $html .= '<strong><label>' . __('Options') . ':</label></strong><br>'; + $html .= '<input type="radio" id ="what_structure" value="structure" name="what"/>'; + $html .= '<label for="what_structure">' . __('Structure only') . '</label><br>'; + $html .= '<input type="radio" id ="what_data" value="data" name="what" checked="checked"/>'; + $html .= '<label for="what_data">' . __('Structure and data') . '</label><br>'; + $html .= '<input type="radio" id ="what_dataonly" value="dataonly" name="what"/>'; + $html .= '<label for="what_dataonly">' . __('Data only') . '</label><br><br>'; + $html .= '<input type="checkbox" id="checkbox_drop" value="1" name="drop_if_exists"/>'; + $html .= '<label for="checkbox_drop">' . __('Add DROP TABLE') . '</label><br>'; + $html .= '<input type="checkbox" id="checkbox_auto_increment_cp" value="1" name="sql_auto_increment"/>'; + $html .= '<label for="checkbox_auto_increment_cp">' . __('Add AUTO INCREMENT value') . '</label><br>'; + $html .= '<input type="checkbox" id="checkbox_constraints" value="1" name="sql_auto_increment" checked="checked"/>'; + $html .= '<label for="checkbox_constraints">' . __('Add constraints') . '</label><br><br>'; + $html .= '<input name="adjust_privileges" value="1" id="checkbox_adjust_privileges" checked="checked" type="checkbox"/>'; + $html .= '<label for="checkbox_adjust_privileges">' . __('Adjust privileges') . '<a href="./doc/html/faq.html#faq6-39" target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation" class="icon ic_b_help"></a></label>'; + $html .= '</fieldset>'; + $html .= '<input type="hidden" name="mult_btn" value="' . __('Yes') . '" />'; + $html .= '</form>'; + return $html; + } + + /** + * Gets HTML for replace_prefix_tbl or copy_tbl_change_prefix + * + * @param string $action action type + * @param array $_url_params URL params + * + * @return string + */ + public static function getHtmlForReplacePrefixTable($action, $_url_params) + { + $html = '<form id="ajax_form" action="' . $action . '" method="post">'; + $html .= Url::getHiddenInputs($_url_params); + $html .= '<fieldset class = "input">'; + $html .= '<table>'; + $html .= '<tr>'; + $html .= '<td>' . __('From') . '</td>'; + $html .= '<td>'; + $html .= '<input type="text" name="from_prefix" id="initialPrefix" />'; + $html .= '</td>'; + $html .= '</tr>'; + $html .= '<tr>'; + $html .= '<td>' . __('To') . '</td>'; + $html .= '<td>'; + $html .= '<input type="text" name="to_prefix" id="newPrefix" />'; + $html .= '</td>'; + $html .= '</tr>'; + $html .= '</table>'; + $html .= '</fieldset>'; + $html .= '<input type="hidden" name="mult_btn" value="' . __('Yes') . '" />'; + $html .= '</form>'; + + return $html; + } + + /** + * Gets HTML for add_prefix_tbl + * + * @param string $action action type + * @param array $_url_params URL params + * + * @return string + */ + public static function getHtmlForAddPrefixTable($action, $_url_params) + { + $html = '<form id="ajax_form" action="' . $action . '" method="post">'; + $html .= Url::getHiddenInputs($_url_params); + $html .= '<fieldset class = "input">'; + $html .= '<table>'; + $html .= '<tr>'; + $html .= '<td>' . __('Add prefix') . '</td>'; + $html .= '<td>'; + $html .= '<input type="text" name="add_prefix" id="txtPrefix" />'; + $html .= '</td>'; + $html .= '</tr>'; + $html .= '<tr>'; + $html .= '</table>'; + $html .= '</fieldset>'; + $html .= '<input type="hidden" name="mult_btn" value="' . __('Yes') . '" />'; + $html .= '</form>'; + + return $html; + } + + /** + * Gets HTML for other mult_submits actions + * + * @param string $what mult_submit type + * @param string $action action type + * @param array $_url_params URL params + * @param string $full_query full sql query string + * + * @return string + */ + public static function getHtmlForOtherActions($what, $action, $_url_params, $full_query) + { + $html = '<form action="' . $action . '" method="post">'; + $html .= Url::getHiddenInputs($_url_params); + $html .= '<fieldset class="confirmation">'; + $html .= '<legend>'; + if ($what == 'drop_db') { + $html .= __('You are about to DESTROY a complete database!') . ' '; + } + $html .= __('Do you really want to execute the following query?'); + $html .= '</legend>'; + $html .= '<code>' . $full_query . '</code>'; + $html .= '</fieldset>'; + $html .= '<fieldset class="tblFooters">'; + // Display option to disable foreign key checks while dropping tables + if ($what === 'drop_tbl' || $what === 'empty_tbl' || $what === 'row_delete') { + $html .= '<div id="foreignkeychk">'; + $html .= Util::getFKCheckbox(); + $html .= '</div>'; + } + $html .= '<input id="buttonYes" type="submit" name="mult_btn" value="' + . __('Yes') . '" />'; + $html .= '<input id="buttonNo" type="submit" name="mult_btn" value="' + . __('No') . '" />'; + $html .= '</fieldset>'; + $html .= '</form>'; + + return $html; + } + + /** + * Get query string from Selected + * + * @param string $what mult_submit type + * @param string $table table name + * @param array $selected the selected columns + * @param array $views table views + * + * @return array + */ + public static function getQueryFromSelected($what, $table, $selected, $views) + { + $reload = false; + $full_query_views = null; + $full_query = ''; + + if ($what == 'drop_tbl') { + $full_query_views = ''; + } + + $selected_cnt = count($selected); + $i = 0; + foreach ($selected as $sval) { + switch ($what) { + case 'row_delete': + $full_query .= 'DELETE FROM ' + . Util::backquote(htmlspecialchars($table)) + // Do not append a "LIMIT 1" clause here + // (it's not binlog friendly). + // We don't need the clause because the calling panel permits + // this feature only when there is a unique index. + . ' WHERE ' . htmlspecialchars($sval) + . ';<br />'; + break; + case 'drop_db': + $full_query .= 'DROP DATABASE ' + . Util::backquote(htmlspecialchars($sval)) + . ';<br />'; + $reload = true; + break; + + case 'drop_tbl': + $current = $sval; + if (!empty($views) && in_array($current, $views)) { + $full_query_views .= (empty($full_query_views) ? 'DROP VIEW ' : ', ') + . Util::backquote(htmlspecialchars($current)); + } else { + $full_query .= (empty($full_query) ? 'DROP TABLE ' : ', ') + . Util::backquote(htmlspecialchars($current)); + } + break; + + case 'empty_tbl': + $full_query .= 'TRUNCATE '; + $full_query .= Util::backquote(htmlspecialchars($sval)) + . ';<br />'; + break; + + case 'primary_fld': + if ($full_query == '') { + $full_query .= 'ALTER TABLE ' + . Util::backquote(htmlspecialchars($table)) + . '<br /> DROP PRIMARY KEY,' + . '<br /> ADD PRIMARY KEY(' + . '<br /> ' + . Util::backquote(htmlspecialchars($sval)) + . ','; + } else { + $full_query .= '<br /> ' + . Util::backquote(htmlspecialchars($sval)) + . ','; + } + if ($i == $selected_cnt-1) { + $full_query = preg_replace('@,$@', ');<br />', $full_query); + } + break; + + case 'drop_fld': + if ($full_query == '') { + $full_query .= 'ALTER TABLE ' + . Util::backquote(htmlspecialchars($table)); + } + $full_query .= '<br /> DROP ' + . Util::backquote(htmlspecialchars($sval)) + . ','; + if ($i == $selected_cnt - 1) { + $full_query = preg_replace('@,$@', ';<br />', $full_query); + } + break; + } // end switch + $i++; + } + + if ($what == 'drop_tbl') { + if (!empty($full_query)) { + $full_query .= ';<br />' . "\n"; + } + if (!empty($full_query_views)) { + $full_query .= $full_query_views . ';<br />' . "\n"; + } + unset($full_query_views); + } + + $full_query_views = isset($full_query_views)? $full_query_views : null; + + return array($full_query, $reload, $full_query_views); + } +} diff --git a/libraries/classes/Navigation/NavigationHeader.php b/libraries/classes/Navigation/NavigationHeader.php index 2a6d5d8558..4af2e2c43a 100644 --- a/libraries/classes/Navigation/NavigationHeader.php +++ b/libraries/classes/Navigation/NavigationHeader.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin\Navigation; use PhpMyAdmin\Sanitize; +use PhpMyAdmin\Server\Select; use PhpMyAdmin\Template; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -240,10 +241,9 @@ class NavigationHeader if ($GLOBALS['cfg']['NavigationDisplayServers'] && count($GLOBALS['cfg']['Servers']) > 1 ) { - include_once './libraries/select_server.lib.php'; $retval .= '<!-- SERVER CHOICE START -->'; $retval .= '<div id="serverChoice">'; - $retval .= PMA_selectServer(true, true); + $retval .= Select::render(true, true); $retval .= '</div>'; $retval .= '<!-- SERVER CHOICE END -->'; } diff --git a/libraries/classes/ParseAnalyze.php b/libraries/classes/ParseAnalyze.php new file mode 100644 index 0000000000..c30af3e2c6 --- /dev/null +++ b/libraries/classes/ParseAnalyze.php @@ -0,0 +1,78 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Parse and analyse a SQL query + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin; + +use PhpMyAdmin\Response; +use PhpMyAdmin\SqlParser\Utils\Query; + +/** + * PhpMyAdmin\ParseAnalyze class + * + * @package PhpMyAdmin + */ +class ParseAnalyze +{ + /** + * Calls the parser on a query + * + * @param string $sql_query the query to parse + * @param string $db the current database + * + * @return array + * + * @access public + */ + public static function sqlQuery($sql_query, $db) + { + // @todo: move to returned results (also in all the calling chain) + $GLOBALS['unparsed_sql'] = $sql_query; + + // Get details about the SQL query. + $analyzed_sql_results = Query::getAll($sql_query); + + extract($analyzed_sql_results); + $table = ''; + + // If the targeted table (and database) are different than the ones that is + // currently browsed, edit `$db` and `$table` to match them so other elements + // (page headers, links, navigation panel) can be updated properly. + if (!empty($analyzed_sql_results['select_tables'])) { + + // Previous table and database name is stored to check if it changed. + $prev_db = $db; + + if (count($analyzed_sql_results['select_tables']) > 1) { + + /** + * @todo if there are more than one table name in the Select: + * - do not extract the first table name + * - do not show a table name in the page header + * - do not display the sub-pages links) + */ + $table = ''; + } else { + $table = $analyzed_sql_results['select_tables'][0][0]; + if (!empty($analyzed_sql_results['select_tables'][0][1])) { + $db = $analyzed_sql_results['select_tables'][0][1]; + } + } + // There is no point checking if a reload is required if we already decided + // to reload. Also, no reload is required for AJAX requests. + $response = Response::getInstance(); + if (empty($reload) && ! $response->isAjax()) { + // NOTE: Database names are case-insensitive. + $reload = strcasecmp($db, $prev_db) != 0; + } + + // Updating the array. + $analyzed_sql_results['reload'] = $reload; + } + + return array($analyzed_sql_results, $db, $table); + } +} diff --git a/libraries/classes/Plugins.php b/libraries/classes/Plugins.php new file mode 100644 index 0000000000..a9569ecd61 --- /dev/null +++ b/libraries/classes/Plugins.php @@ -0,0 +1,584 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Generic plugin interface. + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin; + +use PhpMyAdmin\Properties\Options\Groups\OptionsPropertySubgroup; +use PhpMyAdmin\Properties\Options\OptionsPropertyItem; +use PhpMyAdmin\Properties\Plugins\ExportPluginProperties; +use PhpMyAdmin\Properties\Plugins\PluginPropertyItem; +use PhpMyAdmin\Properties\Plugins\SchemaPluginProperties; + +/** + * PhpMyAdmin\Plugins class + * + * @package PhpMyAdmin + */ +class Plugins +{ + /** + * Includes and instantiates the specified plugin type for a certain format + * + * @param string $plugin_type the type of the plugin (import, export, etc) + * @param string $plugin_format the format of the plugin (sql, xml, et ) + * @param string $plugins_dir directory with plugins + * @param mixed $plugin_param parameter to plugin by which they can + * decide whether they can work + * + * @return object|null new plugin instance + */ + public static function getPlugin( + $plugin_type, + $plugin_format, + $plugins_dir, + $plugin_param = false + ) { + $GLOBALS['plugin_param'] = $plugin_param; + $class_name = mb_strtoupper($plugin_type[0]) + . mb_strtolower(mb_substr($plugin_type, 1)) + . mb_strtoupper($plugin_format[0]) + . mb_strtolower(mb_substr($plugin_format, 1)); + $file = $class_name . ".php"; + if (is_file($plugins_dir . $file)) { + //include_once $plugins_dir . $file; + $fqnClass = 'PhpMyAdmin\\' . str_replace('/', '\\', mb_substr($plugins_dir, 18)) . $class_name; + // check if class exists, could be caused by skip_import + if (class_exists($fqnClass)) { + return new $fqnClass; + } + } + + return null; + } + + /** + * Reads all plugin information from directory $plugins_dir + * + * @param string $plugin_type the type of the plugin (import, export, etc) + * @param string $plugins_dir directory with plugins + * @param mixed $plugin_param parameter to plugin by which they can + * decide whether they can work + * + * @return array list of plugin instances + */ + public static function getPlugins($plugin_type, $plugins_dir, $plugin_param) + { + $GLOBALS['plugin_param'] = $plugin_param; + /* Scan for plugins */ + $plugin_list = array(); + if (!($handle = @opendir($plugins_dir))) { + return $plugin_list; + } + + $namespace = 'PhpMyAdmin\\' . str_replace('/', '\\', mb_substr($plugins_dir, 18)); + $class_type = mb_strtoupper($plugin_type[0], 'UTF-8') + . mb_strtolower(mb_substr($plugin_type, 1), 'UTF-8'); + + $prefix_class_name = $namespace . $class_type; + + while ($file = @readdir($handle)) { + // In some situations, Mac OS creates a new file for each file + // (for example ._csv.php) so the following regexp + // matches a file which does not start with a dot but ends + // with ".php" + if (is_file($plugins_dir . $file) + && preg_match( + '@^' . $class_type . '([^\.]+)\.php$@i', + $file, + $matches + ) + ) { + $GLOBALS['skip_import'] = false; + include_once $plugins_dir . $file; + if (! $GLOBALS['skip_import']) { + $class_name = $prefix_class_name . $matches[1]; + $plugin = new $class_name; + if (null !== $plugin->getProperties()) { + $plugin_list[] = $plugin; + } + } + } + } + + usort($plugin_list, function($cmp_name_1, $cmp_name_2) { + return strcasecmp( + $cmp_name_1->getProperties()->getText(), + $cmp_name_2->getProperties()->getText() + ); + }); + return $plugin_list; + } + + /** + * Returns locale string for $name or $name if no locale is found + * + * @param string $name for local string + * + * @return string locale string for $name + */ + public static function getString($name) + { + return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name; + } + + /** + * Returns html input tag option 'checked' if plugin $opt + * should be set by config or request + * + * @param string $section name of config section in + * $GLOBALS['cfg'][$section] for plugin + * @param string $opt name of option + * + * @return string html input tag option 'checked' + */ + public static function checkboxCheck($section, $opt) + { + // If the form is being repopulated using $_GET data, that is priority + if (isset($_GET[$opt]) + || ! isset($_GET['repopulate']) + && ((! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) + || ! empty($GLOBALS['cfg'][$section][$opt])) + ) { + return ' checked="checked"'; + } + return ''; + } + + /** + * Returns default value for option $opt + * + * @param string $section name of config section in + * $GLOBALS['cfg'][$section] for plugin + * @param string $opt name of option + * + * @return string default value for option $opt + */ + public static function getDefault($section, $opt) + { + if (isset($_GET[$opt])) { + // If the form is being repopulated using $_GET data, that is priority + return htmlspecialchars($_GET[$opt]); + } + + if (isset($GLOBALS['timeout_passed']) + && $GLOBALS['timeout_passed'] + && isset($_REQUEST[$opt]) + ) { + return htmlspecialchars($_REQUEST[$opt]); + } + + if (!isset($GLOBALS['cfg'][$section][$opt])) { + return ''; + } + + $matches = array(); + /* Possibly replace localised texts */ + if (!preg_match_all( + '/(str[A-Z][A-Za-z0-9]*)/', + $GLOBALS['cfg'][$section][$opt], + $matches + )) { + return htmlspecialchars($GLOBALS['cfg'][$section][$opt]); + } + + $val = $GLOBALS['cfg'][$section][$opt]; + foreach ($matches[0] as $match) { + if (isset($GLOBALS[$match])) { + $val = str_replace($match, $GLOBALS[$match], $val); + } + } + return htmlspecialchars($val); + } + + /** + * Returns html select form element for plugin choice + * and hidden fields denoting whether each plugin must be exported as a file + * + * @param string $section name of config section in + * $GLOBALS['cfg'][$section] for plugin + * @param string $name name of select element + * @param array &$list array with plugin instances + * @param string $cfgname name of config value, if none same as $name + * + * @return string html select tag + */ + public static function getChoice($section, $name, &$list, $cfgname = null) + { + if (! isset($cfgname)) { + $cfgname = $name; + } + $ret = '<select id="plugins" name="' . $name . '">'; + $default = self::getDefault($section, $cfgname); + $hidden = null; + foreach ($list as $plugin) { + $elem = explode('\\', get_class($plugin)); + $plugin_name = array_pop($elem); + unset($elem); + $plugin_name = mb_strtolower( + mb_substr( + $plugin_name, + mb_strlen($section) + ) + ); + $ret .= '<option'; + // If the form is being repopulated using $_GET data, that is priority + if (isset($_GET[$name]) + && $plugin_name == $_GET[$name] + || ! isset($_GET[$name]) + && $plugin_name == $default + ) { + $ret .= ' selected="selected"'; + } + + /** @var PluginPropertyItem $properties */ + $properties = $plugin->getProperties(); + $text = null; + if ($properties != null) { + $text = $properties->getText(); + } + $ret .= ' value="' . $plugin_name . '">' + . self::getString($text) + . '</option>' . "\n"; + + // Whether each plugin has to be saved as a file + $hidden .= '<input type="hidden" id="force_file_' . $plugin_name + . '" value="'; + /** @var ExportPluginProperties|SchemaPluginProperties $properties */ + $properties = $plugin->getProperties(); + if (! strcmp($section, 'Import') + || ($properties != null && $properties->getForceFile() != null) + ) { + $hidden .= 'true'; + } else { + $hidden .= 'false'; + } + $hidden .= '" />' . "\n"; + } + $ret .= '</select>' . "\n" . $hidden; + + return $ret; + } + + /** + * Returns single option in a list element + * + * @param string $section name of config section in $GLOBALS['cfg'][$section] for plugin + * @param string $plugin_name unique plugin name + * @param array|\PhpMyAdmin\Properties\PropertyItem &$propertyGroup options property main group instance + * @param boolean $is_subgroup if this group is a subgroup + * + * @return string table row with option + */ + public static function getOneOption( + $section, + $plugin_name, + &$propertyGroup, + $is_subgroup = false + ) { + $ret = "\n"; + + if (! $is_subgroup) { + // for subgroup headers + if (mb_strpos(get_class($propertyGroup), "PropertyItem")) { + $properties = array($propertyGroup); + } else { + // for main groups + $ret .= '<div class="export_sub_options" id="' . $plugin_name . '_' + . $propertyGroup->getName() . '">'; + + if (method_exists($propertyGroup, 'getText')) { + $text = $propertyGroup->getText(); + } + + if ($text != null) { + $ret .= '<h4>' . self::getString($text) . '</h4>'; + } + $ret .= '<ul>'; + } + } + + if (! isset($properties)) { + $not_subgroup_header = true; + if (method_exists($propertyGroup, 'getProperties')) { + $properties = $propertyGroup->getProperties(); + } + } + + if (isset($properties)) { + /** @var OptionsPropertySubgroup $propertyItem */ + foreach ($properties as $propertyItem) { + $property_class = get_class($propertyItem); + // if the property is a subgroup, we deal with it recursively + if (mb_strpos($property_class, "Subgroup")) { + // for subgroups + // each subgroup can have a header, which may also be a form element + /** @var OptionsPropertyItem $subgroup_header */ + $subgroup_header = $propertyItem->getSubgroupHeader(); + if (isset($subgroup_header)) { + $ret .= self::getOneOption( + $section, + $plugin_name, + $subgroup_header + ); + } + + $ret .= '<li class="subgroup"><ul'; + if (isset($subgroup_header)) { + $ret .= ' id="ul_' . $subgroup_header->getName() . '">'; + } else { + $ret .= '>'; + } + + $ret .= self::getOneOption( + $section, + $plugin_name, + $propertyItem, + true + ); + continue; + } + + // single property item + $ret .= self::getHtmlForProperty( + $section, $plugin_name, $propertyItem + ); + } + } + + if ($is_subgroup) { + // end subgroup + $ret .= '</ul></li>'; + } else { + // end main group + if (! empty($not_subgroup_header)) { + $ret .= '</ul></div>'; + } + } + + if (method_exists($propertyGroup, "getDoc")) { + $doc = $propertyGroup->getDoc(); + if ($doc != null) { + if (count($doc) == 3) { + $ret .= PhpMyAdmin\Util::showMySQLDocu( + $doc[1], + false, + $doc[2] + ); + } elseif (count($doc) == 1) { + $ret .= PhpMyAdmin\Util::showDocu('faq', $doc[0]); + } else { + $ret .= PhpMyAdmin\Util::showMySQLDocu( + $doc[1] + ); + } + } + } + + // Close the list element after $doc link is displayed + if (isset($property_class)) { + if ($property_class == 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem' + || $property_class == 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem' + || $property_class == 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem' + || $property_class == 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem' + ) { + $ret .= '</li>'; + } + } + $ret .= "\n"; + return $ret; + } + + /** + * Get HTML for properties items + * + * @param string $section name of config section in + * $GLOBALS['cfg'][$section] for plugin + * @param string $plugin_name unique plugin name + * @param OptionsPropertyItem $propertyItem Property item + * + * @return string + */ + public static function getHtmlForProperty( + $section, $plugin_name, $propertyItem + ) { + $ret = null; + $property_class = get_class($propertyItem); + switch ($property_class) { + case 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem': + $ret .= '<li>' . "\n"; + $ret .= '<input type="checkbox" name="' . $plugin_name . '_' + . $propertyItem->getName() . '"' + . ' value="something" id="checkbox_' . $plugin_name . '_' + . $propertyItem->getName() . '"' + . ' ' + . self::checkboxCheck( + $section, + $plugin_name . '_' . $propertyItem->getName() + ); + + if ($propertyItem->getForce() != null) { + // Same code is also few lines lower, update both if needed + $ret .= ' onclick="if (!this.checked && ' + . '(!document.getElementById(\'checkbox_' . $plugin_name + . '_' . $propertyItem->getForce() . '\') ' + . '|| !document.getElementById(\'checkbox_' + . $plugin_name . '_' . $propertyItem->getForce() + . '\').checked)) ' + . 'return false; else return true;"'; + } + $ret .= ' />'; + $ret .= '<label for="checkbox_' . $plugin_name . '_' + . $propertyItem->getName() . '">' + . self::getString($propertyItem->getText()) . '</label>'; + break; + case 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem': + echo 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem'; + break; + case 'PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem': + $ret .= '<li><input type="hidden" name="' . $plugin_name . '_' + . $propertyItem->getName() . '"' + . ' value="' . self::getDefault( + $section, + $plugin_name . '_' . $propertyItem->getName() + ) + . '"' . ' /></li>'; + break; + case 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem': + $ret .= '<li>' . "\n"; + $ret .= '<p>' . self::getString($propertyItem->getText()) . '</p>'; + break; + case 'PhpMyAdmin\Properties\Options\Items\RadioPropertyItem': + $default = self::getDefault( + $section, + $plugin_name . '_' . $propertyItem->getName() + ); + foreach ($propertyItem->getValues() as $key => $val) { + $ret .= '<li><input type="radio" name="' . $plugin_name + . '_' . $propertyItem->getName() . '" value="' . $key + . '" id="radio_' . $plugin_name . '_' + . $propertyItem->getName() . '_' . $key . '"'; + if ($key == $default) { + $ret .= ' checked="checked"'; + } + $ret .= ' />' . '<label for="radio_' . $plugin_name . '_' + . $propertyItem->getName() . '_' . $key . '">' + . self::getString($val) . '</label></li>'; + } + break; + case 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem': + $ret .= '<li>' . "\n"; + $ret .= '<label for="select_' . $plugin_name . '_' + . $propertyItem->getName() . '" class="desc">' + . self::getString($propertyItem->getText()) . '</label>'; + $ret .= '<select name="' . $plugin_name . '_' + . $propertyItem->getName() . '"' + . ' id="select_' . $plugin_name . '_' + . $propertyItem->getName() . '">'; + $default = self::getDefault( + $section, + $plugin_name . '_' . $propertyItem->getName() + ); + foreach ($propertyItem->getValues() as $key => $val) { + $ret .= '<option value="' . $key . '"'; + if ($key == $default) { + $ret .= ' selected="selected"'; + } + $ret .= '>' . self::getString($val) . '</option>'; + } + $ret .= '</select>'; + break; + case 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem': + case 'PhpMyAdmin\Properties\Options\Items\NumberPropertyItem': + $ret .= '<li>' . "\n"; + $ret .= '<label for="text_' . $plugin_name . '_' + . $propertyItem->getName() . '" class="desc">' + . self::getString($propertyItem->getText()) . '</label>'; + $ret .= '<input type="text" name="' . $plugin_name . '_' + . $propertyItem->getName() . '"' + . ' value="' . self::getDefault( + $section, + $plugin_name . '_' . $propertyItem->getName() + ) . '"' + . ' id="text_' . $plugin_name . '_' + . $propertyItem->getName() . '"' + . ($propertyItem->getSize() != null + ? ' size="' . $propertyItem->getSize() . '"' + : '') + . ($propertyItem->getLen() != null + ? ' maxlength="' . $propertyItem->getLen() . '"' + : '') + . ' />'; + break; + default: + break; + } + return $ret; + } + + /** + * Returns html div with editable options for plugin + * + * @param string $section name of config section in $GLOBALS['cfg'][$section] + * @param array &$list array with plugin instances + * + * @return string html fieldset with plugin options + */ + public static function getOptions($section, &$list) + { + $ret = ''; + // Options for plugins that support them + foreach ($list as $plugin) { + $properties = $plugin->getProperties(); + if ($properties != null) { + $text = $properties->getText(); + $options = $properties->getOptions(); + } + + $elem = explode('\\', get_class($plugin)); + $plugin_name = array_pop($elem); + unset($elem); + $plugin_name = mb_strtolower( + mb_substr( + $plugin_name, + mb_strlen($section) + ) + ); + + $ret .= '<div id="' . $plugin_name + . '_options" class="format_specific_options">'; + $ret .= '<h3>' . self::getString($text) . '</h3>'; + + $no_options = true; + if (! is_null($options) && count($options) > 0) { + foreach ($options->getProperties() + as $propertyMainGroup + ) { + // check for hidden properties + $no_options = true; + foreach ($propertyMainGroup->getProperties() as $propertyItem) { + if (strcmp('PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem', get_class($propertyItem))) { + $no_options = false; + break; + } + } + + $ret .= self::getOneOption( + $section, + $plugin_name, + $propertyMainGroup + ); + } + } + + if ($no_options) { + $ret .= '<p>' . __('This format has no options') . '</p>'; + } + $ret .= '</div>'; + } + return $ret; + } +} diff --git a/libraries/classes/Plugins/Auth/AuthenticationConfig.php b/libraries/classes/Plugins/Auth/AuthenticationConfig.php index 79a2242efc..9d53919249 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationConfig.php +++ b/libraries/classes/Plugins/Auth/AuthenticationConfig.php @@ -10,6 +10,7 @@ namespace PhpMyAdmin\Plugins\Auth; use PhpMyAdmin\Plugins\AuthenticationPlugin; use PhpMyAdmin\Response; +use PhpMyAdmin\Server\Select; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -161,10 +162,9 @@ class AuthenticationConfig extends AuthenticationPlugin </tr>' , "\n"; if (count($GLOBALS['cfg']['Servers']) > 1) { // offer a chance to login to other servers if the current one failed - include_once './libraries/select_server.lib.php'; echo '<tr>' , "\n"; echo ' <td>' , "\n"; - echo PMA_selectServer(true, true); + echo Select::render(true, true); echo ' </td>' , "\n"; echo '</tr>' , "\n"; } diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php index 5831c9c0e4..78ef5a7ccc 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php +++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php @@ -14,6 +14,7 @@ use PhpMyAdmin\LanguageManager; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\AuthenticationPlugin; use PhpMyAdmin\Response; +use PhpMyAdmin\Server\Select; use PhpMyAdmin\Session; use PhpMyAdmin\Util; use PhpMyAdmin\Url; @@ -218,10 +219,7 @@ class AuthenticationCookie extends AuthenticationPlugin , 'elements[\'pma_servername\'].value = \'\'" '; } echo '>'; - - include_once './libraries/select_server.lib.php'; - echo PMA_selectServer(false, false); - + echo Select::render(false, false); echo '</select></div>'; } else { echo ' <input type="hidden" name="server" value="' diff --git a/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php b/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php index 5d5231125b..c6918724c7 100644 --- a/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php +++ b/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php @@ -34,7 +34,7 @@ use PhpMyAdmin\Relation; class SvgRelationSchema extends ExportRelationSchema { /** - * @var \PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia[]|TableStatsEps[]|TableStatsPdf[]|TableStatsSvg[] + * @var PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia[]|TableStatsEps[]|TableStatsPdf[]|TableStatsSvg[] */ private $_tables = array(); /** @var RelationStatsDia[] Relations */ diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index 02442b6bbd..416f089db3 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -807,10 +807,10 @@ class Relation ) { if ($isInformationSchema) { $relations_key = 'information_schema_relations'; - include_once './libraries/information_schema_relations.lib.php'; + include_once './libraries/information_schema_relations.inc.php'; } else { $relations_key = 'mysql_relations'; - include_once './libraries/mysql_relations.lib.php'; + include_once './libraries/mysql_relations.inc.php'; } if (isset($GLOBALS[$relations_key][$table])) { foreach ($GLOBALS[$relations_key][$table] as $field => $relations) { diff --git a/libraries/classes/RelationCleanup.php b/libraries/classes/RelationCleanup.php new file mode 100644 index 0000000000..d84690fdc6 --- /dev/null +++ b/libraries/classes/RelationCleanup.php @@ -0,0 +1,367 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Set of functions used for cleaning up phpMyAdmin tables + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin; + +use PhpMyAdmin\Relation; +use PhpMyAdmin\Util; + +/** + * PhpMyAdmin\RelationCleanup class + * + * @package PhpMyAdmin + */ +class RelationCleanup +{ + /** + * Cleanup column related relation stuff + * + * @param string $db database name + * @param string $table table name + * @param string $column column name + * + * @return void + */ + public static function column($db, $table, $column) + { + $cfgRelation = Relation::getRelationsParam(); + + if ($cfgRelation['commwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['column_info']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' + . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND column_name = \'' . $GLOBALS['dbi']->escapeString($column) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['displaywork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_info']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' + . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND display_field = \'' . $GLOBALS['dbi']->escapeString($column) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['relwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['relation']) + . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) + . '\'' + . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND master_field = \'' . $GLOBALS['dbi']->escapeString($column) + . '\''; + Relation::queryAsControlUser($remove_query); + + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['relation']) + . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) + . '\'' + . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND foreign_field = \'' . $GLOBALS['dbi']->escapeString($column) + . '\''; + Relation::queryAsControlUser($remove_query); + } + } + + /** + * Cleanup table related relation stuff + * + * @param string $db database name + * @param string $table table name + * + * @return void + */ + public static function table($db, $table) + { + $cfgRelation = Relation::getRelationsParam(); + + if ($cfgRelation['commwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['column_info']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' + . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['displaywork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_info']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' + . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['pdfwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_coords']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' + . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['relwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['relation']) + . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) + . '\'' + . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) + . '\''; + Relation::queryAsControlUser($remove_query); + + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['relation']) + . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) + . '\'' + . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['uiprefswork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_uiprefs']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' + . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['navwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['navigationhiding']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' + . ' AND (table_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' OR (item_name = \'' . $GLOBALS['dbi']->escapeString($table) + . '\'' + . ' AND item_type = \'table\'))'; + Relation::queryAsControlUser($remove_query); + } + } + + /** + * Cleanup database related relation stuff + * + * @param string $db database name + * + * @return void + */ + public static function database($db) + { + $cfgRelation = Relation::getRelationsParam(); + + if ($cfgRelation['commwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['column_info']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['bookmarkwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['bookmark']) + . ' WHERE dbase = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['displaywork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_info']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['pdfwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['pdf_pages']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_coords']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['relwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['relation']) + . ' WHERE master_db = \'' + . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['relation']) + . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) + . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['uiprefswork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['table_uiprefs']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['navwork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['navigationhiding']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['savedsearcheswork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['savedsearches']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['centralcolumnswork']) { + $remove_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['central_columns']) + . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; + Relation::queryAsControlUser($remove_query); + } + } + + /** + * Cleanup user related relation stuff + * + * @param string $username username + * + * @return void + */ + public static function user($username) + { + $cfgRelation = Relation::getRelationsParam(); + + if ($cfgRelation['bookmarkwork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['bookmark']) + . " WHERE `user` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['historywork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['history']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['recentwork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['recent']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['favoritework']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['favorite']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['uiprefswork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['table_uiprefs']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['userconfigwork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['userconfig']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['menuswork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['users']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['navwork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['navigationhiding']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['savedsearcheswork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['savedsearches']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + + if ($cfgRelation['designersettingswork']) { + $remove_query = "DELETE FROM " + . Util::backquote($cfgRelation['db']) + . "." . Util::backquote($cfgRelation['designer_settings']) + . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) + . "'"; + Relation::queryAsControlUser($remove_query); + } + } +} diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index df195907c9..473698be0e 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -12,6 +12,7 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\ChangePassword; use PhpMyAdmin\Message; use PhpMyAdmin\Relation; +use PhpMyAdmin\RelationCleanup; use PhpMyAdmin\Response; use PhpMyAdmin\Template; use PhpMyAdmin\Url; @@ -4042,7 +4043,7 @@ class Privileges $queries[] = 'DROP USER \'' . $GLOBALS['dbi']->escapeString($this_user) . '\'@\'' . $GLOBALS['dbi']->escapeString($this_host) . '\';'; - PMA_relationsCleanupUser($this_user); + RelationCleanup::user($this_user); if (isset($_REQUEST['drop_users_db'])) { $queries[] = 'DROP DATABASE IF EXISTS ' diff --git a/libraries/classes/Server/Select.php b/libraries/classes/Server/Select.php new file mode 100644 index 0000000000..b5b434de83 --- /dev/null +++ b/libraries/classes/Server/Select.php @@ -0,0 +1,125 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Code for displaying server selection + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin\Server; + +use PhpMyAdmin\Url; +use PhpMyAdmin\Util; + +/** + * PhpMyAdmin\Server\Select class + * + * @package PhpMyAdmin + */ +class Select +{ + /** + * Renders the server selection in list or selectbox form, or option tags only + * + * @param boolean $not_only_options whether to include form tags or not + * @param boolean $omit_fieldset whether to omit fieldset tag or not + * + * @return string + */ + public static function render($not_only_options, $omit_fieldset) + { + $retval = ''; + + // Show as list? + if ($not_only_options) { + $list = $GLOBALS['cfg']['DisplayServersList']; + $not_only_options =! $list; + } else { + $list = false; + } + + if ($not_only_options) { + $retval .= '<form method="post" action="' + . Util::getScriptNameForOption( + $GLOBALS['cfg']['DefaultTabServer'], 'server' + ) + . '" class="disableAjax">'; + + if (! $omit_fieldset) { + $retval .= '<fieldset>'; + } + + $retval .= Url::getHiddenFields(array()); + $retval .= '<label for="select_server">' + . __('Current server:') . '</label> '; + + $retval .= '<select name="server" id="select_server" class="autosubmit">'; + $retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n"; + } elseif ($list) { + $retval .= __('Current server:') . '<br />'; + $retval .= '<ul id="list_server">'; + } + + foreach ($GLOBALS['cfg']['Servers'] as $key => $server) { + if (empty($server['host'])) { + continue; + } + + if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) { + $selected = 1; + } else { + $selected = 0; + } + if (!empty($server['verbose'])) { + $label = $server['verbose']; + } else { + $label = $server['host']; + if (!empty($server['port'])) { + $label .= ':' . $server['port']; + } + } + if (! empty($server['only_db'])) { + if (! is_array($server['only_db'])) { + $label .= ' - ' . $server['only_db']; + // try to avoid displaying a too wide selector + } elseif (count($server['only_db']) < 4) { + $label .= ' - ' . implode(', ', $server['only_db']); + } + } + if (!empty($server['user']) && $server['auth_type'] == 'config') { + $label .= ' (' . $server['user'] . ')'; + } + + if ($list) { + $retval .= '<li>'; + if ($selected) { + $retval .= '<strong>' . htmlspecialchars($label) . '</strong>'; + } else { + + $retval .= '<a class="disableAjax item" href="' + . Util::getScriptNameForOption( + $GLOBALS['cfg']['DefaultTabServer'], 'server' + ) + . Url::getCommon(array('server' => $key)) + . '" >' . htmlspecialchars($label) . '</a>'; + } + $retval .= '</li>'; + } else { + $retval .= '<option value="' . $key . '" ' + . ($selected ? ' selected="selected"' : '') . '>' + . htmlspecialchars($label) . '</option>' . "\n"; + } + } // end while + + if ($not_only_options) { + $retval .= '</select>'; + if (! $omit_fieldset) { + $retval .= '</fieldset>'; + } + $retval .= '</form>'; + } elseif ($list) { + $retval .= '</ul>'; + } + + return $retval; + } +} diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php index 3d22d456d8..53b9370704 100644 --- a/libraries/classes/Sql.php +++ b/libraries/classes/Sql.php @@ -14,7 +14,9 @@ use PhpMyAdmin\Display\Results as DisplayResults; use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Operations; +use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\Relation; +use PhpMyAdmin\RelationCleanup; use PhpMyAdmin\Response; use PhpMyAdmin\SqlParser\Statements\AlterStatement; use PhpMyAdmin\SqlParser\Statements\DropStatement; @@ -45,10 +47,7 @@ class Sql if (($db === null) && (!empty($GLOBALS['db']))) { $db = $GLOBALS['db']; } - - include_once 'libraries/parse_analyze.lib.php'; - list($analyzed_sql_results,,) = PMA_parseAnalyze($sql_query, $db); - + list($analyzed_sql_results,,) = ParseAnalyze::sqlQuery($sql_query, $db); return $analyzed_sql_results; } @@ -1094,17 +1093,15 @@ EOT; */ public static function cleanupRelations($db, $table, $column, $purge) { - include_once 'libraries/relation_cleanup.lib.php'; - if (! empty($purge) && strlen($db) > 0) { if (strlen($table) > 0) { if (isset($column) && strlen($column) > 0) { - PMA_relationsCleanupColumn($db, $table, $column); + RelationCleanup::column($db, $table, $column); } else { - PMA_relationsCleanupTable($db, $table); + RelationCleanup::table($db, $table); } } else { - PMA_relationsCleanupDatabase($db); + RelationCleanup::database($db); } } } @@ -2064,12 +2061,11 @@ EOT; ) { if ($analyzed_sql_results == null) { // Parse and analyze the query - include_once 'libraries/parse_analyze.lib.php'; list( $analyzed_sql_results, $db, $table_from_sql - ) = PMA_parseAnalyze($sql_query, $db); + ) = ParseAnalyze::sqlQuery($sql_query, $db); // @todo: possibly refactor extract($analyzed_sql_results); diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index 44d442dddc..ad79f2e193 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -10,6 +10,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Index; use PhpMyAdmin\Message; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\Export\ExportSql; use PhpMyAdmin\Relation; use PhpMyAdmin\SqlParser\Components\Expression; @@ -908,15 +909,12 @@ class Table // No table is created when this is a data-only operation. if ($what != 'dataonly') { - - include_once "libraries/plugin_interface.lib.php"; - /** * Instance used for exporting the current structure of the table. * - * @var \PhpMyAdmin\Plugins\Export\ExportSql + * @var PhpMyAdmin\Plugins\Export\ExportSql */ - $export_sql_plugin = PMA_getPlugin( + $export_sql_plugin = Plugins::getPlugin( "export", "sql", 'libraries/classes/Plugins/Export/', diff --git a/libraries/classes/Tracker.php b/libraries/classes/Tracker.php index ac9c999f79..fa9e8cdf89 100644 --- a/libraries/classes/Tracker.php +++ b/libraries/classes/Tracker.php @@ -7,6 +7,7 @@ */ namespace PhpMyAdmin; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\Export\ExportSql; use PhpMyAdmin\Relation; use PhpMyAdmin\SqlParser\Parser; @@ -192,9 +193,8 @@ class Tracker } // get Export SQL instance - include_once "libraries/plugin_interface.lib.php"; - /* @var $export_sql_plugin \PhpMyAdmin\Plugins\Export\ExportSql */ - $export_sql_plugin = PMA_getPlugin( + /* @var $export_sql_plugin PhpMyAdmin\Plugins\Export\ExportSql */ + $export_sql_plugin = Plugins::getPlugin( "export", "sql", 'libraries/classes/Plugins/Export/', 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 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Functions for displaying user preferences pages + * + * @package PhpMyAdmin + */ +namespace PhpMyAdmin; + +use PhpMyAdmin\Config\ConfigFile; +use PhpMyAdmin\Config\Forms\User\UserFormList; +use PhpMyAdmin\Core; +use PhpMyAdmin\Message; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Template; +use PhpMyAdmin\Url; +use PhpMyAdmin\Util; + +/** + * PhpMyAdmin\UserPreferences class + * + * @package PhpMyAdmin + */ +class UserPreferences +{ + /** + * Common initialization for user preferences modification pages + * + * @param ConfigFile $cf Config file instance + * + * @return void + */ + public static function pageInit(ConfigFile $cf) + { + $forms_all_keys = UserFormList::getFields(); + $cf->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']) + ), + '<br /><br />' + ); + 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/common.inc.php b/libraries/common.inc.php index 750151df74..cc22b1e8ac 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -36,6 +36,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\DbList; use PhpMyAdmin\ErrorHandler; +use PhpMyAdmin\IpAllowDeny; use PhpMyAdmin\LanguageManager; use PhpMyAdmin\Logging; use PhpMyAdmin\Message; @@ -635,30 +636,24 @@ if (! defined('PMA_MINIMUM_COMMON')) { if (isset($cfg['Server']['AllowDeny']) && isset($cfg['Server']['AllowDeny']['order']) ) { - - /** - * ip based access library - */ - include_once './libraries/ip_allow_deny.lib.php'; - $allowDeny_forbidden = false; // default if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') { $allowDeny_forbidden = true; - if (PMA_allowDeny('allow')) { + if (IpAllowDeny::allowDeny('allow')) { $allowDeny_forbidden = false; } - if (PMA_allowDeny('deny')) { + if (IpAllowDeny::allowDeny('deny')) { $allowDeny_forbidden = true; } } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') { - if (PMA_allowDeny('deny')) { + if (IpAllowDeny::allowDeny('deny')) { $allowDeny_forbidden = true; } - if (PMA_allowDeny('allow')) { + if (IpAllowDeny::allowDeny('allow')) { $allowDeny_forbidden = false; } } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') { - if (PMA_allowDeny('allow') && ! PMA_allowDeny('deny')) { + if (IpAllowDeny::allowDeny('allow') && ! IpAllowDeny::allowDeny('deny')) { $allowDeny_forbidden = false; } else { $allowDeny_forbidden = true; diff --git a/libraries/information_schema_relations.lib.php b/libraries/information_schema_relations.inc.php index 3c1b618d3b..3c1b618d3b 100644 --- a/libraries/information_schema_relations.lib.php +++ b/libraries/information_schema_relations.inc.php diff --git a/libraries/ip_allow_deny.lib.php b/libraries/ip_allow_deny.lib.php deleted file mode 100644 index 87ea8125b1..0000000000 --- a/libraries/ip_allow_deny.lib.php +++ /dev/null @@ -1,303 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * This library is used with the server IP allow/deny host authentication - * feature - * - * @package PhpMyAdmin - */ - -use PhpMyAdmin\Core; -require_once './libraries/hash.lib.php'; - -/** - * Matches for IPv4 or IPv6 addresses - * - * @param string $testRange string of IP range to match - * @param string $ipToTest string of IP to test against range - * - * @return boolean whether the IP mask matches - * - * @access public - */ -function PMA_ipMaskTest($testRange, $ipToTest) -{ - if (mb_strpos($testRange, ':') > -1 - || mb_strpos($ipToTest, ':') > -1 - ) { - // assume IPv6 - $result = PMA_ipv6MaskTest($testRange, $ipToTest); - } else { - $result = PMA_ipv4MaskTest($testRange, $ipToTest); - } - - return $result; -} // end of the "PMA_ipMaskTest()" function - - -/** - * Based on IP Pattern Matcher - * Originally by J.Adams <jna@retina.net> - * Found on <https://secure.php.net/manual/en/function.ip2long.php> - * Modified for phpMyAdmin - * - * Matches: - * xxx.xxx.xxx.xxx (exact) - * xxx.xxx.xxx.[yyy-zzz] (range) - * xxx.xxx.xxx.xxx/nn (CIDR) - * - * Does not match: - * xxx.xxx.xxx.xx[yyy-zzz] (range, partial octets not supported) - * - * @param string $testRange string of IP range to match - * @param string $ipToTest string of IP to test against range - * - * @return boolean whether the IP mask matches - * - * @access public - */ -function PMA_ipv4MaskTest($testRange, $ipToTest) -{ - $result = true; - $match = preg_match( - '|([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/([0-9]+)|', - $testRange, - $regs - ); - if ($match) { - // performs a mask match - $ipl = ip2long($ipToTest); - $rangel = ip2long( - $regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4] - ); - - $maskl = 0; - - for ($i = 0; $i < 31; $i++) { - if ($i < $regs[5] - 1) { - $maskl = $maskl + pow(2, (30 - $i)); - } // end if - } // end for - - if (($maskl & $rangel) == ($maskl & $ipl)) { - return true; - } - - return false; - } - - // range based - $maskocts = explode('.', $testRange); - $ipocts = explode('.', $ipToTest); - - // perform a range match - for ($i = 0; $i < 4; $i++) { - if (preg_match('|\[([0-9]+)\-([0-9]+)\]|', $maskocts[$i], $regs)) { - if (($ipocts[$i] > $regs[2]) || ($ipocts[$i] < $regs[1])) { - $result = false; - } // end if - } else { - if ($maskocts[$i] <> $ipocts[$i]) { - $result = false; - } // end if - } // end if/else - } //end for - - return $result; -} // end of the "PMA_ipv4MaskTest()" function - - -/** - * IPv6 matcher - * CIDR section taken from https://stackoverflow.com/a/10086404 - * Modified for phpMyAdmin - * - * Matches: - * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx - * (exact) - * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:[yyyy-zzzz] - * (range, only at end of IP - no subnets) - * xxxx:xxxx:xxxx:xxxx/nn - * (CIDR) - * - * Does not match: - * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xx[yyy-zzz] - * (range, partial octets not supported) - * - * @param string $test_range string of IP range to match - * @param string $ip_to_test string of IP to test against range - * - * @return boolean whether the IP mask matches - * - * @access public - */ -function PMA_ipv6MaskTest($test_range, $ip_to_test) -{ - $result = true; - - // convert to lowercase for easier comparison - $test_range = mb_strtolower($test_range); - $ip_to_test = mb_strtolower($ip_to_test); - - $is_cidr = mb_strpos($test_range, '/') > -1; - $is_range = mb_strpos($test_range, '[') > -1; - $is_single = ! $is_cidr && ! $is_range; - - $ip_hex = bin2hex(inet_pton($ip_to_test)); - - if ($is_single) { - $range_hex = bin2hex(inet_pton($test_range)); - $result = hash_equals($ip_hex, $range_hex); - return $result; - } - - if ($is_range) { - // what range do we operate on? - $range_match = array(); - $match = preg_match( - '/\[([0-9a-f]+)\-([0-9a-f]+)\]/', $test_range, $range_match - ); - if ($match) { - $range_start = $range_match[1]; - $range_end = $range_match[2]; - - // get the first and last allowed IPs - $first_ip = str_replace($range_match[0], $range_start, $test_range); - $first_hex = bin2hex(inet_pton($first_ip)); - $last_ip = str_replace($range_match[0], $range_end, $test_range); - $last_hex = bin2hex(inet_pton($last_ip)); - - // check if the IP to test is within the range - $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex); - } - return $result; - } - - if ($is_cidr) { - // Split in address and prefix length - list($first_ip, $subnet) = explode('/', $test_range); - - // Parse the address into a binary string - $first_bin = inet_pton($first_ip); - $first_hex = bin2hex($first_bin); - - $flexbits = 128 - $subnet; - - // Build the hexadecimal string of the last address - $last_hex = $first_hex; - - $pos = 31; - while ($flexbits > 0) { - // Get the character at this position - $orig = mb_substr($last_hex, $pos, 1); - - // Convert it to an integer - $origval = hexdec($orig); - - // OR it with (2^flexbits)-1, with flexbits limited to 4 at a time - $newval = $origval | (pow(2, min(4, $flexbits)) - 1); - - // Convert it back to a hexadecimal character - $new = dechex($newval); - - // And put that character back in the string - $last_hex = substr_replace($last_hex, $new, $pos, 1); - - // We processed one nibble, move to previous position - $flexbits -= 4; - --$pos; - } - - // check if the IP to test is within the range - $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex); - } - - return $result; -} // end of the "PMA_ipv6MaskTest()" function - - -/** - * Runs through IP Allow/Deny rules the use of it below for more information - * - * @param string $type 'allow' | 'deny' type of rule to match - * - * @return bool Whether rule has matched - * - * @access public - * - * @see Core::getIp() - */ -function PMA_allowDeny($type) -{ - global $cfg; - - // Grabs true IP of the user and returns if it can't be found - $remote_ip = Core::getIp(); - if (empty($remote_ip)) { - return false; - } - - // copy username - $username = $cfg['Server']['user']; - - // copy rule database - if (isset($cfg['Server']['AllowDeny']['rules'])) { - $rules = $cfg['Server']['AllowDeny']['rules']; - if (! is_array($rules)) { - $rules = array(); - } - } else { - $rules = array(); - } - - // lookup table for some name shortcuts - $shortcuts = array( - 'all' => '0.0.0.0/0', - 'localhost' => '127.0.0.1/8' - ); - - // Provide some useful shortcuts if server gives us address: - if (Core::getenv('SERVER_ADDR')) { - $shortcuts['localnetA'] = Core::getenv('SERVER_ADDR') . '/8'; - $shortcuts['localnetB'] = Core::getenv('SERVER_ADDR') . '/16'; - $shortcuts['localnetC'] = Core::getenv('SERVER_ADDR') . '/24'; - } - - foreach ($rules as $rule) { - // extract rule data - $rule_data = explode(' ', $rule); - - // check for rule type - if ($rule_data[0] != $type) { - continue; - } - - // check for username - if (($rule_data[1] != '%') //wildcarded first - && (! hash_equals($rule_data[1], $username)) - ) { - continue; - } - - // check if the config file has the full string with an extra - // 'from' in it and if it does, just discard it - if ($rule_data[2] == 'from') { - $rule_data[2] = $rule_data[3]; - } - - // Handle shortcuts with above array - if (isset($shortcuts[$rule_data[2]])) { - $rule_data[2] = $shortcuts[$rule_data[2]]; - } - - // Add code for host lookups here - // Excluded for the moment - - // Do the actual matching now - if (PMA_ipMaskTest($rule_data[2], $remote_ip)) { - return true; - } - } // end while - - return false; -} // end of the "PMA_AllowDeny()" function diff --git a/libraries/mime.lib.php b/libraries/mime.lib.php deleted file mode 100644 index f1a7757ac0..0000000000 --- a/libraries/mime.lib.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * MIME detection code. - * - * @package PhpMyAdmin - * @todo Maybe we could try to use fileinfo module if loaded - */ - -/** - * Tries to detect MIME type of content. - * - * @param string &$test First few bytes of content to use for detection - * - * @return string - */ -function PMA_detectMIME(&$test) -{ - $len = mb_strlen($test); - if ($len >= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) { - return 'image/jpeg'; - } - if ($len >= 3 && substr($test, 0, 3) == 'GIF') { - return 'image/gif'; - } - if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") { - return 'image/png'; - } - return 'application/octet-stream'; -} diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 946bfcc7f0..27e2a4805e 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -8,6 +8,7 @@ use PhpMyAdmin\CentralColumns; use PhpMyAdmin\Message; +use PhpMyAdmin\MultSubmits; use PhpMyAdmin\Response; use PhpMyAdmin\Sql; @@ -15,8 +16,6 @@ if (! defined('PHPMYADMIN')) { exit; } -require_once 'libraries/mult_submits.lib.php'; - $request_params = array( 'clause_is_unique', 'from_prefix', @@ -92,17 +91,17 @@ if (! empty($submit_mult) case 'copy_tbl': $views = $GLOBALS['dbi']->getVirtualTables($db); list($full_query, $reload, $full_query_views) - = PMA_getQueryFromSelected( + = MultSubmits::getQueryFromSelected( $submit_mult, $table, $selected, $views ); - $_url_params = PMA_getUrlParams( + $_url_params = MultSubmits::getUrlParams( $submit_mult, $reload, $action, $db, $table, $selected, $views, isset($original_sql_query)? $original_sql_query : null, isset($original_url_query)? $original_url_query : null ); $response->disable(); $response->addHTML( - PMA_getHtmlForCopyMultipleTables($action, $_url_params) + MultSubmits::getHtmlForCopyMultipleTables($action, $_url_params) ); exit; case 'show_create': @@ -180,12 +179,12 @@ if (!empty($submit_mult) && !empty($what)) { // Builds the query list($full_query, $reload, $full_query_views) - = PMA_getQueryFromSelected( + = MultSubmits::getQueryFromSelected( $what, $table, $selected, $views ); // Displays the confirmation form - $_url_params = PMA_getUrlParams( + $_url_params = MultSubmits::getUrlParams( $what, $reload, $action, $db, $table, $selected, $views, isset($original_sql_query)? $original_sql_query : null, isset($original_url_query)? $original_url_query : null @@ -195,14 +194,14 @@ if (!empty($submit_mult) && !empty($what)) { if ($what == 'replace_prefix_tbl' || $what == 'copy_tbl_change_prefix') { $response->disable(); $response->addHTML( - PMA_getHtmlForReplacePrefixTable($action, $_url_params) + MultSubmits::getHtmlForReplacePrefixTable($action, $_url_params) ); } elseif ($what == 'add_prefix_tbl') { $response->disable(); - $response->addHTML(PMA_getHtmlForAddPrefixTable($action, $_url_params)); + $response->addHTML(MultSubmits::getHtmlForAddPrefixTable($action, $_url_params)); } else { $response->addHTML( - PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query) + MultSubmits::getHtmlForOtherActions($what, $action, $_url_params, $full_query) ); } exit; @@ -211,13 +210,6 @@ if (!empty($submit_mult) && !empty($what)) { /** * Executes the query - dropping rows, columns/fields, tables or dbs */ - if ($query_type == 'drop_db' - || $query_type == 'drop_tbl' - || $query_type == 'drop_fld' - ) { - include_once './libraries/relation_cleanup.lib.php'; - } - if ($query_type == 'primary_fld') { // Gets table primary key $GLOBALS['dbi']->selectDb($db); @@ -244,7 +236,7 @@ if (!empty($submit_mult) && !empty($what)) { list( $result, $rebuild_database_list, $reload_ret, $run_parts, $execute_query_later, $sql_query, $sql_query_views - ) = PMA_buildOrExecuteQueryForMulti( + ) = MultSubmits::buildOrExecuteQueryForMulti( $query_type, $selected, $db, $table, $views, isset($primary) ? $primary : null, isset($from_prefix) ? $from_prefix : null, diff --git a/libraries/mult_submits.lib.php b/libraries/mult_submits.lib.php deleted file mode 100644 index aee828eb70..0000000000 --- a/libraries/mult_submits.lib.php +++ /dev/null @@ -1,577 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * functions for multi submit forms - * - * @usedby mult_submits.inc.php - * - * @package PhpMyAdmin - */ - -use PhpMyAdmin\Operations; -use PhpMyAdmin\Sql; -use PhpMyAdmin\Table; -use PhpMyAdmin\Transformations; -use PhpMyAdmin\Url; -use PhpMyAdmin\Util; - -/** - * Gets url params - * - * @param string $what mult submit type - * @param bool $reload is reload - * @param string $action action type - * @param string $db database name - * @param string $table table name - * @param array $selected selected rows(table,db) - * @param array $views table views - * @param string $original_sql_query original sql query - * @param string $original_url_query original url query - * - * @return array - */ -function PMA_getUrlParams( - $what, $reload, $action, $db, $table, $selected, $views, - $original_sql_query, $original_url_query -) { - $_url_params = array( - 'query_type' => $what, - 'reload' => (! empty($reload) ? 1 : 0), - ); - if (mb_strpos(' ' . $action, 'db_') == 1) { - $_url_params['db']= $db; - } elseif (mb_strpos(' ' . $action, 'tbl_') == 1 - || $what == 'row_delete' - ) { - $_url_params['db']= $db; - $_url_params['table']= $table; - } - foreach ($selected as $sval) { - if ($what == 'row_delete') { - $_url_params['selected'][] = 'DELETE FROM ' - . Util::backquote($table) - . ' WHERE ' . $sval . ' LIMIT 1;'; - } else { - $_url_params['selected'][] = $sval; - } - } - if ($what == 'drop_tbl' && !empty($views)) { - foreach ($views as $current) { - $_url_params['views'][] = $current; - } - } - if ($what == 'row_delete') { - $_url_params['original_sql_query'] = $original_sql_query; - if (! empty($original_url_query)) { - $_url_params['original_url_query'] = $original_url_query; - } - } - - return $_url_params; -} - -/** - * Builds or execute queries for multiple elements, depending on $query_type - * - * @param string $query_type query type - * @param array $selected selected tables - * @param string $db db name - * @param string $table table name - * @param array $views table views - * @param string $primary table primary - * @param string $from_prefix from prefix original - * @param string $to_prefix to prefix original - * - * @return array - */ -function PMA_buildOrExecuteQueryForMulti( - $query_type, $selected, $db, $table, $views, $primary, - $from_prefix, $to_prefix -) { - $rebuild_database_list = false; - $reload = null; - $a_query = null; - $sql_query = ''; - $sql_query_views = null; - // whether to run query after each pass - $run_parts = false; - // whether to execute the query at the end (to display results) - $execute_query_later = false; - $result = null; - - if ($query_type == 'drop_tbl') { - $sql_query_views = ''; - } - - $selected_cnt = count($selected); - $deletes = false; - $copy_tbl =false; - - for ($i = 0; $i < $selected_cnt; $i++) { - switch ($query_type) { - case 'row_delete': - $deletes = true; - $a_query = $selected[$i]; - $run_parts = true; - break; - - case 'drop_db': - PMA_relationsCleanupDatabase($selected[$i]); - $a_query = 'DROP DATABASE ' - . Util::backquote($selected[$i]); - $reload = 1; - $run_parts = true; - $rebuild_database_list = true; - break; - - case 'drop_tbl': - PMA_relationsCleanupTable($db, $selected[$i]); - $current = $selected[$i]; - if (!empty($views) && in_array($current, $views)) { - $sql_query_views .= (empty($sql_query_views) ? 'DROP VIEW ' : ', ') - . Util::backquote($current); - } else { - $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ') - . Util::backquote($current); - } - $reload = 1; - break; - - case 'check_tbl': - $sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ') - . Util::backquote($selected[$i]); - $execute_query_later = true; - break; - - case 'optimize_tbl': - $sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ') - . Util::backquote($selected[$i]); - $execute_query_later = true; - break; - - case 'analyze_tbl': - $sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ') - . Util::backquote($selected[$i]); - $execute_query_later = true; - break; - - case 'checksum_tbl': - $sql_query .= (empty($sql_query) ? 'CHECKSUM TABLE ' : ', ') - . Util::backquote($selected[$i]); - $execute_query_later = true; - break; - - case 'repair_tbl': - $sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ') - . Util::backquote($selected[$i]); - $execute_query_later = true; - break; - - case 'empty_tbl': - $deletes = true; - $a_query = 'TRUNCATE '; - $a_query .= Util::backquote($selected[$i]); - $run_parts = true; - break; - - case 'drop_fld': - PMA_relationsCleanupColumn($db, $table, $selected[$i]); - $sql_query .= (empty($sql_query) - ? 'ALTER TABLE ' . Util::backquote($table) - : ',') - . ' DROP ' . Util::backquote($selected[$i]) - . (($i == $selected_cnt-1) ? ';' : ''); - break; - - case 'primary_fld': - $sql_query .= (empty($sql_query) - ? 'ALTER TABLE ' . Util::backquote($table) - . (empty($primary) - ? '' - : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' - : ', ') - . Util::backquote($selected[$i]) - . (($i == $selected_cnt-1) ? ');' : ''); - break; - - case 'index_fld': - $sql_query .= (empty($sql_query) - ? 'ALTER TABLE ' . Util::backquote($table) - . ' ADD INDEX( ' - : ', ') - . Util::backquote($selected[$i]) - . (($i == $selected_cnt-1) ? ');' : ''); - break; - - case 'unique_fld': - $sql_query .= (empty($sql_query) - ? 'ALTER TABLE ' . Util::backquote($table) - . ' ADD UNIQUE( ' - : ', ') - . Util::backquote($selected[$i]) - . (($i == $selected_cnt-1) ? ');' : ''); - break; - - case 'spatial_fld': - $sql_query .= (empty($sql_query) - ? 'ALTER TABLE ' . Util::backquote($table) - . ' ADD SPATIAL( ' - : ', ') - . Util::backquote($selected[$i]) - . (($i == $selected_cnt-1) ? ');' : ''); - break; - - case 'fulltext_fld': - $sql_query .= (empty($sql_query) - ? 'ALTER TABLE ' . Util::backquote($table) - . ' ADD FULLTEXT( ' - : ', ') - . Util::backquote($selected[$i]) - . (($i == $selected_cnt-1) ? ');' : ''); - break; - - case 'add_prefix_tbl': - $newtablename = $_POST['add_prefix'] . $selected[$i]; - // ADD PREFIX TO TABLE NAME - $a_query = 'ALTER TABLE ' - . Util::backquote($selected[$i]) - . ' RENAME ' - . Util::backquote($newtablename); - $run_parts = true; - break; - - case 'replace_prefix_tbl': - $current = $selected[$i]; - $subFromPrefix = mb_substr( - $current, - 0, - mb_strlen($from_prefix) - ); - if ($subFromPrefix == $from_prefix) { - $newtablename = $to_prefix - . mb_substr( - $current, - mb_strlen($from_prefix) - ); - } else { - $newtablename = $current; - } - // CHANGE PREFIX PATTERN - $a_query = 'ALTER TABLE ' - . Util::backquote($selected[$i]) - . ' RENAME ' - . Util::backquote($newtablename); - $run_parts = true; - break; - - case 'copy_tbl_change_prefix': - $run_parts = true; - $copy_tbl = true; - - $current = $selected[$i]; - $newtablename = $to_prefix . - mb_substr($current, mb_strlen($from_prefix)); - - // COPY TABLE AND CHANGE PREFIX PATTERN - Table::moveCopy( - $db, $current, $db, $newtablename, - 'data', false, 'one_table' - ); - break; - - case 'copy_tbl': - $run_parts = true; - $copy_tbl = true; - Table::moveCopy($db, $selected[$i], $_POST['target_db'], $selected[$i], $_POST['what'], false, 'one_table'); - if (isset($_POST['adjust_privileges']) && !empty($_POST['adjust_privileges'])) { - Operations::adjustPrivilegesCopyTable($db, $selected[$i], $_POST['target_db'], $selected[$i]); - } - break; - } // end switch - - // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE" - // statements will be run at once below - if ($run_parts && !$copy_tbl) { - $sql_query .= $a_query . ';' . "\n"; - if ($query_type != 'drop_db') { - $GLOBALS['dbi']->selectDb($db); - } - $result = $GLOBALS['dbi']->query($a_query); - - if ($query_type == 'drop_db') { - Transformations::clear($selected[$i]); - } elseif ($query_type == 'drop_tbl') { - Transformations::clear($db, $selected[$i]); - } else if ($query_type == 'drop_fld') { - Transformations::clear($db, $table, $selected[$i]); - } - } // end if - } // end for - - if ($deletes && ! empty($_REQUEST['pos'])) { - $_REQUEST['pos'] = Sql::calculatePosForLastPage( - $db, $table, isset($_REQUEST['pos']) ? $_REQUEST['pos'] : null - ); - } - - return array( - $result, $rebuild_database_list, $reload, - $run_parts, $execute_query_later, $sql_query, $sql_query_views - ); -} - -/** - * Gets HTML for copy tables form - * - * @param string $action action type - * @param array $_url_params URL params - * - * @return string - */ -function PMA_getHtmlForCopyMultipleTables($action, $_url_params) -{ - $html = '<form id="ajax_form" action="' . $action . '" method="post">'; - $html .= Url::getHiddenInputs($_url_params); - $html .= '<fieldset class = "input">'; - $databases_list = $GLOBALS['dblist']->databases; - foreach ($databases_list as $key => $db_name) - if ($db_name == $GLOBALS['db']){ - $databases_list->offsetUnset($key); - break; - } - $html .= '<strong><label for="db_name_dropdown">' . __('Database') . ':</label></strong>'; - $html .= '<select id="db_name_dropdown" class="halfWidth" name="target_db" >' - . $databases_list->getHtmlOptions(true, false) - . '</select>'; - $html .= '<br><br>'; - $html .= '<strong><label>' . __('Options') . ':</label></strong><br>'; - $html .= '<input type="radio" id ="what_structure" value="structure" name="what"/>'; - $html .= '<label for="what_structure">' . __('Structure only') . '</label><br>'; - $html .= '<input type="radio" id ="what_data" value="data" name="what" checked="checked"/>'; - $html .= '<label for="what_data">' . __('Structure and data') . '</label><br>'; - $html .= '<input type="radio" id ="what_dataonly" value="dataonly" name="what"/>'; - $html .= '<label for="what_dataonly">' . __('Data only') . '</label><br><br>'; - $html .= '<input type="checkbox" id="checkbox_drop" value="1" name="drop_if_exists"/>'; - $html .= '<label for="checkbox_drop">' . __('Add DROP TABLE') . '</label><br>'; - $html .= '<input type="checkbox" id="checkbox_auto_increment_cp" value="1" name="sql_auto_increment"/>'; - $html .= '<label for="checkbox_auto_increment_cp">' . __('Add AUTO INCREMENT value') . '</label><br>'; - $html .= '<input type="checkbox" id="checkbox_constraints" value="1" name="sql_auto_increment" checked="checked"/>'; - $html .= '<label for="checkbox_constraints">' . __('Add constraints') . '</label><br><br>'; - $html .= '<input name="adjust_privileges" value="1" id="checkbox_adjust_privileges" checked="checked" type="checkbox"/>'; - $html .= '<label for="checkbox_adjust_privileges">' . __('Adjust privileges') . '<a href="./doc/html/faq.html#faq6-39" target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation" class="icon ic_b_help"></a></label>'; - $html .= '</fieldset>'; - $html .= '<input type="hidden" name="mult_btn" value="' . __('Yes') . '" />'; - $html .= '</form>'; - return $html; -} - -/** - * Gets HTML for replace_prefix_tbl or copy_tbl_change_prefix - * - * @param string $action action type - * @param array $_url_params URL params - * - * @return string - */ -function PMA_getHtmlForReplacePrefixTable($action, $_url_params) -{ - $html = '<form id="ajax_form" action="' . $action . '" method="post">'; - $html .= Url::getHiddenInputs($_url_params); - $html .= '<fieldset class = "input">'; - $html .= '<table>'; - $html .= '<tr>'; - $html .= '<td>' . __('From') . '</td>'; - $html .= '<td>'; - $html .= '<input type="text" name="from_prefix" id="initialPrefix" />'; - $html .= '</td>'; - $html .= '</tr>'; - $html .= '<tr>'; - $html .= '<td>' . __('To') . '</td>'; - $html .= '<td>'; - $html .= '<input type="text" name="to_prefix" id="newPrefix" />'; - $html .= '</td>'; - $html .= '</tr>'; - $html .= '</table>'; - $html .= '</fieldset>'; - $html .= '<input type="hidden" name="mult_btn" value="' . __('Yes') . '" />'; - $html .= '</form>'; - - return $html; -} - -/** - * Gets HTML for add_prefix_tbl - * - * @param string $action action type - * @param array $_url_params URL params - * - * @return string - */ -function PMA_getHtmlForAddPrefixTable($action, $_url_params) -{ - $html = '<form id="ajax_form" action="' . $action . '" method="post">'; - $html .= Url::getHiddenInputs($_url_params); - $html .= '<fieldset class = "input">'; - $html .= '<table>'; - $html .= '<tr>'; - $html .= '<td>' . __('Add prefix') . '</td>'; - $html .= '<td>'; - $html .= '<input type="text" name="add_prefix" id="txtPrefix" />'; - $html .= '</td>'; - $html .= '</tr>'; - $html .= '<tr>'; - $html .= '</table>'; - $html .= '</fieldset>'; - $html .= '<input type="hidden" name="mult_btn" value="' . __('Yes') . '" />'; - $html .= '</form>'; - - return $html; -} - -/** - * Gets HTML for other mult_submits actions - * - * @param string $what mult_submit type - * @param string $action action type - * @param array $_url_params URL params - * @param string $full_query full sql query string - * - * @return string - */ -function PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query) -{ - $html = '<form action="' . $action . '" method="post">'; - $html .= Url::getHiddenInputs($_url_params); - $html .= '<fieldset class="confirmation">'; - $html .= '<legend>'; - if ($what == 'drop_db') { - $html .= __('You are about to DESTROY a complete database!') . ' '; - } - $html .= __('Do you really want to execute the following query?'); - $html .= '</legend>'; - $html .= '<code>' . $full_query . '</code>'; - $html .= '</fieldset>'; - $html .= '<fieldset class="tblFooters">'; - // Display option to disable foreign key checks while dropping tables - if ($what === 'drop_tbl' || $what === 'empty_tbl' || $what === 'row_delete') { - $html .= '<div id="foreignkeychk">'; - $html .= Util::getFKCheckbox(); - $html .= '</div>'; - } - $html .= '<input id="buttonYes" type="submit" name="mult_btn" value="' - . __('Yes') . '" />'; - $html .= '<input id="buttonNo" type="submit" name="mult_btn" value="' - . __('No') . '" />'; - $html .= '</fieldset>'; - $html .= '</form>'; - - return $html; -} - -/** - * Get query string from Selected - * - * @param string $what mult_submit type - * @param string $table table name - * @param array $selected the selected columns - * @param array $views table views - * - * @return array - */ -function PMA_getQueryFromSelected($what, $table, $selected, $views) -{ - $reload = false; - $full_query_views = null; - $full_query = ''; - - if ($what == 'drop_tbl') { - $full_query_views = ''; - } - - $selected_cnt = count($selected); - $i = 0; - foreach ($selected as $sval) { - switch ($what) { - case 'row_delete': - $full_query .= 'DELETE FROM ' - . Util::backquote(htmlspecialchars($table)) - // Do not append a "LIMIT 1" clause here - // (it's not binlog friendly). - // We don't need the clause because the calling panel permits - // this feature only when there is a unique index. - . ' WHERE ' . htmlspecialchars($sval) - . ';<br />'; - break; - case 'drop_db': - $full_query .= 'DROP DATABASE ' - . Util::backquote(htmlspecialchars($sval)) - . ';<br />'; - $reload = true; - break; - - case 'drop_tbl': - $current = $sval; - if (!empty($views) && in_array($current, $views)) { - $full_query_views .= (empty($full_query_views) ? 'DROP VIEW ' : ', ') - . Util::backquote(htmlspecialchars($current)); - } else { - $full_query .= (empty($full_query) ? 'DROP TABLE ' : ', ') - . Util::backquote(htmlspecialchars($current)); - } - break; - - case 'empty_tbl': - $full_query .= 'TRUNCATE '; - $full_query .= Util::backquote(htmlspecialchars($sval)) - . ';<br />'; - break; - - case 'primary_fld': - if ($full_query == '') { - $full_query .= 'ALTER TABLE ' - . Util::backquote(htmlspecialchars($table)) - . '<br /> DROP PRIMARY KEY,' - . '<br /> ADD PRIMARY KEY(' - . '<br /> ' - . Util::backquote(htmlspecialchars($sval)) - . ','; - } else { - $full_query .= '<br /> ' - . Util::backquote(htmlspecialchars($sval)) - . ','; - } - if ($i == $selected_cnt-1) { - $full_query = preg_replace('@,$@', ');<br />', $full_query); - } - break; - - case 'drop_fld': - if ($full_query == '') { - $full_query .= 'ALTER TABLE ' - . Util::backquote(htmlspecialchars($table)); - } - $full_query .= '<br /> DROP ' - . Util::backquote(htmlspecialchars($sval)) - . ','; - if ($i == $selected_cnt - 1) { - $full_query = preg_replace('@,$@', ';<br />', $full_query); - } - break; - } // end switch - $i++; - } - - if ($what == 'drop_tbl') { - if (!empty($full_query)) { - $full_query .= ';<br />' . "\n"; - } - if (!empty($full_query_views)) { - $full_query .= $full_query_views . ';<br />' . "\n"; - } - unset($full_query_views); - } - - $full_query_views = isset($full_query_views)? $full_query_views : null; - - return array($full_query, $reload, $full_query_views); -} diff --git a/libraries/mysql_relations.lib.php b/libraries/mysql_relations.inc.php index a6bc43a522..a6bc43a522 100644 --- a/libraries/mysql_relations.lib.php +++ b/libraries/mysql_relations.inc.php diff --git a/libraries/parse_analyze.lib.php b/libraries/parse_analyze.lib.php deleted file mode 100644 index b45f3a6334..0000000000 --- a/libraries/parse_analyze.lib.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Parse and analyse a SQL query - * - * @package PhpMyAdmin - */ -use PhpMyAdmin\Response; - -if (! defined('PHPMYADMIN')) { - exit; -} - -/** - * Calls the parser on a query - * - * @param string $sql_query the query to parse - * @param string $db the current database - * - * @return array - * - * @access public - */ -function PMA_parseAnalyze($sql_query, $db) -{ - // @todo: move to returned results (also in all the calling chain) - $GLOBALS['unparsed_sql'] = $sql_query; - - // Get details about the SQL query. - $analyzed_sql_results = PhpMyAdmin\SqlParser\Utils\Query::getAll($sql_query); - - extract($analyzed_sql_results); - $table = ''; - - // If the targeted table (and database) are different than the ones that is - // currently browsed, edit `$db` and `$table` to match them so other elements - // (page headers, links, navigation panel) can be updated properly. - if (!empty($analyzed_sql_results['select_tables'])) { - - // Previous table and database name is stored to check if it changed. - $prev_db = $db; - - if (count($analyzed_sql_results['select_tables']) > 1) { - - /** - * @todo if there are more than one table name in the Select: - * - do not extract the first table name - * - do not show a table name in the page header - * - do not display the sub-pages links) - */ - $table = ''; - } else { - $table = $analyzed_sql_results['select_tables'][0][0]; - if (!empty($analyzed_sql_results['select_tables'][0][1])) { - $db = $analyzed_sql_results['select_tables'][0][1]; - } - } - // There is no point checking if a reload is required if we already decided - // to reload. Also, no reload is required for AJAX requests. - $response = Response::getInstance(); - if (empty($reload) && ! $response->isAjax()) { - // NOTE: Database names are case-insensitive. - $reload = strcasecmp($db, $prev_db) != 0; - } - - // Updating the array. - $analyzed_sql_results['reload'] = $reload; - } - - return array($analyzed_sql_results, $db, $table); -} diff --git a/libraries/plugin_interface.lib.php b/libraries/plugin_interface.lib.php deleted file mode 100644 index add6671665..0000000000 --- a/libraries/plugin_interface.lib.php +++ /dev/null @@ -1,583 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Generic plugin interface. - * - * @package PhpMyAdmin - */ -use PhpMyAdmin\Properties\Options\Groups\OptionsPropertySubgroup; -use PhpMyAdmin\Properties\Options\OptionsPropertyItem; -use PhpMyAdmin\Properties\Plugins\ExportPluginProperties; -use PhpMyAdmin\Properties\Plugins\PluginPropertyItem; -use PhpMyAdmin\Properties\Plugins\SchemaPluginProperties; - -/** - * Includes and instantiates the specified plugin type for a certain format - * - * @param string $plugin_type the type of the plugin (import, export, etc) - * @param string $plugin_format the format of the plugin (sql, xml, et ) - * @param string $plugins_dir directory with plugins - * @param mixed $plugin_param parameter to plugin by which they can - * decide whether they can work - * - * @return object|null new plugin instance - */ -function PMA_getPlugin( - $plugin_type, - $plugin_format, - $plugins_dir, - $plugin_param = false -) { - $GLOBALS['plugin_param'] = $plugin_param; - $class_name = mb_strtoupper($plugin_type[0]) - . mb_strtolower(mb_substr($plugin_type, 1)) - . mb_strtoupper($plugin_format[0]) - . mb_strtolower(mb_substr($plugin_format, 1)); - $file = $class_name . ".php"; - if (is_file($plugins_dir . $file)) { - //include_once $plugins_dir . $file; - $fqnClass = 'PhpMyAdmin\\' . str_replace('/', '\\', mb_substr($plugins_dir, 18)) . $class_name; - // check if class exists, could be caused by skip_import - if (class_exists($fqnClass)) { - return new $fqnClass; - } - } - - return null; -} - -/** - * Reads all plugin information from directory $plugins_dir - * - * @param string $plugin_type the type of the plugin (import, export, etc) - * @param string $plugins_dir directory with plugins - * @param mixed $plugin_param parameter to plugin by which they can - * decide whether they can work - * - * @return array list of plugin instances - */ -function PMA_getPlugins($plugin_type, $plugins_dir, $plugin_param) -{ - $GLOBALS['plugin_param'] = $plugin_param; - /* Scan for plugins */ - $plugin_list = array(); - if (!($handle = @opendir($plugins_dir))) { - return $plugin_list; - } - - $namespace = 'PhpMyAdmin\\' . str_replace('/', '\\', mb_substr($plugins_dir, 18)); - $class_type = mb_strtoupper($plugin_type[0], 'UTF-8') - . mb_strtolower(mb_substr($plugin_type, 1), 'UTF-8'); - - $prefix_class_name = $namespace . $class_type; - - while ($file = @readdir($handle)) { - // In some situations, Mac OS creates a new file for each file - // (for example ._csv.php) so the following regexp - // matches a file which does not start with a dot but ends - // with ".php" - if (is_file($plugins_dir . $file) - && preg_match( - '@^' . $class_type . '([^\.]+)\.php$@i', - $file, - $matches - ) - ) { - $GLOBALS['skip_import'] = false; - include_once $plugins_dir . $file; - if (! $GLOBALS['skip_import']) { - $class_name = $prefix_class_name . $matches[1]; - $plugin = new $class_name; - if (null !== $plugin->getProperties()) { - $plugin_list[] = $plugin; - } - } - } - } - - usort($plugin_list, function($cmp_name_1, $cmp_name_2) { - return strcasecmp( - $cmp_name_1->getProperties()->getText(), - $cmp_name_2->getProperties()->getText() - ); - }); - return $plugin_list; -} - -/** - * Returns locale string for $name or $name if no locale is found - * - * @param string $name for local string - * - * @return string locale string for $name - */ -function PMA_getString($name) -{ - return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name; -} - -/** - * Returns html input tag option 'checked' if plugin $opt - * should be set by config or request - * - * @param string $section name of config section in - * $GLOBALS['cfg'][$section] for plugin - * @param string $opt name of option - * - * @return string html input tag option 'checked' - */ -function PMA_pluginCheckboxCheck($section, $opt) -{ - // If the form is being repopulated using $_GET data, that is priority - if (isset($_GET[$opt]) - || ! isset($_GET['repopulate']) - && ((! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) - || ! empty($GLOBALS['cfg'][$section][$opt])) - ) { - return ' checked="checked"'; - } - return ''; -} - -/** - * Returns default value for option $opt - * - * @param string $section name of config section in - * $GLOBALS['cfg'][$section] for plugin - * @param string $opt name of option - * - * @return string default value for option $opt - */ -function PMA_pluginGetDefault($section, $opt) -{ - if (isset($_GET[$opt])) { - // If the form is being repopulated using $_GET data, that is priority - return htmlspecialchars($_GET[$opt]); - } - - if (isset($GLOBALS['timeout_passed']) - && $GLOBALS['timeout_passed'] - && isset($_REQUEST[$opt]) - ) { - return htmlspecialchars($_REQUEST[$opt]); - } - - if (!isset($GLOBALS['cfg'][$section][$opt])) { - return ''; - } - - $matches = array(); - /* Possibly replace localised texts */ - if (!preg_match_all( - '/(str[A-Z][A-Za-z0-9]*)/', - $GLOBALS['cfg'][$section][$opt], - $matches - )) { - return htmlspecialchars($GLOBALS['cfg'][$section][$opt]); - } - - $val = $GLOBALS['cfg'][$section][$opt]; - foreach ($matches[0] as $match) { - if (isset($GLOBALS[$match])) { - $val = str_replace($match, $GLOBALS[$match], $val); - } - } - return htmlspecialchars($val); -} - -/** - * Returns html select form element for plugin choice - * and hidden fields denoting whether each plugin must be exported as a file - * - * @param string $section name of config section in - * $GLOBALS['cfg'][$section] for plugin - * @param string $name name of select element - * @param array &$list array with plugin instances - * @param string $cfgname name of config value, if none same as $name - * - * @return string html select tag - */ -function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null) -{ - if (! isset($cfgname)) { - $cfgname = $name; - } - $ret = '<select id="plugins" name="' . $name . '">'; - $default = PMA_pluginGetDefault($section, $cfgname); - $hidden = null; - foreach ($list as $plugin) { - $elem = explode('\\', get_class($plugin)); - $plugin_name = array_pop($elem); - unset($elem); - $plugin_name = mb_strtolower( - mb_substr( - $plugin_name, - mb_strlen($section) - ) - ); - $ret .= '<option'; - // If the form is being repopulated using $_GET data, that is priority - if (isset($_GET[$name]) - && $plugin_name == $_GET[$name] - || ! isset($_GET[$name]) - && $plugin_name == $default - ) { - $ret .= ' selected="selected"'; - } - - /** @var PluginPropertyItem $properties */ - $properties = $plugin->getProperties(); - $text = null; - if ($properties != null) { - $text = $properties->getText(); - } - $ret .= ' value="' . $plugin_name . '">' - . PMA_getString($text) - . '</option>' . "\n"; - - // Whether each plugin has to be saved as a file - $hidden .= '<input type="hidden" id="force_file_' . $plugin_name - . '" value="'; - /** @var ExportPluginProperties|SchemaPluginProperties $properties */ - $properties = $plugin->getProperties(); - if (! strcmp($section, 'Import') - || ($properties != null && $properties->getForceFile() != null) - ) { - $hidden .= 'true'; - } else { - $hidden .= 'false'; - } - $hidden .= '" />' . "\n"; - } - $ret .= '</select>' . "\n" . $hidden; - - return $ret; -} - -/** - * Returns single option in a list element - * - * @param string $section name of config section in $GLOBALS['cfg'][$section] for plugin - * config - * section in - * $GLOBALS['cfg'][$section] - * for plugin - * @param string $plugin_name unique plugin name - * name - * @param array|\PhpMyAdmin\Properties\PropertyItem &$propertyGroup options - * property main - * group - * instance - * @param boolean $is_subgroup if this group is a subgroup - * is a subgroup - * - * @return string table row with option - */ -function PMA_pluginGetOneOption( - $section, - $plugin_name, - &$propertyGroup, - $is_subgroup = false -) { - $ret = "\n"; - - if (! $is_subgroup) { - // for subgroup headers - if (mb_strpos(get_class($propertyGroup), "PropertyItem")) { - $properties = array($propertyGroup); - } else { - // for main groups - $ret .= '<div class="export_sub_options" id="' . $plugin_name . '_' - . $propertyGroup->getName() . '">'; - - if (method_exists($propertyGroup, 'getText')) { - $text = $propertyGroup->getText(); - } - - if ($text != null) { - $ret .= '<h4>' . PMA_getString($text) . '</h4>'; - } - $ret .= '<ul>'; - } - } - - if (! isset($properties)) { - $not_subgroup_header = true; - if (method_exists($propertyGroup, 'getProperties')) { - $properties = $propertyGroup->getProperties(); - } - } - - if (isset($properties)) { - /** @var OptionsPropertySubgroup $propertyItem */ - foreach ($properties as $propertyItem) { - $property_class = get_class($propertyItem); - // if the property is a subgroup, we deal with it recursively - if (mb_strpos($property_class, "Subgroup")) { - // for subgroups - // each subgroup can have a header, which may also be a form element - /** @var OptionsPropertyItem $subgroup_header */ - $subgroup_header = $propertyItem->getSubgroupHeader(); - if (isset($subgroup_header)) { - $ret .= PMA_pluginGetOneOption( - $section, - $plugin_name, - $subgroup_header - ); - } - - $ret .= '<li class="subgroup"><ul'; - if (isset($subgroup_header)) { - $ret .= ' id="ul_' . $subgroup_header->getName() . '">'; - } else { - $ret .= '>'; - } - - $ret .= PMA_pluginGetOneOption( - $section, - $plugin_name, - $propertyItem, - true - ); - continue; - } - - // single property item - $ret .= PMA_getHtmlForProperty( - $section, $plugin_name, $propertyItem - ); - } - } - - if ($is_subgroup) { - // end subgroup - $ret .= '</ul></li>'; - } else { - // end main group - if (! empty($not_subgroup_header)) { - $ret .= '</ul></div>'; - } - } - - if (method_exists($propertyGroup, "getDoc")) { - $doc = $propertyGroup->getDoc(); - if ($doc != null) { - if (count($doc) == 3) { - $ret .= PhpMyAdmin\Util::showMySQLDocu( - $doc[1], - false, - $doc[2] - ); - } elseif (count($doc) == 1) { - $ret .= PhpMyAdmin\Util::showDocu('faq', $doc[0]); - } else { - $ret .= PhpMyAdmin\Util::showMySQLDocu( - $doc[1] - ); - } - } - } - - // Close the list element after $doc link is displayed - if (isset($property_class)) { - if ($property_class == 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem' - || $property_class == 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem' - || $property_class == 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem' - || $property_class == 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem' - ) { - $ret .= '</li>'; - } - } - $ret .= "\n"; - return $ret; -} - -/** - * Get HTML for properties items - * - * @param string $section name of config section in - * $GLOBALS['cfg'][$section] for plugin - * @param string $plugin_name unique plugin name - * @param OptionsPropertyItem $propertyItem Property item - * - * @return string - */ -function PMA_getHtmlForProperty( - $section, $plugin_name, $propertyItem -) { - $ret = null; - $property_class = get_class($propertyItem); - switch ($property_class) { - case 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem': - $ret .= '<li>' . "\n"; - $ret .= '<input type="checkbox" name="' . $plugin_name . '_' - . $propertyItem->getName() . '"' - . ' value="something" id="checkbox_' . $plugin_name . '_' - . $propertyItem->getName() . '"' - . ' ' - . PMA_pluginCheckboxCheck( - $section, - $plugin_name . '_' . $propertyItem->getName() - ); - - if ($propertyItem->getForce() != null) { - // Same code is also few lines lower, update both if needed - $ret .= ' onclick="if (!this.checked && ' - . '(!document.getElementById(\'checkbox_' . $plugin_name - . '_' . $propertyItem->getForce() . '\') ' - . '|| !document.getElementById(\'checkbox_' - . $plugin_name . '_' . $propertyItem->getForce() - . '\').checked)) ' - . 'return false; else return true;"'; - } - $ret .= ' />'; - $ret .= '<label for="checkbox_' . $plugin_name . '_' - . $propertyItem->getName() . '">' - . PMA_getString($propertyItem->getText()) . '</label>'; - break; - case 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem': - echo 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem'; - break; - case 'PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem': - $ret .= '<li><input type="hidden" name="' . $plugin_name . '_' - . $propertyItem->getName() . '"' - . ' value="' . PMA_pluginGetDefault( - $section, - $plugin_name . '_' . $propertyItem->getName() - ) - . '"' . ' /></li>'; - break; - case 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem': - $ret .= '<li>' . "\n"; - $ret .= '<p>' . PMA_getString($propertyItem->getText()) . '</p>'; - break; - case 'PhpMyAdmin\Properties\Options\Items\RadioPropertyItem': - $default = PMA_pluginGetDefault( - $section, - $plugin_name . '_' . $propertyItem->getName() - ); - foreach ($propertyItem->getValues() as $key => $val) { - $ret .= '<li><input type="radio" name="' . $plugin_name - . '_' . $propertyItem->getName() . '" value="' . $key - . '" id="radio_' . $plugin_name . '_' - . $propertyItem->getName() . '_' . $key . '"'; - if ($key == $default) { - $ret .= ' checked="checked"'; - } - $ret .= ' />' . '<label for="radio_' . $plugin_name . '_' - . $propertyItem->getName() . '_' . $key . '">' - . PMA_getString($val) . '</label></li>'; - } - break; - case 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem': - $ret .= '<li>' . "\n"; - $ret .= '<label for="select_' . $plugin_name . '_' - . $propertyItem->getName() . '" class="desc">' - . PMA_getString($propertyItem->getText()) . '</label>'; - $ret .= '<select name="' . $plugin_name . '_' - . $propertyItem->getName() . '"' - . ' id="select_' . $plugin_name . '_' - . $propertyItem->getName() . '">'; - $default = PMA_pluginGetDefault( - $section, - $plugin_name . '_' . $propertyItem->getName() - ); - foreach ($propertyItem->getValues() as $key => $val) { - $ret .= '<option value="' . $key . '"'; - if ($key == $default) { - $ret .= ' selected="selected"'; - } - $ret .= '>' . PMA_getString($val) . '</option>'; - } - $ret .= '</select>'; - break; - case 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem': - case 'PhpMyAdmin\Properties\Options\Items\NumberPropertyItem': - $ret .= '<li>' . "\n"; - $ret .= '<label for="text_' . $plugin_name . '_' - . $propertyItem->getName() . '" class="desc">' - . PMA_getString($propertyItem->getText()) . '</label>'; - $ret .= '<input type="text" name="' . $plugin_name . '_' - . $propertyItem->getName() . '"' - . ' value="' . PMA_pluginGetDefault( - $section, - $plugin_name . '_' . $propertyItem->getName() - ) . '"' - . ' id="text_' . $plugin_name . '_' - . $propertyItem->getName() . '"' - . ($propertyItem->getSize() != null - ? ' size="' . $propertyItem->getSize() . '"' - : '') - . ($propertyItem->getLen() != null - ? ' maxlength="' . $propertyItem->getLen() . '"' - : '') - . ' />'; - break; - default: - break; - } - return $ret; -} - -/** - * Returns html div with editable options for plugin - * - * @param string $section name of config section in $GLOBALS['cfg'][$section] - * @param array &$list array with plugin instances - * - * @return string html fieldset with plugin options - */ -function PMA_pluginGetOptions($section, &$list) -{ - $ret = ''; - // Options for plugins that support them - foreach ($list as $plugin) { - $properties = $plugin->getProperties(); - if ($properties != null) { - $text = $properties->getText(); - $options = $properties->getOptions(); - } - - $elem = explode('\\', get_class($plugin)); - $plugin_name = array_pop($elem); - unset($elem); - $plugin_name = mb_strtolower( - mb_substr( - $plugin_name, - mb_strlen($section) - ) - ); - - $ret .= '<div id="' . $plugin_name - . '_options" class="format_specific_options">'; - $ret .= '<h3>' . PMA_getString($text) . '</h3>'; - - $no_options = true; - if (! is_null($options) && count($options) > 0) { - foreach ($options->getProperties() - as $propertyMainGroup - ) { - // check for hidden properties - $no_options = true; - foreach ($propertyMainGroup->getProperties() as $propertyItem) { - if (strcmp('PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem', get_class($propertyItem))) { - $no_options = false; - break; - } - } - - $ret .= PMA_pluginGetOneOption( - $section, - $plugin_name, - $propertyMainGroup - ); - } - } - - if ($no_options) { - $ret .= '<p>' . __('This format has no options') . '</p>'; - } - $ret .= '</div>'; - } - return $ret; -} diff --git a/libraries/relation_cleanup.lib.php b/libraries/relation_cleanup.lib.php deleted file mode 100644 index 54290dc811..0000000000 --- a/libraries/relation_cleanup.lib.php +++ /dev/null @@ -1,357 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Set of functions used for cleaning up phpMyAdmin tables - * - * @package PhpMyAdmin - */ - -use PhpMyAdmin\Relation; - -/** - * Cleanup column related relation stuff - * - * @param string $db database name - * @param string $table table name - * @param string $column column name - * - * @return void - */ -function PMA_relationsCleanupColumn($db, $table, $column) -{ - $cfgRelation = Relation::getRelationsParam(); - - if ($cfgRelation['commwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND column_name = \'' . $GLOBALS['dbi']->escapeString($column) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['displaywork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_info']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND display_field = \'' . $GLOBALS['dbi']->escapeString($column) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['relwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) - . '\'' - . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND master_field = \'' . $GLOBALS['dbi']->escapeString($column) - . '\''; - Relation::queryAsControlUser($remove_query); - - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) - . '\'' - . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND foreign_field = \'' . $GLOBALS['dbi']->escapeString($column) - . '\''; - Relation::queryAsControlUser($remove_query); - } -} - -/** - * Cleanup table related relation stuff - * - * @param string $db database name - * @param string $table table name - * - * @return void - */ -function PMA_relationsCleanupTable($db, $table) -{ - $cfgRelation = Relation::getRelationsParam(); - - if ($cfgRelation['commwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['displaywork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_info']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['pdfwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_coords']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['relwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db) - . '\'' - . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table) - . '\''; - Relation::queryAsControlUser($remove_query); - - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) - . '\'' - . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['uiprefswork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_uiprefs']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' - . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['navwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['navigationhiding']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'' - . ' AND (table_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' OR (item_name = \'' . $GLOBALS['dbi']->escapeString($table) - . '\'' - . ' AND item_type = \'table\'))'; - Relation::queryAsControlUser($remove_query); - } -} - -/** - * Cleanup database related relation stuff - * - * @param string $db database name - * - * @return void - */ -function PMA_relationsCleanupDatabase($db) -{ - $cfgRelation = Relation::getRelationsParam(); - - if ($cfgRelation['commwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['column_info']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['bookmarkwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['bookmark']) - . ' WHERE dbase = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['displaywork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_info']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['pdfwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['pdf_pages']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_coords']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['relwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' WHERE master_db = \'' - . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['relation']) - . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db) - . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['uiprefswork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['table_uiprefs']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['navwork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['navigationhiding']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['savedsearcheswork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['savedsearches']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['centralcolumnswork']) { - $remove_query = 'DELETE FROM ' - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . '.' . PhpMyAdmin\Util::backquote($cfgRelation['central_columns']) - . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''; - Relation::queryAsControlUser($remove_query); - } -} - -/** - * Cleanup user related relation stuff - * - * @param string $username username - * - * @return void - */ -function PMA_relationsCleanupUser($username) -{ - $cfgRelation = Relation::getRelationsParam(); - - if ($cfgRelation['bookmarkwork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['bookmark']) - . " WHERE `user` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['historywork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['history']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['recentwork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['recent']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['favoritework']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['favorite']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['uiprefswork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['table_uiprefs']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['userconfigwork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['userconfig']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['menuswork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['users']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['navwork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['navigationhiding']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['savedsearcheswork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['savedsearches']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } - - if ($cfgRelation['designersettingswork']) { - $remove_query = "DELETE FROM " - . PhpMyAdmin\Util::backquote($cfgRelation['db']) - . "." . PhpMyAdmin\Util::backquote($cfgRelation['designer_settings']) - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) - . "'"; - Relation::queryAsControlUser($remove_query); - } -} diff --git a/libraries/select_server.lib.php b/libraries/select_server.lib.php deleted file mode 100644 index 49bac63dd2..0000000000 --- a/libraries/select_server.lib.php +++ /dev/null @@ -1,115 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Code for displaying server selection - * - * @package PhpMyAdmin - */ - -use PhpMyAdmin\Url; - -/** - * Renders the server selection in list or selectbox form, or option tags only - * - * @param boolean $not_only_options whether to include form tags or not - * @param boolean $omit_fieldset whether to omit fieldset tag or not - * - * @return string - */ -function PMA_selectServer($not_only_options, $omit_fieldset) -{ - $retval = ''; - - // Show as list? - if ($not_only_options) { - $list = $GLOBALS['cfg']['DisplayServersList']; - $not_only_options =! $list; - } else { - $list = false; - } - - if ($not_only_options) { - $retval .= '<form method="post" action="' - . PhpMyAdmin\Util::getScriptNameForOption( - $GLOBALS['cfg']['DefaultTabServer'], 'server' - ) - . '" class="disableAjax">'; - - if (! $omit_fieldset) { - $retval .= '<fieldset>'; - } - - $retval .= Url::getHiddenFields(array()); - $retval .= '<label for="select_server">' - . __('Current server:') . '</label> '; - - $retval .= '<select name="server" id="select_server" class="autosubmit">'; - $retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n"; - } elseif ($list) { - $retval .= __('Current server:') . '<br />'; - $retval .= '<ul id="list_server">'; - } - - foreach ($GLOBALS['cfg']['Servers'] as $key => $server) { - if (empty($server['host'])) { - continue; - } - - if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) { - $selected = 1; - } else { - $selected = 0; - } - if (!empty($server['verbose'])) { - $label = $server['verbose']; - } else { - $label = $server['host']; - if (!empty($server['port'])) { - $label .= ':' . $server['port']; - } - } - if (! empty($server['only_db'])) { - if (! is_array($server['only_db'])) { - $label .= ' - ' . $server['only_db']; - // try to avoid displaying a too wide selector - } elseif (count($server['only_db']) < 4) { - $label .= ' - ' . implode(', ', $server['only_db']); - } - } - if (!empty($server['user']) && $server['auth_type'] == 'config') { - $label .= ' (' . $server['user'] . ')'; - } - - if ($list) { - $retval .= '<li>'; - if ($selected) { - $retval .= '<strong>' . htmlspecialchars($label) . '</strong>'; - } else { - - $retval .= '<a class="disableAjax item" href="' - . PhpMyAdmin\Util::getScriptNameForOption( - $GLOBALS['cfg']['DefaultTabServer'], 'server' - ) - . Url::getCommon(array('server' => $key)) - . '" >' . htmlspecialchars($label) . '</a>'; - } - $retval .= '</li>'; - } else { - $retval .= '<option value="' . $key . '" ' - . ($selected ? ' selected="selected"' : '') . '>' - . htmlspecialchars($label) . '</option>' . "\n"; - } - } // end while - - if ($not_only_options) { - $retval .= '</select>'; - if (! $omit_fieldset) { - $retval .= '</fieldset>'; - } - $retval .= '</form>'; - } elseif ($list) { - $retval .= '</ul>'; - } - - return $retval; -} 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 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Functions for displaying user preferences pages - * - * @package PhpMyAdmin - */ -use PhpMyAdmin\Config\ConfigFile; -use PhpMyAdmin\Config\Forms\User\UserFormList; -use PhpMyAdmin\Core; -use PhpMyAdmin\Message; -use PhpMyAdmin\Relation; -use PhpMyAdmin\Url; - -if (! defined('PHPMYADMIN')) { - exit; -} - -/** - * Common initialization for user preferences modification pages - * - * @param ConfigFile $cf Config file instance - * - * @return void - */ -function PMA_userprefsPageInit(ConfigFile $cf) -{ - $forms_all_keys = UserFormList::getFields(); - $cf->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']) - ), - '<br /><br />' - ); - 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/schema_export.php b/schema_export.php index 040768dd2b..936cc0c263 100644 --- a/schema_export.php +++ b/schema_export.php @@ -7,6 +7,7 @@ */ use PhpMyAdmin\Core; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\SchemaPlugin; use PhpMyAdmin\Relation; @@ -22,7 +23,6 @@ require_once 'libraries/common.inc.php'; $cfgRelation = Relation::getRelationsParam(); require_once 'libraries/pmd_common.php'; -require_once 'libraries/plugin_interface.lib.php'; if (! isset($_REQUEST['export_type'])) { PhpMyAdmin\Util::checkParameters(array('export_type')); @@ -56,7 +56,7 @@ function PMA_processExportSchema($export_type) // get the specific plugin /* @var $export_plugin SchemaPlugin */ - $export_plugin = PMA_getPlugin( + $export_plugin = Plugins::getPlugin( "schema", $export_type, 'libraries/classes/Plugins/Schema/' diff --git a/server_privileges.php b/server_privileges.php index 7643365c08..77228113dc 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -278,7 +278,6 @@ if (isset($_REQUEST['change_pw'])) { if (isset($_REQUEST['delete']) || (isset($_REQUEST['change_copy']) && $_REQUEST['mode'] < 4) ) { - include_once 'libraries/relation_cleanup.lib.php'; $queries = Privileges::getDataForDeleteUsers($queries); if (empty($_REQUEST['change_copy'])) { list($sql_query, $message) = Privileges::deleteUser($queries); 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(); - @@ -8,6 +8,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\Response; use PhpMyAdmin\Sql; use PhpMyAdmin\Url; @@ -130,12 +131,11 @@ if (empty($sql_query) && strlen($table) > 0 && strlen($db) > 0) { /** * Parse and analyze the query */ -require_once 'libraries/parse_analyze.lib.php'; list( $analyzed_sql_results, $db, $table_from_sql -) = PMA_parseAnalyze($sql_query, $db); +) = ParseAnalyze::sqlQuery($sql_query, $db); // @todo: possibly refactor extract($analyzed_sql_results); diff --git a/tbl_get_field.php b/tbl_get_field.php index 366dd683e5..526410eea9 100644 --- a/tbl_get_field.php +++ b/tbl_get_field.php @@ -7,6 +7,7 @@ */ use PhpMyAdmin\Core; +use PhpMyAdmin\Mime; /** * Common functions. @@ -15,7 +16,6 @@ use PhpMyAdmin\Core; // data define('PMA_BYPASS_GET_INSTANCE', 1); require_once 'libraries/common.inc.php'; -require_once 'libraries/mime.lib.php'; /* Check parameters */ PhpMyAdmin\Util::checkParameters( @@ -53,7 +53,7 @@ if ($result === false) { Core::downloadHeader( $table . '-' . $_GET['transform_key'] . '.bin', - PMA_detectMIME($result), + Mime::detect($result), strlen($result) ); echo $result; diff --git a/tbl_operations.php b/tbl_operations.php index 36f6868239..54a6630bc8 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -426,7 +426,7 @@ if (! (isset($db_is_system_schema) && $db_is_system_schema)) { htmlspecialchars($table) ), // table name is needed to avoid running - // PMA_relationsCleanupDatabase() on the whole db later + // PhpMyAdmin\RelationCleanup::database() on the whole db later 'table' => $GLOBALS['table'], ) ); diff --git a/templates/database/designer/schema_export.phtml b/templates/database/designer/schema_export.phtml index 6364edc452..ec0dcf66ee 100644 --- a/templates/database/designer/schema_export.phtml +++ b/templates/database/designer/schema_export.phtml @@ -2,10 +2,10 @@ <fieldset> <?= PhpMyAdmin\Url::getHiddenInputs($db); ?> <label><?= __('Select Export Relational Type'); ?></label><br/> - <?= PMA_pluginGetChoice( + <?= PhpMyAdmin\Plugins::getChoice( 'Schema', 'export_type', $export_list, 'format' ); ?> <input type="hidden" name="page_number" value="<?= htmlspecialchars($page); ?>" /> - <?= PMA_pluginGetOptions('Schema', $export_list); ?> + <?= PhpMyAdmin\Plugins::getOptions('Schema', $export_list); ?> </fieldset> </form> diff --git a/test/classes/Database/DesignerTest.php b/test/classes/Database/DesignerTest.php index eab496922b..c3039e69c7 100644 --- a/test/classes/Database/DesignerTest.php +++ b/test/classes/Database/DesignerTest.php @@ -9,11 +9,6 @@ namespace PhpMyAdmin\Tests\Database; use PhpMyAdmin\Database\Designer; use PhpMyAdmin\DatabaseInterface; -/* - * Include to test. - */ -require_once 'libraries/plugin_interface.lib.php'; - /** * Tests for PhpMyAdmin\Database\Designer * diff --git a/test/classes/Display/ExportTest.php b/test/classes/Display/ExportTest.php index b737e4e5e9..5ca4ae8b41 100644 --- a/test/classes/Display/ExportTest.php +++ b/test/classes/Display/ExportTest.php @@ -9,12 +9,11 @@ namespace PhpMyAdmin\Tests\Display; use PhpMyAdmin\Core; use PhpMyAdmin\Display\Export; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Theme; use PhpMyAdmin\Url; use PhpMyAdmin\Util; -require_once 'libraries/plugin_interface.lib.php'; - /** * class PhpMyAdmin\Tests\Display\ExportTest * @@ -148,7 +147,7 @@ class ExportTest extends \PHPUnit_Framework_TestCase $GLOBALS['dbi'] = $dbi; /* Scan for plugins */ - $export_list = PMA_getPlugins( + $export_list = Plugins::getPlugins( "export", 'libraries/classes/Plugins/Export/', array( diff --git a/test/libraries/PMA_ip_allow_deny_test.php b/test/classes/IpAllowDenyTest.php index 51dcdc498f..a54661e509 100644 --- a/test/libraries/PMA_ip_allow_deny_test.php +++ b/test/classes/IpAllowDenyTest.php @@ -1,23 +1,23 @@ <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * tests for ip_allow_deny.lib.php + * tests for PhpMyAdmin\IpAllowDeny * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin\Tests; use PhpMyAdmin\Core; - -require_once 'libraries/ip_allow_deny.lib.php'; +use PhpMyAdmin\IpAllowDeny; /** - * PMA_Ip_Allow_Deny_Test class + * PhpMyAdmin\Tests\IpAllowDenyTest class * - * this class is for testing ip_allow_deny.lib.php + * this class is for testing PhpMyAdmin\IpAllowDeny * * @package PhpMyAdmin-test */ -class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase +class IpAllowDenyTest extends \PHPUnit_Framework_TestCase { /** * Prepares environment for the test. @@ -101,7 +101,7 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_ipMaskTest + * Test for IpAllowDeny::ipMaskTest * * @return void */ @@ -112,26 +112,26 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase $ipToTest = "10.0.0.0"; $this->assertEquals( false, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); $testRange = "255.255.0.0/4"; $ipToTest = "255.3.0.0"; $this->assertEquals( true, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); $testRange = "255.255.0.[0-10]"; $ipToTest = "255.3.0.3"; $this->assertEquals( false, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); $ipToTest = "255.3.0.12"; $this->assertEquals( false, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); //IPV6 testing @@ -140,13 +140,13 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase $testRange = "2001:4998:c:a0d:0000:0000:4998:1020"; $this->assertEquals( true, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); $ipToTest = "2001:4998:c:a0d:0000:0000:4998:1020"; $testRange = "2001:4998:c:a0d:0000:0000:4998:2020"; $this->assertEquals( false, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); //range @@ -154,13 +154,13 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase $testRange = "2001:4998:c:a0d:0000:0000:4998:[1001-2010]"; $this->assertEquals( true, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); $ipToTest = "2001:4998:c:a0d:0000:0000:4998:3020"; $testRange = "2001:4998:c:a0d:0000:0000:4998:[1001-2010]"; $this->assertEquals( false, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); //CDIR @@ -168,18 +168,18 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase $testRange = "2001:4998:c:a0d:0000:0000:4998:[1001-2010]"; $this->assertEquals( true, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); $ipToTest = "2001:4998:c:a0d:0000:0000:4998:1000"; $testRange = "2001:4998:c:a0d:0000:0000:4998:3020/24"; $this->assertEquals( false, - PMA_ipMaskTest($testRange, $ipToTest) + IpAllowDeny::ipMaskTest($testRange, $ipToTest) ); } /** - * Test for PMA_allowDeny + * Test for IpAllowDeny::allowDeny * * @return void */ @@ -188,51 +188,51 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase $_SERVER['REMOTE_ADDR'] = ""; $this->assertEquals( false, - PMA_allowDeny("allow") + IpAllowDeny::allowDeny("allow") ); $_SERVER['REMOTE_ADDR'] = "255.0.1.0"; $this->assertEquals( true, - PMA_allowDeny("allow") + IpAllowDeny::allowDeny("allow") ); $_SERVER['REMOTE_ADDR'] = "10.0.0.0"; $this->assertEquals( false, - PMA_allowDeny("allow") + IpAllowDeny::allowDeny("allow") ); $_SERVER['REMOTE_ADDR'] = "255.255.0.1"; $this->assertEquals( true, - PMA_allowDeny("deny") + IpAllowDeny::allowDeny("deny") ); $_SERVER['REMOTE_ADDR'] = "255.124.0.5"; $this->assertEquals( true, - PMA_allowDeny("deny") + IpAllowDeny::allowDeny("deny") ); $_SERVER['REMOTE_ADDR'] = "122.124.0.5"; $this->assertEquals( false, - PMA_allowDeny("deny") + IpAllowDeny::allowDeny("deny") ); //IPV6 $_SERVER['REMOTE_ADDR'] = "2001:4998:c:a0d:0000:0000:4998:1020"; $this->assertEquals( true, - PMA_allowDeny("allow") + IpAllowDeny::allowDeny("allow") ); $_SERVER['REMOTE_ADDR'] = "2001:4998:c:a0d:0000:0000:4998:1000"; $this->assertEquals( false, - PMA_allowDeny("allow") + IpAllowDeny::allowDeny("allow") ); $_SERVER['REMOTE_ADDR'] = "2001:4998:c:a0d:0000:0000:4998:1020"; $this->assertEquals( true, - PMA_allowDeny("allow") + IpAllowDeny::allowDeny("allow") ); } } diff --git a/test/libraries/PMA_mime_test.php b/test/classes/MimeTest.php index b49bac52be..5d0a09bd8d 100644 --- a/test/libraries/PMA_mime_test.php +++ b/test/classes/MimeTest.php @@ -1,48 +1,45 @@ <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * tests for mime.lib.php + * tests for PhpMyAdmin\Mime * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin; -/* - * Include to test. - */ - -require_once 'libraries/mime.lib.php'; +use PhpMyAdmin\Mime; /** * Test for mime detection. * * @package PhpMyAdmin-test */ -class PMA_MIME_Test extends PHPUnit_Framework_TestCase +class MimeTest extends \PHPUnit_Framework_TestCase { /** - * Test for PMA_detectMIME + * Test for Mime::detect * * @param string $test MIME to test * @param string $output Expected output * * @return void - * @dataProvider providerForTestDetectMIME + * @dataProvider providerForTestDetect */ - public function testDetectMIME($test, $output) + public function testDetect($test, $output) { $this->assertEquals( - PMA_detectMIME($test), + Mime::detect($test), $output ); } /** - * Provider for testPMA_detectMIME + * Provider for testDetect * - * @return array data for testPMA_detectMIME + * @return array data for testDetect */ - public function providerForTestDetectMIME() + public function providerForTestDetect() { return array( array( diff --git a/test/libraries/PMA_mult_submits_test.php b/test/classes/MultSubmitsTest.php index b80b2fd243..11df782139 100644 --- a/test/libraries/PMA_mult_submits_test.php +++ b/test/classes/MultSubmitsTest.php @@ -1,28 +1,24 @@ <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * tests for mult_submits.lib.php + * tests for PhpMyAdmin\MultSubmits * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin\Tests; -/* - * Include to test. - */ +use PhpMyAdmin\MultSubmits; use PhpMyAdmin\Theme; use PhpMyAdmin\Url; -require_once 'libraries/mult_submits.lib.php'; -require_once 'libraries/relation_cleanup.lib.php'; - /** - * class PMA_MultSubmits_Test + * PhpMyAdmin\Tests\MultSubmitsTest class * - * this class is for testing mult_submits.lib.php functions + * this class is for testing PhpMyAdmin\MultSubmits methods * * @package PhpMyAdmin-test */ -class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase +class MultSubmitsTest extends \PHPUnit_Framework_TestCase { /** * Test for setUp @@ -73,7 +69,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getHtmlForReplacePrefixTable + * Test for MultSubmits::getHtmlForReplacePrefixTable * * @return void */ @@ -83,7 +79,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase $_url_params = array('url_query'=>'PMA_original_url_query'); //Call the test function - $html = PMA_getHtmlForReplacePrefixTable($action, $_url_params); + $html = MultSubmits::getHtmlForReplacePrefixTable($action, $_url_params); //form action $this->assertContains( @@ -103,7 +99,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getHtmlForAddPrefixTable + * Test for MultSubmits::getHtmlForAddPrefixTable * * @return void */ @@ -113,7 +109,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase $_url_params = array('url_query'=>'PMA_original_url_query'); //Call the test function - $html = PMA_getHtmlForAddPrefixTable($action, $_url_params); + $html = MultSubmits::getHtmlForAddPrefixTable($action, $_url_params); //form action $this->assertContains( @@ -133,7 +129,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getHtmlForOtherActions + * Test for MultSubmits::getHtmlForOtherActions * * @return void */ @@ -145,7 +141,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase $full_query = 'select column from PMA_table'; //Call the test function - $html = PMA_getHtmlForOtherActions( + $html = MultSubmits::getHtmlForOtherActions( $what, $action, $_url_params, $full_query ); @@ -181,7 +177,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getUrlParams + * Test for MultSubmits::getUrlParams * * @return void */ @@ -199,7 +195,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase $original_sql_query = "original_sql_query"; $original_url_query = "original_url_query"; - $_url_params = PMA_getUrlParams( + $_url_params = MultSubmits::getUrlParams( $what, $reload, $action, $db, $table, $selected, $views, $original_sql_query, $original_url_query ); @@ -226,7 +222,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_buildOrExecuteQueryForMulti + * Test for MultSubmits::buildOrExecuteQueryForMulti * * @return void */ @@ -250,7 +246,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase list( $result, $rebuild_database_list, $reload_ret, $run_parts, $execute_query_later,, - ) = PMA_buildOrExecuteQueryForMulti( + ) = MultSubmits::buildOrExecuteQueryForMulti( $query_type, $selected, $db, $table, $views, $primary, $from_prefix, $to_prefix ); @@ -282,7 +278,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase $query_type = 'analyze_tbl'; list( ,,,, $execute_query_later,, - ) = PMA_buildOrExecuteQueryForMulti( + ) = MultSubmits::buildOrExecuteQueryForMulti( $query_type, $selected, $db, $table, $views, $primary, $from_prefix, $to_prefix ); @@ -295,7 +291,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getQueryFromSelected + * Test for MultSubmits::getQueryFromSelected * * @return void */ @@ -311,7 +307,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase ); list($full_query, $reload, $full_query_views) - = PMA_getQueryFromSelected( + = MultSubmits::getQueryFromSelected( $what, $table, $selected, $views ); @@ -336,7 +332,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase $what = "drop_db"; list($full_query, $reload, $full_query_views) - = PMA_getQueryFromSelected( + = MultSubmits::getQueryFromSelected( $what, $table, $selected, $views ); diff --git a/test/libraries/PMA_relation_cleanup_test.php b/test/classes/RelationCleanupTest.php index 2aa2d6cbb3..2129ac9a72 100644 --- a/test/libraries/PMA_relation_cleanup_test.php +++ b/test/classes/RelationCleanupTest.php @@ -1,27 +1,25 @@ <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * tests for relation_cleanup.lib.php + * tests for PhpMyAdmin\RelationCleanup * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin\Tests; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Relation; - -/* -* Include to test. -*/ -require_once 'libraries/relation_cleanup.lib.php'; +use PhpMyAdmin\RelationCleanup; +use PHPUnit_Framework_TestCase as TestCase; /** - * PMA_Relation_Cleanup_Test class + * PhpMyAdmin\Tests\RelationCleanupTest class * - * this class is for testing relation_cleanup.lib.php functions + * this class is for testing PhpMyAdmin\RelationCleanup methods * * @package PhpMyAdmin-test */ -class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase +class RelationCleanupTest extends TestCase { /** * Prepares environment for the test. @@ -70,7 +68,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_relationsCleanupColumn + * Test for RelationCleanup::column * * @return void * @group medium @@ -123,7 +121,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase ); //cleanup - PMA_relationsCleanupColumn($db, $table, $column); + RelationCleanup::column($db, $table, $column); //the $cfgRelation value after cleanup column $cfgRelation = Relation::checkRelationsParam(); @@ -151,7 +149,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_relationsCleanupTable + * Test for RelationCleanup::table * * @return void */ @@ -180,8 +178,8 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase $cfgRelation['relation'] ); - //PMA_relationsCleanupTable - PMA_relationsCleanupTable($db, $table); + //RelationCleanup::table + RelationCleanup::table($db, $table); //the $cfgRelation value after cleanup column $cfgRelation = Relation::checkRelationsParam(); @@ -216,7 +214,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_relationsCleanupDatabase + * Test for RelationCleanup::database * * @return void */ @@ -253,7 +251,7 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase ); //cleanup - PMA_relationsCleanupDatabase($db); + RelationCleanup::database($db); //the value after cleanup column $cfgRelation = Relation::checkRelationsParam(); diff --git a/test/classes/Server/PrivilegesTest.php b/test/classes/Server/PrivilegesTest.php index e06fc0107e..75a9b226ff 100644 --- a/test/classes/Server/PrivilegesTest.php +++ b/test/classes/Server/PrivilegesTest.php @@ -14,8 +14,6 @@ use PhpMyAdmin\Theme; use PhpMyAdmin\Url; use PhpMyAdmin\Util; -require_once 'libraries/relation_cleanup.lib.php'; - /** * PhpMyAdmin\Tests\Server\PrivilegesTest class * diff --git a/test/libraries/PMA_select_server_test.php b/test/classes/Server/SelectTest.php index 733b336a70..71bc09a248 100644 --- a/test/libraries/PMA_select_server_test.php +++ b/test/classes/Server/SelectTest.php @@ -1,28 +1,25 @@ <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * tests for select_server.lib.php + * tests for PhpMyAdmin\Server\Select * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin\Tests\Server; -/* - * Include to test. - */ +use PhpMyAdmin\Server\Select; use PhpMyAdmin\Theme; - - -require_once 'libraries/select_server.lib.php'; - +use PhpMyAdmin\Util; +use PHPUnit_Framework_TestCase as TestCase; /** - * PMA_SelectServer_Test class + * PhpMyAdmin\Tests\Server\SelectTest class * - * this class is for testing select_server.lib.php functions + * this class is for testing PhpMyAdmin\Server\Select methods * * @package PhpMyAdmin-test */ -class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase +class SelectTest extends TestCase { /** * Prepares environment for the test. @@ -52,11 +49,11 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_selectServer + * Test for Select::render * * @return void */ - public function testPMASelectServer() + public function testRender() { $not_only_options = false; $omit_fieldset = false; @@ -81,7 +78,7 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase ); //$not_only_options=false & $omit_fieldset=false - $html = PMA_selectServer($not_only_options, $omit_fieldset); + $html = Select::render($not_only_options, $omit_fieldset); $server = $GLOBALS['cfg']['Servers']['0']; //server items @@ -107,11 +104,11 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['DisplayServersList'] = null; //$not_only_options=true & $omit_fieldset=true - $html = PMA_selectServer($not_only_options, $omit_fieldset); + $html = Select::render($not_only_options, $omit_fieldset); //$GLOBALS['cfg']['DefaultTabServer'] $this->assertContains( - PhpMyAdmin\Util::getScriptNameForOption( + Util::getScriptNameForOption( $GLOBALS['cfg']['DefaultTabServer'], 'server' ), $html diff --git a/test/libraries/PMA_user_preferences_test.php b/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 @@ <?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * tests for methods under user_preferences library + * tests for methods under PhpMyAdmin\UserPreferences class * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin\Tests; -/* - * Include to test - */ use PhpMyAdmin\Config\ConfigFile; - -require_once 'libraries/user_preferences.lib.php'; +use PhpMyAdmin\UserPreferences; /** - * tests for methods under user_preferences library + * tests for methods under PhpMyAdmin\UserPreferences class * * @package PhpMyAdmin-test */ -class PMA_User_Preferences_Test extends PMATestCase +class UserPreferencesTest extends \PMATestCase { - /** * Setup various pre conditions * @@ -35,7 +31,7 @@ class PMA_User_Preferences_Test extends PMATestCase } /** - * Test for PMA_userprefsPageInit + * Test for UserPreferences::pageInit * * @return void */ @@ -48,7 +44,7 @@ class PMA_User_Preferences_Test extends PMATestCase $GLOBALS['cfg']['AvailableCharsets'] = array(); $GLOBALS['cfg']['UserprefsDeveloperTab'] = null; - PMA_userprefsPageInit(new ConfigFile()); + UserPreferences::pageInit(new ConfigFile()); $this->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<br /><br />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( '<form action="prefs_manage.php" method="post" class="disableAjax">', diff --git a/test/classes/config/FormDisplayTest.php b/test/classes/config/FormDisplayTest.php index d1130b6e59..05036722c3 100644 --- a/test/classes/config/FormDisplayTest.php +++ b/test/classes/config/FormDisplayTest.php @@ -11,7 +11,6 @@ use PhpMyAdmin\Config\ConfigFile; use PhpMyAdmin\Config\FormDisplay; require_once 'test/PMATestCase.php'; -require_once 'libraries/user_preferences.lib.php'; /** * Tests for PMA_FormDisplay class diff --git a/test/libraries/PMA_FormDisplay_tpl_test.php b/test/libraries/PMA_FormDisplay_tpl_test.php index 392443e406..fcc1c5a6cc 100644 --- a/test/libraries/PMA_FormDisplay_tpl_test.php +++ b/test/libraries/PMA_FormDisplay_tpl_test.php @@ -9,7 +9,6 @@ use PhpMyAdmin\Theme; require_once 'libraries/config/FormDisplay.tpl.php'; -require_once 'libraries/user_preferences.lib.php'; /** * Tests for FromDisplay.tpl.php |