From b598e40c1b388857ff1f0856401a1a030ba3003f Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 22 May 2012 14:02:49 +0100 Subject: [PATCH 01/82] Return string from PMA_userprefs_autoload_header() --- libraries/header.inc.php | 2 +- libraries/user_preferences.lib.php | 49 +++++++++++++++++++----------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/libraries/header.inc.php b/libraries/header.inc.php index be455590a3..e4a51b8514 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -95,7 +95,7 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { // offer to load user preferences from localStorage if ($userprefs_offer_import) { include_once './libraries/user_preferences.lib.php'; - PMA_userprefs_autoload_header(); + echo PMA_userprefs_autoload_header(); } // add recently used table and reload the navigation diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php index 083e7016cd..cd5c5492b8 100644 --- a/libraries/user_preferences.lib.php +++ b/libraries/user_preferences.lib.php @@ -270,29 +270,42 @@ function PMA_userprefs_redirect(array $forms, array $old_settings, $file_name, } /** - * Shows form which allows to quickly load settings stored in browser's local storage + * Shows form which allows to quickly load + * settings stored in browser's local storage * + * @return string */ function PMA_userprefs_autoload_header() { - if (isset($_REQUEST['prefs_autoload']) && $_REQUEST['prefs_autoload'] == 'hide') { + $retval = ''; + + if (isset($_REQUEST['prefs_autoload']) + && $_REQUEST['prefs_autoload'] == 'hide' + ) { $_SESSION['userprefs_autoload'] = true; - exit; + } else { + $script_name = basename(basename($GLOBALS['PMA_PHP_SELF'])); + $return_url = htmlspecialchars( + $script_name . '?' . http_build_query($_GET, '', '&') + ); + + $retval .= ''; } - $script_name = basename(basename($GLOBALS['PMA_PHP_SELF'])); - $return_url = $script_name . '?' . http_build_query($_GET, '', '&'); - ?> - - From 315fa0af0458f4647b196e05aa23c919b9e66746 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 22 May 2012 14:03:28 +0100 Subject: [PATCH 02/82] Renamed PMA_userprefs_autoload_header() to PMA_userprefsAutoloadGetHeader() --- libraries/header.inc.php | 2 +- libraries/user_preferences.lib.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/header.inc.php b/libraries/header.inc.php index e4a51b8514..551b6e92c7 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -95,7 +95,7 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { // offer to load user preferences from localStorage if ($userprefs_offer_import) { include_once './libraries/user_preferences.lib.php'; - echo PMA_userprefs_autoload_header(); + echo PMA_userprefsAutoloadGetHeader(); } // add recently used table and reload the navigation diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php index cd5c5492b8..6c9e51b451 100644 --- a/libraries/user_preferences.lib.php +++ b/libraries/user_preferences.lib.php @@ -275,7 +275,7 @@ function PMA_userprefs_redirect(array $forms, array $old_settings, $file_name, * * @return string */ -function PMA_userprefs_autoload_header() +function PMA_userprefsAutoloadGetHeader() { $retval = ''; From d6f58a27e38edad0c7132198a43b0779eac89748 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 22 May 2012 14:15:25 +0100 Subject: [PATCH 03/82] Return string from PMA_reloadNavigation() --- libraries/common.lib.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 1b1d9b82eb..44d4454ac3 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -941,6 +941,7 @@ function PMA_whichCrlf() */ function PMA_reloadNavigation($jsonly = false) { + $retval = ''; // Reloads the navigation frame via JavaScript if required if (isset($GLOBALS['reload']) && $GLOBALS['reload']) { // one of the reasons for a reload is when a table is dropped @@ -948,29 +949,29 @@ function PMA_reloadNavigation($jsonly = false) // we have a problem when dropping a table on the last page // and the offset becomes greater than the total number of tables unset($_SESSION['tmp_user_values']['table_limit_offset']); - echo "\n"; $reload_url = './navigation.php?' . PMA_generate_common_url( $GLOBALS['db'], '', '&' ); if (! $jsonly) { - echo '' . PHP_EOL; + $retval .= '' . PHP_EOL; } unset($GLOBALS['reload']); } + return $retval; } /** From d817f6cccc7eb14294c2618235a6eaff99e530bd Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 22 May 2012 14:19:10 +0100 Subject: [PATCH 04/82] Renamed PMA_reloadNavigation() to PMA_getReloadNavigationScript() --- libraries/common.lib.php | 2 +- libraries/display_import.lib.php | 2 +- libraries/header_scripts.inc.php | 2 +- server_privileges.php | 4 ++-- test/libraries/core/PMA_headerLocation_test_disabled.php | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 44d4454ac3..1d890ffd47 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -939,7 +939,7 @@ function PMA_whichCrlf() * * @access public */ -function PMA_reloadNavigation($jsonly = false) +function PMA_getReloadNavigationScript($jsonly = false) { $retval = ''; // Reloads the navigation frame via JavaScript if required diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index f8ff0c25eb..b25a679525 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -130,7 +130,7 @@ if ($_SESSION[$SESSION_KEY]["handler"]!="noplugin") { } // if finished diff --git a/libraries/header_scripts.inc.php b/libraries/header_scripts.inc.php index 61fc2643d9..3ea96d37e6 100644 --- a/libraries/header_scripts.inc.php +++ b/libraries/header_scripts.inc.php @@ -90,6 +90,6 @@ foreach ($GLOBALS['js_events'] as $js_event) { diff --git a/server_privileges.php b/server_privileges.php index 006f2e8933..5606079f60 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -1184,7 +1184,7 @@ if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) { // this is needed in case tracking is on: $GLOBALS['db'] = $username; $GLOBALS['reload'] = true; - PMA_reloadNavigation(); + echo PMA_getReloadNavigationScript(); } $q = 'GRANT ALL PRIVILEGES ON ' @@ -1474,7 +1474,7 @@ if (isset($_REQUEST['delete']) || (isset($_REQUEST['change_copy']) && $_REQUEST[ $GLOBALS['reload'] = true; if ($GLOBALS['is_ajax_request'] != true) { - PMA_reloadNavigation(); + echo PMA_getReloadNavigationScript(); } } } diff --git a/test/libraries/core/PMA_headerLocation_test_disabled.php b/test/libraries/core/PMA_headerLocation_test_disabled.php index 240352ff69..4869483b40 100644 --- a/test/libraries/core/PMA_headerLocation_test_disabled.php +++ b/test/libraries/core/PMA_headerLocation_test_disabled.php @@ -277,7 +277,7 @@ class PMA_headerLocation_test extends PHPUnit_Framework_TestCase $GLOBALS['db'] = 'test_db'; $url = './navigation.php?'.PMA_generate_common_url($GLOBALS['db'], '', '&'); - $write = PHP_EOL . '' . PHP_EOL; $this->expectOutputString($write); - PMA_reloadNavigation(); + echo PMA_getReloadNavigationScript(); $this->assertFalse(isset($GLOBALS['reload'])); unset($GLOBALS['db']); From 65f11c69468f7beb2ff5143787195366995660a2 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 22 May 2012 14:30:36 +0100 Subject: [PATCH 05/82] Return string from PMA_addRecentTable() --- libraries/header.inc.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 551b6e92c7..f1602eda97 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -22,13 +22,17 @@ require_once 'libraries/Menu.class.php'; */ function PMA_addRecentTable($db, $table) { - $tmp_result = PMA_RecentTable::getInstance()->add($db, $table); - if ($tmp_result === true) { - echo ''; - } else { - $error = $tmp_result; - $error->display(); + $retval = ''; + if (strlen($table) && $GLOBALS['cfg']['LeftRecentTable'] > 0) { + $tmp_result = PMA_RecentTable::getInstance()->add($db, $table); + if ($tmp_result === true) { + $retval = ''; + } else { + $error = $tmp_result; + $retval = $error->getDisplay(); + } } + return $retval; } /** @@ -99,9 +103,7 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { } // add recently used table and reload the navigation - if (strlen($GLOBALS['table']) && $GLOBALS['cfg']['LeftRecentTable'] > 0) { - PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']); - } + echo PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']); if (! defined('PMA_DISPLAY_HEADING')) { define('PMA_DISPLAY_HEADING', 1); From 97449dae42a11cfa7f4571aaadeab3fefc30acf7 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 23 May 2012 21:22:08 +0100 Subject: [PATCH 06/82] New classes PMA_Header and PMA_Scripts --- libraries/Header.class.php | 235 ++++++++++++++++++++++++++++++++++++ libraries/Menu.class.php | 23 +++- libraries/Scripts.class.php | 134 ++++++++++++++++++++ libraries/common.inc.php | 5 + 4 files changed, 394 insertions(+), 3 deletions(-) create mode 100644 libraries/Header.class.php create mode 100644 libraries/Scripts.class.php diff --git a/libraries/Header.class.php b/libraries/Header.class.php new file mode 100644 index 0000000000..e59f1caf4d --- /dev/null +++ b/libraries/Header.class.php @@ -0,0 +1,235 @@ +_menu = PMA_Menu::getInstance(); + $this->_scripts = new PMA_Scripts(); + $this->headerIsSent = false; + // if database storage for user preferences is transient, + // offer to load exported settings from localStorage + // (detection will be done in JavaScript) + $this->_userprefs_offer_import = false; + if ($GLOBALS['PMA_Config']->get('user_preferences') == 'session' + && ! isset($_SESSION['userprefs_autoload']) + ) { + $this->_userprefs_offer_import = true; + } + } + + public static function getInstance() + { + if (empty(self::$_instance)) { + self::$_instance = new PMA_Header(); + } + return self::$_instance; + } + + public function getScripts() + { + return $this->_scripts; + } + + public function display() + { + echo $this->getDisplay(); + } + + public function getDisplay() + { + $retval = ''; + if (! $this->headerIsSent) { + $this->headerIsSent = true; + $this->sendHttpHeaders(); + if ($GLOBALS['is_ajax_request'] === false) { + $retval .= $this->_getHtmlStart(); + $retval .= $this->_getMetaTags(); + $retval .= $this->_getLinkTags(); + $retval .= $this->_getTitleTag(); + if ($this->_userprefs_offer_import) { + $this->_scripts->addFile('config.js'); + } + $retval .= $this->_scripts->getDisplay(); + $retval .= $this->_getBodyStart(); + // Include possible custom headers + if (file_exists(CUSTOM_HEADER_FILE)) { + ob_start(); + include CUSTOM_HEADER_FILE; + $retval .= ob_end_clean(); + } + // offer to load user preferences from localStorage + if ($this->_userprefs_offer_import) { + include_once './libraries/user_preferences.lib.php'; + $retval .= PMA_userprefsAutoloadGetHeader(); + } + // pass configuration for hint tooltip display + // (to be used by PMA_createqTip in js/functions.js) + if (! $GLOBALS['cfg']['ShowHint']) { + $retval .= ''; + } + $retval .= $this->_getWarnings(); + if (! defined('PMA_DISPLAY_HEADING')) { + define('PMA_DISPLAY_HEADING', 1); + } + if (PMA_DISPLAY_HEADING && $GLOBALS['server'] > 0) { + $retval .= $this->_menu->getDisplay(); + } + $retval .= $this->_addRecentTable( + $GLOBALS['db'], + $GLOBALS['table'] + ); + } + } + return $retval; + } + + public function sendHttpHeaders() + { + $this->headerIsSent = true; + /** + * Starts output buffering work + */ + PMA_outBufferPre(); + /** + * Sends http headers + */ + $GLOBALS['now'] = gmdate('D, d M Y H:i:s') . ' GMT'; + /* Prevent against ClickJacking by allowing frames only from same origin */ + if (! $GLOBALS['cfg']['AllowThirdPartyFraming']) { + header('X-Frame-Options: SAMEORIGIN'); + header("X-Content-Security-Policy: allow 'self'; options inline-script eval-script; frame-ancestors 'self'; img-src 'self' data:; script-src 'self' http://www.phpmyadmin.net"); + header("X-WebKit-CSP: allow 'self' http://www.phpmyadmin.net; options inline-script eval-script"); + } + if (! defined('IS_TRANSFORMATION_WRAPPER')) { + // Define the charset to be used + header('Content-Type: text/html; charset=utf-8'); + } + PMA_no_cache_header(); + } + + private function _getHtmlStart() + { + $lang = $GLOBALS['available_languages'][$GLOBALS['lang']][1]; + $dir = $GLOBALS['text_dir']; + + $retval = ""; + $retval .= ""; + + return $retval; + } + + private function _getMetaTags() + { + $retval = ''; + $retval .= ''; + return $retval; + } + + private function _getLinkTags() + { + $retval = ''; + $retval .= ''; + + // stylesheets + $basedir = defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : ''; + $common_url = PMA_generate_common_url(array('server' => $GLOBALS['server'])); + $theme_id = $GLOBALS['PMA_Config']->getThemeUniqueValue(); + $theme_path = $GLOBALS['pmaThemePath']; + + $retval .= ''; + $retval .= ''; + $retval .= ''; + + return $retval; + } + + private function _getTitleTag() + { + $retval = ""; + if (empty($GLOBALS['page_title'])) { + $retval .= 'phpMyAdmin'; + } else { + $retval .= htmlspecialchars($GLOBALS['page_title']); + } + $retval .= ""; + return $retval; + } + + private function _getBodyStart() + { + return ""; + } + + private function _getWarnings() + { + $retval = ''; + // message of "Cookies required" displayed for auth_type http or config + // note: here, the decoration won't work because without cookies, + // our standard CSS is not operational + if (empty($_COOKIE)) { + $retval .= PMA_Message::notice( + __('Cookies must be enabled past this point.') + )->getDisplay(); + } + $retval .= ""; + return $retval; + } + + /** + * Add recently used table and reload the navigation. + * + * @param string $db Database name where the table is located. + * @param string $table The table name + */ + private function _addRecentTable($db, $table) + { + $retval = ''; + if (strlen($table) && $GLOBALS['cfg']['LeftRecentTable'] > 0) { + $tmp_result = PMA_RecentTable::getInstance()->add($db, $table); + if ($tmp_result === true) { + $retval = ''; + } else { + $error = $tmp_result; + $retval = $error->getDisplay(); + } + } + return $retval; + } +} + +?> diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 4d4f5d668f..5b234346d2 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -86,12 +86,29 @@ class PMA_Menu */ public function display() { - echo $this->_getBreadcrumbs(); - echo $this->_getMenu(); + echo $this->getDisplay(); + } + + /** + * Returns the menu and the breadcrumbs as a string + * + * @return string + */ + public function getDisplay() + { + $retval = $this->_getBreadcrumbs(); + $retval .= $this->_getMenu(); if (! empty($GLOBALS['message'])) { - echo PMA_getMessage($GLOBALS['message']); + if (isset($GLOBALS['buffer_message'])) { + $buffer_message = $GLOBALS['buffer_message']; + } + $retval .= PMA_getMessage($GLOBALS['message']); unset($GLOBALS['message']); + if (isset($buffer_message)) { + $GLOBALS['buffer_message'] = $buffer_message; + } } + return $retval; } /** diff --git a/libraries/Scripts.class.php b/libraries/Scripts.class.php new file mode 100644 index 0000000000..9e8768fb52 --- /dev/null +++ b/libraries/Scripts.class.php @@ -0,0 +1,134 @@ +_files = array(); + $this->_code = ''; + $this->_events = array(); + // Include default scripts + $this->_addDefaults(); + + } + + public function addFile($filename) + { + if (! in_array($filename, $this->_files)) { + $this->_files[] = $filename; + } + } + + public function addCode($code) + { + $this->_code .= "$code\n"; + } + + public function addEvent($event, $function) + { + $this->_events[] = array( + 'event' => $event, + 'function' => $function + ); + } + + private function _addDefaults() + { + $this->addFile('jquery/jquery-1.6.2.js'); + $this->addFile('jquery/jquery-ui-1.8.16.custom.js'); + $this->addFile('jquery/jquery.sprintf.js'); + $this->addFile('update-location.js'); + + $this->addFile('functions.js'); + $this->addFile('jquery/jquery.qtip-1.0.0-rc3.js'); + if ($GLOBALS['cfg']['CodemirrorEnable']) { + $this->addFile('codemirror/lib/codemirror.js'); + $this->addFile('codemirror/mode/mysql/mysql.js'); + } + // Cross-framing protection + if ($GLOBALS['cfg']['AllowThirdPartyFraming'] === false) { + $this->addFile('cross_framing_protection.js'); + } + // Localised strings + $params = array('lang' => $GLOBALS['lang']); + if (isset($GLOBALS['db'])) { + $params['db'] = $GLOBALS['db']; + } + $this->addFile('messages.php' . PMA_generate_common_url($params)); + // Append the theme id to this url to invalidate + // the cache on a theme change + $this->addFile( + 'get_image.js.php?theme=' + . urlencode($_SESSION['PMA_Theme']->getId()) + ); + + // generate title (unless we already have + // $GLOBALS['page_title'], from cookie auth) + if (! isset($GLOBALS['page_title'])) { + if ($GLOBALS['server'] > 0) { + if (! empty($GLOBALS['table'])) { + $temp_title = $GLOBALS['cfg']['TitleTable']; + } else if (! empty($GLOBALS['db'])) { + $temp_title = $GLOBALS['cfg']['TitleDatabase']; + } elseif (! empty($GLOBALS['cfg']['Server']['host'])) { + $temp_title = $GLOBALS['cfg']['TitleServer']; + } else { + $temp_title = $GLOBALS['cfg']['TitleDefault']; + } + $title = PMA_expandUserString($temp_title); + } + } else { + $title = $GLOBALS['page_title']; + } + if (isset($title)) { + $title = PMA_sanitize( + PMA_escapeJsString($title), + false, + true + ); + $this->addCode( + "if (typeof(parent.document) != 'undefined'" + . " && typeof(parent.document) != 'unknown'" + . " && typeof(parent.document.title) == 'string')" + . "{" + . "parent.document.title = '$title'" + . "}" + ); + } + $this->addCode(PMA_getReloadNavigationScript(true)); + } + + public function getDisplay() + { + $retval = ''; + + foreach ($this->_files as $file) { + $retval .= PMA_includeJS($file); + } + $retval .= ''; + + return $retval; + } +} diff --git a/libraries/common.inc.php b/libraries/common.inc.php index c3a0f6a2f8..6054355c06 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -1106,4 +1106,9 @@ if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) { include $__redirect; exit(); } + +/** + * Used to generate the header of the page + */ +include_once 'libraries/Header.class.php'; ?> From 4a740376c89755698ae5fac3746eb57ba07142ae Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 23 May 2012 21:25:48 +0100 Subject: [PATCH 07/82] Dropped header.inc.php in favor of the PMA_Header class --- chk_rel.php | 2 +- db_create.php | 4 - db_events.php | 7 +- db_export.php | 3 +- db_import.php | 3 +- db_operations.php | 3 +- db_routines.php | 7 +- db_search.php | 9 +- db_sql.php | 7 +- db_structure.php | 7 +- db_tracking.php | 3 +- db_triggers.php | 6 +- export.php | 7 +- import.php | 2 +- libraries/PDF.class.php | 2 +- libraries/auth/config.auth.lib.php | 2 +- libraries/common.inc.php | 41 ++---- libraries/common.lib.php | 2 +- libraries/core.lib.php | 2 +- libraries/db_common.inc.php | 5 +- libraries/display_tbl.lib.php | 2 +- libraries/header.inc.php | 137 ------------------ libraries/header_printview.inc.php | 2 +- libraries/header_scripts.inc.php | 2 +- libraries/insert_edit.lib.php | 4 +- libraries/mult_submits.inc.php | 1 - .../schema/Export_Relation_Schema.class.php | 2 +- libraries/server_common.inc.php | 4 +- libraries/tbl_common.inc.php | 2 +- main.php | 2 +- prefs_forms.php | 5 +- prefs_manage.php | 7 +- querywindow.php | 20 +-- server_databases.php | 4 +- server_export.php | 6 +- server_import.php | 3 +- server_plugins.php | 7 +- server_privileges.php | 5 +- server_replication.php | 6 +- server_sql.php | 6 +- server_status.php | 28 ++-- server_synchronize.php | 3 +- server_variables.php | 3 +- sql.php | 41 +++--- tbl_addfield.php | 2 +- tbl_alter.php | 2 - tbl_change.php | 12 +- tbl_chart.php | 11 +- tbl_create.php | 3 +- tbl_export.php | 3 +- tbl_gis_visualization.php | 13 +- tbl_import.php | 3 +- tbl_indexes.php | 3 +- tbl_printview.php | 4 +- tbl_relation.php | 3 +- tbl_replace.php | 14 +- tbl_select.php | 13 +- tbl_sql.php | 6 +- tbl_structure.php | 6 +- tbl_zoom_select.php | 29 ++-- transformation_overview.php | 3 +- transformation_wrapper.php | 6 +- user_password.php | 11 +- 63 files changed, 211 insertions(+), 362 deletions(-) delete mode 100644 libraries/header.inc.php diff --git a/chk_rel.php b/chk_rel.php index 3e8a0269bb..ccf62af5f7 100644 --- a/chk_rel.php +++ b/chk_rel.php @@ -10,7 +10,7 @@ * Gets some core libraries */ require_once 'libraries/common.inc.php'; -require_once 'libraries/header.inc.php'; +PMA_Header::getInstance()->display(); /** diff --git a/db_create.php b/db_create.php index 0dff8e4553..c0618b1ca8 100644 --- a/db_create.php +++ b/db_create.php @@ -9,7 +9,6 @@ * Gets some core libraries */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'functions.js'; require_once 'libraries/mysql_charsets.lib.php'; if (! PMA_DRIZZLE) { @@ -67,8 +66,6 @@ if (! $result) { if ($GLOBALS['is_ajax_request'] == true) { PMA_ajaxResponse($message, false); } - - include_once 'libraries/header.inc.php'; include_once 'main.php'; } else { $message = PMA_Message::success(__('Database %1$s has been created.')); @@ -145,7 +142,6 @@ if (! $result) { PMA_ajaxResponse($message, true, $extra_data); } - include_once 'libraries/header.inc.php'; include_once '' . $cfg['DefaultTabDatabase']; } ?> diff --git a/db_events.php b/db_events.php index 84deaade94..af1d0a2926 100644 --- a/db_events.php +++ b/db_events.php @@ -15,9 +15,10 @@ require_once 'libraries/common.lib.php'; /** * Include JavaScript libraries */ -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; -$GLOBALS['js_include'][] = 'rte/common.js'; -$GLOBALS['js_include'][] = 'rte/events.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('jquery/timepicker.js'); +$scripts->addFile('rte/common.js'); +$scripts->addFile('rte/events.js'); /** * Include all other files diff --git a/db_export.php b/db_export.php index 732b88b217..ae937f6d1c 100644 --- a/db_export.php +++ b/db_export.php @@ -11,7 +11,8 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'export.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('export.js'); // $sub_part is also used in db_info.inc.php to see if we are coming from // db_export.php, in which case we don't obey $cfg['MaxTableList'] diff --git a/db_import.php b/db_import.php index 146e331e9c..e804657928 100644 --- a/db_import.php +++ b/db_import.php @@ -10,7 +10,8 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'import.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('import.js'); /** * Gets tables informations and displays top links diff --git a/db_operations.php b/db_operations.php index 5a04bde59c..8771d11d6c 100644 --- a/db_operations.php +++ b/db_operations.php @@ -19,7 +19,8 @@ require_once 'libraries/common.inc.php'; require_once 'libraries/mysql_charsets.lib.php'; // add a javascript file for jQuery functions to handle Ajax actions -$GLOBALS['js_include'][] = 'db_operations.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('db_operations.js'); /** * Sets globals from $_REQUEST (we're using GET on ajax, POST otherwise) diff --git a/db_routines.php b/db_routines.php index 0dd2e66c44..b9d9cdc1b1 100644 --- a/db_routines.php +++ b/db_routines.php @@ -16,9 +16,10 @@ require_once 'libraries/mysql_charsets.lib.php'; /** * Include JavaScript libraries */ -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; -$GLOBALS['js_include'][] = 'rte/common.js'; -$GLOBALS['js_include'][] = 'rte/routines.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('jquery/timepicker.js'); +$scripts->addFile('rte/common.js'); +$scripts->addFile('rte/routines.js'); /** * Include all other files diff --git a/db_search.php b/db_search.php index 17571a7cd7..4faa1ace6f 100644 --- a/db_search.php +++ b/db_search.php @@ -13,10 +13,11 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'db_search.js'; -$GLOBALS['js_include'][] = 'sql.js'; -$GLOBALS['js_include'][] = 'makegrid.js'; -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('db_search.js'); +$scripts->addFile('sql.js'); +$scripts->addFile('makegrid.js'); +$scripts->addFile('jquery/timepicker.js'); /** * Gets some core libraries and send headers diff --git a/db_sql.php b/db_sql.php index c4b5c84111..2fdeb0a8c6 100644 --- a/db_sql.php +++ b/db_sql.php @@ -13,9 +13,10 @@ require_once 'libraries/common.inc.php'; /** * Runs common work */ -$GLOBALS['js_include'][] = 'functions.js'; -$GLOBALS['js_include'][] = 'makegrid.js'; -$GLOBALS['js_include'][] = 'sql.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('functions.js'); +$scripts->addFile('makegrid.js'); +$scripts->addFile('sql.js'); require 'libraries/db_common.inc.php'; require_once 'libraries/sql_query_form.lib.php'; diff --git a/db_structure.php b/db_structure.php index 302e036850..d337c24e7d 100644 --- a/db_structure.php +++ b/db_structure.php @@ -10,9 +10,10 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'db_structure.js'; -$GLOBALS['js_include'][] = 'tbl_change.js'; -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('db_structure.js'); +$scripts->addFile('tbl_change.js'); +$scripts->addFile('jquery/timepicker.js'); /** * Sets globals from $_POST diff --git a/db_tracking.php b/db_tracking.php index e151977baf..5573f56203 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -10,7 +10,8 @@ require_once 'libraries/common.inc.php'; //Get some js files needed for Ajax requests -$GLOBALS['js_include'][] = 'db_structure.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('db_structure.js'); /** * If we are not in an Ajax request, then do the common work and show the links etc. diff --git a/db_triggers.php b/db_triggers.php index d94ea90d69..80db582947 100644 --- a/db_triggers.php +++ b/db_triggers.php @@ -10,13 +10,13 @@ * Include required files */ require_once 'libraries/common.inc.php'; -require_once 'libraries/common.lib.php'; /** * Include JavaScript libraries */ -$GLOBALS['js_include'][] = 'rte/common.js'; -$GLOBALS['js_include'][] = 'rte/triggers.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('rte/common.js'); +$scripts->addFile('rte/triggers.js'); /** * Include all other files diff --git a/export.php b/export.php index 5b49a3145f..20432ab750 100644 --- a/export.php +++ b/export.php @@ -88,7 +88,6 @@ if ($_REQUEST['output_format'] == 'astext') { // Does export require to be into file? if (isset($export_list[$type]['force_file']) && ! $asfile) { $message = PMA_Message::error(__('Selected export type has to be saved in file!')); - include_once 'libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; include 'server_export.php'; @@ -369,7 +368,6 @@ if ($save_on_server) { } } if (isset($message)) { - include_once 'libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; include 'server_export.php'; @@ -403,14 +401,13 @@ if (! $save_on_server) { $num_tables = count($tables); if ($num_tables == 0) { $message = PMA_Message::error(__('No tables found in database.')); - include_once 'libraries/header.inc.php'; $active_page = 'db_export.php'; include 'db_export.php'; exit(); } } $backup_cfgServer = $cfg['Server']; - include_once 'libraries/header.inc.php'; + PMA_Header::getInstance()->display(); $cfg['Server'] = $backup_cfgServer; unset($backup_cfgServer); echo "\n" . '
' . "\n"; @@ -720,7 +717,6 @@ do { // End of fake loop if ($save_on_server && isset($message)) { - include_once 'libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; include 'server_export.php'; @@ -788,7 +784,6 @@ if (! empty($asfile)) { ); } - include_once 'libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; include_once 'server_export.php'; diff --git a/import.php b/import.php index 1c93cc119f..f801c9bbde 100644 --- a/import.php +++ b/import.php @@ -83,7 +83,7 @@ if (! empty($sql_query)) { // upload limit has been reached, let's assume the second possibility. ; if ($_POST == array() && $_GET == array()) { - include_once 'libraries/header.inc.php'; + PMA_Header::getInstance()->display(); $message = PMA_Message::error(__('You probably tried to upload too large file. Please refer to %sdocumentation%s for ways to workaround this limit.')); $message->addParam('[a@./Documentation.html#faq1_16@_blank]'); $message->addParam('[/a]'); diff --git a/libraries/PDF.class.php b/libraries/PDF.class.php index 99ea2035a9..6a2597cdd6 100644 --- a/libraries/PDF.class.php +++ b/libraries/PDF.class.php @@ -85,7 +85,7 @@ class PMA_PDF extends TCPDF */ function Error($error_message = '') { - include './libraries/header.inc.php'; + PMA_Header::getInstance()->display(); PMA_Message::error(__('Error while creating PDF:') . ' ' . $error_message)->display(); include './libraries/footer.inc.php'; } diff --git a/libraries/auth/config.auth.lib.php b/libraries/auth/config.auth.lib.php index fbe39e7c8b..461a2862ef 100644 --- a/libraries/auth/config.auth.lib.php +++ b/libraries/auth/config.auth.lib.php @@ -93,7 +93,7 @@ function PMA_auth_fails() isHeaderSent = true; if (isset($GLOBALS['allowDeny_forbidden']) && $GLOBALS['allowDeny_forbidden']) { trigger_error(__('Access denied'), E_USER_NOTICE); diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 6054355c06..df979aebe7 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -149,6 +149,10 @@ if (!defined('PMA_MINIMUM_COMMON')) { /******************************************************************************/ /* start procedural code label_start_procedural */ +if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) { + PMA_fatalError(__("GLOBALS overwrite attempt")); +} + /** * protect against possible exploits - there is no need to have so much variables */ @@ -558,34 +562,6 @@ if (PMA_isValid($_REQUEST['sql_query'])) { //$_REQUEST['server']; // checked later in this file //$_REQUEST['lang']; // checked by LABEL_loading_language_file - -/** - * holds name of JavaScript files to be included in HTML header - * @global array $js_include - */ -$GLOBALS['js_include'] = array(); -$GLOBALS['js_include'][] = 'jquery/jquery-1.6.2.js'; -$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js'; -$GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js'; -$GLOBALS['js_include'][] = 'update-location.js'; - -/** - * holds an array of javascript code snippets to be included in the HTML header - * Can be used with PMA_addJSCode() to pass on js variables to the browser. - * @global array $js_script - */ -$GLOBALS['js_script'] = array(); - -/** - * Add common jQuery functions script here if necessary. - */ - -/** - * JavaScript events that will be registered - * @global array $js_events - */ -$GLOBALS['js_events'] = array(); - /** * footnotes to be displayed ot the page bottom * @global array $footnotes @@ -600,6 +576,15 @@ $GLOBALS['footnotes'] = array(); */ require './libraries/select_lang.lib.php'; +// Defines the cell alignment values depending on text direction +if ($GLOBALS['text_dir'] == 'ltr') { + $GLOBALS['cell_align_left'] = 'left'; + $GLOBALS['cell_align_right'] = 'right'; +} else { + $GLOBALS['cell_align_left'] = 'right'; + $GLOBALS['cell_align_right'] = 'left'; +} + /** * check for errors occurred while loading configuration * this check is done here after loading language files to present errors in locale diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 1d890ffd47..01d971493b 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -598,7 +598,7 @@ function PMA_mysqlDie( /** * start http output, display html headers */ - include_once './libraries/header.inc.php'; + PMA_Header::getInstance()->display(); $error_msg = ''; diff --git a/libraries/core.lib.php b/libraries/core.lib.php index ffcde8c867..1a1c3ea4e6 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -783,7 +783,7 @@ function PMA_includeJS($url, $ie_conditional = false) */ function PMA_addJSCode($str) { - $GLOBALS['js_script'][] = $str; + PMA_Header::getInstance()->getScripts()->addCode($str); } /** diff --git a/libraries/db_common.inc.php b/libraries/db_common.inc.php index 296685cdb4..d8c40cb390 100644 --- a/libraries/db_common.inc.php +++ b/libraries/db_common.inc.php @@ -76,7 +76,10 @@ if (isset($submitcollation) && !empty($db_collation)) { }; } -require_once './libraries/header.inc.php'; +/** + * Displays headers + */ +PMA_Header::getInstance()->display(); /** * Set parameters for links diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 8287dbe335..dc8a41200f 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1061,7 +1061,7 @@ function PMA_getTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, } elseif ((($GLOBALS['cfg']['RowActionLinks'] == 'left') || ($GLOBALS['cfg']['RowActionLinks'] == 'both')) && (($is_display['edit_lnk'] == 'nn') && ($is_display['del_lnk'] == 'nn')) - && (! isset($GLOBALS['is_header_sent']) || ! $GLOBALS['is_header_sent']) + && ! PMA_Header::getInstance()->headerIsSent ) { // ... elseif no button, displays empty columns if required // (unless coming from Browse mode print view) diff --git a/libraries/header.inc.php b/libraries/header.inc.php deleted file mode 100644 index f1602eda97..0000000000 --- a/libraries/header.inc.php +++ /dev/null @@ -1,137 +0,0 @@ - 0) { - $tmp_result = PMA_RecentTable::getInstance()->add($db, $table); - if ($tmp_result === true) { - $retval = ''; - } else { - $error = $tmp_result; - $retval = $error->getDisplay(); - } - } - return $retval; -} - -/** - * This is not an Ajax request so we need to generate all this output. - */ -if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { - - if (empty($GLOBALS['is_header_sent'])) { - - /** - * Gets a core script and starts output buffering work - */ - include_once './libraries/ob.lib.php'; - PMA_outBufferPre(); - - // if database storage for user preferences is transient, offer to load - // exported settings from localStorage (detection will be done in JavaScript) - $userprefs_offer_import = $GLOBALS['PMA_Config']->get('user_preferences') == 'session' - && ! isset($_SESSION['userprefs_autoload']); - if ($userprefs_offer_import) { - $GLOBALS['js_include'][] = 'config.js'; - } - - // For re-usability, moved http-headers and stylesheets - // to a seperate file. It can now be included by header.inc.php, - // querywindow.php. - - include_once './libraries/header_http.inc.php'; - include_once './libraries/header_meta_style.inc.php'; - include_once './libraries/header_scripts.inc.php'; - - /* remove vertical scroll bar bug in ie */ ?> - - - - - display(); - } - - echo "\n"; - - // offer to load user preferences from localStorage - if ($userprefs_offer_import) { - include_once './libraries/user_preferences.lib.php'; - echo PMA_userprefsAutoloadGetHeader(); - } - - // add recently used table and reload the navigation - echo PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']); - - if (! defined('PMA_DISPLAY_HEADING')) { - define('PMA_DISPLAY_HEADING', 1); - } - - // pass configuration for hint tooltip display - // (to be used by PMA_createqTip in js/functions.js) - if (! $GLOBALS['cfg']['ShowHint']) { - echo ''; - } - - /** - * Display heading if needed. Design can be set in css file. - */ - if (PMA_DISPLAY_HEADING && $GLOBALS['server'] > 0) { - PMA_Menu::getInstance()->display(); - } - } - - /** - * Sets a variable to remember headers have been sent - */ - $GLOBALS['is_header_sent'] = true; - //end if (!$GLOBALS['is_ajax_request']) -} else { - if (empty($GLOBALS['is_header_sent'])) { - include_once './libraries/header_http.inc.php'; - $GLOBALS['is_header_sent'] = true; - } -} -?> diff --git a/libraries/header_printview.inc.php b/libraries/header_printview.inc.php index 47188ad472..723d38763a 100644 --- a/libraries/header_printview.inc.php +++ b/libraries/header_printview.inc.php @@ -52,5 +52,5 @@ require_once './libraries/header_scripts.inc.php'; /** * Sets a variable to remember headers have been sent */ -$is_header_sent = true; +PMA_Header::getInstance()->isHeaderSent = true; ?> diff --git a/libraries/header_scripts.inc.php b/libraries/header_scripts.inc.php index 3ea96d37e6..06be58def5 100644 --- a/libraries/header_scripts.inc.php +++ b/libraries/header_scripts.inc.php @@ -32,7 +32,7 @@ if (! isset($page_title)) { // here, the function does not exist with this configuration: // $cfg['ServerDefault'] = 0; $is_superuser = function_exists('PMA_isSuperuser') && PMA_isSuperuser(); - +$GLOBALS['js_include'][] = 'jquery/jquery-1.6.2.js'; $GLOBALS['js_include'][] = 'functions.js'; $GLOBALS['js_include'][] = 'jquery/jquery.qtip-1.0.0-rc3.js'; if ($GLOBALS['cfg']['CodemirrorEnable']) { diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 1a9678bf6e..5b6fe7064d 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -1551,8 +1551,8 @@ function PMA_isInsertRow() && $_REQUEST['insert_rows'] != $GLOBALS['cfg']['InsertRows'] ) { $GLOBALS['cfg']['InsertRows'] = $_REQUEST['insert_rows']; - $GLOBALS['js_include'][] = 'tbl_change.js'; - include_once 'libraries/header.inc.php'; + $scripts = PMA_Header::getInstance()->getScripts(); + $scripts->addFile('tbl_change.js'); include 'tbl_change.php'; exit; } diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 476e5c4f20..5b7dd44ea8 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -142,7 +142,6 @@ if (! empty($submit_mult) if (!empty($submit_mult) && !empty($what)) { unset($message); - include_once './libraries/header.inc.php'; if (strlen($table)) { include './libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php'; diff --git a/libraries/schema/Export_Relation_Schema.class.php b/libraries/schema/Export_Relation_Schema.class.php index e4ccef1b25..1933b88424 100644 --- a/libraries/schema/Export_Relation_Schema.class.php +++ b/libraries/schema/Export_Relation_Schema.class.php @@ -226,7 +226,7 @@ class PMA_Export_Relation_Schema { global $db; - include_once './libraries/header.inc.php'; + PMA_Header::getInstance()->display(); echo "

" . __("SCHEMA ERROR: ") . $type . "

" . "\n"; if (!empty($error_message)) { $error_message = htmlspecialchars($error_message); diff --git a/libraries/server_common.inc.php b/libraries/server_common.inc.php index 84298bf854..50e2143d1a 100644 --- a/libraries/server_common.inc.php +++ b/libraries/server_common.inc.php @@ -28,9 +28,9 @@ $url_query = PMA_generate_common_url($db); $err_url = 'main.php' . $url_query; /** - * Displays the headers + * Displays headers */ -require_once './libraries/header.inc.php'; +PMA_Header::getInstance()->display(); /** * @global boolean Checks for superuser privileges diff --git a/libraries/tbl_common.inc.php b/libraries/tbl_common.inc.php index d903dc9125..398050a164 100644 --- a/libraries/tbl_common.inc.php +++ b/libraries/tbl_common.inc.php @@ -48,7 +48,7 @@ require_once './libraries/db_table_exists.lib.php'; /** * Displays headers */ -require_once './libraries/header.inc.php'; +PMA_Header::getInstance()->display(); if (PMA_Tracker::isActive() && PMA_Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"]) diff --git a/main.php b/main.php index 202eb86627..ff9cc6f855 100644 --- a/main.php +++ b/main.php @@ -26,7 +26,7 @@ if ($GLOBALS['PMA_Config']->isGitRevision()) { $GLOBALS['db'] = ''; $GLOBALS['table'] = ''; $show_query = '1'; -require_once 'libraries/header.inc.php'; +PMA_Header::getInstance()->display(); // Any message to display? if (! empty($message)) { diff --git a/prefs_forms.php b/prefs_forms.php index 6ae7adf6d8..6871afccf9 100644 --- a/prefs_forms.php +++ b/prefs_forms.php @@ -69,8 +69,9 @@ if ($form_display->process(false) && !$form_display->hasErrors()) { } // display forms -$GLOBALS['js_include'][] = 'config.js'; -require 'libraries/header.inc.php'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('config.js'); +PMA_Header::getInstance()->display(); require 'libraries/user_preferences.inc.php'; if ($error) { $error->display(); diff --git a/prefs_manage.php b/prefs_manage.php index cdbeeeed07..096ca5dee3 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -109,7 +109,7 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == } if (!$all_ok) { // mimic original form and post json in a hidden field - include 'libraries/header.inc.php'; + PMA_Header::getInstance()->display(); include 'libraries/user_preferences.inc.php'; $msg = PMA_Message::error(__('Configuration contains incorrect data for some fields.')); $msg->display(); @@ -216,8 +216,9 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == exit; } -$GLOBALS['js_include'][] = 'config.js'; -require 'libraries/header.inc.php'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('config.js'); +PMA_Header::getInstance()->display(); require 'libraries/user_preferences.inc.php'; if ($error) { if (!$error instanceof PMA_Message) { diff --git a/querywindow.php b/querywindow.php index 200a106fc8..cde4b889d0 100644 --- a/querywindow.php +++ b/querywindow.php @@ -118,27 +118,19 @@ $sql_query = ''; /** * prepare JavaScript functionality */ -$js_include[] = 'common.js'; -$js_include[] = 'querywindow.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('common.js'); +$scripts->addFile('querywindow.js'); if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) { - $js_events[] = array( - 'event' => 'load', - 'function' => 'PMA_queryAutoCommit', - ); + $scripts->addEvent('load','PMA_queryAutoCommit'); } if (PMA_isValid($_REQUEST['init'])) { - $js_events[] = array( - 'event' => 'load', - 'function' => 'PMA_querywindowResize', - ); + $scripts->addEvent('load','PMA_querywindowResize'); } // always set focus to the textarea if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') { - $js_events[] = array( - 'event' => 'load', - 'function' => 'PMA_querywindowSetFocus', - ); + $scripts->addEvent('load','PMA_querywindowSetFocus'); } /** diff --git a/server_databases.php b/server_databases.php index 143e1f1c39..9fb4974041 100644 --- a/server_databases.php +++ b/server_databases.php @@ -10,8 +10,8 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'server_databases.js'; -$GLOBALS['js_include'][] = 'functions.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('server_databases.js'); require 'libraries/server_common.inc.php'; if (! PMA_DRIZZLE) { diff --git a/server_export.php b/server_export.php index 3f5d50b7cf..5dc8f7f023 100644 --- a/server_export.php +++ b/server_export.php @@ -9,9 +9,11 @@ * Does the common work */ require_once 'libraries/common.inc.php'; -require 'libraries/server_common.inc.php'; -$GLOBALS['js_include'][] = 'export.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('export.js'); + +require 'libraries/server_common.inc.php'; $export_page_title = __('View dump (schema) of databases') . "\n"; $checkall_url = 'server_export.php?' diff --git a/server_import.php b/server_import.php index ef6200d468..3ba59c8c36 100644 --- a/server_import.php +++ b/server_import.php @@ -10,7 +10,8 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'import.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('import.js'); /** * Does the common work diff --git a/server_plugins.php b/server_plugins.php index 04d638fa67..09f3004fbe 100644 --- a/server_plugins.php +++ b/server_plugins.php @@ -13,9 +13,10 @@ require_once 'libraries/common.inc.php'; /** * JS includes */ -$GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; -$GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js'; -$GLOBALS['js_include'][] = 'server_plugins.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('jquery/jquery.cookie.js'); +$scripts->addFile('jquery/jquery.tablesorter.js'); +$scripts->addFile('server_plugins.js'); /** * Does the common work diff --git a/server_privileges.php b/server_privileges.php index 5606079f60..a73dc6c0de 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -13,8 +13,8 @@ require_once 'libraries/common.inc.php'; /** * Does the common work */ -$GLOBALS['js_include'][] = 'server_privileges.js'; -$GLOBALS['js_include'][] = 'functions.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('server_privileges.js'); $_add_user_error = false; @@ -175,7 +175,6 @@ if (isset($dbname)) { * Checks if the user is allowed to do what he tries to... */ if (! $is_superuser) { - include 'libraries/header.inc.php'; echo '

' . "\n" . PMA_getIcon('b_usrlist.png') . __('Privileges') . "\n" diff --git a/server_replication.php b/server_replication.php index 7f10eeed72..13447f8e74 100644 --- a/server_replication.php +++ b/server_replication.php @@ -13,8 +13,9 @@ require_once 'libraries/common.inc.php'; /** * Does the common work */ -$GLOBALS['js_include'][] = 'server_privileges.js'; -$GLOBALS['js_include'][] = 'replication.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('server_privileges.js'); +$scripts->addFile('replication.js'); require 'libraries/server_common.inc.php'; require 'libraries/replication.inc.php'; @@ -25,7 +26,6 @@ require_once 'libraries/server_synchronize.lib.php'; * Checks if the user is allowed to do what he tries to... */ if (! $is_superuser) { - include 'libraries/header.inc.php'; echo '

' . "\n" . PMA_getIcon('s_replication.png') . __('Replication') . "\n" diff --git a/server_sql.php b/server_sql.php index 82924a22f0..e750054e06 100644 --- a/server_sql.php +++ b/server_sql.php @@ -13,9 +13,9 @@ require_once 'libraries/common.inc.php'; /** * Does the common work */ -$GLOBALS['js_include'][] = 'functions.js'; -$GLOBALS['js_include'][] = 'makegrid.js'; -$GLOBALS['js_include'][] = 'sql.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('makegrid.js'); +$scripts->addFile('sql.js'); require_once 'libraries/server_common.inc.php'; require_once 'libraries/sql_query_form.lib.php'; diff --git a/server_status.php b/server_status.php index 75b7695d10..5618acea57 100644 --- a/server_status.php +++ b/server_status.php @@ -7,12 +7,12 @@ * @package PhpMyAdmin */ -if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { - $GLOBALS['is_header_sent'] = true; -} - require_once 'libraries/common.inc.php'; +if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { + PMA_Header::getInstance()->isHeaderSent = true; +} + /** * Ajax request */ @@ -430,22 +430,24 @@ if (PMA_DRIZZLE) { * JS Includes */ -$GLOBALS['js_include'][] = 'server_status.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('server_status.js'); -$GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js'; -$GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence +$scripts->addFile('jquery/jquery.tablesorter.js'); +$scripts->addFile('jquery/jquery.cookie.js'); // For tab persistence // Charting -$GLOBALS['js_include'][] = 'highcharts/highcharts.js'; +$scripts->addFile('highcharts/highcharts.js'); /* Files required for chart exporting */ -$GLOBALS['js_include'][] = 'highcharts/exporting.js'; +$scripts->addFile('highcharts/exporting.js'); /* < IE 9 doesn't support canvas natively */ if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) { - $GLOBALS['js_include'][] = 'canvg/flashcanvas.js'; + $scripts->addFile('canvg/flashcanvas.js'); } -$GLOBALS['js_include'][] = 'canvg/canvg.js'; + +$scripts->addFile('canvg/canvg.js'); // for profiling chart -$GLOBALS['js_include'][] = 'jqplot/jquery.jqplot.js'; -$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.pieRenderer.js'; +$scripts->addFile('jqplot/jquery.jqplot.js'); +$scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js'); /** * flush status variables if requested diff --git a/server_synchronize.php b/server_synchronize.php index e7aba3ad43..11ede98a81 100644 --- a/server_synchronize.php +++ b/server_synchronize.php @@ -14,7 +14,8 @@ require_once 'libraries/common.inc.php'; /** * Does the common work */ -$GLOBALS['js_include'][] = 'server_synchronize.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('server_synchronize.js'); require_once 'libraries/server_common.inc.php'; /** diff --git a/server_variables.php b/server_variables.php index ab023a97e6..1ff766e6c3 100644 --- a/server_variables.php +++ b/server_variables.php @@ -7,7 +7,8 @@ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'server_variables.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('server_variables.js'); PMA_addJSVar('pma_token', $_SESSION[' PMA_token ']); PMA_addJSVar('url_query', str_replace('&', '&', PMA_generate_common_url($db))); diff --git a/sql.php b/sql.php index 2dcbc77726..b918c8af27 100644 --- a/sql.php +++ b/sql.php @@ -11,15 +11,17 @@ */ require_once 'libraries/common.inc.php'; require_once 'libraries/Table.class.php'; +require_once 'libraries/Header.class.php'; require_once 'libraries/check_user_privileges.lib.php'; require_once 'libraries/bookmark.lib.php'; -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; -$GLOBALS['js_include'][] = 'tbl_change.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('jquery/timepicker.js'); +$scripts->addFile('tbl_change.js'); // the next one needed because sql.php may do a "goto" to tbl_structure.php -$GLOBALS['js_include'][] = 'tbl_structure.js'; -$GLOBALS['js_include'][] = 'indexes.js'; -$GLOBALS['js_include'][] = 'gis_data_editor.js'; +$scripts->addFile('tbl_structure.js'); +$scripts->addFile('indexes.js'); +$scripts->addFile('gis_data_editor.js'); /** * Sets globals from $_POST @@ -55,12 +57,14 @@ if (isset($_REQUEST['printview'])) { } if (isset($_SESSION['profiling'])) { + $scripts = PMA_Header::getInstance()->getScripts(); /* < IE 9 doesn't support canvas natively */ if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) { - $GLOBALS['js_include'][] = 'canvg/flashcanvas.js'; + $scripts->addFile('canvg/flashcanvas.js'); } - $GLOBALS['js_include'][] = 'jqplot/jquery.jqplot.js'; - $GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.pieRenderer.js'; + $scripts->addFile('jqplot/jquery.jqplot.js'); + $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js'); + $scripts->addFile('canvg/canvg.js'); } /** @@ -283,7 +287,7 @@ if (! defined('PMA_CHK_DROP') && $is_drop_database && ! $is_superuser ) { - include_once 'libraries/header.inc.php'; + PMA_Header::getInstance()->display(); PMA_mysqlDie(__('"DROP DATABASE" statements are disabled.'), '', '', $err_url); } // end if @@ -379,7 +383,7 @@ if (! $cfg['Confirm'] if ($do_confirm) { $stripped_sql_query = $sql_query; - include_once 'libraries/header.inc.php'; + PMA_Header::getInstance()->display(); if ($is_drop_database) { echo '

' . __( 'You are about to DESTROY a complete database!' @@ -844,9 +848,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $goto = 'main.php'; } // Loads to target script - if ($goto != 'main.php') { - include_once 'libraries/header.inc.php'; - } $active_page = $goto; include '' . $goto; } else { @@ -870,9 +871,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { } if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['table_maintenance'])) { - $GLOBALS['js_include'][] = 'functions.js'; - $GLOBALS['js_include'][] = 'makegrid.js'; - $GLOBALS['js_include'][] = 'sql.js'; + $scripts = PMA_Header::getInstance()->getScripts(); + $scripts->addFile('makegrid.js'); + $scripts->addFile('sql.js'); // Gets the list of fields properties if (isset($result) && $result) { @@ -936,9 +937,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { echo "

"; } else { - $GLOBALS['js_include'][] = 'functions.js'; - $GLOBALS['js_include'][] = 'makegrid.js'; - $GLOBALS['js_include'][] = 'sql.js'; + $scripts = PMA_Header::getInstance()->getScripts(); + $scripts->addFile('makegrid.js'); + $scripts->addFile('sql.js'); unset($message); @@ -954,7 +955,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { include 'libraries/server_common.inc.php'; } } else { - include_once 'libraries/header.inc.php'; + PMA_Header::getInstance()->display(); //we don't need to buffer the output in PMA_getMessage here. //set a global variable and check against it in the function $GLOBALS['buffer_message'] = false; diff --git a/tbl_addfield.php b/tbl_addfield.php index 4d24a49469..959fd91055 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -10,7 +10,7 @@ */ require_once 'libraries/common.inc.php'; -require_once 'libraries/header.inc.php'; +PMA_Header::getInstance()->display(); // Check parameters PMA_checkParameters(array('db', 'table')); diff --git a/tbl_alter.php b/tbl_alter.php index 053ea71f95..4da743c6cc 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -14,8 +14,6 @@ */ require_once 'libraries/common.inc.php'; -require_once 'libraries/header.inc.php'; - if (isset($_REQUEST['field'])) { $GLOBALS['field'] = $_REQUEST['field']; } diff --git a/tbl_change.php b/tbl_change.php index 59addef9ad..00bfc241ba 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -12,7 +12,6 @@ * Gets the variables sent or posted to this script and displays the header */ require_once 'libraries/common.inc.php'; -require_once 'libraries/common.lib.php'; /** * Ensures db and table are valid, else moves to the "parent" script @@ -110,15 +109,16 @@ if ($GLOBALS['cfg']['ShowPropertyComments']) { /** * used in ./libraries/header.inc.php to load JavaScript library file */ -$GLOBALS['js_include'][] = 'functions.js'; -$GLOBALS['js_include'][] = 'tbl_change.js'; -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; -$GLOBALS['js_include'][] = 'gis_data_editor.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('functions.js'); +$scripts->addFile('tbl_change.js'); +$scripts->addFile('jquery/timepicker.js'); +$scripts->addFile('gis_data_editor.js'); /** * HTTP and HTML headers */ -require_once 'libraries/header.inc.php'; +PMA_Header::getInstance()->display(); /** * Displays the query submitted and its result diff --git a/tbl_chart.php b/tbl_chart.php index 8a6d059c09..368e4a2ba2 100644 --- a/tbl_chart.php +++ b/tbl_chart.php @@ -11,15 +11,16 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'tbl_chart.js'; -$GLOBALS['js_include'][] = 'highcharts/highcharts.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('tbl_chart.js'); +$scripts->addFile('highcharts/highcharts.js'); /* Files required for chart exporting */ -$GLOBALS['js_include'][] = 'highcharts/exporting.js'; +$scripts->addFile('highcharts/exporting.js'); /* < IE 9 doesn't support canvas natively */ if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) { - $GLOBALS['js_include'][] = 'canvg/flashcanvas.js'; + $scripts->addFile('canvg/flashcanvas.js'); } -$GLOBALS['js_include'][] = 'canvg/canvg.js'; +$scripts->addFile('canvg/canvg.js'); /** * Runs common work diff --git a/tbl_create.php b/tbl_create.php index 10580095f3..ed3369848d 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -11,7 +11,8 @@ require_once 'libraries/common.inc.php'; $action = 'tbl_create.php'; -require_once 'libraries/header.inc.php'; +PMA_Header::getInstance()->display(); + $titles = PMA_buildActionTitles(); // Check parameters diff --git a/tbl_export.php b/tbl_export.php index 57e2364e6d..d25bd5d0e2 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -10,7 +10,8 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'export.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('export.js'); /** * Gets tables informations and displays top links diff --git a/tbl_gis_visualization.php b/tbl_gis_visualization.php index 7060737ea1..6c11359680 100644 --- a/tbl_gis_visualization.php +++ b/tbl_gis_visualization.php @@ -8,12 +8,13 @@ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'openlayers/OpenLayers.js'; -$GLOBALS['js_include'][] = 'jquery/jquery.svg.js'; -$GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js'; -$GLOBALS['js_include'][] = 'jquery/jquery.event.drag-2.0.js'; -$GLOBALS['js_include'][] = 'tbl_gis_visualization.js'; -$GLOBALS['js_include'][] = 'OpenStreetMap.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('openlayers/OpenLayers.js'); +$scripts->addFile('jquery/jquery.svg.js'); +$scripts->addFile('jquery/jquery.mousewheel.js'); +$scripts->addFile('jquery/jquery.event.drag-2.0.js'); +$scripts->addFile('tbl_gis_visualization.js'); +$scripts->addFile('OpenStreetMap.js'); // Allows for resending headers even after sending some data ob_start(); diff --git a/tbl_import.php b/tbl_import.php index abe6f10a1c..31fa9fcae5 100644 --- a/tbl_import.php +++ b/tbl_import.php @@ -10,7 +10,8 @@ */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'import.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('import.js'); /** * Gets tables informations and displays top links diff --git a/tbl_indexes.php b/tbl_indexes.php index af268a61ae..08f474cbc2 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -129,7 +129,8 @@ if (isset($_REQUEST['do_save_data'])) { */ // Displays headers (if needed) -$GLOBALS['js_include'][] = 'indexes.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('indexes.js'); require_once 'libraries/tbl_info.inc.php'; if (isset($_REQUEST['index']) && is_array($_REQUEST['index'])) { diff --git a/tbl_printview.php b/tbl_printview.php index 78d5876154..77bcd2b6eb 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -61,9 +61,7 @@ if (isset($selected_tbl) && is_array($selected_tbl)) { $multi_tables = (count($the_tables) > 1); if ($multi_tables) { - if (empty($GLOBALS['is_header_sent'])) { - include_once 'libraries/header.inc.php'; - } + PMA_Header::getInstance()->display(); $tbl_list = ''; foreach ($the_tables as $key => $table) { $tbl_list .= (empty($tbl_list) ? '' : ', ') diff --git a/tbl_relation.php b/tbl_relation.php index 06df554797..657001b767 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -17,7 +17,8 @@ * Gets some core libraries */ require_once 'libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'tbl_relation.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('tbl_relation.js'); require_once 'libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_sql.php'; diff --git a/tbl_replace.php b/tbl_replace.php index 8fc95e0182..04753f2a03 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -31,9 +31,10 @@ PMA_DBI_select_db($GLOBALS['db']); */ $goto_include = false; -$GLOBALS['js_include'][] = 'makegrid.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('makegrid.js'); // Needed for generation of Inline Edit anchors -$GLOBALS['js_include'][] = 'sql.js'; +$scripts->addFile('sql.js'); // check whether insert row moode, if so include tbl_change.php PMA_isInsertRow(); @@ -264,9 +265,6 @@ if ($is_insert && count($value_sets) > 0) { // Note: logic passes here for inline edit $message = PMA_Message::success(__('No change')); $active_page = $goto_include; - if (! $GLOBALS['is_ajax_request'] == true) { - include_once 'libraries/header.inc.php'; - } include '' . PMA_securePath($goto_include); exit; } @@ -433,7 +431,7 @@ if (isset($return_to_sql_query)) { $GLOBALS['sql_query'] = $return_to_sql_query; } -$GLOBALS['js_include'][] = 'tbl_change.js'; +$scripts->addFile('tbl_change.js'); $active_page = $goto_include; @@ -446,10 +444,6 @@ if (isset($_REQUEST['after_insert']) && 'new_insert' == $_REQUEST['after_insert' unset($_REQUEST['where_clause']); } -/** - * Load header. - */ -require_once 'libraries/header.inc.php'; /** * Load target page. */ diff --git a/tbl_select.php b/tbl_select.php index fd86203715..3323d0b8e9 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -16,12 +16,13 @@ require_once 'libraries/common.inc.php'; require_once 'libraries/mysql_charsets.lib.php'; require_once 'libraries/tbl_select.lib.php'; -$GLOBALS['js_include'][] = 'makegrid.js'; -$GLOBALS['js_include'][] = 'sql.js'; -$GLOBALS['js_include'][] = 'tbl_select.js'; -$GLOBALS['js_include'][] = 'tbl_change.js'; -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; -$GLOBALS['js_include'][] = 'gis_data_editor.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('makegrid.js'); +$scripts->addFile('sql.js'); +$scripts->addFile('tbl_select.js'); +$scripts->addFile('tbl_change.js'); +$scripts->addFile('jquery/timepicker.js'); +$scripts->addFile('gis_data_editor.js'); $post_params = array( 'ajax_request', diff --git a/tbl_sql.php b/tbl_sql.php index 3420a051af..e2841a4cbb 100644 --- a/tbl_sql.php +++ b/tbl_sql.php @@ -13,9 +13,9 @@ require_once 'libraries/common.inc.php'; /** * Runs common work */ -$GLOBALS['js_include'][] = 'functions.js'; -$GLOBALS['js_include'][] = 'makegrid.js'; -$GLOBALS['js_include'][] = 'sql.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('makegrid.js'); +$scripts->addFile('sql.js'); require 'libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php'; diff --git a/tbl_structure.php b/tbl_structure.php index 013cab4bc5..9068c18622 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -12,8 +12,9 @@ require_once 'libraries/common.inc.php'; require_once 'libraries/mysql_charsets.lib.php'; -$GLOBALS['js_include'][] = 'tbl_structure.js'; -$GLOBALS['js_include'][] = 'indexes.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('tbl_structure.js'); +$scripts->addFile('indexes.js'); /** * handle multiple field commands if required @@ -69,7 +70,6 @@ if (! empty($submit_mult) && isset($_REQUEST['selected_fld'])) { // handle confirmation of deleting multiple fields/columns $action = 'tbl_structure.php'; include 'libraries/mult_submits.inc.php'; - //require_once 'libraries/header.inc.php'; if (empty($message)) { $message = PMA_Message::success(); diff --git a/tbl_zoom_select.php b/tbl_zoom_select.php index f2ddbc7ed8..0f553b8364 100644 --- a/tbl_zoom_select.php +++ b/tbl_zoom_select.php @@ -17,24 +17,23 @@ require_once './libraries/tbl_select.lib.php'; require_once './libraries/relation.lib.php'; require_once './libraries/tbl_info.inc.php'; -$GLOBALS['js_include'][] = 'makegrid.js'; -$GLOBALS['js_include'][] = 'sql.js'; -$GLOBALS['js_include'][] = 'functions.js'; -$GLOBALS['js_include'][] = 'date.js'; +$scripts = PMA_Header::getInstance()->getScripts(); +$scripts->addFile('makegrid.js'); +$scripts->addFile('sql.js'); +$scripts->addFile('date.js'); /* < IE 9 doesn't support canvas natively */ if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) { - $GLOBALS['js_include'][] = 'canvg/flashcanvas.js'; + $scripts->addFile('canvg/flashcanvas.js'); } - -$GLOBALS['js_include'][] = 'jqplot/jquery.jqplot.js'; -$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.canvasTextRenderer.js'; -$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.canvasAxisLabelRenderer.js'; -$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.dateAxisRenderer.js'; -$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.highlighter.js'; -$GLOBALS['js_include'][] = 'jqplot/plugins/jqplot.cursor.js'; -$GLOBALS['js_include'][] = 'canvg/canvg.js'; -$GLOBALS['js_include'][] = 'jquery/timepicker.js'; -$GLOBALS['js_include'][] = 'tbl_zoom_plot_jqplot.js'; +$scripts->addFile('jqplot/jquery.jqplot.js'); +$scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js'); +$scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js'); +$scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js'); +$scripts->addFile('jqplot/plugins/jqplot.highlighter.js'); +$scripts->addFile('jqplot/plugins/jqplot.cursor.js'); +$scripts->addFile('canvg/canvg.js'); +$scripts->addFile('jquery/timepicker.js'); +$scripts->addFile('tbl_zoom_plot_jqplot.js'); /** * Sets globals from $_POST diff --git a/transformation_overview.php b/transformation_overview.php index ae80a506e8..c2076c515b 100644 --- a/transformation_overview.php +++ b/transformation_overview.php @@ -15,9 +15,10 @@ define('PMA_DISPLAY_HEADING', 0); * Gets some core libraries and displays a top message if required */ require_once './libraries/common.inc.php'; -require_once './libraries/header.inc.php'; require_once './libraries/transformations.lib.php'; +PMA_Header::getInstance()->display(); + $types = PMA_getAvailableMIMEtypes(); ?> diff --git a/transformation_wrapper.php b/transformation_wrapper.php index 722ef2b2d6..317ff3875b 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -84,11 +84,9 @@ if ($cfgRelation['commwork'] && $cfgRelation['mimework']) { } } -// For re-usability, moved http-headers and stylesheets -// to a seperate file. It can now be included by libraries/header.inc.php, -// querywindow.php. +// Only output the http headers +PMA_Header::getInstance()->sendHttpHeaders(); -require_once './libraries/header_http.inc.php'; // [MIME] if (isset($ct) && !empty($ct)) { $mime_type = $ct; diff --git a/user_password.php b/user_password.php index 8a9937eb00..d28550bb93 100644 --- a/user_password.php +++ b/user_password.php @@ -12,7 +12,9 @@ */ require_once './libraries/common.inc.php'; -$GLOBALS['js_include'][] = 'server_privileges.js'; +$header = PMA_Header::getInstance(); +$scripts = $header->getScripts(); +$scripts->addFile('server_privileges.js'); /** * Displays an error message and exits if the user isn't allowed to use this @@ -22,7 +24,7 @@ if (! $cfg['ShowChgPassword']) { $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql'); } if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) { - include_once './libraries/header.inc.php'; + $header->display(); PMA_Message::error(__('You don\'t have sufficient privileges to be here right now!'))->display(); include './libraries/footer.inc.php'; } // end if @@ -50,8 +52,7 @@ if (isset($_REQUEST['nopass'])) { * If the "change password" form hasn't been submitted or the values submitted * aren't valid -> displays the form */ -// Loads the headers -require_once './libraries/header.inc.php'; +$header->display(); // Displays an error message if required if (isset($message)) { @@ -203,7 +204,7 @@ function PMA_changePassAuthType($_url_params, $password) */ function PMA_changePassDisplayPage($message, $sql_query, $_url_params) { - include_once './libraries/header.inc.php'; + PMA_Header::getInstance()->display(); echo '

' . __('Change password') . '

' . "\n\n"; echo PMA_getMessage($message, $sql_query, 'success'); echo ''. "\n" From 372335a8cad0295c170ccfdb36c42972a389eadc Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 23 May 2012 22:06:17 +0100 Subject: [PATCH 08/82] Removed some references to the non-existent header.inc.php file --- Documentation.html | 2 +- libraries/core.lib.php | 7 ++++--- libraries/tbl_info.inc.php | 1 - tbl_change.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation.html b/Documentation.html index 42b906ef49..af2a5ea00f 100644 --- a/Documentation.html +++ b/Documentation.html @@ -2700,7 +2700,7 @@ setfacl -d -m "g:www-data:rwx" tmp

This seems to be a PWS bug. Filippo Simoncini found a workaround (at this time there is no better fix): remove or comment the DOCTYPE - declarations (2 lines) from the scripts libraries/header.inc.php, + declarations (2 lines) from the scripts libraries/Header.class.php, libraries/header_printview.inc.php, index.php, navigation.php and libraries/common.lib.php.

diff --git a/libraries/core.lib.php b/libraries/core.lib.php index 1a1c3ea4e6..8d125fab3b 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -774,8 +774,8 @@ function PMA_includeJS($url, $ie_conditional = false) } /** - * Adds JS code snippets to be displayed by header.inc.php. Adds a - * newline to each snippet. + * Adds JS code snippets to be displayed by the PMA_Header class. + * Adds a newline to each snippet. * * @param string $str Js code to be added (e.g. "token=1234;") * @@ -787,7 +787,8 @@ function PMA_addJSCode($str) } /** - * Adds JS code snippet for variable assignment to be displayed by header.inc.php. + * Adds JS code snippet for variable assignment + * to be displayed by the PMA_Header class. * * @param string $key Name of value to set * @param mixed $value Value to set, can be either string or array of strings diff --git a/libraries/tbl_info.inc.php b/libraries/tbl_info.inc.php index fb01dcdcae..1fec07595e 100644 --- a/libraries/tbl_info.inc.php +++ b/libraries/tbl_info.inc.php @@ -17,7 +17,6 @@ PMA_checkParameters(array('db', 'table')); /** * Defining global variables, in case this script is included by a function. - * This is necessary because this script can be included by libraries/header.inc.php. */ global $showtable, $tbl_is_view, $tbl_storage_engine, $show_comment, $tbl_collation, $table_info_num_rows, $auto_increment; diff --git a/tbl_change.php b/tbl_change.php index 00bfc241ba..f4246ccc97 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -107,7 +107,7 @@ if ($GLOBALS['cfg']['ShowPropertyComments']) { */ /** - * used in ./libraries/header.inc.php to load JavaScript library file + * Load JavaScript files */ $scripts = PMA_Header::getInstance()->getScripts(); $scripts->addFile('functions.js'); From 54d47b89db2bcb2641f59f9ca1941698cb13b549 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Thu, 24 May 2012 00:11:26 +0100 Subject: [PATCH 09/82] Use PMA_Header class in themes.php --- libraries/Header.class.php | 36 +++++++++++++++++++++++++++++++----- themes.php | 17 +++++------------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index e59f1caf4d..6f4906d660 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -25,11 +25,17 @@ class PMA_Header { private $_scripts; private $_menu; private $_userprefs_offer_import; + private $_title; + private $_bodyId; + private $_menuEnabled; public $headerIsSent; private function __construct() { + $this->_bodyId = ''; + $this->_title = 'phpMyAdmin'; $this->_menu = PMA_Menu::getInstance(); + $this->_menuEnabled = true; $this->_scripts = new PMA_Scripts(); $this->headerIsSent = false; // if database storage for user preferences is transient, @@ -56,6 +62,21 @@ class PMA_Header { return $this->_scripts; } + public function setBodyId($id) + { + $this->_bodyId = htmlspecialchars($id); + } + + public function setTitle($title) + { + $this->_title = htmlspecialchars($title); + } + + public function disableMenu() + { + $this->_menuEnabled = false; + } + public function display() { echo $this->getDisplay(); @@ -97,7 +118,7 @@ class PMA_Header { if (! defined('PMA_DISPLAY_HEADING')) { define('PMA_DISPLAY_HEADING', 1); } - if (PMA_DISPLAY_HEADING && $GLOBALS['server'] > 0) { + if (PMA_DISPLAY_HEADING && $GLOBALS['server'] > 0 && $this->_menuEnabled) { $retval .= $this->_menu->getDisplay(); } $retval .= $this->_addRecentTable( @@ -177,10 +198,10 @@ class PMA_Header { private function _getTitleTag() { $retval = ""; - if (empty($GLOBALS['page_title'])) { - $retval .= 'phpMyAdmin'; - } else { + if (! empty($GLOBALS['page_title'])) { $retval .= htmlspecialchars($GLOBALS['page_title']); + } else { + $retval .= $this->_title; } $retval .= ""; return $retval; @@ -188,7 +209,12 @@ class PMA_Header { private function _getBodyStart() { - return ""; + $retval = "_bodyId)) { + $retval .= " id='" . $this->_bodyId . "'"; + } + $retval .= ">"; + return $retval; } private function _getWarnings() diff --git a/themes.php b/themes.php index 9c6d6731f2..eb587beceb 100644 --- a/themes.php +++ b/themes.php @@ -10,20 +10,13 @@ */ require './libraries/common.inc.php'; -/* Theme Select */ -$path_to_themes = $cfg['ThemePath'] . '/'; +$header = PMA_Header::getInstance(); +$header->setBodyId('bodythemes'); +$header->setTitle('phpMyAdmin - ' . __('Theme')); +$header->disableMenu(); +$header->display(); -/* set language and charset */ -require './libraries/header_http.inc.php'; - -/* HTML header */ -$page_title = 'phpMyAdmin - ' . __('Theme'); -require './libraries/header_meta_style.inc.php'; -require './libraries/header_scripts.inc.php'; ?> - - -

phpMyAdmin -

Date: Thu, 24 May 2012 00:14:35 +0100 Subject: [PATCH 10/82] The PMA_Menu class no longer need to be a singleton --- libraries/Header.class.php | 6 +++++- libraries/Menu.class.php | 29 ++--------------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 6f4906d660..0fc819c74f 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -34,7 +34,11 @@ class PMA_Header { { $this->_bodyId = ''; $this->_title = 'phpMyAdmin'; - $this->_menu = PMA_Menu::getInstance(); + $this->_menu = new PMA_Menu( + $GLOBALS['server'], + $GLOBALS['db'], + $GLOBALS['table'] + ); $this->_menuEnabled = true; $this->_scripts = new PMA_Scripts(); $this->headerIsSent = false; diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 5b234346d2..61c188c096 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -37,17 +37,9 @@ class PMA_Menu * @var string */ private $_table; - /** - * PMA_Menu instance - * - * @access private - * @static - * @var object - */ - private static $_instance; /** - * Private constructor disables direct object creation + * Creates a new instance of PMA_Menu * * @param int $server Server id * @param string $db Database name @@ -55,30 +47,13 @@ class PMA_Menu * * @return New PMA_Table */ - private function __construct($server, $db, $table) + public function __construct($server, $db, $table) { $this->_server = $server; $this->_db = $db; $this->_table = $table; } - /** - * Prints the menu and the breadcrumbs - * - * @return void - */ - public static function getInstance() - { - if (empty(self::$_instance)) { - self::$_instance = new PMA_Menu( - $GLOBALS['server'], - $GLOBALS['db'], - $GLOBALS['table'] - ); - } - return self::$_instance; - } - /** * Prints the menu and the breadcrumbs * From 753dd1a7d2df0e80d1b5a1810b9c2d4d46ab0626 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Thu, 24 May 2012 00:48:53 +0100 Subject: [PATCH 11/82] Use PMA_Header class in browse_foreigners.php --- browse_foreigners.php | 160 +++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 88 deletions(-) diff --git a/browse_foreigners.php b/browse_foreigners.php index 0379a2f531..eebfeee413 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -6,24 +6,21 @@ * @package PhpMyAdmin */ -/** - * Gets a core script and starts output buffering work - */ require_once 'libraries/common.inc.php'; +require_once 'libraries/transformations.lib.php'; $field = $_REQUEST['field']; PMA_checkParameters(array('db', 'table', 'field')); -require_once 'libraries/ob.lib.php'; -PMA_outBufferPre(); - -require_once 'libraries/header_http.inc.php'; +$header = PMA_Header::getInstance(); +$header->disableMenu(); +$header->setBodyId('body_browse_foreigners'); /** * Displays the frame */ -require_once 'libraries/transformations.lib.php'; // Transformations + $cfgRelation = PMA_getRelationsParam(); $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : false); @@ -79,93 +76,80 @@ if (is_array($foreignData['disp_row'])) { ); } } -?> - - - - - phpMyAdmin - - - - - - + alert('$error'); +} +HERE; +$header->getScripts()->addCode($code); +$header->display(); + +?>
From a1e255dde47d6abf1798e337bb1ad76d5119adad Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Thu, 24 May 2012 00:50:30 +0100 Subject: [PATCH 12/82] Drop constant PMA_DISPLAY_HEADING --- libraries/Header.class.php | 5 +---- transformation_overview.php | 10 +++------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 0fc819c74f..a08d4e35cb 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -119,10 +119,7 @@ class PMA_Header { $retval .= ''; } $retval .= $this->_getWarnings(); - if (! defined('PMA_DISPLAY_HEADING')) { - define('PMA_DISPLAY_HEADING', 1); - } - if (PMA_DISPLAY_HEADING && $GLOBALS['server'] > 0 && $this->_menuEnabled) { + if ($this->_menuEnabled && $GLOBALS['server'] > 0) { $retval .= $this->_menu->getDisplay(); } $retval .= $this->_addRecentTable( diff --git a/transformation_overview.php b/transformation_overview.php index c2076c515b..cc5c513ef5 100644 --- a/transformation_overview.php +++ b/transformation_overview.php @@ -5,19 +5,15 @@ * @package PhpMyAdmin */ -/** - * Don't display the page heading - * @ignore - */ -define('PMA_DISPLAY_HEADING', 0); - /** * Gets some core libraries and displays a top message if required */ require_once './libraries/common.inc.php'; require_once './libraries/transformations.lib.php'; -PMA_Header::getInstance()->display(); +$header = PMA_Header::getInstance(); +$header->disableMenu(); +$header->display(); $types = PMA_getAvailableMIMEtypes(); ?> From 3d18fb588afbccabd26dc49624d084380b1676fd Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 29 May 2012 13:01:58 +0100 Subject: [PATCH 13/82] Got rid of some dead code from gis_data_editor.php --- gis_data_editor.php | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/gis_data_editor.php b/gis_data_editor.php index 70c96718b3..83b59fe34a 100644 --- a/gis_data_editor.php +++ b/gis_data_editor.php @@ -1,10 +1,6 @@ and tags -if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) { - ob_start(); -} else { -?> - - - @@ -323,18 +311,7 @@ if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) { - - - From 0aee714983a57a9cbf062ebfdb0b94b6bc8c0738 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 29 May 2012 13:20:41 +0100 Subject: [PATCH 14/82] Drop old header_*.inc.php scripts from querywindow.php --- querywindow.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/querywindow.php b/querywindow.php index cde4b889d0..c3683d78dc 100644 --- a/querywindow.php +++ b/querywindow.php @@ -118,7 +118,10 @@ $sql_query = ''; /** * prepare JavaScript functionality */ -$scripts = PMA_Header::getInstance()->getScripts(); +$header = PMA_Header::getInstance(); +$header->disableMenu(); +$header->setBodyId('bodyquerywindow'); +$scripts = $header->getScripts(); $scripts->addFile('common.js'); $scripts->addFile('querywindow.js'); @@ -133,18 +136,9 @@ if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') { $scripts->addEvent('load','PMA_querywindowSetFocus'); } -/** - * start HTTP/HTML output - */ -require_once 'libraries/header_http.inc.php'; -require_once 'libraries/header_meta_style.inc.php'; -require_once 'libraries/header_scripts.inc.php'; -?> - +$header->display(); - -
-'; if ($tabs) { echo PMA_generateHtmlTabs($tabs, array()); From 05e7653f2add8e585324ba640123492ef8b56633 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 29 May 2012 14:05:34 +0100 Subject: [PATCH 15/82] Use PMA_Header class in navigation.php --- libraries/navigation_header.inc.php | 2 +- navigation.php | 74 ++++++----------------------- 2 files changed, 15 insertions(+), 61 deletions(-) diff --git a/libraries/navigation_header.inc.php b/libraries/navigation_header.inc.php index 21f74e2dbb..480eabec64 100644 --- a/libraries/navigation_header.inc.php +++ b/libraries/navigation_header.inc.php @@ -53,7 +53,7 @@ if ($GLOBALS['cfg']['LeftDisplayLogo']) { ?> - - From 5765eaabb09b9e235ec48605c1b68f9e572ca98e Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Fri, 1 Jun 2012 22:25:12 +0100 Subject: [PATCH 41/82] Don't force 'text/html' on ajax requests --- libraries/Error_Handler.class.php | 2 +- libraries/Header.class.php | 2 +- libraries/Response.class.php | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/Error_Handler.class.php b/libraries/Error_Handler.class.php index 17cc1d194b..5dafa8ca81 100644 --- a/libraries/Error_Handler.class.php +++ b/libraries/Error_Handler.class.php @@ -324,7 +324,7 @@ class PMA_Error_Handler } //$this->errors = array_merge($_SESSION['errors'], $this->errors); - // delet stored errors + // delete stored errors $_SESSION['errors'] = array(); unset($_SESSION['errors']); } diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 43262cf14e..efda2dd91c 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -298,8 +298,8 @@ class PMA_Header { $retval = ''; if (! self::$headerIsSent) { - $this->sendHttpHeaders(); if (! $this->_isAjax && $this->_isEnabled) { + $this->sendHttpHeaders(); $retval .= $this->_getHtmlStart(); $retval .= $this->_getMetaTags(); $retval .= $this->_getLinkTags(); diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 1163cd4396..c2d35e489d 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -102,6 +102,10 @@ class PMA_Response private function getDisplay() { + // The header may contain nothing at all, + // if it's content was already rendered + // and in this case the header will be + // in the content part of the request $retval = $this->_header->getDisplay(); $retval .= $this->_content; $retval .= $this->_footer->getDisplay(); From 7e35bbf6d1ff629ca68e7fde2c814ef0f3250227 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 12:05:04 +0100 Subject: [PATCH 42/82] Fixed multiple errors display --- libraries/Error_Handler.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Error_Handler.class.php b/libraries/Error_Handler.class.php index 5dafa8ca81..31e3b33ee1 100644 --- a/libraries/Error_Handler.class.php +++ b/libraries/Error_Handler.class.php @@ -283,7 +283,7 @@ class PMA_Error_Handler foreach ($this->getErrors() as $error) { if ($error instanceof PMA_Error) { if (! $error->isDisplayed()) { - $retval = $error->getDisplay(); + $retval .= $error->getDisplay(); } } else { ob_start(); From 093725794c79b06993aee62f4dd733fd3bcf8fc0 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 12:29:44 +0100 Subject: [PATCH 43/82] Added JSON responses to the PMA_Response class --- libraries/Response.class.php | 151 +++++++++++++++++++++++++++++------ 1 file changed, 126 insertions(+), 25 deletions(-) diff --git a/libraries/Response.class.php b/libraries/Response.class.php index c2d35e489d..79bda66f21 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -28,11 +28,35 @@ class PMA_Response * @var object */ private static $_instance; - + /** + * PMA_Header instance + * + * @access private + * @var object + */ private $_header; - private $_content; + /** + * HTML data to be used in the response + * + * @access private + * @var string + */ + private $_HTML; + /** + * An array of JSON key-value pairs + * to be sent back for ajax requests + * + * @access private + * @var array + */ + private $_JSON; + /** + * PMA_Footer instance + * + * @access private + * @var object + */ private $_footer; - /** * Whether we are servicing an ajax request. * We can't simply use $GLOBALS['is_ajax_request'] @@ -50,17 +74,18 @@ class PMA_Response */ private function __construct() { + $buffer = PMA_OutputBuffering::getInstance(); + $buffer->start(); + $this->_header = new PMA_Header(); + $this->_HTML = ''; + $this->_JSON = array(); + $this->_footer = new PMA_Footer(); + $this->_isAjax = false; if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $this->_isAjax = true; } - $buffer = PMA_OutputBuffering::getInstance(); - $buffer->start(); - $this->_data = array(); - $this->_header = new PMA_Header(); $this->_header->isAjax($this->_isAjax); - $this->_content = ''; - $this->_footer = new PMA_Footer(); $this->_footer->isAjax($this->_isAjax); } @@ -77,67 +102,143 @@ class PMA_Response return self::$_instance; } + /** + * Disables the rendering of the header + * and the footer in responses + * + * @return void + */ public function disable() { $this->_header->disable(); $this->_footer->disable(); } + /** + * Returns a PMA_Header object + * + * @return object + */ public function getHeader() { return $this->_header; } + /** + * Returns a PMA_Footer object + * + * @return object + */ public function getFooter() { return $this->_footer; } + /** + * Add HTML code to the response + * + * @param string $content A string to be appended to + * the current output buffer + * + * @return void + */ public function addHTML($content) { if (is_string($content)) { - $this->_content .= $content; + $this->_HTML .= $content; } } - private function getDisplay() + /** + * Add JSON code to the response + * + * @param mixed $json Either a key (string) or an + * array or key-value pairs + * @param mixed $value Null, if passing an array in $json otherwise + * it's a string value to the key + * + * @return void + */ + public function addJSON($json, $value) + { + if (is_array($json)) { + foreach ($json as $key => $value) { + $this->addJSON($key, $value); + } + } else { + $this->_JSON[$json] .= $value; + } + + } + + /** + * Renders the HTML response text + * + * @return string + */ + private function _getDisplay() { // The header may contain nothing at all, // if it's content was already rendered - // and in this case the header will be + // and, in this case, the header will be // in the content part of the request $retval = $this->_header->getDisplay(); - $retval .= $this->_content; + $retval .= $this->_HTML; $retval .= $this->_footer->getDisplay(); return $retval; } - public function simpleResponse() + /** + * Sends an HTML response to the browser + * + * @return void + */ + private function _htmlResponse() { - echo $this->getDisplay(); - exit; + echo $this->_getDisplay(); } - public function ajaxResponse() + /** + * Sends a JSON response to the browser + * + * @return void + */ + private function _ajaxResponse() { - echo $this->getDisplay(); - //PMA_ajaxResponse($this->getDisplay()); // FIXME - exit; + if (empty($this->_JSON)) { + // header('Content-Type: text/html; charset=utf-8'); + echo $this->_getDisplay(); + } else { + if (isset($this->_JSON['message'])) { + $message = $this->_JSON['message']; + unset($this->_JSON['message']); + } else { + $message = $this->_getDisplay(); + } + PMA_ajaxResponse($message, true, $this->_JSON); + } } + /** + * Sends an HTML response to the browser + * + * @static + * @return void + */ public static function response() { $response = PMA_Response::getInstance(); - $buffer = PMA_OutputBuffering::getInstance(); - if (empty($response->_content)) { - $response->_content = $buffer->getContents(); + $buffer = PMA_OutputBuffering::getInstance(); + if (empty($response->_HTML)) { + $response->_HTML = $buffer->getContents(); } if ($response->_isAjax) { - $response->ajaxResponse(); + $response->_ajaxResponse(); } else { - $response->simpleResponse(); + $response->_htmlResponse(); } $buffer->flush(); + exit; } } From 4d83b7f147bb13bc46586dd13d9a18a1ac5c4b39 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 12:43:15 +0100 Subject: [PATCH 44/82] Added missing library include --- libraries/Footer.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 80e0b35efb..2241b00103 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -9,6 +9,7 @@ if (! defined('PHPMYADMIN')) { exit; } +require_once 'libraries/Scripts.class.php'; require_once 'libraries/Footnotes.class.php'; /** From eb98110541b3b6e8436e004f67f077ad7126af43 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 13:43:09 +0100 Subject: [PATCH 45/82] Dropped footer.inc.php --- db_datadict.php | 1 - db_export.php | 5 ---- db_import.php | 4 --- db_operations.php | 4 --- db_printview.php | 2 -- db_qbe.php | 7 ----- db_search.php | 6 ----- db_sql.php | 4 --- db_structure.php | 9 ------- db_tracking.php | 7 ----- export.php | 4 +-- import.php | 3 +-- js/common.js | 2 +- libraries/PDF.class.php | 2 +- libraries/common.lib.php | 5 +--- libraries/display_export.lib.php | 2 +- libraries/display_import.lib.php | 2 +- libraries/footer.inc.php | 27 ------------------- libraries/insert_edit.lib.php | 3 +-- libraries/mult_submits.inc.php | 2 +- libraries/rte/rte_events.lib.php | 3 +-- libraries/rte/rte_main.inc.php | 7 ----- libraries/rte/rte_routines.lib.php | 6 ++--- libraries/rte/rte_triggers.lib.php | 3 +-- .../schema/Export_Relation_Schema.class.php | 3 +-- main.php | 5 ---- prefs_forms.php | 5 ---- prefs_manage.php | 9 +------ schema_edit.php | 13 +++------ server_binlog.php | 9 ------- server_collations.php | 2 -- server_databases.php | 5 ---- server_engines.php | 5 ---- server_export.php | 5 ---- server_import.php | 5 +--- server_plugins.php | 7 ----- server_privileges.php | 11 ++------ server_replication.php | 4 +-- server_sql.php | 4 --- server_status.php | 4 --- server_synchronize.php | 4 --- server_variables.php | 5 ---- sql.php | 7 ++--- tbl_addfield.php | 3 --- tbl_alter.php | 6 ----- tbl_change.php | 4 --- tbl_chart.php | 7 ----- tbl_create.php | 2 -- tbl_export.php | 6 ----- tbl_gis_visualization.php | 7 ----- tbl_import.php | 4 --- tbl_indexes.php | 7 ----- tbl_operations.php | 7 ----- tbl_printview.php | 2 -- tbl_relation.php | 4 --- tbl_row_action.php | 7 +---- tbl_select.php | 2 -- tbl_sql.php | 4 --- tbl_structure.php | 4 --- tbl_tracking.php | 6 ----- tbl_zoom_select.php | 1 - transformation_overview.php | 6 ----- user_password.php | 10 +++---- view_create.php | 7 ----- view_operations.php | 6 ----- 65 files changed, 30 insertions(+), 314 deletions(-) delete mode 100644 libraries/footer.inc.php diff --git a/db_datadict.php b/db_datadict.php index cf77a38904..506a1ba09a 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -283,5 +283,4 @@ foreach ($tables as $table) { */ PMA_printButton(); -require 'libraries/footer.inc.php'; ?> diff --git a/db_export.php b/db_export.php index a7d2bb162c..00f518f22c 100644 --- a/db_export.php +++ b/db_export.php @@ -31,7 +31,6 @@ $export_page_title = __('View dump (schema) of database'); // exit if no tables in db found if ($num_tables < 1) { PMA_Message::error(__('No tables found in database.'))->display(); - include 'libraries/footer.inc.php'; exit; } // end if @@ -84,8 +83,4 @@ $multi_values .= '
'; $export_type = 'database'; require_once 'libraries/display_export.lib.php'; -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/db_import.php b/db_import.php index 39ec68004d..f8ea8097ac 100644 --- a/db_import.php +++ b/db_import.php @@ -24,9 +24,5 @@ require 'libraries/db_info.inc.php'; $import_type = 'database'; require 'libraries/display_import.lib.php'; -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/db_operations.php b/db_operations.php index b2d29a1ee5..4e77fe8822 100644 --- a/db_operations.php +++ b/db_operations.php @@ -636,8 +636,4 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?> echo __('Edit or export relational schema') . '
'; } // end if -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/db_printview.php b/db_printview.php index a32de036d4..d3433ea918 100644 --- a/db_printview.php +++ b/db_printview.php @@ -248,6 +248,4 @@ if ($num_tables == 0) { PMA_printButton(); echo "
\n"; - -require 'libraries/footer.inc.php'; ?> diff --git a/db_qbe.php b/db_qbe.php index 27ba771966..df022b4873 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -102,7 +102,6 @@ $tbl_result = PMA_DBI_query( $tbl_result_cnt = PMA_DBI_num_rows($tbl_result); if (0 == $tbl_result_cnt) { PMA_Message::error(__('No tables found in database.'))->display(); - include 'libraries/footer.inc.php'; exit; } @@ -949,9 +948,3 @@ if (! empty($qry_orderby)) { - diff --git a/db_search.php b/db_search.php index 4d12e8fe3a..1222e42d41 100644 --- a/db_search.php +++ b/db_search.php @@ -371,9 +371,3 @@ $alter_select - diff --git a/db_sql.php b/db_sql.php index aa82ef946b..baced44072 100644 --- a/db_sql.php +++ b/db_sql.php @@ -62,8 +62,4 @@ PMA_sqlQueryForm( isset($_REQUEST['delimiter']) ? htmlspecialchars($_REQUEST['delimiter']) : ';' ); -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/db_structure.php b/db_structure.php index cb5a765fa7..d711e0e75a 100644 --- a/db_structure.php +++ b/db_structure.php @@ -89,11 +89,6 @@ if ($num_tables == 0) { if (empty($db_is_information_schema)) { include 'libraries/display_create_table.lib.php'; } // end if (Create Table dialog) - - /** - * Displays the footer - */ - include_once 'libraries/footer.inc.php'; exit; } @@ -759,8 +754,4 @@ if (empty($db_is_information_schema)) { include 'libraries/display_create_table.lib.php'; } // end if (Create Table dialog) -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/db_tracking.php b/db_tracking.php index 5cc0b90e30..91b33147a3 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -52,9 +52,6 @@ if ($num_tables == 0 && count($data['ddlog']) == 0) { if (empty($db_is_information_schema)) { include 'libraries/display_create_table.lib.php'; } - - // Display the footer - include 'libraries/footer.inc.php'; exit; } @@ -231,8 +228,4 @@ if (count($data['ddlog']) > 0) { echo PMA_getMessage(__('Database Log'), $log); } -/** - * Display the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/export.php b/export.php index c79ebe9e4e..48dbb58a56 100644 --- a/export.php +++ b/export.php @@ -765,7 +765,7 @@ if (! empty($asfile)) { } } - /* If ve saved on server, we have to close file now */ + /* If we saved on server, we have to close file now */ if ($save_on_server) { $write_result = @fwrite($file_handle, $dump_buffer); fclose($file_handle); @@ -797,6 +797,7 @@ if (! empty($asfile)) { } exit(); } else { + PMA_Response::getInstance()->disable(); echo $dump_buffer; } } else { @@ -834,6 +835,5 @@ if (! empty($asfile)) { //]]> diff --git a/import.php b/import.php index 7dcf9966c6..cc8cd5f811 100644 --- a/import.php +++ b/import.php @@ -94,7 +94,7 @@ if ($_POST == array() && $_GET == array()) { $_SESSION['Import_message']['go_back_url'] = $goto; $message->display(); - include 'libraries/footer.inc.php'; + exit; // the footer is displayed automatically } /** @@ -524,5 +524,4 @@ if ($go_sql) { $active_page = $goto; include '' . $goto; } -exit(); ?> diff --git a/js/common.js b/js/common.js index 79453153cb..449f35ff94 100644 --- a/js/common.js +++ b/js/common.js @@ -159,7 +159,7 @@ function markDbTable(db, table) } /** - * sets current selected server, table and db (called from libraries/footer.inc.php) + * sets current selected server, table and db (called from the footer) */ function setAll( new_lang, new_collation_connection, new_server, new_db, new_table, new_token ) { diff --git a/libraries/PDF.class.php b/libraries/PDF.class.php index 013c0f0235..e11a2f49c6 100644 --- a/libraries/PDF.class.php +++ b/libraries/PDF.class.php @@ -88,7 +88,7 @@ class PMA_PDF extends TCPDF $response = PMA_Response::getInstance(); $response->getHeader()->display(); PMA_Message::error(__('Error while creating PDF:') . ' ' . $error_message)->display(); - include './libraries/footer.inc.php'; + exit; } /** diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 01a32d4cc3..a6ed1e640d 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -703,10 +703,7 @@ function PMA_mysqlDie( } echo $error_msg; - /** - * display footer and exit - */ - include './libraries/footer.inc.php'; + exit; } else { echo $error_msg; } diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index f21a71bc9d..37cc81b4c3 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -38,7 +38,7 @@ $export_list = PMA_getPlugins('./libraries/export/', array('export_type' => $exp /* Fail if we didn't find any plugin */ if (empty($export_list)) { PMA_Message::error(__('Could not load export plugins, please check your installation!'))->display(); - include './libraries/footer.inc.php'; + exit; } ?> diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index b25a679525..7d5d5fb950 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -21,7 +21,7 @@ $import_list = PMA_getPlugins('./libraries/import/', $import_type); /* Fail if we didn't find any plugin */ if (empty($import_list)) { PMA_Message::error(__('Could not load import plugins, please check your installation!'))->display(); - include './libraries/footer.inc.php'; + exit; } ?> diff --git a/libraries/footer.inc.php b/libraries/footer.inc.php deleted file mode 100644 index 1f5e448c87..0000000000 --- a/libraries/footer.inc.php +++ /dev/null @@ -1,27 +0,0 @@ -getFooter(); -//$footer->display(); - -exit; - -?> diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 4500c393e2..007c1a3eb1 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -126,8 +126,7 @@ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, if (! $rows[$key_id]) { unset($rows[$key_id], $where_clause_array[$key_id]); PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); - echo "\n"; - include 'libraries/footer.inc.php'; + exit; } else {// end if (no row returned) $meta = PMA_DBI_get_fields_meta($result[$key_id]); list($unique_condition, $tmp_clause_is_unique) diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 5b7dd44ea8..856742a021 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -324,7 +324,7 @@ if (!empty($submit_mult) && !empty($what)) { $title\n\n$editor"; unset($_POST); - include './libraries/footer.inc.php'; } - // exit; + exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf( diff --git a/libraries/rte/rte_main.inc.php b/libraries/rte/rte_main.inc.php index fa5226bda9..b9a559ac8b 100644 --- a/libraries/rte/rte_main.inc.php +++ b/libraries/rte/rte_main.inc.php @@ -87,11 +87,4 @@ case 'EVN': break; } -/** - * Display the footer, if necessary - */ -if ($GLOBALS['is_ajax_request'] != true) { - include './libraries/footer.inc.php'; -} - ?> diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php index 69cda0d833..da85edd8ee 100644 --- a/libraries/rte/rte_routines.lib.php +++ b/libraries/rte/rte_routines.lib.php @@ -366,8 +366,7 @@ function PMA_RTN_handleEditor() PMA_ajaxResponse($editor, true, $extra_data); } echo "\n\n

$title

\n\n$editor"; - include './libraries/footer.inc.php'; - // exit; + exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf( @@ -1317,8 +1316,7 @@ function PMA_RTN_handleExecute() } else { echo "\n\n

" . __("Execute routine") . "

\n\n"; echo $form; - include './libraries/footer.inc.php'; - // exit; + exit; } } else if (($GLOBALS['is_ajax_request'] == true)) { $message = __('Error in processing request') . ' : '; diff --git a/libraries/rte/rte_triggers.lib.php b/libraries/rte/rte_triggers.lib.php index 11a4592bb5..25414eadd3 100644 --- a/libraries/rte/rte_triggers.lib.php +++ b/libraries/rte/rte_triggers.lib.php @@ -180,9 +180,8 @@ function PMA_TRI_handleEditor() } else { echo "\n\n

$title

\n\n$editor"; unset($_POST); - include './libraries/footer.inc.php'; } - // exit; + exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf( diff --git a/libraries/schema/Export_Relation_Schema.class.php b/libraries/schema/Export_Relation_Schema.class.php index 26bc8f19cd..3c61e8e07e 100644 --- a/libraries/schema/Export_Relation_Schema.class.php +++ b/libraries/schema/Export_Relation_Schema.class.php @@ -239,8 +239,7 @@ class PMA_Export_Relation_Schema . '&do=selectpage&chpage=' . $pageNumber . '&action_choose=0' . '">' . __('Back') . ''; echo "\n"; - include_once './libraries/footer.inc.php'; - exit(); + exit; } } ?> diff --git a/main.php b/main.php index 6da2886067..def28a0521 100644 --- a/main.php +++ b/main.php @@ -453,9 +453,4 @@ function PMA_printListItem($name, $id = null, $url = null, $mysql_help_page = nu } echo ''; } - -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/prefs_forms.php b/prefs_forms.php index 5b7c435667..b0ae664978 100644 --- a/prefs_forms.php +++ b/prefs_forms.php @@ -89,9 +89,4 @@ if ($form_display->hasErrors()) { display(true, true); - -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/prefs_manage.php b/prefs_manage.php index 94977aa6de..ff639e082b 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -133,8 +133,7 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
- diff --git a/schema_edit.php b/schema_edit.php index e472ab5f6e..6067cb42b7 100644 --- a/schema_edit.php +++ b/schema_edit.php @@ -35,24 +35,24 @@ $cfgRelation = PMA_getRelationsParam(); if (! $cfgRelation['relwork']) { echo sprintf(__('%s table not found or not set in %s'), 'relation', 'config.inc.php') . '
' . "\n" . PMA_showDocu('relation') . "\n"; - include_once 'libraries/footer.inc.php'; + exit; } if (! $cfgRelation['displaywork']) { echo sprintf(__('%s table not found or not set in %s'), 'table_info', 'config.inc.php') . '
' . "\n" . PMA_showDocu('table_info') . "\n"; - include_once 'libraries/footer.inc.php'; + exit; } if (! isset($cfgRelation['table_coords'])) { echo sprintf(__('%s table not found or not set in %s'), 'table_coords', 'config.inc.php') . '
' . "\n" . PMA_showDocu('table_coords') . "\n"; - include_once 'libraries/footer.inc.php'; + exit; } if (! isset($cfgRelation['pdf_pages'])) { echo sprintf(__('%s table not found or not set in %s'), 'pdf_page', 'config.inc.php') . '
' . "\n" . PMA_showDocu('pdf_pages') . "\n"; - include_once 'libraries/footer.inc.php'; + exit; } if ($cfgRelation['pdfwork']) { @@ -123,9 +123,4 @@ if ($cfgRelation['pdfwork']) { } // end if } // end if ($cfgRelation['pdfwork']) -/** - * Displays the footer - */ -echo "\n"; -require_once 'libraries/footer.inc.php'; ?> diff --git a/server_binlog.php b/server_binlog.php index 679674bc57..81fa58c8e3 100644 --- a/server_binlog.php +++ b/server_binlog.php @@ -202,12 +202,3 @@ while ($value = PMA_DBI_fetch_assoc($result)) { ?> - diff --git a/server_collations.php b/server_collations.php index 5e7844345b..b3872fc253 100644 --- a/server_collations.php +++ b/server_collations.php @@ -81,6 +81,4 @@ unset($table_row_count); echo '' . "\n" . '' . "\n"; -require 'libraries/footer.inc.php'; - ?> diff --git a/server_databases.php b/server_databases.php index cacf35c9be..f267fb9d7d 100644 --- a/server_databases.php +++ b/server_databases.php @@ -313,9 +313,4 @@ if ($databases_count > 0) { } unset($databases_count); -/** - * Sends the footer - */ -require 'libraries/footer.inc.php'; - ?> diff --git a/server_engines.php b/server_engines.php index c50723ce78..1a8a0cadf6 100644 --- a/server_engines.php +++ b/server_engines.php @@ -126,9 +126,4 @@ if (empty($_REQUEST['engine']) } } -/** - * Sends the footer - */ -require 'libraries/footer.inc.php'; - ?> diff --git a/server_export.php b/server_export.php index 910d574730..a080fd0946 100644 --- a/server_export.php +++ b/server_export.php @@ -60,9 +60,4 @@ $multi_values .= ''; $export_type = 'server'; require_once 'libraries/display_export.lib.php'; - -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/server_import.php b/server_import.php index 13c93df45b..2a7d38f7df 100644 --- a/server_import.php +++ b/server_import.php @@ -22,9 +22,6 @@ require 'libraries/server_common.inc.php'; $import_type = 'server'; require 'libraries/display_import.lib.php'; -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; + ?> diff --git a/server_plugins.php b/server_plugins.php index 16fb6d5799..5c4c6ffdda 100644 --- a/server_plugins.php +++ b/server_plugins.php @@ -183,10 +183,3 @@ pma_theme_image = ''; - diff --git a/server_privileges.php b/server_privileges.php index 673d3fd47c..0bf3955079 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -182,7 +182,7 @@ if (! $is_superuser) { . __('Privileges') . "\n" . '' . "\n"; PMA_Message::error(__('No Privileges'))->display(); - include 'libraries/footer.inc.php'; + exit; } // a random number that will be appended to the id of the user forms @@ -2034,7 +2034,7 @@ if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs if ($user_does_not_exists) { PMA_Message::error(__('The selected user was not found in the privilege table.'))->display(); PMA_displayLoginInformationFields(); - //require 'libraries/footer.inc.php'; + //exit; } echo '
' . "\n"; @@ -2584,11 +2584,4 @@ if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs } // end if (empty($_REQUEST['adduser']) && empty($checkprivs)) ... elseif ... else ... - -/** - * Displays the footer - */ -echo "\n\n"; -require 'libraries/footer.inc.php'; - ?> diff --git a/server_replication.php b/server_replication.php index bdace06135..dcecc0e422 100644 --- a/server_replication.php +++ b/server_replication.php @@ -33,7 +33,7 @@ if (! $is_superuser) { . __('Replication') . "\n" . '' . "\n"; PMA_Message::error(__('No Privileges'))->display(); - include 'libraries/footer.inc.php'; + exit; } /** @@ -265,7 +265,6 @@ if (isset($GLOBALS['mr_configure'])) { echo '
'; echo ''; - include 'libraries/footer.inc.php'; exit; } @@ -398,5 +397,4 @@ if (! isset($GLOBALS['repl_clear_scr'])) { if (isset($GLOBALS['sl_configure'])) { PMA_replication_gui_changemaster("slave_changemaster"); } -require 'libraries/footer.inc.php'; ?> diff --git a/server_sql.php b/server_sql.php index fbaf554556..408d2b2858 100644 --- a/server_sql.php +++ b/server_sql.php @@ -27,8 +27,4 @@ require_once 'libraries/sql_query_form.lib.php'; */ PMA_sqlQueryForm(); -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/server_status.php b/server_status.php index 737b861178..93d0157042 100644 --- a/server_status.php +++ b/server_status.php @@ -1839,8 +1839,4 @@ function cleanDeprecated(&$server_status) } } -/** - * Sends the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/server_synchronize.php b/server_synchronize.php index cceb1ec2d1..51fc214044 100644 --- a/server_synchronize.php +++ b/server_synchronize.php @@ -1487,8 +1487,4 @@ if (! isset($_REQUEST['submit_connect'])
' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '
'; } - /** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/server_variables.php b/server_variables.php index 41f01b62fb..7a5e1c49fe 100644 --- a/server_variables.php +++ b/server_variables.php @@ -184,9 +184,4 @@ function formatVariable($name, $value) return htmlspecialchars($value); } -/** - * Sends the footer - */ -require 'libraries/footer.inc.php'; - ?> diff --git a/sql.php b/sql.php index 5343b5fcfe..b018530e90 100644 --- a/sql.php +++ b/sql.php @@ -418,10 +418,7 @@ if ($do_confirm) { echo '' . "\n" . '' . "\n"; - /** - * Displays the footer and exit - */ - include 'libraries/footer.inc.php'; + exit; } // end if $do_confirm @@ -1127,6 +1124,6 @@ $(makeProfilingChart); * Displays the footer */ if (! isset($_REQUEST['table_maintenance'])) { - include 'libraries/footer.inc.php'; + exit; } ?> diff --git a/tbl_addfield.php b/tbl_addfield.php index 74664c55ec..015c235bd9 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -230,9 +230,6 @@ if ($abort == false) { */ $action = 'tbl_addfield.php'; include_once 'libraries/tbl_properties.inc.php'; - - // Diplays the footer - include 'libraries/footer.inc.php'; } ?> diff --git a/tbl_alter.php b/tbl_alter.php index 4da743c6cc..8c41860fa0 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -317,10 +317,4 @@ if ($abort == false) { */ include 'libraries/tbl_properties.inc.php'; } - - -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/tbl_change.php b/tbl_change.php index ea89f7b500..db2a667826 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -387,9 +387,5 @@ if ($insert_mode) { $html_output .= PMA_getContinueInsertionForm($table, $db, $where_clause_array, $err_url); } echo $html_output; -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/tbl_chart.php b/tbl_chart.php index ce35a8ce18..66f7419b10 100644 --- a/tbl_chart.php +++ b/tbl_chart.php @@ -158,10 +158,3 @@ url_query = ''; chart_data = '<', '>' => '>')); ?>; //]]> - diff --git a/tbl_create.php b/tbl_create.php index 6051751c4e..b4945a93b2 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -367,8 +367,6 @@ if ($GLOBALS['is_ajax_request'] != true) { } require 'libraries/tbl_properties.inc.php'; -// Displays the footer -require 'libraries/footer.inc.php'; if ($GLOBALS['is_ajax_request'] != true) { echo(''); diff --git a/tbl_export.php b/tbl_export.php index 7d261f8d39..042fd9a001 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -84,10 +84,4 @@ if (! empty($sql_query)) { $export_type = 'table'; require_once 'libraries/display_export.lib.php'; - - -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/tbl_gis_visualization.php b/tbl_gis_visualization.php index 98baeaf8ee..73ea8210ab 100644 --- a/tbl_gis_visualization.php +++ b/tbl_gis_visualization.php @@ -192,10 +192,3 @@ $visualization = PMA_GIS_visualizationResults($data, $visualizationSettings, $fo - diff --git a/tbl_import.php b/tbl_import.php index fb864b2fe1..9c399e0bd6 100644 --- a/tbl_import.php +++ b/tbl_import.php @@ -26,9 +26,5 @@ require_once 'libraries/tbl_info.inc.php'; $import_type = 'table'; require_once 'libraries/display_import.lib.php'; -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/tbl_indexes.php b/tbl_indexes.php index 2eca4f94e9..dc07c9c925 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -320,10 +320,3 @@ echo '' . "\n" ?> - diff --git a/tbl_operations.php b/tbl_operations.php index 9baa8c5d2a..3d44a7e684 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -860,13 +860,6 @@ if ($cfgRelation['relwork'] && ! $is_innodb) { } // end if (!empty($cfg['Server']['relation'])) - -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; - - function PMA_set_global_variables_for_engine($tbl_storage_engine) { global $is_myisam_or_aria, $is_innodb, $is_isam, $is_berkeleydb, $is_aria, $is_pbxt; diff --git a/tbl_printview.php b/tbl_printview.php index 4da57090aa..4c7ec509dc 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -472,6 +472,4 @@ foreach ($the_tables as $key => $table) { PMA_printButton(); echo "
\n"; - -require 'libraries/footer.inc.php'; ?> diff --git a/tbl_relation.php b/tbl_relation.php index cbe36ceee6..0bf1941393 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -575,8 +575,4 @@ if (count($columns) > 0) { diff --git a/tbl_row_action.php b/tbl_row_action.php index f4414a1a85..d55e5e0b03 100644 --- a/tbl_row_action.php +++ b/tbl_row_action.php @@ -21,7 +21,7 @@ if (! PMA_isValid($_REQUEST['rows_to_delete'], 'array') $disp_message = __('No rows selected'); $disp_query = ''; include 'sql.php'; - include 'libraries/footer.inc.php'; + exit; } if (isset($_REQUEST['submit_mult'])) { @@ -137,11 +137,6 @@ if (!empty($submit_mult)) { $active_page = 'sql.php'; include 'sql.php'; - - /** - * Displays the footer - */ - include 'libraries/footer.inc.php'; break; } } diff --git a/tbl_select.php b/tbl_select.php index 81762f60cf..d956d5009c 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -71,8 +71,6 @@ if (! isset($_POST['columnsToDisplay']) || $_POST['columnsToDisplay'][0] == '') $goto, $db, $table, $columnNames, $columnTypes, $columnCollations, $columnNullFlags, $geomColumnFlag, $foreigners, "normal" ); - - include 'libraries/footer.inc.php'; } else { /** * Selection criteria have been submitted -> do the work diff --git a/tbl_sql.php b/tbl_sql.php index 3ec346bb7f..b06be2760c 100644 --- a/tbl_sql.php +++ b/tbl_sql.php @@ -43,8 +43,4 @@ PMA_sqlQueryForm( isset($_REQUEST['delimiter']) ? htmlspecialchars($_REQUEST['delimiter']) : ';' ); -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/tbl_structure.php b/tbl_structure.php index 2bf35b1906..8ccc21782d 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -1001,8 +1001,4 @@ if ($cfg['ShowStats']) { echo '
' . "\n"; -/** - * Displays the footer - */ -require 'libraries/footer.inc.php'; ?> diff --git a/tbl_tracking.php b/tbl_tracking.php index eb9d760bd8..17ab096eaf 100644 --- a/tbl_tracking.php +++ b/tbl_tracking.php @@ -816,9 +816,3 @@ if ($last_version > 0) {
- diff --git a/tbl_zoom_select.php b/tbl_zoom_select.php index 27a16633ed..cdb37b5b38 100644 --- a/tbl_zoom_select.php +++ b/tbl_zoom_select.php @@ -264,5 +264,4 @@ if (isset($zoom_submit) diff --git a/transformation_overview.php b/transformation_overview.php index cfe0d809b2..6caea6a4d1 100644 --- a/transformation_overview.php +++ b/transformation_overview.php @@ -62,9 +62,3 @@ foreach ($types['transformation'] as $key => $transform) { - diff --git a/user_password.php b/user_password.php index 2be7b839c6..575cc575e0 100644 --- a/user_password.php +++ b/user_password.php @@ -27,7 +27,7 @@ if (! $cfg['ShowChgPassword']) { if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) { $header->display(); PMA_Message::error(__('You don\'t have sufficient privileges to be here right now!'))->display(); - include './libraries/footer.inc.php'; + exit; } // end if /** @@ -61,11 +61,7 @@ if (isset($message)) { } require_once './libraries/display_change_password.lib.php'; - -/** - * Displays the footer - */ -require './libraries/footer.inc.php'; +exit; /** * Send the message as an ajax request @@ -211,6 +207,6 @@ function PMA_changePassDisplayPage($message, $sql_query, $_url_params) echo PMA_getMessage($message, $sql_query, 'success'); echo ''. "\n" .''.__('Back').''; - include './libraries/footer.inc.php'; + exit; } ?> diff --git a/view_create.php b/view_create.php index 2808144638..b0cf55764b 100644 --- a/view_create.php +++ b/view_create.php @@ -186,10 +186,3 @@ $url_params['reload'] = 1; ?> - diff --git a/view_operations.php b/view_operations.php index 700610fe56..7205668cbc 100644 --- a/view_operations.php +++ b/view_operations.php @@ -96,9 +96,3 @@ $url_params['back'] = 'view_operations.php'; - From ed853f9e7c8e35be073457df632a9fc5416a674b Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 14:56:02 +0100 Subject: [PATCH 46/82] Fixed undefined variable --- user_password.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user_password.php b/user_password.php index 575cc575e0..d43959dc4b 100644 --- a/user_password.php +++ b/user_password.php @@ -178,7 +178,10 @@ function PMA_changePassAuthType($_url_params, $password) * Duration = till the browser is closed for password (we don't want this to be saved) */ if ($GLOBALS['cfg']['Server']['auth_type'] == 'cookie') { - $GLOBALS['PMA_Config']->setCookie('pmaPass-' . $server, PMA_blowfish_encrypt($password, $GLOBALS['cfg']['blowfish_secret'])); + $GLOBALS['PMA_Config']->setCookie( + 'pmaPass-' . $GLOBALS['server'], + PMA_blowfish_encrypt($password, $GLOBALS['cfg']['blowfish_secret']) + ); } /** * For http auth. mode, the "back" link will also enforce new From bc7753ee7ccdd6c6509c0656470795c3403820fa Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 14:56:32 +0100 Subject: [PATCH 47/82] Don't display error messages in ajax responses --- libraries/Footer.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 2241b00103..711472f822 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -327,9 +327,9 @@ class PMA_Footer // display Footnotes and error messages even in ajax reqests // FIXME: nootnotes should be sent as JSON $retval .= $this->_footnotes->getDisplay(); - $retval .= $this->_getErrorMessages(); } if (! $this->_isAjax && ! $this->_isMinimal) { + $retval .= $this->_getErrorMessages(); $retval .= $this->_scripts->getDisplay(); // Include possible custom footers if (file_exists(CUSTOM_FOOTER_FILE)) { From 3cf937022ee6d0a164f39780acf69b4602642d95 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 15:34:32 +0100 Subject: [PATCH 48/82] Integrated ajax responses from user_password.php with PMA_Response class --- js/functions.js | 2 +- libraries/Response.class.php | 46 +++++++++++++++++++++++++++++------- user_password.php | 13 +++++++--- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/js/functions.js b/js/functions.js index 1cf4adc9f3..5dd7c8d65b 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2631,7 +2631,7 @@ $(function() { $.post($the_form.attr('action'), $the_form.serialize() + '&change_pw='+ this_value, function(data) { if (data.success == true) { - $("#floating_menubar").after(data.sql_query); + $("#floating_menubar").after(data.message); $("#change_password_dialog").hide().remove(); $("#edit_user_dialog").dialog("close").remove(); $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax'); diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 79bda66f21..10bed3d265 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -66,6 +66,14 @@ class PMA_Response * @var bool */ private $_isAjax; + /** + * Whether there were any errors druing the processing of the request + * Only used for ajax responses + * + * @access private + * @var bool + */ + private $_isSuccess; /** * Cretes a new class instance @@ -81,6 +89,7 @@ class PMA_Response $this->_JSON = array(); $this->_footer = new PMA_Footer(); + $this->_isSuccess = true; $this->_isAjax = false; if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $this->_isAjax = true; @@ -102,6 +111,20 @@ class PMA_Response return self::$_instance; } + /** + * FIXME + * + * @return void + */ + public function isSuccess($state) + { + if ($state) { + $this->_isSuccess = true; + } else { + $this->_isSuccess = false; + } + } + /** * Disables the rendering of the header * and the footer in responses @@ -144,8 +167,10 @@ class PMA_Response */ public function addHTML($content) { - if (is_string($content)) { - $this->_HTML .= $content; + if ($value instanceof PMA_Message) { + $this->_HTML = $value->getDisplay(); + } else { + $this->_HTML = $value; } } @@ -166,7 +191,11 @@ class PMA_Response $this->addJSON($key, $value); } } else { - $this->_JSON[$json] .= $value; + if ($value instanceof PMA_Message) { + $this->_JSON[$json] = $value->getDisplay(); + } else { + $this->_JSON[$json] = $value; + } } } @@ -209,13 +238,12 @@ class PMA_Response // header('Content-Type: text/html; charset=utf-8'); echo $this->_getDisplay(); } else { - if (isset($this->_JSON['message'])) { - $message = $this->_JSON['message']; - unset($this->_JSON['message']); - } else { - $message = $this->_getDisplay(); + if (! isset($this->_JSON['message'])) { + $this->_JSON['message'] = $this->_getDisplay(); } - PMA_ajaxResponse($message, true, $this->_JSON); + $message = $this->_JSON['message']; + unset($this->_JSON['message']); + PMA_ajaxResponse($message, $this->_isSuccess, $this->_JSON); } } diff --git a/user_password.php b/user_password.php index d43959dc4b..a462ba2951 100644 --- a/user_password.php +++ b/user_password.php @@ -77,12 +77,19 @@ function PMA_getChangePassMessage($change_password_message, $sql_query = '') /** * If in an Ajax request, we don't need to show the rest of the page */ + $response = PMA_Response::getInstance(); if ($change_password_message['error']) { - PMA_ajaxResponse($change_password_message['msg'], false); + $response->addJSON('message', $change_password_message['msg']); + $response->isSuccess(false); } else { - $extra_data['sql_query'] = PMA_getMessage($change_password_message['msg'], $sql_query, 'success'); - PMA_ajaxResponse($change_password_message['msg'], true, $extra_data); + $sql_query = PMA_getMessage( + $change_password_message['msg'], + $sql_query, + 'success' + ); + $response->addJSON('message', $sql_query); } + exit; } } From 9c144428770d0676ca3db6cbc8e5865e9dca284d Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Sun, 3 Jun 2012 20:46:19 +0200 Subject: [PATCH 49/82] Fix typo --- libraries/Footer.class.php | 2 +- libraries/Header.class.php | 2 +- libraries/Response.class.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 711472f822..546640381f 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -59,7 +59,7 @@ class PMA_Footer private $_isEnabled; /** - * Cretes a new class instance + * Creates a new class instance * * @return new PMA_Footer object */ diff --git a/libraries/Header.class.php b/libraries/Header.class.php index efda2dd91c..4f031e4f78 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -101,7 +101,7 @@ class PMA_Header public static $headerIsSent; /** - * Cretes a new class instance + * Creates a new class instance * * @return new PMA_Header object */ diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 10bed3d265..f3ad1aca55 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -76,7 +76,7 @@ class PMA_Response private $_isSuccess; /** - * Cretes a new class instance + * Creates a new class instance * * @return new PMA_Response object */ From 4edb55f722e442b48550018aefdbf4bb0ad7db20 Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Sun, 3 Jun 2012 21:32:28 +0200 Subject: [PATCH 50/82] improve DocBlock --- libraries/OutputBuffering.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/OutputBuffering.class.php b/libraries/OutputBuffering.class.php index 2941c7bcd1..782e7d0686 100644 --- a/libraries/OutputBuffering.class.php +++ b/libraries/OutputBuffering.class.php @@ -60,9 +60,9 @@ class PMA_OutputBuffering } /** - * Returns the singleton PMA_Response object + * Returns the singleton PMA_OutputBuffering object * - * @return PMA_Response object + * @return PMA_OutputBuffering object */ public static function getInstance() { From 0b3c5b9694547e2310f0f210b057fe3129d8bad5 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 4 Jun 2012 15:32:04 +0100 Subject: [PATCH 51/82] Fixed variable name --- libraries/Response.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Response.class.php b/libraries/Response.class.php index f3ad1aca55..5d0e4669ef 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -167,10 +167,10 @@ class PMA_Response */ public function addHTML($content) { - if ($value instanceof PMA_Message) { - $this->_HTML = $value->getDisplay(); + if ($content instanceof PMA_Message) { + $this->_HTML .= $content->getDisplay(); } else { - $this->_HTML = $value; + $this->_HTML .= $content; } } From e7cd6a1e8aa60924ffc264942df3ab53827df4a1 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 4 Jun 2012 16:50:09 +0100 Subject: [PATCH 52/82] PHP seems to reset the CWD after a call to exit, so we need to collect the file timestamps early --- libraries/Scripts.class.php | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/libraries/Scripts.class.php b/libraries/Scripts.class.php index 6ad3a18351..604f310ede 100644 --- a/libraries/Scripts.class.php +++ b/libraries/Scripts.class.php @@ -41,6 +41,36 @@ class PMA_Scripts */ private $_events; + /** + * Returns HTML code to include javascript file. + * + * @param string $url Location of javascript, relative to js/ folder. + * @param int $timestamp The date when the file was last modified + * @param string $ie_conditional true - wrap with IE conditional comment + * 'lt 9' etc. - wrap for specific IE version + * + * @return string HTML code for javascript inclusion. + */ + private function _includeFile($url, $timestamp = null, $ie_conditional = false) + { + $include = ''; + if ($ie_conditional !== false) { + if ($ie_conditional === true) { + $include .= '' . "\n"; + } + return $include; + } /** * Generates new PMA_Scripts objects @@ -66,10 +96,16 @@ class PMA_Scripts */ public function addFile($filename, $conditional_ie = false) { + $filename = 'js/' . $filename; $hash = md5($filename); if (empty($this->_files[$hash])) { + $timestamp = null; + if (strpos($filename, '?') === false) { + $timestamp = filemtime($filename); + } $this->_files[$hash] = array( 'filename' => $filename, + 'timestamp' => $timestamp, 'conditional_ie' => $conditional_ie ); } @@ -115,7 +151,7 @@ class PMA_Scripts $retval = ''; foreach ($this->_files as $file) { - $retval .= PMA_includeJS( + $retval .= $this->_includeFile( $file['filename'], $file['conditional_ie'] ); From 1f7daca60072a23b237a1f2025c7f5fbacf95bc1 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 4 Jun 2012 17:03:09 +0100 Subject: [PATCH 53/82] Dropped PMA_includeJS() in favor of the PMA_Scripts class --- index.php | 8 +++--- libraries/core.lib.php | 32 ----------------------- test/libraries/core/PMA_getLinks_test.php | 21 +-------------- 3 files changed, 6 insertions(+), 55 deletions(-) diff --git a/index.php b/index.php index e3a7fd5488..99ac95d499 100644 --- a/index.php +++ b/index.php @@ -139,9 +139,11 @@ $response->disable(); // ]]> addFile('jquery/jquery-1.6.2.js'); +$scripts->addFile('update-location.js'); +$scripts->addFile('common.js'); +echo $scripts->getDisplay(); ?> ' . "\n "; - } - } - if (strpos($url, '?') === false) { - $include .= '' . "\n"; - } else { - $include .= '' . "\n"; - } - if ($ie_conditional !== false) { - $include .= '' . "\n"; - } - return $include; -} - /** * Adds JS code snippets to be displayed by the PMA_Response class. * Adds a newline to each snippet. diff --git a/test/libraries/core/PMA_getLinks_test.php b/test/libraries/core/PMA_getLinks_test.php index 069e633bfc..2082c7926f 100644 --- a/test/libraries/core/PMA_getLinks_test.php +++ b/test/libraries/core/PMA_getLinks_test.php @@ -1,7 +1,7 @@ assertEquals(PMA_linkURL($link), $url); } - - public function testPMA_includeJS() - { - $filename = "common.js"; - $mod = 0; - - if (file_exists('./js/'.$filename)) { - $mod = filemtime('./js/'.$filename); - } else { - $this->fail("JS file doesn't exists."); - } - $this->assertEquals(PMA_includeJS($filename), ''. "\n"); - - $filename = '?file.js'; - $this->assertEquals(PMA_includeJS($filename), ''."\n"); - - //$this->assertFalse(PMA_includeJS(null)); - } - } From fd005fe4c48a8569b9ecef95ed0b0c9f5f20f752 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 4 Jun 2012 18:35:01 +0100 Subject: [PATCH 54/82] The filename and line number sometimes are unavailable --- libraries/Error.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/Error.class.php b/libraries/Error.class.php index 698ff7b5d7..306d2c19b5 100644 --- a/libraries/Error.class.php +++ b/libraries/Error.class.php @@ -255,7 +255,9 @@ class PMA_Error extends PMA_Message $retval = ''; foreach ($this->getBacktrace() as $step) { - $retval .= PMA_Error::relPath($step['file']) . '#' . $step['line'] . ': '; + if (isset($step['file']) && isset($step['line'])) { + $retval .= PMA_Error::relPath($step['file']) . '#' . $step['line'] . ': '; + } if (isset($step['class'])) { $retval .= $step['class'] . $step['type']; } From 4995de86f4c9b00c34276ebf52283aeedb8903a5 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 4 Jun 2012 19:21:29 +0100 Subject: [PATCH 55/82] Display "Too many error messages" only once --- libraries/Error_Handler.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Error_Handler.class.php b/libraries/Error_Handler.class.php index 31e3b33ee1..d623c321ca 100644 --- a/libraries/Error_Handler.class.php +++ b/libraries/Error_Handler.class.php @@ -64,8 +64,8 @@ class PMA_Error_Handler if (count($_SESSION['errors']) >= 20) { $error = new PMA_Error(0, __('Too many error messages, some are not displayed.'), __FILE__, __LINE__); $_SESSION['errors'][$error->getHash()] = $error; - } - if (($error instanceof PMA_Error) && ! $error->isDisplayed()) { + break; + } else if (($error instanceof PMA_Error) && ! $error->isDisplayed()) { $_SESSION['errors'][$key] = $error; } } From ec4b3d9e4621ce8f9f318ddd7364f67ae46e2854 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 10:54:39 +0100 Subject: [PATCH 56/82] Disable warnings in header for cookie auth --- libraries/Header.class.php | 22 +++++++++++++++++++++- libraries/auth/cookie.auth.lib.php | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 4f031e4f78..1684d82f0e 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -67,6 +67,13 @@ class PMA_Header * @var bool */ private $_menuEnabled; + /** + * Whether to show the warnings + * + * @access private + * @var bool + */ + private $_warningsEnabled; /** * Whether the page is in 'print view' mode * @@ -117,6 +124,7 @@ class PMA_Header $GLOBALS['table'] ); $this->_menuEnabled = true; + $this->_warningsEnabled = true; $this->_isPrintView = false; $this->_scripts = new PMA_Scripts(); $this->_addDefaultScripts(); @@ -267,6 +275,16 @@ class PMA_Header $this->_menuEnabled = false; } + /** + * Disables the display of the top menu + * + * @return void + */ + public function disableWarnings() + { + $this->_warningsEnabled = false; + } + /** * Turns on 'print view' mode * @@ -325,7 +343,9 @@ class PMA_Header if (! $GLOBALS['cfg']['ShowHint']) { $retval .= ''; } - $retval .= $this->_getWarnings(); + if ($this->_warningsEnabled) { + $retval .= $this->_getWarnings(); + } if ($this->_menuEnabled && $GLOBALS['server'] > 0) { $retval .= $this->_menu->getDisplay(); } diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index 2082f65057..24c8b6a049 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -160,6 +160,7 @@ function PMA_auth() $header = $response->getHeader(); $header->setBodyId('loginform'); $header->disableMenu(); + $header->disableWarnings(); $header->display(); if (file_exists(CUSTOM_HEADER_FILE)) { From ae6e50a8a82a70a1bff90cadc200f06819306615 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 15:08:09 +0100 Subject: [PATCH 57/82] Drop display() from Header and Footer classes. The Response class will do all the rendering. --- browse_foreigners.php | 2 +- db_printview.php | 1 - export.php | 2 -- import.php | 2 -- libraries/Footer.class.php | 10 ---------- libraries/Header.class.php | 10 ---------- libraries/PDF.class.php | 2 -- libraries/auth/config.auth.lib.php | 1 - libraries/auth/cookie.auth.lib.php | 1 - libraries/auth/http.auth.lib.php | 1 - libraries/common.lib.php | 6 ------ libraries/db_common.inc.php | 6 ------ libraries/schema/Export_Relation_Schema.class.php | 2 -- libraries/server_common.inc.php | 6 ------ libraries/tbl_common.inc.php | 6 ------ main.php | 2 -- navigation.php | 1 - pmd_pdf.php | 1 - prefs_forms.php | 1 - prefs_manage.php | 4 +--- querywindow.php | 2 -- sql.php | 7 ------- tbl_addfield.php | 3 --- tbl_change.php | 5 ----- tbl_create.php | 3 --- transformation_overview.php | 1 - user_password.php | 4 ---- 27 files changed, 2 insertions(+), 90 deletions(-) diff --git a/browse_foreigners.php b/browse_foreigners.php index 0799b9594e..c4b47e7af0 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -14,6 +14,7 @@ $field = $_REQUEST['field']; PMA_checkParameters(array('db', 'table', 'field')); $response = PMA_Response::getInstance(); +$response->getFooter()->setMinimal(); $header = $response->getHeader(); $header->disableMenu(); $header->setBodyId('body_browse_foreigners'); @@ -148,7 +149,6 @@ function formupdate(fieldmd5, key) { EOC; $header->getScripts()->addCode($code); -$header->display(); ?>
diff --git a/db_printview.php b/db_printview.php index d3433ea918..3160089361 100644 --- a/db_printview.php +++ b/db_printview.php @@ -13,7 +13,6 @@ require_once 'libraries/common.inc.php'; $response = PMA_Response::getInstance(); $header = $response->getHeader(); $header->enablePrintView(); -$header->display(); PMA_checkParameters(array('db')); diff --git a/export.php b/export.php index 48dbb58a56..ef519cc732 100644 --- a/export.php +++ b/export.php @@ -407,8 +407,6 @@ if (! $save_on_server) { } } $backup_cfgServer = $cfg['Server']; - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); $cfg['Server'] = $backup_cfgServer; unset($backup_cfgServer); echo "\n" . '
' . "\n"; diff --git a/import.php b/import.php index cc8cd5f811..1522c0d048 100644 --- a/import.php +++ b/import.php @@ -83,8 +83,6 @@ if (! empty($sql_query)) { // upload limit has been reached, let's assume the second possibility. ; if ($_POST == array() && $_GET == array()) { - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); $message = PMA_Message::error(__('You probably tried to upload too large file. Please refer to %sdocumentation%s for ways to workaround this limit.')); $message->addParam('[a@./Documentation.html#faq1_16@_blank]'); $message->addParam('[/a]'); diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 546640381f..21bf6a734e 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -345,14 +345,4 @@ class PMA_Footer return $retval; } - - /** - * Renders and displays the footer - * - * @return void - */ - public function display() - { - echo $this->getDisplay(); - } } diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 1684d82f0e..d609f6e0bc 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -297,16 +297,6 @@ class PMA_Header $this->_isPrintView = true; } - /** - * Generates and outputs the header - * - * @return void - */ - public function display() - { - echo $this->getDisplay(); - } - /** * Generates the header * diff --git a/libraries/PDF.class.php b/libraries/PDF.class.php index e11a2f49c6..54b83e1203 100644 --- a/libraries/PDF.class.php +++ b/libraries/PDF.class.php @@ -85,8 +85,6 @@ class PMA_PDF extends TCPDF */ function Error($error_message = '') { - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); PMA_Message::error(__('Error while creating PDF:') . ' ' . $error_message)->display(); exit; } diff --git a/libraries/auth/config.auth.lib.php b/libraries/auth/config.auth.lib.php index 698ca7e859..4378913a0c 100644 --- a/libraries/auth/config.auth.lib.php +++ b/libraries/auth/config.auth.lib.php @@ -79,7 +79,6 @@ function PMA_auth_fails() $header = $response->getHeader(); $header->setTitle(__('Access denied')); $header->disableMenu(); - $header->display(); ?>

diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index 24c8b6a049..a9f30f9121 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -161,7 +161,6 @@ function PMA_auth() $header->setBodyId('loginform'); $header->disableMenu(); $header->disableWarnings(); - $header->display(); if (file_exists(CUSTOM_HEADER_FILE)) { include CUSTOM_HEADER_FILE; diff --git a/libraries/auth/http.auth.lib.php b/libraries/auth/http.auth.lib.php index bf0d8f718f..757df24fff 100644 --- a/libraries/auth/http.auth.lib.php +++ b/libraries/auth/http.auth.lib.php @@ -55,7 +55,6 @@ function PMA_auth() $header = $response->getHeader(); $header->setTitle(__('Access denied')); $header->disableMenu(); - $header->display(); ?>

diff --git a/libraries/common.lib.php b/libraries/common.lib.php index a6ed1e640d..9c98073818 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -567,12 +567,6 @@ function PMA_mysqlDie( ) { global $table, $db; - /** - * start http output, display html headers - */ - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); - $error_msg = ''; if (! $error_message) { diff --git a/libraries/db_common.inc.php b/libraries/db_common.inc.php index 42f8a18461..7516a2dd20 100644 --- a/libraries/db_common.inc.php +++ b/libraries/db_common.inc.php @@ -76,12 +76,6 @@ if (isset($submitcollation) && !empty($db_collation)) { }; } -/** - * Displays headers - */ -$response = PMA_Response::getInstance(); -$response->getHeader()->display(); - /** * Set parameters for links */ diff --git a/libraries/schema/Export_Relation_Schema.class.php b/libraries/schema/Export_Relation_Schema.class.php index 3c61e8e07e..e160681d1b 100644 --- a/libraries/schema/Export_Relation_Schema.class.php +++ b/libraries/schema/Export_Relation_Schema.class.php @@ -226,8 +226,6 @@ class PMA_Export_Relation_Schema { global $db; - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); echo "

" . __("SCHEMA ERROR: ") . $type . "

" . "\n"; if (!empty($error_message)) { $error_message = htmlspecialchars($error_message); diff --git a/libraries/server_common.inc.php b/libraries/server_common.inc.php index e64e769611..129a4feb67 100644 --- a/libraries/server_common.inc.php +++ b/libraries/server_common.inc.php @@ -27,12 +27,6 @@ $url_query = PMA_generate_common_url($db); */ $err_url = 'main.php' . $url_query; -/** - * Displays headers - */ -$response = PMA_Response::getInstance(); -$response->getHeader()->display(); - /** * @global boolean Checks for superuser privileges */ diff --git a/libraries/tbl_common.inc.php b/libraries/tbl_common.inc.php index 54586fd560..4be5ff7b58 100644 --- a/libraries/tbl_common.inc.php +++ b/libraries/tbl_common.inc.php @@ -45,12 +45,6 @@ $err_url = $cfg['DefaultTabTable'] . PMA_generate_common_url($url_params); */ require_once './libraries/db_table_exists.lib.php'; -/** - * Displays headers - */ -$response = PMA_Response::getInstance(); -$response->getHeader()->display(); - if (PMA_Tracker::isActive() && PMA_Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"]) ) { diff --git a/main.php b/main.php index def28a0521..96034690a6 100644 --- a/main.php +++ b/main.php @@ -26,8 +26,6 @@ if ($GLOBALS['PMA_Config']->isGitRevision()) { $GLOBALS['db'] = ''; $GLOBALS['table'] = ''; $show_query = '1'; -$response = PMA_Response::getInstance(); -$response->getHeader()->display(); // Any message to display? if (! empty($message)) { diff --git a/navigation.php b/navigation.php index 2730de57d4..f92abf2883 100644 --- a/navigation.php +++ b/navigation.php @@ -112,7 +112,6 @@ $scripts->addCode(' } }; '); -$header->display(); require 'libraries/navigation_header.inc.php'; diff --git a/pmd_pdf.php b/pmd_pdf.php index 6ec716ab10..18b3bc2a02 100644 --- a/pmd_pdf.php +++ b/pmd_pdf.php @@ -81,7 +81,6 @@ $response = PMA_Response::getInstance(); $response->getFooter()->setMinimal(); $header = $response->getHeader(); $header->disableMenu(); -$header->display(); ?>
diff --git a/prefs_forms.php b/prefs_forms.php index b0ae664978..023d8ba18c 100644 --- a/prefs_forms.php +++ b/prefs_forms.php @@ -73,7 +73,6 @@ $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('config.js'); -$header->display(); require 'libraries/user_preferences.inc.php'; if ($error) { diff --git a/prefs_manage.php b/prefs_manage.php index ff639e082b..2cf8dd0a68 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -109,8 +109,6 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == } if (!$all_ok) { // mimic original form and post json in a hidden field - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); include 'libraries/user_preferences.inc.php'; $msg = PMA_Message::error(__('Configuration contains incorrect data for some fields.')); $msg->display(); @@ -220,7 +218,7 @@ $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('config.js'); -$header->display(); + require 'libraries/user_preferences.inc.php'; if ($error) { if (!$error instanceof PMA_Message) { diff --git a/querywindow.php b/querywindow.php index b69101e584..8ba3530c3e 100644 --- a/querywindow.php +++ b/querywindow.php @@ -132,8 +132,6 @@ if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') { $scripts->addEvent('load','PMA_querywindowSetFocus'); } -$header->display(); - echo '
'; if ($tabs) { diff --git a/sql.php b/sql.php index b018530e90..40b430f281 100644 --- a/sql.php +++ b/sql.php @@ -290,8 +290,6 @@ if (! defined('PMA_CHK_DROP') && $is_drop_database && ! $is_superuser ) { - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); PMA_mysqlDie(__('"DROP DATABASE" statements are disabled.'), '', '', $err_url); } // end if @@ -387,8 +385,6 @@ if (! $cfg['Confirm'] if ($do_confirm) { $stripped_sql_query = $sql_query; - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); if ($is_drop_database) { echo '

' . __( 'You are about to DESTROY a complete database!' @@ -914,7 +910,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $response = PMA_Response::getInstance(); $header = $response->getHeader(); $header->enablePrintView(); - $header->display(); $hostname = ''; if ($cfg['Server']['verbose']) { @@ -964,8 +959,6 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { include 'libraries/server_common.inc.php'; } } else { - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); //we don't need to buffer the output in PMA_getMessage here. //set a global variable and check against it in the function $GLOBALS['buffer_message'] = false; diff --git a/tbl_addfield.php b/tbl_addfield.php index 015c235bd9..e0cf74dda1 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -10,9 +10,6 @@ */ require_once 'libraries/common.inc.php'; -$response = PMA_Response::getInstance(); -$response->getHeader()->display(); - // Check parameters PMA_checkParameters(array('db', 'table')); diff --git a/tbl_change.php b/tbl_change.php index db2a667826..8613410c4f 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -117,11 +117,6 @@ $scripts->addFile('tbl_change.js'); $scripts->addFile('jquery/timepicker.js'); $scripts->addFile('gis_data_editor.js'); -/** - * HTTP and HTML headers - */ -$header->display(); - /** * Displays the query submitted and its result * diff --git a/tbl_create.php b/tbl_create.php index b4945a93b2..43832a887f 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -11,9 +11,6 @@ require_once 'libraries/common.inc.php'; $action = 'tbl_create.php'; -$response = PMA_Response::getInstance(); -$response->getHeader()->display(); - $titles = PMA_buildActionTitles(); // Check parameters diff --git a/transformation_overview.php b/transformation_overview.php index 6caea6a4d1..50a3ab8e9c 100644 --- a/transformation_overview.php +++ b/transformation_overview.php @@ -14,7 +14,6 @@ require_once './libraries/transformations.lib.php'; $response = PMA_Response::getInstance(); $header = $response->getHeader(); $header->disableMenu(); -$header->display(); $types = PMA_getAvailableMIMEtypes(); ?> diff --git a/user_password.php b/user_password.php index a462ba2951..470ab460f6 100644 --- a/user_password.php +++ b/user_password.php @@ -25,7 +25,6 @@ if (! $cfg['ShowChgPassword']) { $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql'); } if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) { - $header->display(); PMA_Message::error(__('You don\'t have sufficient privileges to be here right now!'))->display(); exit; } // end if @@ -53,7 +52,6 @@ if (isset($_REQUEST['nopass'])) { * If the "change password" form hasn't been submitted or the values submitted * aren't valid -> displays the form */ -$header->display(); // Displays an error message if required if (isset($message)) { @@ -211,8 +209,6 @@ function PMA_changePassAuthType($_url_params, $password) */ function PMA_changePassDisplayPage($message, $sql_query, $_url_params) { - $response = PMA_Response::getInstance(); - $response->getHeader()->display(); echo '

' . __('Change password') . '

' . "\n\n"; echo PMA_getMessage($message, $sql_query, 'success'); echo ''. "\n" From 3b2c2ec8611d5ec51f7c510a31a860e4410ffecf Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 15:17:26 +0100 Subject: [PATCH 58/82] Remember CWD after the initial script has shutdown --- libraries/Response.class.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 5d0e4669ef..e7b2923a3a 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -74,6 +74,13 @@ class PMA_Response * @var bool */ private $_isSuccess; + /** + * Workaround for PHP bug + * + * @access private + * @var bool + */ + private $_CWD; /** * Creates a new class instance @@ -96,6 +103,7 @@ class PMA_Response } $this->_header->isAjax($this->_isAjax); $this->_footer->isAjax($this->_isAjax); + $this->_CWD = getcwd(); } /** @@ -125,6 +133,18 @@ class PMA_Response } } + /** + * Returns the path to the current working directory + * Necessary to work around a PHP bug where the CWD is + * reset after the initial script exits + * + * @return string + */ + public function getCWD() + { + return $this->_CWD; + } + /** * Disables the rendering of the header * and the footer in responses @@ -256,6 +276,7 @@ class PMA_Response public static function response() { $response = PMA_Response::getInstance(); + chdir($response->getCWD()); $buffer = PMA_OutputBuffering::getInstance(); if (empty($response->_HTML)) { $response->_HTML = $buffer->getContents(); From 015fce08ee014d42c4ed4042901e412548671831 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 15:20:10 +0100 Subject: [PATCH 59/82] Fixed bad variable name --- libraries/display_export.lib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index 37cc81b4c3..bb9346cd15 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -232,18 +232,18 @@ if (isset($_GET['sql_query'])) { } } - $message = new PMA_Message(__('This value is interpreted using %1$sstrftime%2$s, so you can use time formatting strings. Additionally the following transformations will happen: %3$s. Other text will be kept as is. See the %4$sFAQ%5$s for details.')); - $message->addParam( + $msg = new PMA_Message(__('This value is interpreted using %1$sstrftime%2$s, so you can use time formatting strings. Additionally the following transformations will happen: %3$s. Other text will be kept as is. See the %4$sFAQ%5$s for details.')); + $msg->addParam( '', false ); - $message->addParam('', false); - $message->addParam($trans); - $message->addParam('', false); - $message->addParam('', false); + $msg->addParam('', false); + $msg->addParam($trans); + $msg->addParam('', false); + $msg->addParam('', false); - echo PMA_showHint($message); + echo PMA_showHint($msg); ?> Date: Tue, 5 Jun 2012 15:36:38 +0100 Subject: [PATCH 60/82] Ensure that PMA_Response is instanciated in common.inc.php --- libraries/common.inc.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 3e803768c8..659963aeff 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -130,11 +130,6 @@ require './libraries/Table.class.php'; require './libraries/Types.class.php'; if (! defined('PMA_MINIMUM_COMMON')) { - /** - * Used to generate the page - */ - include_once 'libraries/Response.class.php'; - /** * common functions */ @@ -149,6 +144,11 @@ if (! defined('PMA_MINIMUM_COMMON')) { * Include URL/hidden inputs generating. */ include_once './libraries/url_generating.lib.php'; + + /** + * Used to generate the page + */ + include_once 'libraries/Response.class.php'; } /******************************************************************************/ @@ -756,6 +756,9 @@ if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) { } if (! defined('PMA_MINIMUM_COMMON')) { + // get a dummy object to ensure that the class is instanciated + PMA_Response::getInstance(); + /** * Character set conversion. */ From 31c8ca63011aaa8b08ea69a9cb37ea94077e5a7d Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 16:03:04 +0100 Subject: [PATCH 61/82] Disable Response class for XHR requests in PMD --- pmd_display_field.php | 2 ++ pmd_relation_new.php | 3 +++ pmd_relation_upd.php | 3 +++ 3 files changed, 8 insertions(+) diff --git a/pmd_display_field.php b/pmd_display_field.php index dcf195f17c..dfe61593e4 100644 --- a/pmd_display_field.php +++ b/pmd_display_field.php @@ -9,6 +9,8 @@ */ require_once './libraries/common.inc.php'; +PMA_Response::getInstance()->disable(); + require_once 'libraries/pmd_common.php'; diff --git a/pmd_relation_new.php b/pmd_relation_new.php index a7ca02fce9..e531611ff7 100644 --- a/pmd_relation_new.php +++ b/pmd_relation_new.php @@ -9,6 +9,9 @@ * */ require_once './libraries/common.inc.php'; + +PMA_Response::getInstance()->disable(); + require_once 'libraries/pmd_common.php'; $die_save_pos = 0; require_once 'pmd_save_pos.php'; diff --git a/pmd_relation_upd.php b/pmd_relation_upd.php index 4681e544ab..f29424514a 100644 --- a/pmd_relation_upd.php +++ b/pmd_relation_upd.php @@ -9,6 +9,9 @@ * */ require_once './libraries/common.inc.php'; + +PMA_Response::getInstance()->disable(); + require_once 'libraries/pmd_common.php'; extract($_POST, EXTR_SKIP); extract($_GET, EXTR_SKIP); From f6bcab642526f0e7c0c06cf2acdc65510f719099 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 16:03:30 +0100 Subject: [PATCH 62/82] Don't die before the Response class is instanciated --- libraries/common.inc.php | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 659963aeff..d3dfffe78d 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -154,28 +154,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { /******************************************************************************/ /* start procedural code label_start_procedural */ -if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) { - PMA_fatalError(__("GLOBALS overwrite attempt")); -} - -/** - * protect against possible exploits - there is no need to have so much variables - */ -if (count($_REQUEST) > 1000) { - PMA_fatalError(__('possible exploit')); -} - -/** - * Check for numeric keys - * (if register_globals is on, numeric key can be found in $GLOBALS) - */ -foreach ($GLOBALS as $key => $dummy) { - if (is_numeric($key)) { - PMA_fatalError(__('numeric key detected')); - } -} -unset($dummy); - /** * PATH_INFO could be compromised if set, so remove it from PHP_SELF * and provide a clean PHP_SELF here @@ -1092,6 +1070,28 @@ if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) { $GLOBALS['grid_edit'] = false; } +if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) { + PMA_fatalError(__("GLOBALS overwrite attempt")); +} + +/** + * protect against possible exploits - there is no need to have so much variables + */ +if (count($_REQUEST) > 1000) { + PMA_fatalError(__('possible exploit')); +} + +/** + * Check for numeric keys + * (if register_globals is on, numeric key can be found in $GLOBALS) + */ +foreach ($GLOBALS as $key => $dummy) { + if (is_numeric($key)) { + PMA_fatalError(__('numeric key detected')); + } +} +unset($dummy); + if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) { /** * include subform target page From ca2f16194867fa0de9dd7731360c88532ce39ad2 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 21:57:22 +0100 Subject: [PATCH 63/82] Dropped $GLOBALS['page_title'] --- libraries/Header.class.php | 78 +++++++++++++++--------------- libraries/auth/config.auth.lib.php | 1 - libraries/auth/cookie.auth.lib.php | 2 +- libraries/auth/http.auth.lib.php | 1 - 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index d609f6e0bc..f54a906b1a 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -117,7 +117,7 @@ class PMA_Header $this->_isEnabled = true; $this->_isAjax = false; $this->_bodyId = ''; - $this->_title = 'phpMyAdmin'; + $this->_title = ''; $this->_menu = new PMA_Menu( $GLOBALS['server'], $GLOBALS['db'], @@ -174,40 +174,6 @@ class PMA_Header . urlencode($_SESSION['PMA_Theme']->getId()) ); $this->_scripts->addFile('functions.js'); - - // generate title (unless we already have - // $GLOBALS['page_title'], from cookie auth) - if (! isset($GLOBALS['page_title'])) { - if ($GLOBALS['server'] > 0) { - if (! empty($GLOBALS['table'])) { - $temp_title = $GLOBALS['cfg']['TitleTable']; - } else if (! empty($GLOBALS['db'])) { - $temp_title = $GLOBALS['cfg']['TitleDatabase']; - } elseif (! empty($GLOBALS['cfg']['Server']['host'])) { - $temp_title = $GLOBALS['cfg']['TitleServer']; - } else { - $temp_title = $GLOBALS['cfg']['TitleDefault']; - } - $title = PMA_expandUserString($temp_title); - } - } else { - $title = $GLOBALS['page_title']; - } - if (isset($title)) { - $title = PMA_sanitize( - PMA_escapeJsString($title), - false, - true - ); - $this->_scripts->addCode( - "if (typeof(parent.document) != 'undefined'" - . " && typeof(parent.document) != 'unknown'" - . " && typeof(parent.document.title) == 'string')" - . "{" - . "parent.document.title = '$title'" - . "}" - ); - } $this->_scripts->addCode(PMA_getReloadNavigationScript(true)); } @@ -312,6 +278,19 @@ class PMA_Header $retval .= $this->_getMetaTags(); $retval .= $this->_getLinkTags(); $retval .= $this->_getTitleTag(); + $title = PMA_sanitize( + PMA_escapeJsString($this->_getPageTitle()), + false, + true + ); + $this->_scripts->addCode( + "if (typeof(parent.document) != 'undefined'" + . " && typeof(parent.document) != 'unknown'" + . " && typeof(parent.document.title) == 'string')" + . "{" + . "parent.document.title = '$title'" + . "}" + ); if ($this->_userprefsOfferImport) { $this->_scripts->addFile('config.js'); } @@ -451,15 +430,34 @@ class PMA_Header private function _getTitleTag() { $retval = ""; - if (! empty($GLOBALS['page_title'])) { - $retval .= htmlspecialchars($GLOBALS['page_title']); - } else { - $retval .= $this->_title; - } + $retval .= $this->_getPageTitle(); $retval .= ""; return $retval; } + private function _getPageTitle() + { + if (empty($this->_title)) { + if ($GLOBALS['server'] > 0) { + if (! empty($GLOBALS['table'])) { + $temp_title = $GLOBALS['cfg']['TitleTable']; + } else if (! empty($GLOBALS['db'])) { + $temp_title = $GLOBALS['cfg']['TitleDatabase']; + } elseif (! empty($GLOBALS['cfg']['Server']['host'])) { + $temp_title = $GLOBALS['cfg']['TitleServer']; + } else { + $temp_title = $GLOBALS['cfg']['TitleDefault']; + } + $this->_title = htmlspecialchars( + PMA_expandUserString($temp_title) + ); + } else { + $this->_title = 'phpMyAdmin'; + } + } + return $this->_title; + } + /** * Returns the close tag to the HEAD * and the start tag for the BODY diff --git a/libraries/auth/config.auth.lib.php b/libraries/auth/config.auth.lib.php index 4378913a0c..cea96b9cb1 100644 --- a/libraries/auth/config.auth.lib.php +++ b/libraries/auth/config.auth.lib.php @@ -73,7 +73,6 @@ function PMA_auth_fails() } /* HTML header */ - $GLOBALS['page_title'] = __('Access denied'); $response = PMA_Response::getInstance(); $response->getFooter()->setMinimal(); $header = $response->getHeader(); diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index a9f30f9121..333732ecd7 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -154,11 +154,11 @@ function PMA_auth() $cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right'; - $GLOBALS['page_title'] = 'phpMyAdmin'; $response = PMA_Response::getInstance(); $response->getFooter()->setMinimal(); $header = $response->getHeader(); $header->setBodyId('loginform'); + $header->setTitle('phpMyAdmin'); $header->disableMenu(); $header->disableWarnings(); diff --git a/libraries/auth/http.auth.lib.php b/libraries/auth/http.auth.lib.php index 757df24fff..422fcbbe26 100644 --- a/libraries/auth/http.auth.lib.php +++ b/libraries/auth/http.auth.lib.php @@ -49,7 +49,6 @@ function PMA_auth() } /* HTML header */ - $GLOBALS['page_title'] = __('Access denied'); $response = PMA_Response::getInstance(); $response->getFooter()->setMinimal(); $header = $response->getHeader(); From 30d7d92e0254acd7ada4706e64a8dce43ecfebe3 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 5 Jun 2012 22:56:48 +0100 Subject: [PATCH 64/82] BBCode is never used with PMA_showHint() in the code base --- libraries/Footnotes.class.php | 33 +++++++++------------------------ libraries/common.lib.php | 4 ++-- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/libraries/Footnotes.class.php b/libraries/Footnotes.class.php index 392124cf8f..eb6ee41339 100644 --- a/libraries/Footnotes.class.php +++ b/libraries/Footnotes.class.php @@ -39,12 +39,11 @@ class PMA_Footnotes * * @param mixed $message The message to be used for the footnote. * Can be a string or a PMA_Message object. - * @param bool $bbc Whether to generate BBCode or HTML * * @return string The marker to be displayed near the element * that is being referenced by the footnote */ - public function add($message, $bbc = false) + public function add($message) { if ($message instanceof PMA_Message) { $key = $message->getHash(); @@ -57,8 +56,7 @@ class PMA_Footnotes $id = count($this->_footnotes) + 1; $this->_footnotes[$key] = new PMA_Footnote( $id, - $message, - $bbc + $message ); } return $this->_footnotes[$key]->getMarker(); @@ -105,27 +103,18 @@ class PMA_Footnote * @access private */ private $_message; - /** - * Whether to generate BBCode or HTML - * - * @var bool - * @access private - */ - private $_bbc; /** * Generates new PMA_Footnotes objects * * @param int $id Footnote identifier * @param string $message The message to be used for the footnote - * @param bool $bbc Whether to generate BBCode or HTML * * @return PMA_Footnote object */ - public function __construct($id, $message, $bbc = false) + public function __construct($id, $message) { $this->_id = $id; - $this->_bbc = $bbc; $this->_message = $message; } @@ -137,16 +126,12 @@ class PMA_Footnote */ public function getMarker() { - if ($this->_bbc) { - $retval = '[sup]' . $this->_id . '[/sup]'; - } else { - $retval = '' . $this->_id . ''; - $retval .= PMA_getImage( - 'b_help.png', - '', - array('class' => 'footnotemarker footnote_' . $this->_id) - ); - } + $retval = '' . $this->_id . ''; + $retval .= PMA_getImage( + 'b_help.png', + '', + array('class' => 'footnotemarker footnote_' . $this->_id) + ); return $retval; } diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 9c98073818..41634c20d3 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -538,11 +538,11 @@ function PMA_showPHPDocu($target) * * @access public */ -function PMA_showHint($message, $bbcode = false) +function PMA_showHint($message) { $response = PMA_Response::getInstance(); $footnotes = $response->getFooter()->getFootnotes(); - return $footnotes->add($message, $bbcode); + return $footnotes->add($message); } /** From 796012fcc574215cf95e4fb631501d2b198c70e9 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 6 Jun 2012 12:42:39 +0100 Subject: [PATCH 65/82] Completely drop footnotes and use tooltips instead --- js/db_structure.js | 2 +- js/functions.js | 63 +++------- js/server_privileges.js | 4 +- js/server_status.js | 2 +- js/tbl_structure.js | 6 +- libraries/Footer.class.php | 31 +---- libraries/Footnotes.class.php | 153 ----------------------- libraries/Message.class.php | 8 +- libraries/common.inc.php | 6 - libraries/common.lib.php | 18 +-- setup/styles.css | 12 +- test/PMA_showHint_test.php | 189 ----------------------------- themes/original/css/common.css.php | 14 +-- themes/pmahomme/css/common.css.php | 17 +-- themes/sprites.css.php | 2 +- 15 files changed, 51 insertions(+), 476 deletions(-) delete mode 100644 libraries/Footnotes.class.php delete mode 100644 test/PMA_showHint_test.php diff --git a/js/db_structure.js b/js/db_structure.js index f5d4db94bb..5305431334 100644 --- a/js/db_structure.js +++ b/js/db_structure.js @@ -194,7 +194,7 @@ $(function() { $("table.insertRowTable").addClass("ajax"); $("#buttonYes").addClass("ajax"); $div = $("#insert_table_dialog"); - PMA_convertFootnotesToTooltips($div); + PMA_showHints($div); } PMA_ajaxRemoveMessage($msgbox); }); // end $.get() diff --git a/js/functions.js b/js/functions.js index 5dd7c8d65b..7dbb67110c 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1673,7 +1673,7 @@ function PMA_createTableDialog( $div, url , target) buttons: button_options }); // end dialog options } - PMA_convertFootnotesToTooltips($div); + PMA_showHints($div); PMA_ajaxRemoveMessage($msgbox); }); // end $.get() @@ -2922,10 +2922,6 @@ $(function() { }); }); -$(function() { - PMA_convertFootnotesToTooltips(); -}); - /** * Ensures indexes names are valid according to their type and, for a primary * key, lock index name to 'PRIMARY' @@ -2961,55 +2957,22 @@ function checkIndexName(form_id) } // end of the 'checkIndexName()' function /** - * function to convert the footnotes to tooltips + * Function to display tooltips that were + * generated on the PHP side by PMA_showHint() * - * @param jquery-Object $div a div jquery object which specifies the - * domain for searching footnootes. If we - * ommit this parameter the function searches - * the footnotes in the whole body + * @param object $div a div jquery object which specifies the + * domain for searching for tooltips. If we + * omit this parameter the function searches + * in the whole body **/ -function PMA_convertFootnotesToTooltips($div) +function PMA_showHints($div) { - // Hide the footnotes from the footer (which are displayed for - // JavaScript-disabled browsers) since the tooltip is sufficient - if ($div == undefined || ! $div instanceof jQuery || $div.length == 0) { $div = $("body"); } - - $footnotes = $div.find(".footnotes"); - - $footnotes.hide(); - $footnotes.find('span').each(function() { - $(this).children("sup").remove(); - }); - // The border and padding must be removed otherwise a thin yellow box remains visible - $footnotes.css("border", "none"); - $footnotes.css("padding", "0px"); - - // Replace the superscripts with the help icon - $div.find("sup.footnotemarker").hide(); - $div.find("img.footnotemarker").show(); - - $div.find("img.footnotemarker").each(function() { - var img_class = $(this).attr("class"); - /** img contains two classes, as example "footnotemarker footnote_1". - * We split it by second class and take it for the id of span - */ - img_class = img_class.split(" "); - for (i = 0; i < img_class.length; i++) { - if (img_class[i].split("_")[0] == "footnote") { - var span_id = img_class[i].split("_")[1]; - } - } - /** - * Now we get the #id of the span with span_id variable. As an example if we - * initially get the img class as "footnotemarker footnote_2", now we get - * #2 as the span_id. Using that we can find footnote_2 in footnotes. - * */ - var tooltip_text = $footnotes.find("span#footnote_" + span_id).html(); - $(this).qtip({ - content: tooltip_text, + $div.find('.pma_hint').each(function () { + $(this).children('img').qtip({ + content: $(this).children('span').html(), show: { delay: 0 }, hide: { delay: 1000 }, style: { background: '#ffffcc' } @@ -3017,6 +2980,10 @@ function PMA_convertFootnotesToTooltips($div) }); } +$(function() { + PMA_showHints(); +}); + /** * This function handles the resizing of the content frame * and adjusts the top menu according to the new size of the frame diff --git a/js/server_privileges.js b/js/server_privileges.js index 5394f594dd..d4c8d8d37b 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -218,7 +218,7 @@ $(function() { } }); //dialog options end displayPasswordGenerateButton(); - PMA_convertFootnotesToTooltips($div); + PMA_showHints($div); PMA_ajaxRemoveMessage($msgbox); $div.find("input[autofocus]").focus(); @@ -354,7 +354,7 @@ $(function() { }); //dialog options end displayPasswordGenerateButton(); PMA_ajaxRemoveMessage($msgbox); - PMA_convertFootnotesToTooltips($div); + PMA_showHints($div); }); // end $.get() }); diff --git a/js/server_status.js b/js/server_status.js index edd0c54658..243cbe84d3 100644 --- a/js/server_status.js +++ b/js/server_status.js @@ -437,7 +437,7 @@ $(function() { if (data != null) { tab.find('.tabInnerContent').html(data); } - PMA_convertFootnotesToTooltips(); + PMA_showHints(); break; case 'statustabs_queries': if (data != null) { diff --git a/js/tbl_structure.js b/js/tbl_structure.js index 2a931d206a..c93826504f 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -301,7 +301,7 @@ $(function() { }); checkIndexType(); checkIndexName("index_frm"); - PMA_convertFootnotesToTooltips($div); + PMA_showHints($div); // Add a slider for selecting how many columns to add to the index $div.find('.slider').slider({ animate: true, @@ -542,7 +542,7 @@ $(function() { $div = $("#add_columns"); /*changed the z-index of the enum editor to allow the edit*/ $("#enum_editor").css("z-index", "1100"); - PMA_convertFootnotesToTooltips($div); + PMA_showHints($div); // set focus on first column name input $div.find("input.textfield").eq(0).focus(); } @@ -620,7 +620,7 @@ function changeColumns(action,url) /*changed the z-index of the enum editor to allow the edit*/ $("#enum_editor").css("z-index", "1100"); $div = $("#change_column_dialog"); - PMA_convertFootnotesToTooltips($div); + PMA_showHints($div); } PMA_ajaxRemoveMessage($msgbox); }); // end $.get() diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 21bf6a734e..5be2168c8d 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -10,7 +10,6 @@ if (! defined('PHPMYADMIN')) { } require_once 'libraries/Scripts.class.php'; -require_once 'libraries/Footnotes.class.php'; /** * Class used to output the footer @@ -19,13 +18,6 @@ require_once 'libraries/Footnotes.class.php'; */ class PMA_Footer { - /** - * PMA_Footnotes instance - * - * @access private - * @var object - */ - private $_footnotes; /** * PMA_Scripts instance * @@ -44,7 +36,7 @@ class PMA_Footer private $_isAjax; /** * Whether to only close the BODY and HTML tags - * or also include scripts, footnotes, errors and links + * or also include scripts, errors and links * * @access private * @var bool @@ -66,7 +58,6 @@ class PMA_Footer public function __construct() { $this->_isEnabled = true; - $this->_footnotes = new PMA_Footnotes(); $this->_scripts = new PMA_Scripts(); $this->_isMinimal = false; $this->_addDefaultScripts(); @@ -282,16 +273,6 @@ class PMA_Footer $this->_isMinimal = true; } - /** - * Returns the PMA_Footnotes object - * - * @return PMA_Footnotes object - */ - public function getFootnotes() - { - return $this->_footnotes; - } - /** * Renders the footer * @@ -322,13 +303,6 @@ class PMA_Footer $retval .= $this->_getSelfLink($url_params); } $retval .= $this->_getDebugMessage(); - } - if (! $this->_isMinimal) { - // display Footnotes and error messages even in ajax reqests - // FIXME: nootnotes should be sent as JSON - $retval .= $this->_footnotes->getDisplay(); - } - if (! $this->_isAjax && ! $this->_isMinimal) { $retval .= $this->_getErrorMessages(); $retval .= $this->_scripts->getDisplay(); // Include possible custom footers @@ -337,8 +311,7 @@ class PMA_Footer include CUSTOM_FOOTER_FILE; $retval .= ob_end_clean(); } - } - if (! $this->_isAjax) { + } else if (! $this->_isAjax) { $retval .= ""; } } diff --git a/libraries/Footnotes.class.php b/libraries/Footnotes.class.php deleted file mode 100644 index eb6ee41339..0000000000 --- a/libraries/Footnotes.class.php +++ /dev/null @@ -1,153 +0,0 @@ -_footnotes = array(); - } - - /** - * Setter for the ID attribute in the BODY tag - * - * @param mixed $message The message to be used for the footnote. - * Can be a string or a PMA_Message object. - * - * @return string The marker to be displayed near the element - * that is being referenced by the footnote - */ - public function add($message) - { - if ($message instanceof PMA_Message) { - $key = $message->getHash(); - $message = $message->getDisplay(); - } else { - $key = md5($message); - } - - if (! isset($this->_footnotes[$key])) { - $id = count($this->_footnotes) + 1; - $this->_footnotes[$key] = new PMA_Footnote( - $id, - $message - ); - } - return $this->_footnotes[$key]->getMarker(); - } - - /** - * Renders the footnotes - * - * @return string - */ - public function getDisplay() - { - $retval = ''; - if (count($this->_footnotes)) { - $retval .= '
'; - foreach ($this->_footnotes as $footnote) { - $retval .= $footnote->getDisplay(); - } - $retval .= '
'; - } - return $retval; - } -} - -/** - * Each object of this class represents a footnote - * Used by PMA_Footnotes - * - * @package PhpMyAdmin - */ -class PMA_Footnote -{ - /** - * Footnote identifier - * - * @var int - * @access private - */ - private $_id; - /** - * The message to be used for the footnote - * - * @var string - * @access private - */ - private $_message; - - /** - * Generates new PMA_Footnotes objects - * - * @param int $id Footnote identifier - * @param string $message The message to be used for the footnote - * - * @return PMA_Footnote object - */ - public function __construct($id, $message) - { - $this->_id = $id; - $this->_message = $message; - } - - /** - * Returns the marker to be displayed near the element - * that is being referenced by this footnote - * - * @return string - */ - public function getMarker() - { - $retval = '' . $this->_id . ''; - $retval .= PMA_getImage( - 'b_help.png', - '', - array('class' => 'footnotemarker footnote_' . $this->_id) - ); - return $retval; - } - - /** - * Renders the footnote - * - * @return string - */ - public function getDisplay() - { - $retval = ''; - $retval .= '' . $this->_id . ' '; - $retval .= $this->_message; - $retval .= '
'; - return $retval; - } -} - -?> diff --git a/libraries/Message.class.php b/libraries/Message.class.php index 61e7cda64b..de7cfe9fba 100644 --- a/libraries/Message.class.php +++ b/libraries/Message.class.php @@ -27,15 +27,15 @@ * $message = PMA_Message::success('strSomeLocaleMessage'); * * // create another message, a hint, with a localized string which expects - * // two parameters: $strSomeFootnote = 'Read the %smanual%s' - * $hint = PMA_Message::notice('strSomeFootnote'); + * // two parameters: $strSomeTooltip = 'Read the %smanual%s' + * $hint = PMA_Message::notice('strSomeTooltip'); * // replace %d with the following params * $hint->addParam('[a@./Documentation.html#cfg_Example@_blank]'); * $hint->addParam('[/a]'); - * // add this hint as a footnote + * // add this hint as a tooltip * $hint = PMA_showHint($hint); * - * // add the retrieved footnote reference to the original message + * // add the retrieved tooltip reference to the original message * $message->addMessage($hint); * * // create another message ... diff --git a/libraries/common.inc.php b/libraries/common.inc.php index d3dfffe78d..d0a84f92eb 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -545,12 +545,6 @@ if (PMA_isValid($_REQUEST['sql_query'])) { //$_REQUEST['server']; // checked later in this file //$_REQUEST['lang']; // checked by LABEL_loading_language_file -/** - * footnotes to be displayed ot the page bottom - * @global array $footnotes - */ -$GLOBALS['footnotes'] = array(); - /******************************************************************************/ /* loading language file LABEL_loading_language_file */ diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 41634c20d3..22bf6e6b50 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -528,21 +528,23 @@ function PMA_showPHPDocu($target) } // end of the 'PMA_showPHPDocu()' function /** - * returns HTML for a footnote marker and add the messsage to the footnotes + * Returns HTML code for a tooltip * - * @param string $message the error message - * @param bool $bbcode whether to interpret BB code - * @param string $type message types + * @param string $message the message for the tooltip * - * @return string html code for a footnote marker + * @return string * * @access public */ function PMA_showHint($message) { - $response = PMA_Response::getInstance(); - $footnotes = $response->getFooter()->getFootnotes(); - return $footnotes->add($message); + $retval = ''; + $retval .= PMA_getImage('b_help.png'); + $retval .= ''; + $retval .= $message; + $retval .= ''; + $retval .= ''; + return $retval; } /** diff --git a/setup/styles.css b/setup/styles.css index e7e955c275..c6798c74e2 100644 --- a/setup/styles.css +++ b/setup/styles.css @@ -118,8 +118,7 @@ div.error h4 { div.success, div.notice, -div.error, -div.footnotes { +div.error { margin: .5em 0 1.3em 0; border: 1px solid; background-repeat: no-repeat; @@ -137,8 +136,7 @@ div.footnotes { .success a, .notice a, -.error a, -.footnotes a { +.error a { text-decoration: underline; } @@ -158,15 +156,13 @@ div.success { border-color: #00FF00; } -.notice, -.footnotes { +.notice { color: #000; background-color: #e8eef1; } h1.notice, -div.notice, -div.footnotes { +div.notice { border-color: #3a6c7e; background-image: url(../themes/pmahomme/img/s_notice.png); background-repeat: no-repeat; diff --git a/test/PMA_showHint_test.php b/test/PMA_showHint_test.php deleted file mode 100644 index e99114cb48..0000000000 --- a/test/PMA_showHint_test.php +++ /dev/null @@ -1,189 +0,0 @@ -tmpGlobals = $GLOBALS; - $this->tmpSession = $_SESSION; - } - - /** - * recovering globals and session - */ - public function tearDown() - { - $GLOBALS = $this->tmpGlobals; - $_SESSION = $this->tmpSession; - } - - /** - * PMA_showHint with defined GLOBALS - */ - public function testShowHintReturnValue() - { - $key = md5('test'); - $nr = 1234; - $instance = 1; - - $GLOBALS['footnotes'][$key]['nr'] = $nr; - $GLOBALS['footnotes'][$key]['instance'] = $instance; - $this->assertEquals( - sprintf( - '%d', - $nr, $instance + 1, $nr - ), - PMA_showHint('test') - ); - } - - /** - * PMA_showHint with defined GLOBALS formatted as BB - */ - public function testShowHintReturnValueBbFormat() - { - $key = md5('test'); - $nr = 1234; - $instance = 1; - - $GLOBALS['footnotes'][$key]['nr'] = $nr; - $GLOBALS['footnotes'][$key]['instance'] = $instance; - $this->assertEquals( - sprintf('[sup]%d[/sup]', $nr), - PMA_showHint('test', true) - ); - } - - /** - * PMA_showHint with not defined GLOBALS - */ - public function testShowHintSetting() - { - $key = md5('test'); - $nr = 1; - $instance = 1; - - $this->assertEquals(sprintf('%d', $nr, $instance, $nr), PMA_showHint('test', false, 'notice')); - - $expArray = array( - 'note' => 'test', - 'type' => 'notice', - 'nr' => count($GLOBALS['footnotes']), - 'instance' => 1, - ); - - $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]); - } - - /** - * PMA_showHint with not defined GLOBALS formatted as BB - * @depends testShowHintSetting - */ - public function testShowHintSettingBbFormat() - { - $key = md5('test'); - $nr = 1; - $instance = 1; - - $this->assertEquals(sprintf('[sup]%d[/sup]', $nr), PMA_showHint('test', true, 'notice')); - - $expArray = array( - 'note' => 'test', - 'type' => 'notice', - 'nr' => count($GLOBALS['footnotes']), - 'instance' => 1, - ); - - $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]); - } - - /** - * PMA_showHint with defined GLOBALS using PMA_Message object - */ - public function testShowHintPmaMessageReturnValue() - { - $nr = 1; - $instance = 1; - - $oMock = $this->getMock( - 'PMA_Message', - array('setMessage', 'setNumber', 'getHash', 'getLevel') - ); - $oMock->setMessage('test'); - $oMock->setNumber($nr); - - $key = $oMock->getHash(); - - $GLOBALS['footnotes'][$key]['nr'] = $nr; - $GLOBALS['footnotes'][$key]['instance'] = $instance; - - $this->assertEquals( - sprintf( - '%d', - $nr, $instance + 1, $nr - ), - PMA_showHint($oMock) - ); - } - - /** - * PMA_showHint with not defined GLOBALS using PMA_Message object - */ - public function testShowHintPmaMessageSetting() - { - $nr = 1; - $instance = 1; - - $oMock = $this->getMock( - 'PMA_Message', - array('setMessage', 'setNumber', 'getHash', 'getLevel', 'getNumber') - ); - $oMock->setMessage('test'); - $oMock->setNumber($nr); - - $this->assertEquals( - sprintf( - '%d', - $nr, $instance, $nr - ), - PMA_showHint($oMock, false) - ); - - $key = $oMock->getHash(); - - $expArray = array( - 'note' => $oMock, - 'type' => $oMock->getLevel(), - 'nr' => count($GLOBALS['footnotes']), - 'instance' => 1, - ); - - $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]); - } -} -?> diff --git a/themes/original/css/common.css.php b/themes/original/css/common.css.php index 91c3a65d45..dfbb8882ac 100644 --- a/themes/original/css/common.css.php +++ b/themes/original/css/common.css.php @@ -427,16 +427,12 @@ img.lightbulb { } /* leave some space between icons and text */ -.icon, img.footnotemarker { +.icon { vertical-align: middle; margin-right: 0.3em; margin-left: 0.3em; } -img.footnotemarker { - display: none; -} - /* no extra space in table cells */ td .icon { margin: 0; @@ -459,8 +455,7 @@ div.error h1 { div.success, div.notice, -div.error, -div.footnotes { +div.error { margin: 0.3em 0 0 0; border: 2px solid; background-repeat: no-repeat; @@ -494,13 +489,12 @@ div.success { border-color: #00FF00; } -.notice, .footnotes { +.notice { color: #000000; background-color: #FFFFDD; } h1.notice, -div.notice, -div.footnotes { +div.notice { border-color: #FFD700; background-image: url(getImgPath(); ?>s_notice.png); background-repeat: no-repeat; diff --git a/themes/pmahomme/css/common.css.php b/themes/pmahomme/css/common.css.php index ef19d2dd33..5379c5bc6e 100644 --- a/themes/pmahomme/css/common.css.php +++ b/themes/pmahomme/css/common.css.php @@ -652,11 +652,6 @@ img.lightbulb { .syntax_quote_backtick { } -/* leave some space between icons and text */ -img.footnotemarker { - display: none; -} - /* no extra space in table cells */ td .icon { margin: 0; @@ -679,8 +674,7 @@ div.error h1 { div.success, div.notice, -div.error, -div.footnotes { +div.error { margin: .5em 0 1.3em 0; border: 1px solid; background-repeat: no-repeat; @@ -703,8 +697,7 @@ div.footnotes { .success a, .notice a, -.error a, -.footnotes a { +.error a { text-decoration: underline; } @@ -728,15 +721,13 @@ div.success { border-color: #00FF00; } -.notice, -.footnotes { +.notice { color: #000; background-color: #e8eef1; } h1.notice, -div.notice, -div.footnotes { +div.notice { border-color: #3a6c7e; background-image: url(getImgPath(); ?>s_notice.png); background-repeat: no-repeat; diff --git a/themes/sprites.css.php b/themes/sprites.css.php index e51e1a557a..2c12589a41 100644 --- a/themes/sprites.css.php +++ b/themes/sprites.css.php @@ -17,7 +17,7 @@ if (is_readable($_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php')) { ?> /* Icon sprites */ -.icon, .footnotemarker { +.icon { margin: 0 .3em; padding: 0 !important; width: 16px; From a3d7a055ee2efaa5c1713642affb8ee9113d142d Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 6 Jun 2012 13:17:42 +0100 Subject: [PATCH 66/82] Docblock fixes --- libraries/Footer.class.php | 4 ++-- libraries/Header.class.php | 13 +++++++++++-- libraries/Response.class.php | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 5be2168c8d..5420abbc53 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -244,9 +244,9 @@ class PMA_Footer } /** - * + * Disables the rendering of the footer * - * @return + * @return void */ public function disable() { diff --git a/libraries/Header.class.php b/libraries/Header.class.php index f54a906b1a..e1c22b855b 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -101,6 +101,9 @@ class PMA_Header * Whether the HTTP headers (and possibly some HTML) * have already been sent to the browser * + * FIXME: Shouldn't be static or public, but first + * need to remove references to it from the code base + * * @access public * @static * @var bool @@ -178,9 +181,9 @@ class PMA_Header } /** - * + * Disables the rendering of the header * - * @return + * @return void */ public function disable() { @@ -435,6 +438,12 @@ class PMA_Header return $retval; } + /** + * If the page is missing the title, this function + * will set it to something reasonable + * + * @return string + */ private function _getPageTitle() { if (empty($this->_title)) { diff --git a/libraries/Response.class.php b/libraries/Response.class.php index e7b2923a3a..ede4ac1062 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -120,7 +120,8 @@ class PMA_Response } /** - * FIXME + * Set the status of an ajax response, + * whether it is a success or an error * * @return void */ From 74199dd1146ca7684f997476f8fb34c24c177d88 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 6 Jun 2012 13:18:54 +0100 Subject: [PATCH 67/82] Display messages once on password change --- user_password.php | 1 + 1 file changed, 1 insertion(+) diff --git a/user_password.php b/user_password.php index 470ab460f6..258585e019 100644 --- a/user_password.php +++ b/user_password.php @@ -56,6 +56,7 @@ if (isset($_REQUEST['nopass'])) { // Displays an error message if required if (isset($message)) { $message->display(); + unset($message); } require_once './libraries/display_change_password.lib.php'; From c7d835347ca80e15b93e20e523519ec3842e0bf5 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Thu, 7 Jun 2012 11:18:37 +0100 Subject: [PATCH 68/82] Force JSON response for AJAX requests --- libraries/Footer.class.php | 5 ++-- libraries/Header.class.php | 7 +++-- libraries/Response.class.php | 48 ++++++++++++++++++++++-------- libraries/auth/cookie.auth.lib.php | 16 ++++++++-- libraries/common.inc.php | 9 +++--- 5 files changed, 60 insertions(+), 25 deletions(-) diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index 5420abbc53..f3874fc53e 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -254,11 +254,12 @@ class PMA_Footer } /** - * + * Set the ajax flag to indicate whether + * we are sevicing an ajax request * * @return void */ - public function isAjax($isAjax) + public function setAjax($isAjax) { $this->_isAjax = $isAjax; } diff --git a/libraries/Header.class.php b/libraries/Header.class.php index e1c22b855b..9582936d45 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -191,11 +191,12 @@ class PMA_Header } /** - * + * Set the ajax flag to indicate whether + * we are sevicing an ajax request * - * @return + * @return void */ - public function isAjax($isAjax) + public function setAjax($isAjax) { $this->_isAjax = $isAjax; } diff --git a/libraries/Response.class.php b/libraries/Response.class.php index ede4ac1062..498703ab83 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -101,8 +101,8 @@ class PMA_Response if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $this->_isAjax = true; } - $this->_header->isAjax($this->_isAjax); - $this->_footer->isAjax($this->_isAjax); + $this->_header->setAjax($this->_isAjax); + $this->_footer->setAjax($this->_isAjax); $this->_CWD = getcwd(); } @@ -134,6 +134,17 @@ class PMA_Response } } + /** + * Returns true or false depending on whether + * we are servicing an ajax request + * + * @return void + */ + public function isAjax() + { + return $this->_isAjax; + } + /** * Returns the path to the current working directory * Necessary to work around a PHP bug where the CWD is @@ -255,17 +266,28 @@ class PMA_Response */ private function _ajaxResponse() { - if (empty($this->_JSON)) { - // header('Content-Type: text/html; charset=utf-8'); - echo $this->_getDisplay(); - } else { - if (! isset($this->_JSON['message'])) { - $this->_JSON['message'] = $this->_getDisplay(); - } - $message = $this->_JSON['message']; - unset($this->_JSON['message']); - PMA_ajaxResponse($message, $this->_isSuccess, $this->_JSON); + if (! isset($this->_JSON['message'])) { + $this->_JSON['message'] = $this->_getDisplay(); + } else if ($this->_JSON['message'] instanceof PMA_Message) { + $this->_JSON['message'] = $this->_JSON['message']->getDisplay(); } + + if ($this->_isSuccess) { + $this->_JSON['success'] = true; + } else { + $this->_JSON['success'] = false; + $this->_JSON['error'] = $this->_JSON['message']; + unset($this->_JSON['message']); + } + + // Set the Content-Type header to JSON so that jQuery parses the + // response correctly. + if (! defined('TESTSUITE')) { + header('Cache-Control: no-cache'); + header('Content-Type: application/json'); + } + + echo json_encode($this->_JSON); } /** @@ -282,7 +304,7 @@ class PMA_Response if (empty($response->_HTML)) { $response->_HTML = $buffer->getContents(); } - if ($response->_isAjax) { + if ($response->isAjax()) { $response->_ajaxResponse(); } else { $response->_htmlResponse(); diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index 333732ecd7..7eb487c014 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -130,6 +130,17 @@ function PMA_auth() { global $conn_error; + $response = PMA_Response::getInstance(); + if ($response->isAjax()) { + $response->isSuccess(false); + if (! empty($conn_error)) { + $response->addJSON('message', $conn_error); + } else { + $response->addJSON('message', __('Session expired')); + } + exit; + } + /* Perform logout to custom URL */ if (! empty($_REQUEST['old_usr']) && ! empty($GLOBALS['cfg']['Server']['LogoutURL']) @@ -154,7 +165,6 @@ function PMA_auth() $cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right'; - $response = PMA_Response::getInstance(); $response->getFooter()->setMinimal(); $header = $response->getHeader(); $header->setBodyId('loginform'); @@ -571,11 +581,13 @@ function PMA_auth_set_user() */ PMA_clearUserCache(); + PMA_Response::getInstance()->disable(); + PMA_sendHeaderLocation( $redirect_url . PMA_generate_common_url($url_params, '&'), true ); - exit(); + exit; } // end if return true; diff --git a/libraries/common.inc.php b/libraries/common.inc.php index d0a84f92eb..d4593423b2 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -476,7 +476,9 @@ if (! PMA_isValid($_REQUEST['token']) /* Cookie preferences */ 'pma_lang', 'pma_collation_connection', /* Possible login form */ - 'pma_servername', 'pma_username', 'pma_password' + 'pma_servername', 'pma_username', 'pma_password', + /* Needed to send the correct reply */ + 'ajax_request' ); /** * Allow changing themes in test/theme.php @@ -846,7 +848,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { * the required auth type plugin */ include_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php'; - if (!PMA_auth_check()) { + if (! PMA_auth_check()) { /* Force generating of new session on login */ PMA_secureSession(); PMA_auth(); @@ -897,7 +899,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { PMA_log_user($cfg['Server']['user'], 'allow-denied'); PMA_auth_fails(); } - unset($allowDeny_forbidden); //Clean up after you! } // end if // is root allowed? @@ -905,7 +906,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { $allowDeny_forbidden = true; PMA_log_user($cfg['Server']['user'], 'root-denied'); PMA_auth_fails(); - unset($allowDeny_forbidden); //Clean up after you! } // is a login without password allowed? @@ -913,7 +913,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { $login_without_password_is_forbidden = true; PMA_log_user($cfg['Server']['user'], 'empty-denied'); PMA_auth_fails(); - unset($login_without_password_is_forbidden); //Clean up after you! } // if using TCP socket is not needed From bdb33e4548ab33bf8b4c10674d4b2d02b9a9e76c Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Thu, 7 Jun 2012 11:30:03 +0100 Subject: [PATCH 69/82] Fixed ajax response for change password form --- js/functions.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/js/functions.js b/js/functions.js index 7dbb67110c..40a5c2f38f 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2592,16 +2592,11 @@ $(function() { * Attach Ajax event handler on the change password anchor * @see $cfg['AjaxEnable'] */ - $('#change_password_anchor.dialog_active').live('click', function(event) { - event.preventDefault(); - return false; - }); $('#change_password_anchor.ajax').live('click', function(event) { event.preventDefault(); var $msgbox = PMA_ajaxShowMessage(); - $(this).removeClass('ajax').addClass('dialog_active'); /** * @var button_options Object containing options to be passed to jQueryUI's dialog */ @@ -2634,7 +2629,6 @@ $(function() { $("#floating_menubar").after(data.message); $("#change_password_dialog").hide().remove(); $("#edit_user_dialog").dialog("close").remove(); - $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax'); PMA_ajaxRemoveMessage($msgbox); } else { @@ -2655,11 +2649,9 @@ $(function() { $(this).remove(); }, buttons : button_options, - beforeClose: function(ev, ui) { - $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax'); - } + modal: true }) - .append(data); + .append(data.message); // for this dialog, we remove the fieldset wrapping due to double headings $("fieldset#fieldset_change_password") .find("legend").remove().end() From 1e4d8fd6b45d7da5a558095f265e61c177700b8e Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Thu, 7 Jun 2012 11:30:54 +0100 Subject: [PATCH 70/82] Fixed ajax response for "display git revision" --- libraries/display_git_revision.lib.php | 8 +++----- main.php | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/display_git_revision.lib.php b/libraries/display_git_revision.lib.php index 51b6553a06..f5dee92990 100644 --- a/libraries/display_git_revision.lib.php +++ b/libraries/display_git_revision.lib.php @@ -17,7 +17,9 @@ if (! defined('PHPMYADMIN')) { function PMA_printGitRevision() { if (! $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) { - PMA_ajaxResponse('', false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + return; } // load revision data from repo @@ -56,7 +58,6 @@ function PMA_printGitRevision() $branch = $commit_hash . ' (' . __('no branch') . ')'; } - ob_start(); $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER'); $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR'); PMA_printListItem( @@ -79,7 +80,4 @@ function PMA_printGitRevision() : ''), 'li_pma_version_git', null, null, null ); - $item = ob_get_contents(); - ob_end_clean(); - PMA_ajaxResponse($item, true); } diff --git a/main.php b/main.php index 96034690a6..6bbd41d632 100644 --- a/main.php +++ b/main.php @@ -18,6 +18,7 @@ require_once 'libraries/display_git_revision.lib.php'; if ($GLOBALS['PMA_Config']->isGitRevision()) { if (isset($_REQUEST['git_revision']) && $GLOBALS['is_ajax_request'] == true) { PMA_printGitRevision(); + exit; } PMA_addJSVar('is_git_revision', true); } From 11ccc109513c0b3cf7ae61878e7a70091ed55ee2 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 9 Jun 2012 14:05:12 +0100 Subject: [PATCH 71/82] Moved the check for whether warnings are enabled inside function --- libraries/Header.class.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 9582936d45..6b635737f5 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -316,9 +316,7 @@ class PMA_Header if (! $GLOBALS['cfg']['ShowHint']) { $retval .= ''; } - if ($this->_warningsEnabled) { - $retval .= $this->_getWarnings(); - } + $retval .= $this->_getWarnings(); if ($this->_menuEnabled && $GLOBALS['server'] > 0) { $retval .= $this->_menu->getDisplay(); } @@ -492,19 +490,21 @@ class PMA_Header private function _getWarnings() { $retval = ''; - // message of "Cookies required" displayed for auth_type http or config - // note: here, the decoration won't work because without cookies, - // our standard CSS is not operational - if (empty($_COOKIE)) { - $retval .= PMA_Message::notice( - __('Cookies must be enabled past this point.') + if ($this->_warningsEnabled) { + // message of "Cookies required" displayed for auth_type http or config + // note: here, the decoration won't work because without cookies, + // our standard CSS is not operational + if (empty($_COOKIE)) { + $retval .= PMA_Message::notice( + __('Cookies must be enabled past this point.') + )->getDisplay(); + } + $retval .= ""; } - $retval .= ""; return $retval; } From ef2b98dd8e12c7f7bd11de65930c69556cf0c28b Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 9 Jun 2012 14:18:49 +0100 Subject: [PATCH 72/82] Use PMA_Response class in PMA_ajaxResponse() --- libraries/Response.class.php | 2 +- libraries/common.lib.php | 43 +++++------------------------------- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 498703ab83..f78d98cc98 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -216,7 +216,7 @@ class PMA_Response * * @return void */ - public function addJSON($json, $value) + public function addJSON($json, $value = null) { if (is_array($json)) { foreach ($json as $key => $value) { diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 22bf6e6b50..08b0437c94 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -3259,44 +3259,11 @@ function PMA_expandUserString($string, $escape = null, $updates = array()) */ function PMA_ajaxResponse($message, $success = true, $extra_data = array()) { - $response = array(); - if ( $success == true ) { - $response['success'] = true; - if ($message instanceof PMA_Message) { - $response['message'] = $message->getDisplay(); - } else { - $response['message'] = $message; - } - } else { - $response['success'] = false; - if ($message instanceof PMA_Message) { - $response['error'] = $message->getDisplay(); - } else { - $response['error'] = $message; - } - } - - // If extra_data has been provided, append it to the response array - if ( ! empty($extra_data) && count($extra_data) > 0 ) { - $response = array_merge($response, $extra_data); - } - - // Set the Content-Type header to JSON so that jQuery parses the - // response correctly. - // - // At this point, other headers might have been sent; - // even if $GLOBALS['is_header_sent'] is true, - // we have to send these additional headers. - if (! defined('TESTSUITE')) { - header('Cache-Control: no-cache'); - header("Content-Type: application/json"); - } - - echo json_encode($response); - - if (! defined('TESTSUITE')) { - exit; - } + $response = PMA_Response::getInstance(); + $response->isSuccess($success); + $response->addJSON('message', $message); + $response->addJSON($extra_data); + exit; } /** From 971db49c1143446238157c9bf6b8fc5bed3b55fb Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 9 Jun 2012 17:46:00 +0100 Subject: [PATCH 73/82] Expect JSON for every ajax request in JavaScript --- js/db_operations.js | 9 +++---- js/db_search.js | 8 +++--- js/db_structure.js | 2 +- js/functions.js | 47 ++++++++++++++++----------------- js/makegrid.js | 3 +-- js/navigation.js | 2 ++ js/server_databases.js | 3 +-- js/server_privileges.js | 35 ++++++++----------------- js/server_status.js | 4 +-- js/server_status_monitor.js | 8 +++--- js/server_variables.js | 2 +- js/sql.js | 52 ++++++++++++++----------------------- js/tbl_change.js | 3 +++ js/tbl_select.js | 15 +++-------- js/tbl_structure.js | 28 +++++++++----------- sql.php | 2 +- 16 files changed, 92 insertions(+), 131 deletions(-) diff --git a/js/db_operations.js b/js/db_operations.js index 170ff1ec0e..42c0f4552c 100644 --- a/js/db_operations.js +++ b/js/db_operations.js @@ -69,8 +69,7 @@ $(function() { $("" + PMA_messages['strReloadDatabase'] + "?").dialog({ buttons: button_options }) //end dialog options - } - else { + } else { PMA_ajaxShowMessage(data.error, false); } }) // end $.get() @@ -106,8 +105,7 @@ $(function() { // not refresh it window.parent.refreshNavigation(true); } - } - else { + } else { $('#floating_menubar').after(data.error); } @@ -131,8 +129,7 @@ $(function() { $.get($form.attr('action'), $form.serialize() + "&submitcollation=" + $form.find("input[name=submitcollation]").val(), function(data) { if(data.success == true) { PMA_ajaxShowMessage(data.message); - } - else { + } else { PMA_ajaxShowMessage(data.error, false); } }) // end $.get() diff --git a/js/db_search.js b/js/db_search.js index 5c80bb2f90..f1a18d48b4 100644 --- a/js/db_search.js +++ b/js/db_search.js @@ -193,10 +193,10 @@ $(function() { PMA_prepareForAjaxRequest($form); var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val(); - $.post($form.attr('action'), url, function(response) { - if (typeof response == 'string') { + $.post($form.attr('action'), url, function(data) { + if (data.success == true) { // found results - $("#searchresults").html(response); + $("#searchresults").html(data.message); $('#togglesearchresultlink') // always start with the Show message @@ -219,7 +219,7 @@ $(function() { .show(); } else { // error message (zero rows) - $("#sqlqueryresults").html(response['message']); + $("#sqlqueryresults").html(data.error); } PMA_ajaxRemoveMessage($msgbox); diff --git a/js/db_structure.js b/js/db_structure.js index 5305431334..8b0629713e 100644 --- a/js/db_structure.js +++ b/js/db_structure.js @@ -173,7 +173,7 @@ $(function() { }); // end dialog options } else { var $dialog = $div - .append(data) + .append(data.message) .dialog({ title: PMA_messages['strInsertTable'], height: 600, diff --git a/js/functions.js b/js/functions.js index 40a5c2f38f..a20a204e6b 100644 --- a/js/functions.js +++ b/js/functions.js @@ -157,10 +157,9 @@ function PMA_display_git_revision() $.get("main.php?token=" + $("input[type=hidden][name=token]").val() + "&git_revision=1&ajax_request=true", function (data) { - if (data.error != "undefined" && data.error) { - return; + if (data.success == true) { + $(data.message).insertAfter('#li_pma_version'); } - $(data.message).insertAfter('#li_pma_version'); }); } @@ -1612,12 +1611,11 @@ function PMA_createTableDialog( $div, url , target) })// end dialog options //remove the redundant [Back] link in the error message. .find('fieldset').remove(); - } - else { + } else { var size = getWindowSize(); var timeout; $div - .append(data) + .append(data.message) .dialog({ dialogClass: 'create-table', resizable: false, @@ -1730,7 +1728,7 @@ function PMA_createChart(passedSettings) thisChart.options.realtime.postData, function(data) { try { - curValue = jQuery.parseJSON(data); + curValue = jQuery.parseJSON(data.message); } catch (err) { if (thisChart.options.realtime.error) { thisChart.options.realtime.error(err); @@ -2335,11 +2333,11 @@ $(function() { $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) { // if 'create_table_dialog' exists if ($("#create_table_dialog").length > 0) { - $("#create_table_dialog").html(data); + $("#create_table_dialog").html(data.message); } // if 'create_table_div' exists if ($("#create_table_div").length > 0) { - $("#create_table_div").html(data); + $("#create_table_div").html(data.message); } PMA_verifyColumnsProperties(); PMA_ajaxRemoveMessage($msgbox); @@ -2375,7 +2373,7 @@ $(function() { $("
").insertAfter("#floating_menubar"); $("#sqlqueryresults").html(data.sql_query); $("#result_query .notice").remove(); - $("#result_query").prepend((data.message)); + $("#result_query").prepend(data.message); } else { var $temp_div = $("
"); $temp_div.html(data.error); @@ -2411,7 +2409,7 @@ $(function() { $("
").insertAfter("#floating_menubar"); $("#sqlqueryresults").html(data.sql_query); $("#result_query .notice").remove(); - $("#result_query").prepend((data.message)); + $("#result_query").prepend(data.message); $("#copyTable").find("select[name='target_db'] option").filterByValue(data.db).prop('selected', true); //Refresh navigation frame when the table is coppied @@ -2444,19 +2442,19 @@ $(function() { } //variables which stores the common attributes $.post(href[0], href[1]+"&ajax_request=true", function(data) { - if (data.success == undefined) { - var $temp_div = $("
"); - $temp_div.html(data); - var $success = $temp_div.find("#result_query .success"); - PMA_ajaxShowMessage($success); - $("
").insertAfter("#floating_menubar"); - $("#sqlqueryresults").html(data); - PMA_init_slider(); - $("#sqlqueryresults").children("fieldset").remove(); - } else if (data.success == true ) { + if (data.success == true && data.sql_query != undefined) { PMA_ajaxShowMessage(data.message); $("
").insertAfter("#floating_menubar"); $("#sqlqueryresults").html(data.sql_query); + } else if (data.success == true) { + var $temp_div = $("
"); + $temp_div.html(data.message); + var $success = $temp_div.find("#result_query .success"); + PMA_ajaxShowMessage($success); + $("
").insertAfter("#floating_menubar"); + $("#sqlqueryresults").html(data.message); + PMA_init_slider(); + $("#sqlqueryresults").children("fieldset").remove(); } else { var $temp_div = $("
"); $temp_div.html(data.error); @@ -2535,8 +2533,7 @@ $(function() { if (window.parent && window.parent.frame_navigation) { window.parent.frame_navigation.location.reload(); } - } - else { + } else { PMA_ajaxShowMessage(data.error, false); } }); // end $.post() @@ -3798,13 +3795,13 @@ $(document).ready(function () { buttonOptions[PMA_messages['strClose']] = function () { $(this).dialog("close"); }; - var $dialog = $('
').attr('id', 'createViewDialog').append(data).dialog({ + var $dialog = $('
').attr('id', 'createViewDialog').append(data.message).dialog({ width: 500, minWidth: 300, maxWidth: 620, modal: true, buttons: buttonOptions, - title: $('legend', $(data)).html(), + title: $('legend', $(data.message)).html(), close: function () { $(this).remove(); } diff --git a/js/makegrid.js b/js/makegrid.js index 00f49ea8a9..3edcb7f699 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -950,8 +950,7 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi $editArea.find('textarea').val($(this).val()); }); $editArea.append('
' + g.cellEditHint + '
'); - } - else { + } else { PMA_ajaxShowMessage(data.error, false); } }); // end $.post() diff --git a/js/navigation.js b/js/navigation.js index cd65e595d8..f8e335cf16 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -180,12 +180,14 @@ function fast_filter(value) } fast_filter.ajax_semaphore = true; $.get('db_tables_search.php?db=' + db +'&table=' + lowercase_value, function(data) { + if (data.tables) { var tables = data.tables; var l = tables.length; for(var i = 0; i < l; i++) { $('#subel0').append(tables[i].line); } fast_filter.ajax_semaphore = false; + } }); } } diff --git a/js/server_databases.js b/js/server_databases.js index 5fdff9344b..14684279f0 100644 --- a/js/server_databases.js +++ b/js/server_databases.js @@ -59,8 +59,7 @@ $(function() { window.parent.frame_navigation.location.reload(); } $('#tableslistcontainer').load('server_databases.php form#dbStatsForm'); - } - else { + } else { PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest + ": " + data.error, false); } }); // end $.post() diff --git a/js/server_privileges.js b/js/server_privileges.js index d4c8d8d37b..5303ac276f 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -169,22 +169,12 @@ $(function() { } else { $("#usersForm").remove(); } - var $user_div = $('
'); - /*If the JSON string parsed correctly*/ - if (typeof priv_data.success != 'undefined') { - if (priv_data.success == true) { - $user_div - .html(priv_data.user_form) - .insertAfter('#result_query'); - } else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + priv_data.error, false); - } + if (priv_data.success == true) { + $('
') + .html(priv_data.user_form) + .insertAfter('#result_query'); } else { - /*parse the JSON string*/ - var obj = $.parseJSON(priv_data); - $user_div - .html(obj.user_form) - .insertAfter('#result_query'); + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + priv_data.error, false); } }); } else { @@ -199,7 +189,7 @@ $(function() { $.get($(this).attr("href"), {'ajax_request':true}, function(data) { var $div = $('
') - .prepend(data) + .prepend(data.message) .find("#fieldset_add_user_footer").hide() //showing the "Go" and "Create User" buttons together will confuse the user .end() .find("form[name=usersForm]").append('') @@ -251,8 +241,7 @@ $(function() { $.get($(this).attr("href"), {'ajax_request': true}, function(data) { if(data.success == true) { PMA_ajaxRemoveMessage($msgbox); - } - else { + } else { PMA_ajaxShowMessage(data.error, false); } }); //end $.get() @@ -300,8 +289,7 @@ $(function() { .find('tr:even') .removeClass('odd').addClass('even'); }); - } - else { + } else { PMA_ajaxShowMessage(data.error, false); } }); // end $.post() @@ -343,7 +331,7 @@ $(function() { }, function(data) { var $div = $('
') - .append(data) + .append(data.message) .dialog({ width: 900, height: 600, @@ -436,8 +424,7 @@ $(function() { $("#usersForm") .find('.current_row') .removeClass('current_row'); - } - else { + } else { PMA_ajaxShowMessage(data.error, false); } }); @@ -562,7 +549,7 @@ $(function() { $("#usersForm").hide("medium").remove(); $("#fieldset_add_user").hide("medium").remove(); $("#initials_table") - .after(data).show("medium") + .after(data.message).show("medium") .siblings("h2").not(":first").remove(); PMA_ajaxRemoveMessage($msgbox); diff --git a/js/server_status.js b/js/server_status.js index 243cbe84d3..eb0dfc1c3e 100644 --- a/js/server_status.js +++ b/js/server_status.js @@ -220,7 +220,7 @@ $(function() { $.get($(this).attr('href'), { ajax_request: 1 }, function(data) { $(that).find('img').hide(); - initTab(tab, data); + initTab(tab, data.message); }); tabStatus[tab.attr('id')] = 'data'; @@ -646,7 +646,7 @@ $(function() { $.get('server_status.php?' + url_query, { ajax_request: true, advisor: true }, function(data) { var $tbody, $tr, str, even = true; - data = $.parseJSON(data); + data = $.parseJSON(data.message); $cnt.html(''); diff --git a/js/server_status_monitor.js b/js/server_status_monitor.js index 6904beb21b..c24c91ab09 100644 --- a/js/server_status_monitor.js +++ b/js/server_status_monitor.js @@ -621,7 +621,7 @@ $(function() { $.get('server_status.php?' + url_query, vars, function(data) { - var logVars = $.parseJSON(data), + var logVars = $.parseJSON(data.message), icon = PMA_getImage('s_success.png'), msg='', str=''; if (logVars['general_log'] == 'ON') { @@ -1202,7 +1202,7 @@ $(function() { }, function(data) { var chartData; try { - chartData = $.parseJSON(data); + chartData = $.parseJSON(data.message); } catch(err) { return serverResponseError(); } @@ -1388,7 +1388,7 @@ $(function() { function(data) { var logData; try { - logData = $.parseJSON(data); + logData = $.parseJSON(data.message); } catch(err) { return serverResponseError(); } @@ -1773,7 +1773,7 @@ $(function() { query: codemirror_editor ? codemirror_editor.getValue() : $('#sqlquery').val(), database: db }, function(data) { - data = $.parseJSON(data); + data = $.parseJSON(data.message); var totalTime = 0; if (data.error) { diff --git a/js/server_variables.js b/js/server_variables.js index 94ca6110da..1e952f4784 100644 --- a/js/server_variables.js +++ b/js/server_variables.js @@ -174,7 +174,7 @@ function editVariable(link) $cell.html(''); // put edit field and save/cancel link $cell.prepend('
' + - '
'); + ''); $cell.find('table td:first').append(mySaveLink); $cell.find('table td:first').append(' '); $cell.find('table td:first').append(myCancelLink); diff --git a/js/sql.js b/js/sql.js index 22c37305a3..a31709effc 100644 --- a/js/sql.js +++ b/js/sql.js @@ -197,6 +197,7 @@ $(function() { // // fade out previous messages, if any $('div.success, div.sqlquery_message').fadeOut(); + // show a message that stays on screen if (typeof data.action_bookmark != 'undefined') { // view only @@ -209,7 +210,9 @@ $(function() { if ('2' == data.action_bookmark) { $("#id_bookmark option[value='" + data.id_bookmark + "']").remove(); } - $('#sqlqueryform').before(data.message); + $sqlqueryresults + .show() + .html(data.message); } else if (typeof data.sql_query != 'undefined') { $('
') .html(data.sql_query) @@ -217,9 +220,18 @@ $(function() { // unnecessary div that came from data.sql_query $('div.notice').remove(); } else { - $('#sqlqueryform').before(data.message); + $sqlqueryresults + .show() + .html(data.message); + } + $sqlqueryresults.show().trigger('makegrid'); + $('#togglequerybox').show(); + PMA_init_slider(); + if( $('#sqlqueryform input[name="retain_query_box"]').is(':checked') != true ) { + if ($("#togglequerybox").siblings(":visible").length > 0) { + $("#togglequerybox").trigger('click'); + } } - $sqlqueryresults.show(); // this happens if a USE command was typed if (typeof data.reload != 'undefined') { // Unbind the submit event before reloading. See bug #3295529 @@ -236,29 +248,6 @@ $(function() { // show an error message that stays on screen $('#sqlqueryform').before(data.error); $sqlqueryresults.hide(); - } else { - // real results are returned - // fade out previous messages, if any - $('div.success, div.sqlquery_message').fadeOut(); - var $received_data = $(data); - var $zero_row_results = $received_data.find('textarea[name="sql_query"]'); - // if zero rows are returned from the query execution - if ($zero_row_results.length > 0) { - $('#sqlquery').val($zero_row_results.val()); - setQuery($('#sqlquery').val()); - } else { - $sqlqueryresults - .show() - .html(data) - .trigger('makegrid'); - $('#togglequerybox').show(); - if( $('#sqlqueryform input[name="retain_query_box"]').is(':checked') != true ) { - if ($("#togglequerybox").siblings(":visible").length > 0) { - $("#togglequerybox").trigger('click'); - } - } - PMA_init_slider(); - } } PMA_ajaxRemoveMessage($msgbox); }); // end $.post() @@ -302,10 +291,9 @@ $(function() { $.post($form.attr('action'), $form.serialize(), function(data) { $("#sqlqueryresults") - .html(data) + .html(data.message) .trigger('makegrid'); PMA_init_slider(); - PMA_ajaxRemoveMessage($msgbox); }); // end $.post() } @@ -327,7 +315,7 @@ $(function() { $.post($form.attr('action'), $form.serialize() + '&ajax_request=true', function(data) { $("#sqlqueryresults") - .html(data) + .html(data.message) .trigger('makegrid'); PMA_init_slider(); PMA_ajaxRemoveMessage($msgbox); @@ -353,7 +341,7 @@ $(function() { $.get($anchor.attr('href'), $anchor.serialize() + '&ajax_request=true', function(data) { $("#sqlqueryresults") - .html(data) + .html(data.message) .trigger('makegrid'); PMA_ajaxRemoveMessage($msgbox); }); // end $.get() @@ -372,7 +360,7 @@ $(function() { $.post($form.attr('action'), $form.serialize() + '&ajax_request=true' , function(data) { $("#sqlqueryresults") - .html(data) + .html(data.message) .trigger('makegrid'); PMA_init_slider(); }); // end $.post() @@ -422,7 +410,7 @@ $(function() { }); // end dialog options } else { $div - .append(data) + .append(data.message) .dialog({ title: PMA_messages['strChangeTbl'], height: 600, diff --git a/js/tbl_change.js b/js/tbl_change.js index 04c5247fac..22fb5f8f70 100644 --- a/js/tbl_change.js +++ b/js/tbl_change.js @@ -322,6 +322,9 @@ $(function() { * to previous page" and "insert another new row" actions, using AJAX * has no obvious advantage. If inserting, the "go back to previous" * action needs a page refresh anyway. + * + * 3. The handling of the response is also broken because PMA + * no longher returns plain HTML for an ajax request */ $("#insertFormDEACTIVATED").live('submit', function(event) { diff --git a/js/tbl_select.js b/js/tbl_select.js index bd50a10733..b8c9f386d5 100644 --- a/js/tbl_select.js +++ b/js/tbl_select.js @@ -52,11 +52,11 @@ $(function() { PMA_prepareForAjaxRequest($search_form); - $.post($search_form.attr('action'), $search_form.serialize(), function(response) { + $.post($search_form.attr('action'), $search_form.serialize(), function(data) { PMA_ajaxRemoveMessage($msgbox); - if (typeof response == 'string') { + if (data.success == true) { // found results - $("#sqlqueryresults").html(response); + $("#sqlqueryresults").html(data.message); $("#sqlqueryresults").trigger('makegrid'); $('#tbl_search_form') // workaround for bug #3168569 - Issue on toggling the "Hide search criteria" in chrome. @@ -71,14 +71,7 @@ $(function() { // needed for the display options slider in the results PMA_init_slider(); } else { - // error message (zero rows) - if (response.message != undefined) { - $("#sqlqueryresults").html(response['message']); - } - // other error (syntax error?) - if (response.error != undefined) { - $("#sqlqueryresults").html(response['error']); - } + $("#sqlqueryresults").html(data.error); } }); // end $.post() }); diff --git a/js/tbl_structure.js b/js/tbl_structure.js index c93826504f..64800daf5b 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -64,8 +64,7 @@ $(function() { $curr_row.hide("medium").remove(); // refresh the list of indexes (comes from sql.php) $('#indexes').html(data.indexes_list); - } - else { + } else { PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); } }); // end $.get() @@ -104,8 +103,7 @@ $(function() { if (typeof data.reload != 'undefined') { window.parent.frame_content.location.reload(); } - } - else { + } else { PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); } }); // end $.get() @@ -158,8 +156,7 @@ $(function() { $(this).remove(); }); } - } - else { + } else { PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); } }); // end $.get() @@ -265,7 +262,7 @@ $(function() { $("#edit_index_dialog").dialog("close"); } $('div.no_indexes_defined').hide(); - } else if (data.error != undefined) { + } else { var $temp_div = $("
").append(data.error); if ($temp_div.find(".error code").length != 0) { var $error = $temp_div.find(".error code").addClass("error"); @@ -281,14 +278,14 @@ $(function() { }; var $msgbox = PMA_ajaxShowMessage(); $.get("tbl_indexes.php", url, function(data) { - if (data.error) { + if (data.success == false) { //in the case of an error, show the error message returned. PMA_ajaxShowMessage(data.error, false); } else { PMA_ajaxRemoveMessage($msgbox); // Show dialog if the request was successful $div - .append(data) + .append(data.message) .dialog({ title: title, width: 450, @@ -390,7 +387,7 @@ $(function() { } $.post($form.prop("action"), serialized + "&ajax_request=true", function (data) { - if (data.success != undefined && data.success == false) { + if (data.success == false) { PMA_ajaxRemoveMessage($msgbox); $this .clone() @@ -410,8 +407,7 @@ $(function() { // loop through the correct order for (var i in data.columns) { var the_column = data.columns[i]; - var $the_row - = $rows + var $the_row = $rows .find("input:checkbox[value=" + the_column + "]") .closest("tr"); // append the row for this column to the table @@ -526,7 +522,7 @@ $(function() { }); // end dialog options } else { $div - .append(data) + .append(data.message) .dialog({ title: PMA_messages['strAddColumns'], height: 600, @@ -604,7 +600,7 @@ function changeColumns(action,url) }); // end dialog options } else { $div - .append(data) + .append(data.message) .dialog({ title: PMA_messages['strChangeTbl'], height: 600, @@ -673,7 +669,7 @@ $(function() { /*Reload the field form*/ reloadFieldForm(data.message); } else { - var $temp_div = $("
").append(data); + var $temp_div = $("
").append(data.error); var $error = $temp_div.find(".error code").addClass("error"); PMA_ajaxShowMessage($error, false); } @@ -693,7 +689,7 @@ $(function() { */ function reloadFieldForm(message) { $.post($("#fieldsForm").attr('action'), $("#fieldsForm").serialize()+"&ajax_request=true", function(form_data) { - var $temp_div = $("
").append(form_data); + var $temp_div = $("
").append(form_data.message); $("#fieldsForm").replaceWith($temp_div.find("#fieldsForm")); $("#addColumns").replaceWith($temp_div.find("#addColumns")); $('#move_columns_dialog ul').replaceWith($temp_div.find("#move_columns_dialog ul")); diff --git a/sql.php b/sql.php index 40b430f281..c20ed2bc7f 100644 --- a/sql.php +++ b/sql.php @@ -820,7 +820,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $extra_data['reload'] = 1; $extra_data['db'] = $GLOBALS['db']; } - PMA_ajaxResponse($message, $message->isSuccess(), (isset($extra_data) ? $extra_data : '')); + PMA_ajaxResponse($message, $message->isSuccess(), (isset($extra_data) ? $extra_data : array())); } if ($is_gotofile) { From ec5322ed2617b902144c9b4857b3c2c4dc5becbe Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 9 Jun 2012 18:30:36 +0100 Subject: [PATCH 74/82] Fixed conflicting global variable names --- libraries/user_preferences.inc.php | 3 +-- prefs_manage.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/user_preferences.inc.php b/libraries/user_preferences.inc.php index 50398ceac9..9e81795a03 100644 --- a/libraries/user_preferences.inc.php +++ b/libraries/user_preferences.inc.php @@ -43,8 +43,7 @@ echo '
'; // show "configuration saved" message and reload navigation frame if needed if (!empty($_GET['saved'])) { - $message = PMA_Message::rawSuccess(__('Configuration has been saved')); - $message->display(); + PMA_Message::rawSuccess(__('Configuration has been saved'))->display(); } /* debug code diff --git a/prefs_manage.php b/prefs_manage.php index 2cf8dd0a68..0f55689089 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -295,8 +295,7 @@ PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));

From 8b0f21aa0d38751b674abf949223b0085eb03c97 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 9 Jun 2012 20:07:51 +0100 Subject: [PATCH 75/82] Fixed user preferences export/import --- js/config.js | 1 + prefs_manage.php | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/js/config.js b/js/config.js index df9cbaa6b5..cdd9156ad2 100644 --- a/js/config.js +++ b/js/config.js @@ -690,6 +690,7 @@ function savePrefsToLocalStorage(form) cache: false, type: 'POST', data: { + ajax_request: true, token: form.find('input[name=token]').val(), submit_get_json: true }, diff --git a/prefs_manage.php b/prefs_manage.php index 0f55689089..d18479dfe8 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -23,6 +23,7 @@ PMA_userprefs_pageinit(); $error = ''; if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == 'text_file') { // export to JSON file + PMA_Response::getInstance()->disable(); $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json'; PMA_downloadHeader($filename, 'application/json'); $settings = PMA_load_userprefs(); @@ -30,8 +31,9 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == return; } else if (isset($_POST['submit_get_json'])) { $settings = PMA_load_userprefs(); - header('Content-Type: application/json'); - echo json_encode( + PMA_ajaxResponse( + '', + true, array( 'prefs' => json_encode($settings['config_data']), 'mtime' => $settings['mtime'] From 1871e8279e26c91deea2b0e642dbdd9de479492e Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 9 Jun 2012 20:43:51 +0100 Subject: [PATCH 76/82] Fixed ajax responses in server_variable.php --- server_variables.php | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/server_variables.php b/server_variables.php index 7a5e1c49fe..59a3238bfa 100644 --- a/server_variables.php +++ b/server_variables.php @@ -33,11 +33,10 @@ require 'libraries/server_variables_doc.php'; if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { // Send with correct charset - header('Content-Type: text/html; charset=UTF-8'); - if (isset($_REQUEST['type'])) { switch($_REQUEST['type']) { case 'getval': + header('Content-Type: text/html; charset=UTF-8'); $varValue = PMA_DBI_fetch_single_row( 'SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA_sqlAddslashes($_REQUEST['varName']) . '";', 'NUM' @@ -67,6 +66,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $value="'" . $value . "'"; } + $response = PMA_Response::getInstance(); if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) && PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value) ) { @@ -75,25 +75,18 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { 'SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA_sqlAddslashes($_REQUEST['varName']) . '";', 'NUM' ); - - exit( - json_encode( - array( - 'success' => true, - 'variable' => formatVariable($_REQUEST['varName'], $varValue[1]) - ) - ) + $response->addJSON( + 'variable', + formatVariable($_REQUEST['varName'], $varValue[1]) + ); + } else { + $response->isSuccess(false); + $response->addJSON( + 'error', + __('Setting variable failed') ); } - - exit( - json_encode( - array( - 'success' => false, - 'error' => __('Setting variable failed') - ) - ) - ); + exit; break; } } From a16e723048940f87b4be4b4097d16c4376826f2c Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 11 Jun 2012 17:58:35 +0100 Subject: [PATCH 77/82] Dropped PMA_ajaxResponse() --- db_create.php | 28 ++++---- db_operations.php | 15 ++-- db_tables_search.php | 3 +- db_tracking.php | 9 +-- gis_data_editor.php | 8 ++- import.php | 18 +++-- js/functions.js | 5 +- js/gis_data_editor.js | 9 +-- js/sql.js | 10 ++- js/tbl_zoom_plot_jqplot.js | 5 +- libraries/auth/cookie.auth.lib.php | 2 +- libraries/common.lib.php | 29 ++------ libraries/db_common.inc.php | 7 +- libraries/rte/rte_events.lib.php | 25 ++++--- libraries/rte/rte_export.lib.php | 11 ++- libraries/rte/rte_routines.lib.php | 66 +++++++++-------- libraries/rte/rte_triggers.lib.php | 33 +++++---- navigation.php | 9 +-- prefs_manage.php | 15 ++-- server_databases.php | 5 +- server_privileges.php | 17 +++-- sql.php | 46 ++++++++---- tbl_addfield.php | 8 ++- tbl_alter.php | 30 ++++---- tbl_create.php | 41 ++++++----- tbl_indexes.php | 26 ++++--- tbl_move_copy.php | 23 +++--- tbl_operations.php | 16 +++-- tbl_replace.php | 7 +- tbl_zoom_select.php | 25 +++---- .../common/PMA_ajaxResponse_test.php | 71 ------------------- view_create.php | 18 ++++- 32 files changed, 330 insertions(+), 310 deletions(-) delete mode 100644 test/libraries/common/PMA_ajaxResponse_test.php diff --git a/db_create.php b/db_create.php index c0618b1ca8..b04a793f84 100644 --- a/db_create.php +++ b/db_create.php @@ -61,12 +61,15 @@ if (! $result) { $GLOBALS['table'] = ''; /** - * If in an Ajax request, just display the message with {@link PMA_ajaxResponse} + * If in an Ajax request, just display the message with {@link PMA_Response} */ if ($GLOBALS['is_ajax_request'] == true) { - PMA_ajaxResponse($message, false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $message); + } else { + include_once 'main.php'; } - include_once 'main.php'; } else { $message = PMA_Message::success(__('Database %1$s has been created.')); $message->addParam($new_db); @@ -76,14 +79,6 @@ if (! $result) { * If in an Ajax request, build the output and send it */ if ($GLOBALS['is_ajax_request'] == true) { - - /** - * String containing the SQL Query formatted in pretty HTML - * @global array $GLOBALS['extra_data'] - * @name $extra_data - */ - $extra_data['sql_query'] = PMA_getMessage(null, $sql_query, 'success'); - //Construct the html for the new database, so that it can be appended to // the list of databases on server_databases.php @@ -137,11 +132,12 @@ if (! $result) { $new_db_string .= ''; - $extra_data['new_db_string'] = $new_db_string; - - PMA_ajaxResponse($message, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $message); + $response->addJSON('new_db_string', $new_db_string); + $response->addJSON('sql_query', PMA_getMessage(null, $sql_query, 'success')); + } else { + include_once '' . $cfg['DefaultTabDatabase']; } - - include_once '' . $cfg['DefaultTabDatabase']; } ?> diff --git a/db_operations.php b/db_operations.php index 4e77fe8822..16f6191802 100644 --- a/db_operations.php +++ b/db_operations.php @@ -340,13 +340,16 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) { /** * Database has been successfully renamed/moved. If in an Ajax request, - * generate the output with {@link PMA_ajaxResponse} and exit + * generate the output with {@link PMA_Response} and exit */ - if ( $GLOBALS['is_ajax_request'] == true) { - $extra_data['newname'] = $newname; - $extra_data['sql_query'] = PMA_getMessage(null, $sql_query); - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); - }; + if ($GLOBALS['is_ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + $response->addJSON('newname', $newname); + $response->addJSON('sql_query', PMA_getMessage(null, $sql_query)); + exit; + } } diff --git a/db_tables_search.php b/db_tables_search.php index 6dbb1a4e8f..53542ca9c7 100644 --- a/db_tables_search.php +++ b/db_tables_search.php @@ -63,5 +63,6 @@ foreach ($tables_full as $key => $table) { } } -PMA_ajaxResponse('', true, array('tables' => $tables_response)); +$response = PMA_Response::getInstance(); +$response->addJSON('tables', $tables_response); ?> diff --git a/db_tracking.php b/db_tracking.php index 91b33147a3..94e4fe4847 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -20,8 +20,8 @@ $scripts->addFile('db_structure.js'); */ if ($GLOBALS['is_ajax_request'] != true) { include 'libraries/db_common.inc.php'; + $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php'; } -$url_query .= '&goto=tbl_tracking.php&back=db_tracking.php'; // Get the database structure $sub_part = '_structure'; @@ -34,11 +34,12 @@ if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) { /** * If in an Ajax request, generate the success message and use - * {@link PMA_ajaxResponse()} to send the output + * {@link PMA_Response()} to send the output */ if ($GLOBALS['is_ajax_request'] == true) { - $message = PMA_Message::success(); - PMA_ajaxResponse($message, true); + $response = PMA_Response::getInstance(); + $response->addJSON('message', PMA_Message::success()); + exit; } } diff --git a/gis_data_editor.php b/gis_data_editor.php index 83b59fe34a..9eb0e99744 100644 --- a/gis_data_editor.php +++ b/gis_data_editor.php @@ -62,7 +62,9 @@ if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) { 'visualization' => $visualization, 'openLayers' => $open_layers, ); - PMA_ajaxResponse(null, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON($extra_data); + exit; } ob_start(); @@ -311,7 +313,7 @@ ob_start(); addJSON('gis_editor', ob_get_contents()); +ob_end_clean(); ?> diff --git a/import.php b/import.php index 1522c0d048..85dfaea5e1 100644 --- a/import.php +++ b/import.php @@ -221,10 +221,13 @@ if (! empty($id_bookmark)) { case 1: // bookmarked query that have to be displayed $import_text = PMA_Bookmark_get($db, $id_bookmark); if ($GLOBALS['is_ajax_request'] == true) { - $extra_data['sql_query'] = $import_text; - $extra_data['action_bookmark'] = $action_bookmark; $message = PMA_Message::success(__('Showing bookmark')); - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + $response->addJSON('sql_query', $import_text); + $response->addJSON('action_bookmark', $action_bookmark); + exit; } else { $run_query = false; } @@ -234,9 +237,12 @@ if (! empty($id_bookmark)) { PMA_Bookmark_delete($db, $id_bookmark); if ($GLOBALS['is_ajax_request'] == true) { $message = PMA_Message::success(__('The bookmark has been deleted.')); - $extra_data['action_bookmark'] = $action_bookmark; - $extra_data['id_bookmark'] = $id_bookmark; - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + $response->addJSON('action_bookmark', $action_bookmark); + $response->addJSON('id_bookmark', $id_bookmark); + exit; } else { $run_query = false; $error = true; // this is kind of hack to skip processing the query diff --git a/js/functions.js b/js/functions.js index a20a204e6b..c907328c1e 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2417,10 +2417,7 @@ $(function() { window.parent.frame_navigation.location.reload(); } } else { - var $temp_div = $("
"); - $temp_div.html(data.error); - var $error = $temp_div.find("code").addClass("error"); - PMA_ajaxShowMessage($error, false); + PMA_ajaxShowMessage(data.error, false); } }); // end $.post() } diff --git a/js/gis_data_editor.js b/js/gis_data_editor.js index 477b3988a9..9cba83659d 100644 --- a/js/gis_data_editor.js +++ b/js/gis_data_editor.js @@ -142,7 +142,8 @@ function loadGISEditor(value, field, type, input_name, token) { 'type' : type, 'input_name' : input_name, 'get_gis_editor' : true, - 'token' : token + 'token' : token, + 'ajax_request': true }, function(data) { if (data.success == true) { $gis_editor.html(data.gis_editor); @@ -190,7 +191,7 @@ function insertDataAndClose() { var $form = $('form#gis_data_editor_form'); var input_name = $form.find("input[name='input_name']").val(); - $.post('gis_data_editor.php', $form.serialize() + "&generate=true", function(data) { + $.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) { if(data.success == true) { $("input[name='" + input_name + "']").val(data.result); } else { @@ -226,7 +227,7 @@ $(function() { */ $('#gis_editor').find("input[type='text']").live('change', function() { var $form = $('form#gis_data_editor_form'); - $.post('gis_data_editor.php', $form.serialize() + "&generate=true", function(data) { + $.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) { if(data.success == true) { $('#gis_data_textarea').val(data.result); $('#placeholder').empty().removeClass('hasSVG').html(data.visualization); @@ -246,7 +247,7 @@ $(function() { var $gis_editor = $("#gis_editor"); var $form = $('form#gis_data_editor_form'); - $.post('gis_data_editor.php', $form.serialize() + "&get_gis_editor=true", function(data) { + $.post('gis_data_editor.php', $form.serialize() + "&get_gis_editor=true&ajax_request=true", function(data) { if(data.success == true) { $gis_editor.html(data.gis_editor); initGISEditorVisualization(); diff --git a/js/sql.js b/js/sql.js index a31709effc..895e509386 100644 --- a/js/sql.js +++ b/js/sql.js @@ -227,11 +227,15 @@ $(function() { $sqlqueryresults.show().trigger('makegrid'); $('#togglequerybox').show(); PMA_init_slider(); - if( $('#sqlqueryform input[name="retain_query_box"]').is(':checked') != true ) { - if ($("#togglequerybox").siblings(":visible").length > 0) { - $("#togglequerybox").trigger('click'); + + if (typeof data.action_bookmark == 'undefined') { + if( $('#sqlqueryform input[name="retain_query_box"]').is(':checked') != true ) { + if ($("#togglequerybox").siblings(":visible").length > 0) { + $("#togglequerybox").trigger('click'); + } } } + // this happens if a USE command was typed if (typeof data.reload != 'undefined') { // Unbind the submit event before reloading. See bug #3295529 diff --git a/js/tbl_zoom_plot_jqplot.js b/js/tbl_zoom_plot_jqplot.js index e7d60eeb8d..4c3b0706fa 100644 --- a/js/tbl_zoom_plot_jqplot.js +++ b/js/tbl_zoom_plot_jqplot.js @@ -12,10 +12,7 @@ ** Display Help/Info **/ function displayHelp() { - var msgbox = PMA_ajaxShowMessage(PMA_messages['strDisplayHelp'], 10000); - msgbox.click(function() { - PMA_ajaxRemoveMessage(msgbox); - }); + PMA_ajaxShowMessage(PMA_messages['strDisplayHelp'], 10000); } /** diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index 7eb487c014..c4f5d2fc35 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -136,7 +136,7 @@ function PMA_auth() if (! empty($conn_error)) { $response->addJSON('message', $conn_error); } else { - $response->addJSON('message', __('Session expired')); + $response->addJSON('message', PMA_Message::error(__('Your session has expired. Please login again.'))); } exit; } diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 08b0437c94..77bb491e4e 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -679,10 +679,13 @@ function PMA_mysqlDie( /** * If in an Ajax request * - avoid displaying a Back link - * - use PMA_ajaxResponse() to transmit the message and exit + * - use PMA_Response() to transmit the message and exit */ if ($GLOBALS['is_ajax_request'] == true) { - PMA_ajaxResponse($error_msg, false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $error_msg); + exit; } if (! empty($back_url)) { if (strstr($back_url, '?')) { @@ -3244,28 +3247,6 @@ function PMA_expandUserString($string, $escape = null, $updates = array()) return strtr(strftime($string), $replace); } -/** - * function that generates a json output for an ajax request and ends script - * execution - * - * @param PMA_Message|string $message message string containing the - * html of the message - * @param bool $success success whether the ajax request - * was successfull - * @param array $extra_data extra data optional - any other data - * as part of the json request - * - * @return void - */ -function PMA_ajaxResponse($message, $success = true, $extra_data = array()) -{ - $response = PMA_Response::getInstance(); - $response->isSuccess($success); - $response->addJSON('message', $message); - $response->addJSON($extra_data); - exit; -} - /** * Display the form used to browse anywhere on the local server for a file to * import diff --git a/libraries/db_common.inc.php b/libraries/db_common.inc.php index 7516a2dd20..75ae3a280d 100644 --- a/libraries/db_common.inc.php +++ b/libraries/db_common.inc.php @@ -72,8 +72,11 @@ if (isset($submitcollation) && !empty($db_collation)) { * other pages, we might have to move this to a different location. */ if ( $GLOBALS['is_ajax_request'] == true) { - PMA_ajaxResponse($message, $message->isSuccess()); - }; + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + exit; + } } /** diff --git a/libraries/rte/rte_events.lib.php b/libraries/rte/rte_events.lib.php index 55d7b9c02e..3c5832614e 100644 --- a/libraries/rte/rte_events.lib.php +++ b/libraries/rte/rte_events.lib.php @@ -148,21 +148,22 @@ function PMA_EVN_handleEditor() $output = PMA_getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { - $extra_data = array(); + $response = PMA_Response::getInstance(); if ($message->isSuccess()) { $columns = "`EVENT_NAME`, `EVENT_TYPE`, `STATUS`"; $where = "EVENT_SCHEMA='" . PMA_sqlAddSlashes($db) . "' " . "AND EVENT_NAME='" . PMA_sqlAddSlashes($_REQUEST['item_name']) . "'"; $query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE $where;"; $event = PMA_DBI_fetch_single_row($query); - $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['item_name'])); - $extra_data['new_row'] = PMA_EVN_getRowForList($event); - $extra_data['insert'] = ! empty($event); - $response = $output; + $response->addJSON('name', htmlspecialchars(strtoupper($_REQUEST['item_name']))); + $response->addJSON('new_row', PMA_EVN_getRowForList($event)); + $response->addJSON('insert', ! empty($event)); + $response->addJSON('message', $output); } else { - $response = $message; + $response->isSuccess(false); + $response->addJSON('message', $message); } - PMA_ajaxResponse($response, $message->isSuccess(), $extra_data); + exit; } } /** @@ -200,8 +201,9 @@ function PMA_EVN_handleEditor() // Show form $editor = PMA_EVN_getEditorForm($mode, $operation, $item); if ($GLOBALS['is_ajax_request']) { - $extra_data = array('title' => $title); - PMA_ajaxResponse($editor, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $editor); + $response->addJSON('title', $title); } else { echo "\n\n

$title

\n\n$editor"; unset($_POST); @@ -216,7 +218,10 @@ function PMA_EVN_handleEditor() ); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { - PMA_ajaxResponse($message, false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $message); + exit; } else { $message->display(); } diff --git a/libraries/rte/rte_export.lib.php b/libraries/rte/rte_export.lib.php index 45adb0edea..47751fb4a3 100644 --- a/libraries/rte/rte_export.lib.php +++ b/libraries/rte/rte_export.lib.php @@ -26,8 +26,10 @@ function PMA_RTE_handleExport($item_name, $export_data) . htmlspecialchars(trim($export_data)) . ''; $title = sprintf(PMA_RTE_getWord('export'), $item_name); if ($GLOBALS['is_ajax_request'] == true) { - $extra_data = array('title' => $title); - PMA_ajaxResponse($export_data, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $export_data); + $response->addJSON('title', $title); + exit; } else { echo "
\n" . "$title\n" @@ -40,7 +42,10 @@ function PMA_RTE_handleExport($item_name, $export_data) . sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db); $response = PMA_message::error($response); if ($GLOBALS['is_ajax_request'] == true) { - PMA_ajaxResponse($response, false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $response); + exit; } else { $response->display(); } diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php index da85edd8ee..c5654635d6 100644 --- a/libraries/rte/rte_routines.lib.php +++ b/libraries/rte/rte_routines.lib.php @@ -301,21 +301,22 @@ function PMA_RTN_handleEditor() $output = PMA_getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { - $extra_data = array(); + $response = PMA_Response::getInstance(); if ($message->isSuccess()) { $columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, `DTD_IDENTIFIER`, `ROUTINE_DEFINITION`"; $where = "ROUTINE_SCHEMA='" . PMA_sqlAddSlashes($db) . "' " . "AND ROUTINE_NAME='" . PMA_sqlAddSlashes($_REQUEST['item_name']) . "'" . "AND ROUTINE_TYPE='" . PMA_sqlAddSlashes($_REQUEST['item_type']) . "'"; $routine = PMA_DBI_fetch_single_row("SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE $where;"); - $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['item_name'])); - $extra_data['new_row'] = PMA_RTN_getRowForList($routine); - $extra_data['insert'] = ! empty($routine); - $response = $output; + $response->addJSON('name', htmlspecialchars(strtoupper($_REQUEST['item_name']))); + $response->addJSON('new_row', PMA_RTN_getRowForList($routine)); + $response->addJSON('insert', ! empty($routine)); + $response->addJSON('message', $output); } else { - $response = $message; + $response->isSuccess(false); + $response->addJSON('message', $output); } - PMA_ajaxResponse($response, $message->isSuccess(), $extra_data); + exit; } } @@ -359,13 +360,14 @@ function PMA_RTN_handleEditor() // Show form $editor = PMA_RTN_getEditorForm($mode, $operation, $routine); if ($GLOBALS['is_ajax_request']) { - $template = PMA_RTN_getParameterRow(); - $extra_data = array('title' => $title, - 'param_template' => $template, - 'type' => $routine['item_type']); - PMA_ajaxResponse($editor, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $editor); + $response->addJSON('title', $title); + $response->addJSON('param_template', PMA_RTN_getParameterRow()); + $response->addJSON('type', $routine['item_type']); + } else { + echo "\n\n

$title

\n\n$editor"; } - echo "\n\n

$title

\n\n$editor"; exit; } else { $message = __('Error in processing request') . ' : '; @@ -376,7 +378,9 @@ function PMA_RTN_handleEditor() ); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { - PMA_ajaxResponse($message, false); + $response->isSuccess(false); + $response->addJSON('message', $message); + exit; } else { $message->display(); } @@ -1267,12 +1271,11 @@ function PMA_RTN_handleExecute() } // Print/send output if ($GLOBALS['is_ajax_request']) { - $extra_data = array('dialog' => false); - PMA_ajaxResponse( - $message->getDisplay() . $output, - $message->isSuccess(), - $extra_data - ); + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message->getDisplay() . $output); + $response->addJSON('dialog', false); + exit; } else { echo $message->getDisplay() . $output; if ($message->isError()) { @@ -1292,7 +1295,10 @@ function PMA_RTN_handleExecute() ); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { - PMA_ajaxResponse($message, $message->isSuccess()); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $message); + exit; } else { echo $message->getDisplay(); unset($_POST); @@ -1306,18 +1312,18 @@ function PMA_RTN_handleExecute() if ($routine !== false) { $form = PMA_RTN_getExecuteForm($routine); if ($GLOBALS['is_ajax_request'] == true) { - $extra_data = array(); - $extra_data['dialog'] = true; - $extra_data['title'] = __("Execute routine") . " "; - $extra_data['title'] .= PMA_backquote( + $title = __("Execute routine") . " " . PMA_backquote( htmlentities($_GET['item_name'], ENT_QUOTES) ); - PMA_ajaxResponse($form, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $form); + $response->addJSON('title', $title); + $response->addJSON('dialog', true); } else { echo "\n\n

" . __("Execute routine") . "

\n\n"; echo $form; - exit; } + exit; } else if (($GLOBALS['is_ajax_request'] == true)) { $message = __('Error in processing request') . ' : '; $message .= sprintf( @@ -1326,7 +1332,11 @@ function PMA_RTN_handleExecute() htmlspecialchars(PMA_backquote($db)) ); $message = PMA_message::error($message); - PMA_ajaxResponse($message, false); + + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $message); + exit; } } } diff --git a/libraries/rte/rte_triggers.lib.php b/libraries/rte/rte_triggers.lib.php index 25414eadd3..ba8d3f8b30 100644 --- a/libraries/rte/rte_triggers.lib.php +++ b/libraries/rte/rte_triggers.lib.php @@ -121,7 +121,7 @@ function PMA_TRI_handleEditor() $output = PMA_getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { - $extra_data = array(); + $response = PMA_Response::getInstance(); if ($message->isSuccess()) { $items = PMA_DBI_get_triggers($db, $table, ''); $trigger = false; @@ -130,19 +130,24 @@ function PMA_TRI_handleEditor() $trigger = $value; } } - $extra_data['insert'] = false; + $insert = false; if (empty($table) || ($trigger !== false && $table == $trigger['table'])) { - $extra_data['insert'] = true; - $extra_data['new_row'] = PMA_TRI_getRowForList($trigger); - $extra_data['name'] = htmlspecialchars( - strtoupper($_REQUEST['item_name']) + $insert = true; + $response->addJSON('new_row', PMA_TRI_getRowForList($trigger)); + $response->addJSON( + 'name', + htmlspecialchars( + strtoupper($_REQUEST['item_name']) + ) ); } - $response = $output; + $response->addJSON('insert', $insert); + $response->addJSON('message', $output); } else { - $response = $message; + $response->addJSON('message', $message); + $response->isSuccess(false); } - PMA_ajaxResponse($response, $message->isSuccess(), $extra_data); + exit; } } @@ -175,8 +180,9 @@ function PMA_TRI_handleEditor() // Show form $editor = PMA_TRI_getEditorForm($mode, $item); if ($GLOBALS['is_ajax_request']) { - $extra_data = array('title' => $title); - PMA_ajaxResponse($editor, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $editor); + $response->addJSON('title', $title); } else { echo "\n\n

$title

\n\n$editor"; unset($_POST); @@ -191,7 +197,10 @@ function PMA_TRI_handleEditor() ); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { - PMA_ajaxResponse($message, false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $message); + exit; } else { $message->display(); } diff --git a/navigation.php b/navigation.php index f92abf2883..17d649b6da 100644 --- a/navigation.php +++ b/navigation.php @@ -29,11 +29,12 @@ require_once 'libraries/RecentTable.class.php'; * Check if it is an ajax request to reload the recent tables list. */ if ($GLOBALS['is_ajax_request'] && $_REQUEST['recent_table']) { - PMA_ajaxResponse( - '', - true, - array('options' => PMA_RecentTable::getInstance()->getHtmlSelectOption()) + $response = PMA_Response::getInstance(); + $response->addJSON( + 'options', + PMA_RecentTable::getInstance()->getHtmlSelectOption() ); + exit; } // keep the offset of the db list in session before closing it diff --git a/prefs_manage.php b/prefs_manage.php index d18479dfe8..fac699bfec 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -28,18 +28,13 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == PMA_downloadHeader($filename, 'application/json'); $settings = PMA_load_userprefs(); echo json_encode($settings['config_data']); - return; + exit; } else if (isset($_POST['submit_get_json'])) { $settings = PMA_load_userprefs(); - PMA_ajaxResponse( - '', - true, - array( - 'prefs' => json_encode($settings['config_data']), - 'mtime' => $settings['mtime'] - ) - ); - return; + $response = PMA_Response::getInstance(); + $response->addJSON('prefs', json_encode($settings['config_data'])); + $response->addJSON('mtime', $settings['mtime']); + exit; } else if (isset($_POST['submit_import'])) { // load from JSON file $json = ''; diff --git a/server_databases.php b/server_databases.php index f267fb9d7d..a15e2cd178 100644 --- a/server_databases.php +++ b/server_databases.php @@ -117,7 +117,10 @@ if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type'])) } } if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message) { - PMA_ajaxResponse($message, $message->isSuccess()); + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + exit; } } diff --git a/server_privileges.php b/server_privileges.php index 0bf3955079..cb9cc59b7c 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -1643,7 +1643,11 @@ if ($GLOBALS['is_ajax_request'] && ! isset($_REQUEST['export']) && (! isset($_RE } if ($message instanceof PMA_Message) { - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + $response->addJSON($extra_data); + exit; } } @@ -1705,7 +1709,10 @@ if (isset($_REQUEST['export']) || (isset($_REQUEST['submit_mult']) && $_REQUEST[ $response .= ''; unset($username, $hostname, $grants, $one_grant); if ($GLOBALS['is_ajax_request']) { - PMA_ajaxResponse($response, 1, array('title' => $title)); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $response); + $response->addJSON('title', $title); + exit; } else { echo "

$title

$response"; } @@ -2568,9 +2575,11 @@ if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs . '
' . "\n"; if ($GLOBALS['is_ajax_request'] == true) { - $extra_data['user_form'] = $user_form; $message = PMA_Message::success(__('User has been added.')); - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('message', $message); + $response->addJSON('user_form', $user_form); + exit; } else { // Offer to create a new user for the current database $user_form .= '
' . "\n" diff --git a/sql.php b/sql.php index c20ed2bc7f..0a109a9b5a 100644 --- a/sql.php +++ b/sql.php @@ -146,8 +146,9 @@ if (isset($_REQUEST['get_relational_values']) && $_REQUEST['get_relational_value $dropdown = ''; } - $extra_data['dropdown'] = $dropdown; - PMA_ajaxResponse(null, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('dropdown', $dropdown); + exit; } /** @@ -173,8 +174,9 @@ if (isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true) $dropdown = ''; - $extra_data['dropdown'] = $dropdown; - PMA_ajaxResponse(null, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('dropdown', $dropdown); + exit; } /** @@ -201,8 +203,9 @@ if (isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) { $select_size = (sizeof($values) > 10) ? 10 : sizeof($values); $select = ''; - $extra_data['select'] = $select; - PMA_ajaxResponse(null, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('select', $select); + exit; } /** @@ -220,7 +223,10 @@ if (isset($_REQUEST['set_col_prefs']) && $_REQUEST['set_col_prefs'] == true) { $_REQUEST['table_create_time'] ); if (gettype($retval) != 'boolean') { - PMA_ajaxResponse($retval->getString(), false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $retval->getString()); + exit; } } @@ -232,11 +238,16 @@ if (isset($_REQUEST['set_col_prefs']) && $_REQUEST['set_col_prefs'] == true) { $_REQUEST['table_create_time'] ); if (gettype($retval) != 'boolean') { - PMA_ajaxResponse($retval->getString(), false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $retval->getString()); + exit; } } - PMA_ajaxResponse(null, ($retval == true)); + $response = PMA_Response::getInstance(); + $response->isSuccess($retval == true); + exit; } // Default to browse if no query set and we have table @@ -572,7 +583,10 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { $message = PMA_Message::rawError($error); if ($GLOBALS['is_ajax_request'] == true) { - PMA_ajaxResponse($message, false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $message); + exit; } /** @@ -820,7 +834,11 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $extra_data['reload'] = 1; $extra_data['db'] = $GLOBALS['db']; } - PMA_ajaxResponse($message, $message->isSuccess(), (isset($extra_data) ? $extra_data : array())); + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + $response->addJSON(isset($extra_data) ? $extra_data : array()); + exit; } if ($is_gotofile) { @@ -863,9 +881,9 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // value of a transformed field, show it here and exit if ($GLOBALS['grid_edit'] == true && $GLOBALS['cfg']['AjaxEnable']) { $row = PMA_DBI_fetch_row($result); - $extra_data = array(); - $extra_data['value'] = $row[0]; - PMA_ajaxResponse(null, true, $extra_data); + $response = PMA_Response::getInstance(); + $response->addJSON('value', $row[0]); + exit; } if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['table_maintenance'])) { diff --git a/tbl_addfield.php b/tbl_addfield.php index e0cf74dda1..efde25c048 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -188,9 +188,11 @@ if (isset($_REQUEST['do_save_data'])) { $message = PMA_Message::success(__('Table %1$s has been altered successfully')); $message->addParam($table); - if ( $GLOBALS['is_ajax_request'] == true) { - $extra_data['sql_query'] = PMA_getMessage(null, $sql_query); - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + if ($GLOBALS['is_ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->addJSON('message', $message); + $response->addJSON('sql_query', PMA_getMessage(null, $sql_query)); + exit; } $active_page = 'tbl_structure.php'; diff --git a/tbl_alter.php b/tbl_alter.php index 8c41860fa0..b7e1d74b91 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -113,8 +113,10 @@ if (isset($_REQUEST['move_columns']) // insert moved column array_splice($column_names, $i, 0, $column); } + $response = PMA_Response::getInstance(); if (empty($changes)) { // should never happen - PMA_ajaxResponse('', true); + $response->isSuccess(false); + exit; } $move_query = 'ALTER TABLE ' . PMA_backquote($table) . ' '; $move_query .= implode(', ', $changes); @@ -122,15 +124,16 @@ if (isset($_REQUEST['move_columns']) $result = PMA_DBI_try_query($move_query); $tmp_error = PMA_DBI_getError(); if ($tmp_error) { - PMA_ajaxResponse(PMA_Message::error($tmp_error), false); + $response->isSuccess(false); + $response->addJSON('message', PMA_Message::error($tmp_error)); + } else { + $message = PMA_Message::success( + __('The columns have been moved successfully.') + ); + $response->addJSON('message', $message); + $response->addJSON('columns', $column_names); } - PMA_ajaxResponse( - PMA_Message::success(__('The columns have been moved successfully.')), - true, - array( - 'columns' => $column_names - ) - ); + exit; } /** @@ -249,9 +252,12 @@ if (isset($_REQUEST['do_save_data'])) { } } - if ( $_REQUEST['ajax_request'] == true) { - $extra_data['sql_query'] = PMA_getMessage(null, $sql_query); - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + if ($_REQUEST['ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + $response->addJSON('sql_query', PMA_getMessage(null, $sql_query)); + exit; } $active_page = 'tbl_structure.php'; diff --git a/tbl_create.php b/tbl_create.php index 43832a887f..78f687129e 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -320,29 +320,31 @@ if (isset($_REQUEST['do_save_data'])) { $new_table_string .= '' . "\n"; - $extra_data['new_table_string'] = $new_table_string; - - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); - } - - $display_query = $sql_query; - $sql_query = ''; - - // read table info on this newly created table, in case - // the next page is Structure - $reread_info = true; - include 'libraries/tbl_info.inc.php'; - - // do not switch to sql.php - as there is no row to be displayed on a new table - if ($cfg['DefaultTabTable'] === 'sql.php') { - include 'tbl_structure.php'; + $response = PMA_Response::getInstance(); + $response->addJSON('message', $message); + $response->addJSON('new_table_string', $new_table_string); } else { - include '' . $cfg['DefaultTabTable']; + + $display_query = $sql_query; + $sql_query = ''; + + // read table info on this newly created table, in case + // the next page is Structure + $reread_info = true; + include 'libraries/tbl_info.inc.php'; + + // do not switch to sql.php - as there is no row to be displayed on a new table + if ($cfg['DefaultTabTable'] === 'sql.php') { + include 'tbl_structure.php'; + } else { + include '' . $cfg['DefaultTabTable']; + } } - exit; } else { if ($GLOBALS['is_ajax_request'] == true) { - PMA_ajaxResponse(PMA_DBI_getError(), false); + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', PMA_DBI_getError()); } else { PMA_mysqlDie('', '', '', $err_url, false); // An error happened while inserting/updating a table definition. @@ -352,6 +354,7 @@ if (isset($_REQUEST['do_save_data'])) { $regenerate = true; } } + exit; } // end do create table /** diff --git a/tbl_indexes.php b/tbl_indexes.php index dc07c9c925..5b1462585f 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -105,21 +105,25 @@ if (isset($_REQUEST['do_save_data'])) { 'Table %1$s has been altered successfully')); $message->addParam($table); - if ( $GLOBALS['is_ajax_request'] == true) { - $extra_data['index_table'] = PMA_Index::getView($table, $db); - $extra_data['sql_query'] = PMA_getMessage(null, $sql_query); - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + if ($GLOBALS['is_ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->addJSON('message', $message); + $response->addJSON('index_table', PMA_Index::getView($table, $db)); + $response->addJSON('sql_query', PMA_getMessage(null, $sql_query)); + } else { + $active_page = 'tbl_structure.php'; + include 'tbl_structure.php'; } - - $active_page = 'tbl_structure.php'; - include 'tbl_structure.php'; exit; } else { - if ( $GLOBALS['is_ajax_request'] == true) { - $extra_data['error'] = $error; - PMA_ajaxResponse($error, false); + if ($GLOBALS['is_ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $error); + exit; + } else { + $error->display(); } - $error->display(); } } // end builds the new index diff --git a/tbl_move_copy.php b/tbl_move_copy.php index 6779754a59..c9a6d3aad4 100644 --- a/tbl_move_copy.php +++ b/tbl_move_copy.php @@ -64,16 +64,9 @@ if (PMA_isValid($_REQUEST['new_name'])) { /* Check: Work on new table or on old table? */ if (isset($_REQUEST['submit_move']) || PMA_isValid($_REQUEST['switch_to_new'])) { - $db = $_REQUEST['target_db']; - $table = $_REQUEST['new_name']; + $db = $_REQUEST['target_db']; + $table = $_REQUEST['new_name']; } - - if ( $_REQUEST['ajax_request'] == true) { - $extra_data['sql_query'] = PMA_getMessage(null, $sql_query); - $extra_data['db'] = $GLOBALS['db']; - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); - } - $reload = 1; } } else { @@ -84,6 +77,18 @@ if (PMA_isValid($_REQUEST['new_name'])) { $result = false; } +if ($GLOBALS['is_ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->addJSON('message', $message); + if ($message->isSuccess()) { + $response->addJSON('db', $GLOBALS['db']); + $response->addJSON('sql_query', PMA_getMessage(null, $sql_query)); + } else { + $response->isSuccess(false); + } + exit; +} + /** * Back to the calling script */ diff --git a/tbl_operations.php b/tbl_operations.php index 3d44a7e684..e2d1e25319 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -231,17 +231,23 @@ if (isset($result) && empty($message_to_show)) { $_message = $result ? $message = PMA_Message::success(__('Your SQL query has been executed successfully')) : PMA_Message::error(__('Error')); // $result should exist, regardless of $_message $_type = $result ? 'success' : 'error'; - if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { - $extra_data['sql_query'] = PMA_getMessage(null, $sql_query); - PMA_ajaxResponse($_message, $_message->isSuccess(), $extra_data); + if ($GLOBALS['ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->isSuccess($_message->isSuccess()); + $response->addJSON('message', $_message); + $response->addJSON('sql_query', PMA_getMessage(null, $sql_query)); + exit; } } if (! empty($warning_messages)) { $_message = new PMA_Message; $_message->addMessages($warning_messages); $_message->isError(true); - if ( $_REQUEST['ajax_request'] == true) { - PMA_ajaxResponse($_message, false); + if ($GLOBALS['ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->isSuccess(false); + $response->addJSON('message', $_message); + exit; } unset($warning_messages); } diff --git a/tbl_replace.php b/tbl_replace.php index 2f75331b06..f74281dd69 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -421,7 +421,12 @@ if ($GLOBALS['is_ajax_request'] == true) { /**Get the total row count of the table*/ $extra_data['row_count'] = PMA_Table::countRecords($_REQUEST['db'], $_REQUEST['table']); $extra_data['sql_query'] = PMA_getMessage($message, $GLOBALS['display_query']); - PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); + + $response = PMA_Response::getInstance(); + $response->isSuccess($message->isSuccess()); + $response->addJSON('message', $message); + $response->addJSON($extra_data); + exit; } if (isset($return_to_sql_query)) { diff --git a/tbl_zoom_select.php b/tbl_zoom_select.php index cdb37b5b38..0ff020be97 100644 --- a/tbl_zoom_select.php +++ b/tbl_zoom_select.php @@ -72,7 +72,8 @@ if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) { } $extra_data['row_info'] = $row; } - PMA_ajaxResponse(null, true, $extra_data); + PMA_Response::getInstance()->addJSON($extra_data); + exit; } /** @@ -82,14 +83,14 @@ if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) { */ if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) { - $extra_data = array(); + $response = PMA_Response::getInstance(); $field = $_REQUEST['field']; if ($field == 'pma_null') { - $extra_data['field_type'] = ''; - $extra_data['field_collation'] = ''; - $extra_data['field_operators'] = ''; - $extra_data['field_value'] = ''; - PMA_ajaxResponse(null, true, $extra_data); + $response->addJSON('field_type', ''); + $response->addJSON('field_collation', ''); + $response->addJSON('field_operators', ''); + $response->addJSON('field_value', ''); + exit; } // Gets the list and number of fields list($columnNames, $columnTypes, $columnCollations, $columnNullFlags) @@ -100,11 +101,11 @@ if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) $db, $table, $columnNames, $columnTypes, $columnCollations, $columnNullFlags, $foreigners, $_REQUEST['it'], $key ); - $extra_data['field_type'] = $properties['type']; - $extra_data['field_collation'] = $properties['collation']; - $extra_data['field_operators'] = $properties['func']; - $extra_data['field_value'] = $properties['value']; - PMA_ajaxResponse(null, true, $extra_data); + $response->addJSON('field_type', $properties['type']); + $response->addJSON('field_collation', $properties['collation']); + $response->addJSON('field_operators', $properties['func']); + $response->addJSON('field_value', $properties['value']); + exit; } $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values')); diff --git a/test/libraries/common/PMA_ajaxResponse_test.php b/test/libraries/common/PMA_ajaxResponse_test.php deleted file mode 100644 index 916f15b2b4..0000000000 --- a/test/libraries/common/PMA_ajaxResponse_test.php +++ /dev/null @@ -1,71 +0,0 @@ -expectOutputString('{"success":true,"message":"' . $message . '"}'); - PMA_ajaxResponse($message); - } - - function testAjaxResponseTextWithExtra() - { - $message = 'text'; - $exra = array('str_val' => 'te\x/t"1', 'int_val' => 10); - - $this->expectOutputString('{"success":true,"message":"' . $message . '","str_val":"te\\\\x\/t\"1","int_val":10}'); - PMA_ajaxResponse($message, true, $exra); - } - - function testAjaxResponseTextError() - { - $message = 'error_text'; - - $this->expectOutputString('{"success":false,"error":"' . $message . '"}'); - PMA_ajaxResponse($message, false); - } - - function testAjaxResponseMessage() - { - $message = new PMA_Message("Message Text", 1); - - $this->expectOutputString('{"success":true,"message":"
Message Text<\/div>"}'); - PMA_ajaxResponse($message); - } - - function testAjaxResponseMessageWithExtra() - { - - $message = new PMA_Message("Message Text", 1); - $exra = array('str_val' => 'te\x/t"1', 'int_val' => 10); - - $this->expectOutputString('{"success":true,"message":"
Message Text<\/div>","str_val":"te\\\\x\/t\"1","int_val":10}'); - PMA_ajaxResponse($message, true, $exra); - } - - function testAjaxResponseMessageError() - { - - $message = new PMA_Message("Error Message Text", 1); - - // TODO: class for output div should be "error" - $this->expectOutputString('{"success":false,"error":"
Error Message Text<\/div>"}'); - PMA_ajaxResponse($message, false); - } - -} \ No newline at end of file diff --git a/view_create.php b/view_create.php index b0cf55764b..10ccfbc9d1 100644 --- a/view_create.php +++ b/view_create.php @@ -66,15 +66,27 @@ if (isset($_REQUEST['createview'])) { if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::success(); include './' . $cfg['DefaultTabDatabase']; - exit(); } else { - PMA_ajaxResponse(PMA_getMessage(PMA_Message::success(), $sql_query), 1); + $response = PMA_Response::getInstance(); + $response->addJSON( + 'message', + PMA_getMessage(PMA_Message::success(), $sql_query) + ); } + exit; } else { if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::rawError(PMA_DBI_getError()); } else { - PMA_ajaxResponse(PMA_Message::error("$sql_query

" . PMA_DBI_getError()), 0); + $response = PMA_Response::getInstance(); + $response->addJSON( + 'message', + PMA_Message::error( + "$sql_query

" . PMA_DBI_getError() + ) + ); + $response->isSuccess(false); + exit; } } } From ffe5d7fdc38fa7b0f8d6e851bc94660b9ecfec9c Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 12 Jun 2012 13:55:34 +0100 Subject: [PATCH 78/82] Added missing API call to the PMA_Footer class --- libraries/Footer.class.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index f3874fc53e..c0c4282db4 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -274,6 +274,16 @@ class PMA_Footer $this->_isMinimal = true; } + /** + * Returns the PMA_Scripts object + * + * @return PMA_Scripts object + */ + public function getScripts() + { + return $this->_scripts; + } + /** * Renders the footer * From 1c01c222efd37f889194a85e48df5809f4a8de40 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 12 Jun 2012 14:04:39 +0100 Subject: [PATCH 79/82] Coding style fixes --- libraries/Footer.class.php | 4 +++- libraries/Header.class.php | 7 +++++-- libraries/Response.class.php | 14 ++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/Footer.class.php b/libraries/Footer.class.php index c0c4282db4..d231e134cc 100644 --- a/libraries/Footer.class.php +++ b/libraries/Footer.class.php @@ -257,11 +257,13 @@ class PMA_Footer * Set the ajax flag to indicate whether * we are sevicing an ajax request * + * @param bool $isAjax Whether we are sevicing an ajax request + * * @return void */ public function setAjax($isAjax) { - $this->_isAjax = $isAjax; + $this->_isAjax = ($isAjax == true); } /** diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 6b635737f5..02f69a981f 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -1,6 +1,7 @@ _isAjax = $isAjax; + $this->_isAjax = ($isAjax == true); } /** @@ -431,7 +434,7 @@ class PMA_Header */ private function _getTitleTag() { - $retval = ""; + $retval = "<title>"; $retval .= $this->_getPageTitle(); $retval .= ""; return $retval; diff --git a/libraries/Response.class.php b/libraries/Response.class.php index f78d98cc98..c341acc614 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -97,7 +97,7 @@ class PMA_Response $this->_footer = new PMA_Footer(); $this->_isSuccess = true; - $this->_isAjax = false; + $this->_isAjax = false; if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $this->_isAjax = true; } @@ -123,15 +123,13 @@ class PMA_Response * Set the status of an ajax response, * whether it is a success or an error * + * @param bool $state Whether the request was successfully processed + * * @return void */ public function isSuccess($state) { - if ($state) { - $this->_isSuccess = true; - } else { - $this->_isSuccess = false; - } + $this->_isSuccess = ($state == true); } /** @@ -276,7 +274,7 @@ class PMA_Response $this->_JSON['success'] = true; } else { $this->_JSON['success'] = false; - $this->_JSON['error'] = $this->_JSON['message']; + $this->_JSON['error'] = $this->_JSON['message']; unset($this->_JSON['message']); } @@ -300,7 +298,7 @@ class PMA_Response { $response = PMA_Response::getInstance(); chdir($response->getCWD()); - $buffer = PMA_OutputBuffering::getInstance(); + $buffer = PMA_OutputBuffering::getInstance(); if (empty($response->_HTML)) { $response->_HTML = $buffer->getContents(); } From 007b10e90a23ee798d95d90a0cac7bb9af2b7fbd Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 12 Jun 2012 14:07:00 +0100 Subject: [PATCH 80/82] Moved lost global --- libraries/Header.class.php | 6 ------ libraries/common.inc.php | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 02f69a981f..c7fc7c34fa 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -13,12 +13,6 @@ require_once 'libraries/Scripts.class.php'; require_once 'libraries/RecentTable.class.php'; require_once 'libraries/Menu.class.php'; - -// FIXME: this global got lost :( -// here, the function does not exist with this configuration: -// $cfg['ServerDefault'] = 0; -$is_superuser = function_exists('PMA_isSuperuser') && PMA_isSuperuser(); - /** * Class used to output the HTTP and HTML headers * diff --git a/libraries/common.inc.php b/libraries/common.inc.php index d4593423b2..e0eb6e786c 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -1085,6 +1085,10 @@ foreach ($GLOBALS as $key => $dummy) { } unset($dummy); +// here, the function does not exist with this configuration: +// $cfg['ServerDefault'] = 0; +$GLOBALS['is_superuser'] = function_exists('PMA_isSuperuser') && PMA_isSuperuser(); + if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) { /** * include subform target page From 5e1cb4e7a688373681c81c2b4318956438a4843e Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 12 Jun 2012 14:13:07 +0100 Subject: [PATCH 81/82] Fixed config auth --- libraries/auth/config.auth.lib.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/auth/config.auth.lib.php b/libraries/auth/config.auth.lib.php index cea96b9cb1..da81d5c73a 100644 --- a/libraries/auth/config.auth.lib.php +++ b/libraries/auth/config.auth.lib.php @@ -88,9 +88,7 @@ function PMA_auth_fails()
- Date: Tue, 12 Jun 2012 14:21:48 +0100 Subject: [PATCH 82/82] Set headerIsSent property of PMA_Header class as private, as it's no longer necessary to access it externally --- libraries/Header.class.php | 14 +++++--------- libraries/display_tbl.lib.php | 1 - server_status.php | 4 ---- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/libraries/Header.class.php b/libraries/Header.class.php index c7fc7c34fa..eaabde56c8 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -96,14 +96,10 @@ class PMA_Header * Whether the HTTP headers (and possibly some HTML) * have already been sent to the browser * - * FIXME: Shouldn't be static or public, but first - * need to remove references to it from the code base - * - * @access public - * @static + * @access private * @var bool */ - public static $headerIsSent; + private $_headerIsSent; /** * Creates a new class instance @@ -126,7 +122,7 @@ class PMA_Header $this->_isPrintView = false; $this->_scripts = new PMA_Scripts(); $this->_addDefaultScripts(); - self::$headerIsSent = false; + $this->_headerIsSent = false; // if database storage for user preferences is transient, // offer to load exported settings from localStorage // (detection will be done in JavaScript) @@ -272,7 +268,7 @@ class PMA_Header public function getDisplay() { $retval = ''; - if (! self::$headerIsSent) { + if (! $this->_headerIsSent) { if (! $this->_isAjax && $this->_isEnabled) { $this->sendHttpHeaders(); $retval .= $this->_getHtmlStart(); @@ -358,7 +354,7 @@ class PMA_Header // Define the charset to be used header('Content-Type: text/html; charset=utf-8'); } - self::$headerIsSent = true; + $this->_headerIsSent = true; } /** diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 45021d66fc..503f06d15d 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1061,7 +1061,6 @@ function PMA_getTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, } elseif ((($GLOBALS['cfg']['RowActionLinks'] == 'left') || ($GLOBALS['cfg']['RowActionLinks'] == 'both')) && (($is_display['edit_lnk'] == 'nn') && ($is_display['del_lnk'] == 'nn')) - && ! PMA_Header::$headerIsSent ) { // ... elseif no button, displays empty columns if required // (unless coming from Browse mode print view) diff --git a/server_status.php b/server_status.php index 93d0157042..301ea93c27 100644 --- a/server_status.php +++ b/server_status.php @@ -9,10 +9,6 @@ require_once 'libraries/common.inc.php'; -if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { - PMA_Header::$headerIsSent = true; -} - /** * Ajax request */