From 81645baee2c63b1cd82cc78e4a98ee5fa00a3404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Tue, 10 Mar 2020 17:10:39 -0300 Subject: [PATCH] Use early exit for Header::getDisplay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Header.php | 178 ++++++++++++++++++----------------- templates/header.twig | 7 +- 2 files changed, 93 insertions(+), 92 deletions(-) diff --git a/libraries/classes/Header.php b/libraries/classes/Header.php index 3096905b89..943cfafd59 100644 --- a/libraries/classes/Header.php +++ b/libraries/classes/Header.php @@ -375,93 +375,99 @@ class Header { global $db, $table; - if (! $this->_headerIsSent && $this->_isEnabled) { - if (! $this->_isAjax) { - $this->sendHttpHeaders(); - - $baseDir = defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : ''; - $uniqueValue = $GLOBALS['PMA_Config']->getThemeUniqueValue(); - $themePath = $GLOBALS['pmaThemePath']; - $version = self::getVersionParameter(); - - // The user preferences have been merged at this point - // so we can conditionally add CodeMirror - if ($GLOBALS['cfg']['CodemirrorEnable']) { - $this->_scripts->addFile('vendor/codemirror/lib/codemirror.js'); - $this->_scripts->addFile('vendor/codemirror/mode/sql/sql.js'); - $this->_scripts->addFile('vendor/codemirror/addon/runmode/runmode.js'); - $this->_scripts->addFile('vendor/codemirror/addon/hint/show-hint.js'); - $this->_scripts->addFile('vendor/codemirror/addon/hint/sql-hint.js'); - if ($GLOBALS['cfg']['LintEnable']) { - $this->_scripts->addFile('vendor/codemirror/addon/lint/lint.js'); - $this->_scripts->addFile( - 'codemirror/addon/lint/sql-lint.js' - ); - } - } - $this->_scripts->addCode( - 'ConsoleEnterExecutes=' - . ($GLOBALS['cfg']['ConsoleEnterExecutes'] ? 'true' : 'false') - ); - $this->_scripts->addFiles($this->_console->getScripts()); - if ($this->_userprefsOfferImport) { - $this->_scripts->addFile('config.js'); - } - - if ($this->_menuEnabled && $GLOBALS['server'] > 0) { - $nav = new Navigation( - $this->template, - new Relation($GLOBALS['dbi']), - $GLOBALS['dbi'] - ); - $navigation = $nav->getDisplay(); - } - - $customHeader = Config::renderHeader(); - - // offer to load user preferences from localStorage - if ($this->_userprefsOfferImport) { - $loadUserPreferences = $this->userPreferences->autoloadGetHeader(); - } - - if ($this->_menuEnabled && $GLOBALS['server'] > 0) { - $menu = $this->_menu->getDisplay(); - } - $console = $this->_console->getDisplay(); - $messages = $this->getMessage(); - } - if (empty($_REQUEST['recent_table'])) { - $recentTable = $this->_addRecentTable($db, $table); - } - return $this->template->render('header', [ - 'is_ajax' => $this->_isAjax, - 'is_enabled' => $this->_isEnabled, - 'lang' => $GLOBALS['lang'], - 'allow_third_party_framing' => $GLOBALS['cfg']['AllowThirdPartyFraming'], - 'is_print_view' => $this->_isPrintView, - 'base_dir' => $baseDir ?? '', - 'unique_value' => $uniqueValue ?? '', - 'theme_path' => $themePath ?? '', - 'version' => $version ?? '', - 'text_dir' => $GLOBALS['text_dir'], - 'server' => $GLOBALS['server'] ?? null, - 'title' => $this->getPageTitle(), - 'scripts' => $this->_scripts->getDisplay(), - 'body_id' => $this->_bodyId, - 'navigation' => $navigation ?? '', - 'custom_header' => $customHeader ?? '', - 'load_user_preferences' => $loadUserPreferences ?? '', - 'show_hint' => $GLOBALS['cfg']['ShowHint'], - 'is_warnings_enabled' => $this->_warningsEnabled, - 'is_menu_enabled' => $this->_menuEnabled, - 'menu' => $menu ?? '', - 'console' => $console ?? '', - 'messages' => $messages ?? '', - 'has_recent_table' => empty($_REQUEST['recent_table']), - 'recent_table' => $recentTable ?? '', - ]); + if ($this->_headerIsSent || ! $this->_isEnabled) { + return ''; } - return ''; + + $recentTable = ''; + if (empty($_REQUEST['recent_table'])) { + $recentTable = $this->_addRecentTable($db, $table); + } + + if ($this->_isAjax) { + return $recentTable; + } + + $this->sendHttpHeaders(); + + $baseDir = defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : ''; + $uniqueValue = $GLOBALS['PMA_Config']->getThemeUniqueValue(); + $themePath = $GLOBALS['pmaThemePath']; + $version = self::getVersionParameter(); + + // The user preferences have been merged at this point + // so we can conditionally add CodeMirror + if ($GLOBALS['cfg']['CodemirrorEnable']) { + $this->_scripts->addFile('vendor/codemirror/lib/codemirror.js'); + $this->_scripts->addFile('vendor/codemirror/mode/sql/sql.js'); + $this->_scripts->addFile('vendor/codemirror/addon/runmode/runmode.js'); + $this->_scripts->addFile('vendor/codemirror/addon/hint/show-hint.js'); + $this->_scripts->addFile('vendor/codemirror/addon/hint/sql-hint.js'); + if ($GLOBALS['cfg']['LintEnable']) { + $this->_scripts->addFile('vendor/codemirror/addon/lint/lint.js'); + $this->_scripts->addFile( + 'codemirror/addon/lint/sql-lint.js' + ); + } + } + + $this->_scripts->addCode( + 'ConsoleEnterExecutes=' + . ($GLOBALS['cfg']['ConsoleEnterExecutes'] ? 'true' : 'false') + ); + $this->_scripts->addFiles($this->_console->getScripts()); + + if ($this->_userprefsOfferImport) { + $this->_scripts->addFile('config.js'); + } + + if ($this->_menuEnabled && $GLOBALS['server'] > 0) { + $nav = new Navigation( + $this->template, + new Relation($GLOBALS['dbi']), + $GLOBALS['dbi'] + ); + $navigation = $nav->getDisplay(); + } + + $customHeader = Config::renderHeader(); + + // offer to load user preferences from localStorage + if ($this->_userprefsOfferImport) { + $loadUserPreferences = $this->userPreferences->autoloadGetHeader(); + } + + if ($this->_menuEnabled && $GLOBALS['server'] > 0) { + $menu = $this->_menu->getDisplay(); + } + + $console = $this->_console->getDisplay(); + $messages = $this->getMessage(); + + return $this->template->render('header', [ + 'lang' => $GLOBALS['lang'], + 'allow_third_party_framing' => $GLOBALS['cfg']['AllowThirdPartyFraming'], + 'is_print_view' => $this->_isPrintView, + 'base_dir' => $baseDir, + 'unique_value' => $uniqueValue, + 'theme_path' => $themePath, + 'version' => $version, + 'text_dir' => $GLOBALS['text_dir'], + 'server' => $GLOBALS['server'] ?? null, + 'title' => $this->getPageTitle(), + 'scripts' => $this->_scripts->getDisplay(), + 'body_id' => $this->_bodyId, + 'navigation' => $navigation ?? '', + 'custom_header' => $customHeader, + 'load_user_preferences' => $loadUserPreferences ?? '', + 'show_hint' => $GLOBALS['cfg']['ShowHint'], + 'is_warnings_enabled' => $this->_warningsEnabled, + 'is_menu_enabled' => $this->_menuEnabled, + 'menu' => $menu ?? '', + 'console' => $console, + 'messages' => $messages, + 'recent_table' => $recentTable, + ]); } /** diff --git a/templates/header.twig b/templates/header.twig index c931e8cb80..e372066d9b 100644 --- a/templates/header.twig +++ b/templates/header.twig @@ -1,5 +1,3 @@ -{% if not is_ajax and is_enabled -%} - @@ -59,8 +57,5 @@
{{ messages|raw }} -{% endif %} -{% if is_enabled and has_recent_table %} - {{ recent_table|raw }} -{% endif %} + {{ recent_table|raw }}