Merge pull request #15758 from mauriciofauth/common-includes

Remove server, db and tbl common include files
This commit is contained in:
Maurício Meneghini Fauth 2020-01-07 22:53:18 -03:00 committed by GitHub
commit 5b7e1c0e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 353 additions and 324 deletions

View File

@ -0,0 +1,239 @@
<?php
/**
* @package PhpMyAdmin
*/
declare(strict_types=1);
namespace PhpMyAdmin;
/**
* Shared code for server, database and table level pages.
*
* @package PhpMyAdmin
*/
final class Common
{
/**
* @return void
*/
public static function server(): void
{
global $db, $table, $url_query, $viewing_mode, $err_url, $is_grantuser, $is_createuser, $dbi;
/**
* Handles some variables that may have been sent by the calling script
* Note: this can be called also from the db panel to get the privileges of
* a db, in which case we want to keep displaying the tabs of
* the Database panel
*/
if (empty($viewing_mode)) {
$db = '';
$table = '';
}
/**
* Set parameters for links
*/
$url_query = Url::getCommon();
/**
* Defines the urls to return to in case of error in a sql statement
*/
$err_url = Url::getFromRoute('/');
$is_grantuser = $dbi->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';
}
}
}

View File

@ -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();

View File

@ -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,

View File

@ -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, '&');

View File

@ -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,

View File

@ -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, '&');

View File

@ -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, '&');

View File

@ -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,

View File

@ -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']) {

View File

@ -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

View File

@ -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 [];

View File

@ -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');

View File

@ -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,

View File

@ -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();

View File

@ -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;

View File

@ -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 */

View File

@ -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']);

View File

@ -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'] ?? '';

View File

@ -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');

View File

@ -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',

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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();
}

View File

@ -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 [];

View File

@ -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();

View File

@ -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();

View File

@ -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 = [];

View File

@ -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();

View File

@ -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'] : '';

View File

@ -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');
/**

View File

@ -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);

View File

@ -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'),

View File

@ -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();

View File

@ -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 = '';

View File

@ -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');

View File

@ -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'])) {

View File

@ -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, '&');

View File

@ -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();

View File

@ -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;

View File

@ -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,

View File

@ -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'])

View File

@ -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,

View File

@ -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();

View File

@ -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');

View File

@ -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, '&');

View File

@ -1,153 +0,0 @@
<?php
/**
* Common includes for the database level views
*
* @package PhpMyAdmin
*/
declare(strict_types=1);
use PhpMyAdmin\Core;
use PhpMyAdmin\Message;
use PhpMyAdmin\Operations;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
if (! defined('PHPMYADMIN')) {
exit;
}
Util::checkParameters(['db']);
global $cfg, $db, $is_show_stats, $db_is_system_schema, $err_url, $message, $dbi, $url_query, $errno, $is_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) {
$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]);

View File

@ -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

View File

@ -1,46 +0,0 @@
<?php
/**
* Shared code for server pages
*
* @package PhpMyAdmin
*/
declare(strict_types=1);
use PhpMyAdmin\Url;
if (! defined('PHPMYADMIN')) {
exit;
}
global $db, $table, $url_query, $viewing_mode, $err_url, $is_grantuser, $is_createuser, $dbi;
/**
* Handles some variables that may have been sent by the calling script
* Note: this can be called also from the db panel to get the privileges of
* a db, in which case we want to keep displaying the tabs of
* the Database panel
*/
if (empty($viewing_mode)) {
$db = $table = '';
}
/**
* Set parameters for links
*/
$url_query = Url::getCommon();
/**
* Defines the urls to return to in case of error in a sql statement
*/
$err_url = Url::getFromRoute('/');
/**
* @global boolean Checks for superuser privileges
*/
$is_grantuser = $dbi->isUserType('grant');
$is_createuser = $dbi->isUserType('create');
// now, select the mysql db
if ($dbi->isSuperuser()) {
$dbi->selectDb('mysql');
}

View File

@ -1,58 +0,0 @@
<?php
/**
* Common includes for the table level views
*
* @package PhpMyAdmin
*/
declare(strict_types=1);
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
if (! defined('PHPMYADMIN')) {
exit;
}
global $db, $table, $db_is_system_schema, $url_query, $url_params, $cfg, $dbi;
// Check parameters
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';
}