Skip to content

Commit

Permalink
Refactor server pages common code
Browse files Browse the repository at this point in the history
Extracts server_common.inc.php code to the Common::server() method and
removes the include file.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jan 8, 2020
1 parent 59ce2db commit a1bcb9f
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 71 deletions.
52 changes: 52 additions & 0 deletions libraries/classes/Common.php
@@ -0,0 +1,52 @@
<?php
/**
* @package PhpMyAdmin
*/
declare(strict_types=1);

namespace PhpMyAdmin;

/**
* Shared code for server 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');
}
}
}
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/HomeController.php
Expand Up @@ -12,6 +12,7 @@
use PhpMyAdmin\Charsets\Charset;
use PhpMyAdmin\Charsets\Collation;
use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Common;
use PhpMyAdmin\Config;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Display\GitRevision;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function index(array $params): string
$show_query = '1';

if ($server > 0) {
include ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();
}

$languageManager = LanguageManager::getInstance();
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/BinlogController.php
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function index(array $params): string
{
global $cfg, $pmaThemeImage;

include_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

$position = ! empty($params['pos']) ? (int) $params['pos'] : 0;

Expand Down
Expand Up @@ -11,6 +11,7 @@
use PhpMyAdmin\Charsets;
use PhpMyAdmin\Charsets\Charset;
use PhpMyAdmin\Charsets\Collation;
use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Response;
Expand Down Expand Up @@ -68,7 +69,7 @@ public function __construct(
*/
public function index(): string
{
include_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

$charsets = [];
/** @var Charset $charset */
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/DatabasesController.php
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function index(array $params): string
$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']);
Expand Down
5 changes: 3 additions & 2 deletions libraries/classes/Controllers/Server/EnginesController.php
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\StorageEngine;

Expand All @@ -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(),
Expand All @@ -41,7 +42,7 @@ public function index(): string
*/
public function show(array $params): string
{
require ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

$page = $params['page'] ?? '';

Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/ExportController.php
Expand Up @@ -6,6 +6,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function index(): void
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');

Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/ImportController.php
Expand Up @@ -6,6 +6,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Display\Import;
Expand All @@ -28,7 +29,7 @@ public function index(): void
$scripts = $header->getScripts();
$scripts->addFile('import.js');

require ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

$this->response->addHTML(Import::get(
'server',
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/PluginsController.php
Expand Up @@ -9,6 +9,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Response;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function __construct($response, $dbi, Template $template, Plugins $plugin
*/
public function index(): string
{
include ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

$header = $this->response->getHeader();
$scripts = $header->getScripts();
Expand Down
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function index(): void

Core::setPostAsGlobal($post_patterns);

require ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

/**
* Messages are built using the message name
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\ReplicationGui;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function index(array $params): string
{
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();
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/SqlController.php
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function index(): string

PageSettings::showGroup('Sql');

require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

return $this->sqlQueryForm->getHtml();
}
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server\Status;

use PhpMyAdmin\Common;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Response;
use PhpMyAdmin\Server\Status\Data;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function __construct($response, $dbi, Template $template, $data, $monitor
*/
public function index(): string
{
require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

$header = $this->response->getHeader();
$scripts = $header->getScripts();
Expand Down Expand Up @@ -89,7 +90,7 @@ public function index(): string
*/
public function chartingData(array $params): array
{
require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

if (! $this->response->isAjax()) {
return [];
Expand All @@ -110,7 +111,7 @@ public function chartingData(array $params): array
*/
public function logDataTypeSlow(array $params): array
{
require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

if (! $this->response->isAjax()) {
return [];
Expand All @@ -132,7 +133,7 @@ public function logDataTypeSlow(array $params): array
*/
public function logDataTypeGeneral(array $params): array
{
require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

if (! $this->response->isAjax()) {
return [];
Expand All @@ -156,7 +157,7 @@ public function logDataTypeGeneral(array $params): array
*/
public function loggingVars(array $params): array
{
require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

if (! $this->response->isAjax()) {
return [];
Expand All @@ -178,7 +179,7 @@ public function loggingVars(array $params): array
*/
public function queryAnalyzer(array $params): array
{
require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

if (! $this->response->isAjax()) {
return [];
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server\Status;

use PhpMyAdmin\Common;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\Util;
Expand All @@ -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();
Expand Down
Expand Up @@ -8,6 +8,8 @@

namespace PhpMyAdmin\Controllers\Server\Status;

use PhpMyAdmin\Common;

/**
* @package PhpMyAdmin\Controllers\Server\Status
*/
Expand All @@ -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();
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server\Status;

use PhpMyAdmin\Common;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\ReplicationGui;
use PhpMyAdmin\Response;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function index(): string
{
global $replication_info;

require_once ROOT_PATH . 'libraries/server_common.inc.php';
Common::server();

$traffic = [];
$connections = [];
Expand Down
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server\Status;

use PhpMyAdmin\Common;
use PhpMyAdmin\Html\Generator;

/**
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Controllers/Server/VariablesController.php
Expand Up @@ -8,6 +8,7 @@

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Util;
Expand All @@ -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'] : '';

Expand Down

0 comments on commit a1bcb9f

Please sign in to comment.