diff --git a/libraries/classes/Common.php b/libraries/classes/Common.php new file mode 100644 index 0000000000..371d1d10c0 --- /dev/null +++ b/libraries/classes/Common.php @@ -0,0 +1,239 @@ +isUserType('grant'); + $is_createuser = $dbi->isUserType('create'); + + // now, select the mysql db + if ($dbi->isSuperuser()) { + $dbi->selectDb('mysql'); + } + } + + /** + * @return void + */ + public static function database(): void + { + global $cfg, $db, $is_show_stats, $db_is_system_schema, $err_url; + global $message, $dbi, $url_query, $errno, $is_db, $err_url_0; + + Util::checkParameters(['db']); + + $response = Response::getInstance(); + $is_show_stats = $cfg['ShowStats']; + + $db_is_system_schema = $dbi->isSystemSchema($db); + if ($db_is_system_schema) { + $is_show_stats = false; + } + + $relation = new Relation($dbi); + $operations = new Operations($dbi, $relation); + + /** + * Defines the urls to return to in case of error in a sql statement + */ + $err_url_0 = Url::getFromRoute('/'); + + $err_url = Util::getScriptNameForOption( + $cfg['DefaultTabDatabase'], + 'database' + ); + $err_url .= Url::getCommon(['db' => $db], strpos($err_url, '?') === false ? '?' : '&'); + + /** + * Ensures the database exists (else move to the "parent" script) and displays + * headers + */ + if (! isset($is_db) || ! $is_db) { + if (strlen($db) > 0) { + $is_db = $dbi->selectDb($db); + // This "Command out of sync" 2014 error may happen, for example + // after calling a MySQL procedure; at this point we can't select + // the db but it's not necessarily wrong + if ($dbi->getError() && $errno == 2014) { + $is_db = true; + unset($errno); + } + } else { + $is_db = false; + } + // Not a valid db name -> back to the welcome page + $params = ['reload' => '1']; + if (isset($message)) { + $params['message'] = $message; + } + $uri = './index.php?route=/' . Url::getCommonRaw($params, '&'); + if (strlen($db) === 0 || ! $is_db) { + if ($response->isAjax()) { + $response->setRequestStatus(false); + $response->addJSON( + 'message', + Message::error(__('No databases selected.')) + ); + } else { + Core::sendHeaderLocation($uri); + } + exit; + } + } // end if (ensures db exists) + + /** + * Changes database charset if requested by the user + */ + if (isset($_POST['submitcollation'], $_POST['db_collation']) && ! empty($_POST['db_collation'])) { + [$db_charset] = explode('_', $_POST['db_collation']); + $sql_query = 'ALTER DATABASE ' . Util::backquote($db) + . ' DEFAULT' . Util::getCharsetQueryPart($_POST['db_collation']); + $result = $dbi->query($sql_query); + $message = Message::success(); + + /** + * Changes tables charset if requested by the user + */ + if (isset($_POST['change_all_tables_collations']) && + $_POST['change_all_tables_collations'] === 'on' + ) { + list($tables, , , , , , , ,) = Util::getDbInfo($db, null); + foreach ($tables as $tableName => $data) { + if ($dbi->getTable($db, $tableName)->isView()) { + // Skip views, we can not change the collation of a view. + // issue #15283 + continue; + } + $sql_query = 'ALTER TABLE ' + . Util::backquote($db) + . '.' + . Util::backquote($tableName) + . ' DEFAULT ' + . Util::getCharsetQueryPart($_POST['db_collation']); + $dbi->query($sql_query); + + /** + * Changes columns charset if requested by the user + */ + if (isset($_POST['change_all_tables_columns_collations']) && + $_POST['change_all_tables_columns_collations'] === 'on' + ) { + $operations->changeAllColumnsCollation($db, $tableName, $_POST['db_collation']); + } + } + } + unset($db_charset); + + /** + * If we are in an Ajax request, let us stop the execution here. Necessary for + * db charset change action on /database/operations. If this causes a bug on + * other pages, we might have to move this to a different location. + */ + if ($response->isAjax()) { + $response->setRequestStatus($message->isSuccess()); + $response->addJSON('message', $message); + exit; + } + } elseif (isset($_POST['submitcollation'], $_POST['db_collation']) && empty($_POST['db_collation'])) { + if ($response->isAjax()) { + $response->setRequestStatus(false); + $response->addJSON( + 'message', + Message::error(__('No collation provided.')) + ); + } + } + + /** + * Set parameters for links + */ + $url_query = Url::getCommon(['db' => $db]); + } + + /** + * @return void + */ + public static function table(): void + { + global $db, $table, $db_is_system_schema, $url_query, $url_params, $cfg, $dbi, $err_url, $err_url_0; + + Util::checkParameters(['db', 'table']); + + $db_is_system_schema = $dbi->isSystemSchema($db); + + /** + * Set parameters for links + * + * @deprecated + */ + $url_query = Url::getCommon(['db' => $db, 'table' => $table]); + + /** + * Set parameters for links + */ + $url_params = []; + $url_params['db'] = $db; + $url_params['table'] = $table; + + /** + * Defines the urls to return to in case of error in a sql statement + */ + $err_url_0 = Util::getScriptNameForOption( + $cfg['DefaultTabDatabase'], + 'database' + ); + $err_url_0 .= Url::getCommon(['db' => $db], strpos($err_url_0, '?') === false ? '?' : '&'); + + $err_url = Util::getScriptNameForOption( + $cfg['DefaultTabTable'], + 'table' + ); + $err_url .= Url::getCommon($url_params, strpos($err_url, '?') === false ? '?' : '&'); + + /** + * Ensures the database and the table exist (else move to the "parent" script) + * Skip test if we are exporting as we can't tell whether a table name is an alias (which would fail the test). + */ + if (($_GET['route'] ?? $_POST['route'] ?? '') === '/table/export') { + require_once ROOT_PATH . 'libraries/db_table_exists.inc.php'; + } + } +} diff --git a/libraries/classes/Controllers/Database/DesignerController.php b/libraries/classes/Controllers/Database/DesignerController.php index 032ca9e78f..98a947c329 100644 --- a/libraries/classes/Controllers/Database/DesignerController.php +++ b/libraries/classes/Controllers/Database/DesignerController.php @@ -6,8 +6,9 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Database\Designer; -use PhpMyAdmin\Database\Designer\Common; +use PhpMyAdmin\Database\Designer\Common as DesignerCommon; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Response; use PhpMyAdmin\Template; @@ -21,7 +22,7 @@ class DesignerController extends AbstractController /** @var Designer */ private $databaseDesigner; - /** @var Common */ + /** @var DesignerCommon */ private $designerCommon; /** @@ -30,7 +31,7 @@ class DesignerController extends AbstractController * @param Template $template Template object * @param string $db Database name * @param Designer $databaseDesigner Designer object - * @param Common $designerCommon Designer\Common object + * @param DesignerCommon $designerCommon Designer\Common object */ public function __construct( $response, @@ -38,7 +39,7 @@ class DesignerController extends AbstractController Template $template, $db, Designer $databaseDesigner, - Common $designerCommon + DesignerCommon $designerCommon ) { parent::__construct($response, $dbi, $template, $db); $this->databaseDesigner = $databaseDesigner; @@ -146,7 +147,7 @@ class DesignerController extends AbstractController return; } - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); $script_display_field = $this->designerCommon->getTablesInfo(); diff --git a/libraries/classes/Controllers/Database/EventsController.php b/libraries/classes/Controllers/Database/EventsController.php index 2133e1bc23..72703f08c9 100644 --- a/libraries/classes/Controllers/Database/EventsController.php +++ b/libraries/classes/Controllers/Database/EventsController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Rte\Events; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -34,10 +35,10 @@ class EventsController extends AbstractController * Displays the header and tabs */ if (! empty($table) && in_array($table, $this->dbi->getTables($db))) { - include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); } else { $table = ''; - include_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); list( $tables, diff --git a/libraries/classes/Controllers/Database/ExportController.php b/libraries/classes/Controllers/Database/ExportController.php index ef86c29445..0e5de68040 100644 --- a/libraries/classes/Controllers/Database/ExportController.php +++ b/libraries/classes/Controllers/Database/ExportController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\Export as DisplayExport; @@ -56,7 +57,7 @@ final class ExportController extends AbstractController // /database/export, in which case we don't obey $cfg['MaxTableList'] $sub_part = '_export'; - require_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); $url_params['goto'] = Url::getFromRoute('/database/export'); $url_query .= Url::getCommon($url_params, '&'); diff --git a/libraries/classes/Controllers/Database/ImportController.php b/libraries/classes/Controllers/Database/ImportController.php index b56c24e770..58096f76e7 100644 --- a/libraries/classes/Controllers/Database/ImportController.php +++ b/libraries/classes/Controllers/Database/ImportController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Display\Import; use PhpMyAdmin\Util; @@ -32,7 +33,7 @@ final class ImportController extends AbstractController /** * Gets tables information and displays top links */ - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); list( $tables, diff --git a/libraries/classes/Controllers/Database/OperationsController.php b/libraries/classes/Controllers/Database/OperationsController.php index 02783cb086..51b42e0e1e 100644 --- a/libraries/classes/Controllers/Database/OperationsController.php +++ b/libraries/classes/Controllers/Database/OperationsController.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Html\Generator; @@ -267,7 +268,7 @@ class OperationsController extends AbstractController $this->relation->setDbComment($db, $_POST['comment']); } - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); $url_params['goto'] = Url::getFromRoute('/database/operations'); $url_query .= Url::getCommon($url_params, '&'); diff --git a/libraries/classes/Controllers/Database/QueryByExampleController.php b/libraries/classes/Controllers/Database/QueryByExampleController.php index 149238387e..b8901d7a7f 100644 --- a/libraries/classes/Controllers/Database/QueryByExampleController.php +++ b/libraries/classes/Controllers/Database/QueryByExampleController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Database\Qbe; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Message; @@ -138,7 +139,7 @@ class QueryByExampleController extends AbstractController } $sub_part = '_qbe'; - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); $url_params['goto'] = Url::getFromRoute('/database/qbe'); $url_query .= Url::getCommon($url_params, '&'); diff --git a/libraries/classes/Controllers/Database/RoutinesController.php b/libraries/classes/Controllers/Database/RoutinesController.php index 02f2c3cd48..9a4dd1461d 100644 --- a/libraries/classes/Controllers/Database/RoutinesController.php +++ b/libraries/classes/Controllers/Database/RoutinesController.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Response; use PhpMyAdmin\Rte\Routines; @@ -59,10 +60,10 @@ class RoutinesController extends AbstractController * Displays the header and tabs */ if (! empty($table) && in_array($table, $this->dbi->getTables($db))) { - include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); } else { $table = ''; - include_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); list( $tables, diff --git a/libraries/classes/Controllers/Database/SearchController.php b/libraries/classes/Controllers/Database/SearchController.php index 1b03998319..5223e6e0e3 100644 --- a/libraries/classes/Controllers/Database/SearchController.php +++ b/libraries/classes/Controllers/Database/SearchController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Database\Search; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Url; @@ -30,7 +31,7 @@ class SearchController extends AbstractController $scripts->addFile('sql.js'); $scripts->addFile('makegrid.js'); - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); // If config variable $cfg['UseDbSearch'] is on false : exit. if (! $cfg['UseDbSearch']) { diff --git a/libraries/classes/Controllers/Database/SqlController.php b/libraries/classes/Controllers/Database/SqlController.php index 70f09aae9f..c679fd104a 100644 --- a/libraries/classes/Controllers/Database/SqlController.php +++ b/libraries/classes/Controllers/Database/SqlController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Response; @@ -51,7 +52,7 @@ class SqlController extends AbstractController PageSettings::showGroup('Sql'); - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); /** * After a syntax error, we return to this script diff --git a/libraries/classes/Controllers/Database/StructureController.php b/libraries/classes/Controllers/Database/StructureController.php index 2efe342066..12f33d98b5 100644 --- a/libraries/classes/Controllers/Database/StructureController.php +++ b/libraries/classes/Controllers/Database/StructureController.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; use PhpMyAdmin\Charsets; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; @@ -121,7 +122,7 @@ class StructureController extends AbstractController { global $cfg; - require_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); $this->response->getHeader()->getScripts()->addFiles([ 'database/structure.js', @@ -203,7 +204,7 @@ class StructureController extends AbstractController { global $cfg; - require_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); if (! $this->response->isAjax()) { return []; @@ -291,7 +292,7 @@ class StructureController extends AbstractController */ public function handleRealRowCountRequestAction(array $parameters): array { - require_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); if (! $this->response->isAjax()) { return []; diff --git a/libraries/classes/Controllers/Database/TrackingController.php b/libraries/classes/Controllers/Database/TrackingController.php index 142322f8a9..5703d173f2 100644 --- a/libraries/classes/Controllers/Database/TrackingController.php +++ b/libraries/classes/Controllers/Database/TrackingController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Html\Generator; @@ -57,7 +58,7 @@ class TrackingController extends AbstractController /** * If we are not in an Ajax request, then do the common work and show the links etc. */ - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); $url_params['goto'] = Url::getFromRoute('/table/tracking'); $url_params['back'] = Url::getFromRoute('/database/tracking'); diff --git a/libraries/classes/Controllers/Database/TriggersController.php b/libraries/classes/Controllers/Database/TriggersController.php index 15036cf57b..6399a400ee 100644 --- a/libraries/classes/Controllers/Database/TriggersController.php +++ b/libraries/classes/Controllers/Database/TriggersController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Database; +use PhpMyAdmin\Common; use PhpMyAdmin\Rte\Triggers; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -35,10 +36,10 @@ class TriggersController extends AbstractController * Displays the header and tabs */ if (! empty($table) && in_array($table, $this->dbi->getTables($db))) { - include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); } else { $table = ''; - include_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); list( $tables, diff --git a/libraries/classes/Controllers/HomeController.php b/libraries/classes/Controllers/HomeController.php index f59206f6d5..50cb1cd46a 100644 --- a/libraries/classes/Controllers/HomeController.php +++ b/libraries/classes/Controllers/HomeController.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Charsets; use PhpMyAdmin\Charsets\Charset; use PhpMyAdmin\Charsets\Collation; use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Common; use PhpMyAdmin\Config; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\GitRevision; @@ -76,7 +77,7 @@ class HomeController extends AbstractController $show_query = '1'; if ($server > 0) { - include ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); } $languageManager = LanguageManager::getInstance(); diff --git a/libraries/classes/Controllers/Server/BinlogController.php b/libraries/classes/Controllers/Server/BinlogController.php index 3f5a8ef1d1..89581c1e61 100644 --- a/libraries/classes/Controllers/Server/BinlogController.php +++ b/libraries/classes/Controllers/Server/BinlogController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; @@ -58,7 +59,7 @@ class BinlogController extends AbstractController { global $cfg, $pmaThemeImage; - include_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $position = ! empty($params['pos']) ? (int) $params['pos'] : 0; diff --git a/libraries/classes/Controllers/Server/CollationsController.php b/libraries/classes/Controllers/Server/CollationsController.php index 36b711a668..2c43a84ccd 100644 --- a/libraries/classes/Controllers/Server/CollationsController.php +++ b/libraries/classes/Controllers/Server/CollationsController.php @@ -11,6 +11,7 @@ namespace PhpMyAdmin\Controllers\Server; use PhpMyAdmin\Charsets; use PhpMyAdmin\Charsets\Charset; use PhpMyAdmin\Charsets\Collation; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Response; @@ -68,7 +69,7 @@ class CollationsController extends AbstractController */ public function index(): string { - include_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $charsets = []; /** @var Charset $charset */ diff --git a/libraries/classes/Controllers/Server/DatabasesController.php b/libraries/classes/Controllers/Server/DatabasesController.php index 9546093e3f..9a06142256 100644 --- a/libraries/classes/Controllers/Server/DatabasesController.php +++ b/libraries/classes/Controllers/Server/DatabasesController.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Charsets; use PhpMyAdmin\Charsets\Charset; use PhpMyAdmin\Charsets\Collation; use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; @@ -88,7 +89,7 @@ class DatabasesController extends AbstractController $scripts = $header->getScripts(); $scripts->addFile('server/databases.js'); - include_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); ReplicationInfo::load(); $this->setSortDetails($params['sort_by'], $params['sort_order']); diff --git a/libraries/classes/Controllers/Server/EnginesController.php b/libraries/classes/Controllers/Server/EnginesController.php index 809d3f4c97..df28cbd998 100644 --- a/libraries/classes/Controllers/Server/EnginesController.php +++ b/libraries/classes/Controllers/Server/EnginesController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\StorageEngine; @@ -25,7 +26,7 @@ class EnginesController extends AbstractController */ public function index(): string { - require ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); return $this->template->render('server/engines/index', [ 'engines' => StorageEngine::getStorageEngines(), @@ -41,7 +42,7 @@ class EnginesController extends AbstractController */ public function show(array $params): string { - require ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $page = $params['page'] ?? ''; diff --git a/libraries/classes/Controllers/Server/ExportController.php b/libraries/classes/Controllers/Server/ExportController.php index 82c38b6b88..616d50c939 100644 --- a/libraries/classes/Controllers/Server/ExportController.php +++ b/libraries/classes/Controllers/Server/ExportController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; @@ -41,7 +42,7 @@ final class ExportController extends AbstractController global $db, $table, $sql_query, $num_tables, $unlim_num_rows; global $tmp_select, $select_item, $multi_values, $export_page_title; - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); PageSettings::showGroup('Export'); diff --git a/libraries/classes/Controllers/Server/ImportController.php b/libraries/classes/Controllers/Server/ImportController.php index 9d6d04b0b2..eced9c6fbb 100644 --- a/libraries/classes/Controllers/Server/ImportController.php +++ b/libraries/classes/Controllers/Server/ImportController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Display\Import; @@ -28,7 +29,7 @@ final class ImportController extends AbstractController $scripts = $header->getScripts(); $scripts->addFile('import.js'); - require ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $this->response->addHTML(Import::get( 'server', diff --git a/libraries/classes/Controllers/Server/PluginsController.php b/libraries/classes/Controllers/Server/PluginsController.php index 1a0c40217c..89f75a19a9 100644 --- a/libraries/classes/Controllers/Server/PluginsController.php +++ b/libraries/classes/Controllers/Server/PluginsController.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Response; @@ -46,7 +47,7 @@ class PluginsController extends AbstractController */ public function index(): string { - include ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $header = $this->response->getHeader(); $scripts = $header->getScripts(); diff --git a/libraries/classes/Controllers/Server/PrivilegesController.php b/libraries/classes/Controllers/Server/PrivilegesController.php index 8ab5218175..5de1d0ac74 100644 --- a/libraries/classes/Controllers/Server/PrivilegesController.php +++ b/libraries/classes/Controllers/Server/PrivilegesController.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Controllers\Database\PrivilegesController as DatabaseController; use PhpMyAdmin\Controllers\Table\PrivilegesController as TableController; @@ -116,7 +117,7 @@ class PrivilegesController extends AbstractController Core::setPostAsGlobal($post_patterns); - require ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); /** * Messages are built using the message name diff --git a/libraries/classes/Controllers/Server/ReplicationController.php b/libraries/classes/Controllers/Server/ReplicationController.php index 24899c53d8..b76bf7b87d 100644 --- a/libraries/classes/Controllers/Server/ReplicationController.php +++ b/libraries/classes/Controllers/Server/ReplicationController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\ReplicationGui; @@ -46,7 +47,7 @@ class ReplicationController extends AbstractController { global $replication_info, $server_slave_replication, $url_params; - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); ReplicationInfo::load(); $header = $this->response->getHeader(); diff --git a/libraries/classes/Controllers/Server/SqlController.php b/libraries/classes/Controllers/Server/SqlController.php index 84d0851faa..a89718fa06 100644 --- a/libraries/classes/Controllers/Server/SqlController.php +++ b/libraries/classes/Controllers/Server/SqlController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; @@ -50,7 +51,7 @@ class SqlController extends AbstractController PageSettings::showGroup('Sql'); - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); return $this->sqlQueryForm->getHtml(); } diff --git a/libraries/classes/Controllers/Server/Status/MonitorController.php b/libraries/classes/Controllers/Server/Status/MonitorController.php index 3e762a95ff..2687d9b514 100644 --- a/libraries/classes/Controllers/Server/Status/MonitorController.php +++ b/libraries/classes/Controllers/Server/Status/MonitorController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server\Status; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Status\Data; @@ -43,7 +44,7 @@ class MonitorController extends AbstractController */ public function index(): string { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $header = $this->response->getHeader(); $scripts = $header->getScripts(); @@ -89,7 +90,7 @@ class MonitorController extends AbstractController */ public function chartingData(array $params): array { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); if (! $this->response->isAjax()) { return []; @@ -110,7 +111,7 @@ class MonitorController extends AbstractController */ public function logDataTypeSlow(array $params): array { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); if (! $this->response->isAjax()) { return []; @@ -132,7 +133,7 @@ class MonitorController extends AbstractController */ public function logDataTypeGeneral(array $params): array { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); if (! $this->response->isAjax()) { return []; @@ -156,7 +157,7 @@ class MonitorController extends AbstractController */ public function loggingVars(array $params): array { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); if (! $this->response->isAjax()) { return []; @@ -178,7 +179,7 @@ class MonitorController extends AbstractController */ public function queryAnalyzer(array $params): array { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); if (! $this->response->isAjax()) { return []; diff --git a/libraries/classes/Controllers/Server/Status/ProcessesController.php b/libraries/classes/Controllers/Server/Status/ProcessesController.php index 53ca9375e7..593e8a731a 100644 --- a/libraries/classes/Controllers/Server/Status/ProcessesController.php +++ b/libraries/classes/Controllers/Server/Status/ProcessesController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server\Status; +use PhpMyAdmin\Common; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Message; use PhpMyAdmin\Util; @@ -24,7 +25,7 @@ class ProcessesController extends AbstractController */ public function index(array $params): string { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $header = $this->response->getHeader(); $scripts = $header->getScripts(); diff --git a/libraries/classes/Controllers/Server/Status/QueriesController.php b/libraries/classes/Controllers/Server/Status/QueriesController.php index cd61042d09..92b57932a2 100644 --- a/libraries/classes/Controllers/Server/Status/QueriesController.php +++ b/libraries/classes/Controllers/Server/Status/QueriesController.php @@ -8,6 +8,8 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server\Status; +use PhpMyAdmin\Common; + /** * @package PhpMyAdmin\Controllers\Server\Status */ @@ -18,7 +20,7 @@ class QueriesController extends AbstractController */ public function index(): string { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $header = $this->response->getHeader(); $scripts = $header->getScripts(); diff --git a/libraries/classes/Controllers/Server/Status/StatusController.php b/libraries/classes/Controllers/Server/Status/StatusController.php index 4ca043755c..4e324a0984 100644 --- a/libraries/classes/Controllers/Server/Status/StatusController.php +++ b/libraries/classes/Controllers/Server/Status/StatusController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server\Status; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\ReplicationGui; use PhpMyAdmin\Response; @@ -45,7 +46,7 @@ class StatusController extends AbstractController { global $replication_info; - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $traffic = []; $connections = []; diff --git a/libraries/classes/Controllers/Server/Status/VariablesController.php b/libraries/classes/Controllers/Server/Status/VariablesController.php index 47564ab234..415a77ae76 100644 --- a/libraries/classes/Controllers/Server/Status/VariablesController.php +++ b/libraries/classes/Controllers/Server/Status/VariablesController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server\Status; +use PhpMyAdmin\Common; use PhpMyAdmin\Html\Generator; /** @@ -22,7 +23,7 @@ class VariablesController extends AbstractController */ public function index(array $params): string { - require_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $header = $this->response->getHeader(); $scripts = $header->getScripts(); diff --git a/libraries/classes/Controllers/Server/VariablesController.php b/libraries/classes/Controllers/Server/VariablesController.php index 115c498747..48bbf62d49 100644 --- a/libraries/classes/Controllers/Server/VariablesController.php +++ b/libraries/classes/Controllers/Server/VariablesController.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Util; @@ -30,7 +31,7 @@ class VariablesController extends AbstractController */ public function index(array $params): string { - include ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); $filterValue = ! empty($params['filter']) ? $params['filter'] : ''; diff --git a/libraries/classes/Controllers/Table/AddFieldController.php b/libraries/classes/Controllers/Table/AddFieldController.php index cde4086da6..0dceb1033e 100644 --- a/libraries/classes/Controllers/Table/AddFieldController.php +++ b/libraries/classes/Controllers/Table/AddFieldController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\Config; use PhpMyAdmin\CreateAddField; use PhpMyAdmin\DatabaseInterface; @@ -166,7 +167,7 @@ class AddFieldController extends AbstractController /** * Gets tables information */ - include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $active_page = Url::getFromRoute('/table/structure'); /** diff --git a/libraries/classes/Controllers/Table/ChartController.php b/libraries/classes/Controllers/Table/ChartController.php index dc34240dd7..f408a3f17b 100644 --- a/libraries/classes/Controllers/Table/ChartController.php +++ b/libraries/classes/Controllers/Table/ChartController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\Message; use PhpMyAdmin\SqlParser\Components\Limit; use PhpMyAdmin\SqlParser\Parser; @@ -72,7 +73,7 @@ class ChartController extends AbstractController 'table' ); $url_params['back'] = Url::getFromRoute('/table/sql'); - include ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $this->dbi->selectDb($db); } elseif (strlen($db) > 0) { $url_params['goto'] = Util::getScriptNameForOption( @@ -80,14 +81,14 @@ class ChartController extends AbstractController 'database' ); $url_params['back'] = Url::getFromRoute('/sql'); - include ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); } else { $url_params['goto'] = Util::getScriptNameForOption( $cfg['DefaultTabServer'], 'server' ); $url_params['back'] = Url::getFromRoute('/sql'); - include ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); } $data = []; @@ -149,7 +150,7 @@ class ChartController extends AbstractController global $db, $table, $sql_query; if (strlen($table) > 0 && strlen($db) > 0) { - include ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); } $parser = new Parser($sql_query); diff --git a/libraries/classes/Controllers/Table/ExportController.php b/libraries/classes/Controllers/Table/ExportController.php index 5a58011d8f..7f0a0ab64b 100644 --- a/libraries/classes/Controllers/Table/ExportController.php +++ b/libraries/classes/Controllers/Table/ExportController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\Export; @@ -78,7 +79,7 @@ class ExportController extends AbstractController /** * Gets tables information and displays top links */ - require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $url_params = [ 'goto' => Url::getFromRoute('/table/export'), diff --git a/libraries/classes/Controllers/Table/FindReplaceController.php b/libraries/classes/Controllers/Table/FindReplaceController.php index 3c99931a1c..895a264c83 100644 --- a/libraries/classes/Controllers/Table/FindReplaceController.php +++ b/libraries/classes/Controllers/Table/FindReplaceController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Response; @@ -59,7 +60,7 @@ class FindReplaceController extends AbstractController */ public function index(): void { - require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); if (isset($_POST['find'])) { $this->findAction(); diff --git a/libraries/classes/Controllers/Table/GisVisualizationController.php b/libraries/classes/Controllers/Table/GisVisualizationController.php index 734dac667b..942e0a1bb9 100644 --- a/libraries/classes/Controllers/Table/GisVisualizationController.php +++ b/libraries/classes/Controllers/Table/GisVisualizationController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Gis\GisVisualization; @@ -51,7 +52,7 @@ final class GisVisualizationController extends AbstractController { global $cfg, $url_params; - require_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); // SQL query for retrieving GIS data $sqlQuery = ''; diff --git a/libraries/classes/Controllers/Table/ImportController.php b/libraries/classes/Controllers/Table/ImportController.php index 5e68cfbf39..ac46f95256 100644 --- a/libraries/classes/Controllers/Table/ImportController.php +++ b/libraries/classes/Controllers/Table/ImportController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Display\Import; use PhpMyAdmin\Url; @@ -31,7 +32,7 @@ final class ImportController extends AbstractController /** * Gets tables information and displays top links */ - require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $url_params['goto'] = Url::getFromRoute('/table/import'); $url_params['back'] = Url::getFromRoute('/table/import'); diff --git a/libraries/classes/Controllers/Table/IndexesController.php b/libraries/classes/Controllers/Table/IndexesController.php index 8825515eeb..c58a91554e 100644 --- a/libraries/classes/Controllers/Table/IndexesController.php +++ b/libraries/classes/Controllers/Table/IndexesController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Index; @@ -43,7 +44,7 @@ class IndexesController extends AbstractController public function index(): void { if (! isset($_POST['create_edit_table'])) { - include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); } if (isset($_POST['index'])) { if (is_array($_POST['index'])) { diff --git a/libraries/classes/Controllers/Table/OperationsController.php b/libraries/classes/Controllers/Table/OperationsController.php index 2fe004935d..82522e3443 100644 --- a/libraries/classes/Controllers/Table/OperationsController.php +++ b/libraries/classes/Controllers/Table/OperationsController.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\SqlController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; @@ -90,7 +91,7 @@ class OperationsController extends AbstractController /** * Runs common work */ - require ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $url_params['goto'] = $url_params['back'] = Url::getFromRoute('/table/operations'); $url_query .= Url::getCommon($url_params, '&'); diff --git a/libraries/classes/Controllers/Table/SearchController.php b/libraries/classes/Controllers/Table/SearchController.php index cb821c7d9a..6ceda3748e 100644 --- a/libraries/classes/Controllers/Table/SearchController.php +++ b/libraries/classes/Controllers/Table/SearchController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Relation; @@ -172,7 +173,7 @@ class SearchController extends AbstractController */ public function index(): void { - require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $header = $this->response->getHeader(); $scripts = $header->getScripts(); diff --git a/libraries/classes/Controllers/Table/SqlController.php b/libraries/classes/Controllers/Table/SqlController.php index d1ee92b63d..b40371b39b 100644 --- a/libraries/classes/Controllers/Table/SqlController.php +++ b/libraries/classes/Controllers/Table/SqlController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Response; @@ -52,7 +53,7 @@ final class SqlController extends AbstractController PageSettings::showGroup('Sql'); - require ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $err_url = Url::getFromRoute('/table/sql') . $err_url; diff --git a/libraries/classes/Controllers/Table/StructureController.php b/libraries/classes/Controllers/Table/StructureController.php index 280792a634..6e55ccbb8c 100644 --- a/libraries/classes/Controllers/Table/StructureController.php +++ b/libraries/classes/Controllers/Table/StructureController.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Controllers\Table; use PhpMyAdmin\CentralColumns; use PhpMyAdmin\Charsets; use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Common; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Controllers\SqlController; use PhpMyAdmin\Core; @@ -315,7 +316,7 @@ class StructureController extends AbstractController $table = &$this->table; $url_params = []; - include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $this->_url_query = Url::getCommonRaw([ 'db' => $db, diff --git a/libraries/classes/Controllers/Table/TrackingController.php b/libraries/classes/Controllers/Table/TrackingController.php index aea14c2a8b..b88d735421 100644 --- a/libraries/classes/Controllers/Table/TrackingController.php +++ b/libraries/classes/Controllers/Table/TrackingController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Message; use PhpMyAdmin\Response; @@ -58,7 +59,7 @@ final class TrackingController extends AbstractController $scripts->addFile('table/tracking.js'); define('TABLE_MAY_BE_ABSENT', true); - require ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); if (Tracker::isActive() && Tracker::isTracked($GLOBALS['db'], $GLOBALS['table']) diff --git a/libraries/classes/Controllers/Table/TriggersController.php b/libraries/classes/Controllers/Table/TriggersController.php index 197cbb143d..54af08203b 100644 --- a/libraries/classes/Controllers/Table/TriggersController.php +++ b/libraries/classes/Controllers/Table/TriggersController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\Rte\Triggers; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -33,10 +34,10 @@ class TriggersController extends AbstractController * Displays the header and tabs */ if (! empty($table) && in_array($table, $this->dbi->getTables($db))) { - include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); } else { $table = ''; - include_once ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); list( $tables, diff --git a/libraries/classes/Controllers/Table/ZoomSearchController.php b/libraries/classes/Controllers/Table/ZoomSearchController.php index 314654546c..fe78adf72e 100644 --- a/libraries/classes/Controllers/Table/ZoomSearchController.php +++ b/libraries/classes/Controllers/Table/ZoomSearchController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Relation; @@ -77,7 +78,7 @@ class ZoomSearchController extends AbstractController { global $goto; - require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $header = $this->response->getHeader(); $scripts = $header->getScripts(); diff --git a/libraries/classes/Controllers/ViewCreateController.php b/libraries/classes/Controllers/ViewCreateController.php index 68a19ab01a..6c678a47b8 100644 --- a/libraries/classes/Controllers/ViewCreateController.php +++ b/libraries/classes/Controllers/ViewCreateController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\Table\StructureController; use PhpMyAdmin\Core; use PhpMyAdmin\Html\Generator; @@ -29,7 +30,7 @@ class ViewCreateController extends AbstractController global $message, $sep, $sql_query, $arr, $view_columns, $column_map, $systemDb, $pma_transformation_data; global $containerBuilder, $new_transformations_sql, $view, $item, $parts, $db; - require ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); $url_params['goto'] = Url::getFromRoute('/table/structure'); $url_params['back'] = Url::getFromRoute('/view/create'); diff --git a/libraries/classes/Controllers/ViewOperationsController.php b/libraries/classes/Controllers/ViewOperationsController.php index 1be9b27f63..6e50428d9f 100644 --- a/libraries/classes/Controllers/ViewOperationsController.php +++ b/libraries/classes/Controllers/ViewOperationsController.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers; +use PhpMyAdmin\Common; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Message; @@ -52,7 +53,7 @@ class ViewOperationsController extends AbstractController $scripts = $header->getScripts(); $scripts->addFile('table/operations.js'); - require ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $url_params['goto'] = $url_params['back'] = Url::getFromRoute('/view/operations'); $url_query .= Url::getCommon($url_params, '&'); diff --git a/libraries/db_common.inc.php b/libraries/db_common.inc.php deleted file mode 100644 index 2228894196..0000000000 --- a/libraries/db_common.inc.php +++ /dev/null @@ -1,153 +0,0 @@ -isSystemSchema($db); -if ($db_is_system_schema) { - $is_show_stats = false; -} - -$relation = new Relation($dbi); -$operations = new Operations($dbi, $relation); - -/** - * Defines the urls to return to in case of error in a sql statement - */ -$err_url_0 = Url::getFromRoute('/'); - -$err_url = Util::getScriptNameForOption( - $cfg['DefaultTabDatabase'], - 'database' -); -$err_url .= Url::getCommon(['db' => $db], strpos($err_url, '?') === false ? '?' : '&'); - -/** - * Ensures the database exists (else move to the "parent" script) and displays - * headers - */ -if (! isset($is_db) || ! $is_db) { - if (strlen($db) > 0) { - $is_db = $dbi->selectDb($db); - // This "Command out of sync" 2014 error may happen, for example - // after calling a MySQL procedure; at this point we can't select - // the db but it's not necessarily wrong - if ($dbi->getError() && $errno == 2014) { - $is_db = true; - unset($errno); - } - } else { - $is_db = false; - } - // Not a valid db name -> back to the welcome page - $params = ['reload' => '1']; - if (isset($message)) { - $params['message'] = $message; - } - $uri = './index.php?route=/' . Url::getCommonRaw($params, '&'); - if (strlen($db) === 0 || ! $is_db) { - $response = Response::getInstance(); - if ($response->isAjax()) { - $response->setRequestStatus(false); - $response->addJSON( - 'message', - Message::error(__('No databases selected.')) - ); - } else { - Core::sendHeaderLocation($uri); - } - exit; - } -} // end if (ensures db exists) - -/** - * Changes database charset if requested by the user - */ -if (isset($_POST['submitcollation'], $_POST['db_collation']) && ! empty($_POST['db_collation'])) { - list($db_charset) = explode('_', $_POST['db_collation']); - $sql_query = 'ALTER DATABASE ' - . Util::backquote($db) - . ' DEFAULT' . Util::getCharsetQueryPart($_POST['db_collation']); - $result = $dbi->query($sql_query); - $message = Message::success(); - - /** - * Changes tables charset if requested by the user - */ - if (isset($_POST['change_all_tables_collations']) && - $_POST['change_all_tables_collations'] === 'on' - ) { - list($tables, , , , , , , ,) = Util::getDbInfo($db, null); - foreach ($tables as $tableName => $data) { - if ($dbi->getTable($db, $tableName)->isView()) { - // Skip views, we can not change the collation of a view. - // issue #15283 - continue; - } - $sql_query = 'ALTER TABLE ' - . Util::backquote($db) - . '.' - . Util::backquote($tableName) - . ' DEFAULT ' - . Util::getCharsetQueryPart($_POST['db_collation']); - $dbi->query($sql_query); - - /** - * Changes columns charset if requested by the user - */ - if (isset($_POST['change_all_tables_columns_collations']) && - $_POST['change_all_tables_columns_collations'] === 'on' - ) { - $operations->changeAllColumnsCollation($db, $tableName, $_POST['db_collation']); - } - } - } - unset($db_charset); - - /** - * If we are in an Ajax request, let us stop the execution here. Necessary for - * db charset change action on /database/operations. If this causes a bug on - * other pages, we might have to move this to a different location. - */ - if ($response->isAjax()) { - $response->setRequestStatus($message->isSuccess()); - $response->addJSON('message', $message); - exit; - } -} elseif (isset($_POST['submitcollation'], $_POST['db_collation']) && empty($_POST['db_collation'])) { - $response = Response::getInstance(); - if ($response->isAjax()) { - $response->setRequestStatus(false); - $response->addJSON( - 'message', - Message::error(__('No collation provided.')) - ); - } -} - -/** - * Set parameters for links - */ -$url_query = Url::getCommon(['db' => $db]); diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index e9aad44343..af33448fe8 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -7,6 +7,7 @@ declare(strict_types=1); use PhpMyAdmin\CentralColumns; +use PhpMyAdmin\Common; use PhpMyAdmin\Controllers\Database\ExportController; use PhpMyAdmin\Message; use PhpMyAdmin\MultSubmits; @@ -174,13 +175,13 @@ if (! empty($submit_mult) && ! empty($what)) { unset($message); if (strlen($table) > 0) { - include ROOT_PATH . 'libraries/tbl_common.inc.php'; + Common::table(); $url_query .= Url::getCommon([ 'goto' => Url::getFromRoute('/table/sql'), 'back' => Url::getFromRoute('/table/sql'), ], '&'); } elseif (strlen($db) > 0) { - include ROOT_PATH . 'libraries/db_common.inc.php'; + Common::database(); list( $tables, @@ -194,7 +195,7 @@ if (! empty($submit_mult) && ! empty($what)) { $pos ) = Util::getDbInfo($db, $sub_part ?? ''); } else { - include_once ROOT_PATH . 'libraries/server_common.inc.php'; + Common::server(); } // Builds the query diff --git a/libraries/server_common.inc.php b/libraries/server_common.inc.php deleted file mode 100644 index 260c2e5678..0000000000 --- a/libraries/server_common.inc.php +++ /dev/null @@ -1,46 +0,0 @@ -isUserType('grant'); -$is_createuser = $dbi->isUserType('create'); - -// now, select the mysql db -if ($dbi->isSuperuser()) { - $dbi->selectDb('mysql'); -} diff --git a/libraries/tbl_common.inc.php b/libraries/tbl_common.inc.php deleted file mode 100644 index 318e79d58a..0000000000 --- a/libraries/tbl_common.inc.php +++ /dev/null @@ -1,58 +0,0 @@ -isSystemSchema($db); - -/** - * Set parameters for links - * - * @deprecated - */ -$url_query = Url::getCommon(['db' => $db, 'table' => $table]); - -/** - * Set parameters for links - */ -$url_params = []; -$url_params['db'] = $db; -$url_params['table'] = $table; - -/** - * Defines the urls to return to in case of error in a sql statement - */ -$err_url_0 = Util::getScriptNameForOption( - $cfg['DefaultTabDatabase'], - 'database' -); -$err_url_0 .= Url::getCommon(['db' => $db], strpos($err_url_0, '?') === false ? '?' : '&'); - -$err_url = Util::getScriptNameForOption( - $cfg['DefaultTabTable'], - 'table' -); -$err_url .= Url::getCommon($url_params, strpos($err_url, '?') === false ? '?' : '&'); - -/** - * Ensures the database and the table exist (else move to the "parent" script) - * Skip test if we are exporting as we can't tell whether a table name is an alias (which would fail the test). - */ -if (($_GET['route'] ?? $_POST['route'] ?? '') === '/table/export') { - require_once ROOT_PATH . 'libraries/db_table_exists.inc.php'; -}