diff --git a/ChangeLog b/ChangeLog index 554e407928..ae2e75727d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ phpMyAdmin - ChangeLog ====================== 4.3.0.0 (not yet released) ++ rfe #1502 Smart sorting for int keys + rfe #1521 Confirmation message when dropping user(s) + rfe #1518 Confirm dialog on accidentally leaving a page + rfe #1445 Easy access to "SHOW CREATE ..." diff --git a/doc/config.rst b/doc/config.rst index d05658743d..db62c466db 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -2263,6 +2263,15 @@ Design customization If enabled, remember the sorting of each table when browsing them. +.. config:option:: $cfg['TablePrimaryKeyOrder'] + + :type: string + :default: ``'NONE'`` + + This defines the default sort order for the tables, having a primary key, + when there is no sort order defines externally. + Acceptable values : ['NONE', 'ASC', 'DESC'] + .. config:option:: $cfg['HeaderFlipType'] :type: string diff --git a/libraries/config.default.php b/libraries/config.default.php index 9aa77b7fc8..ff3e04cf75 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2587,6 +2587,12 @@ $cfg['LimitChars'] = 50; */ $cfg['RowActionLinks'] = 'left'; +/** + * Default sort order by primary key. + * @global string $cfg['TablePrimaryKeyOrder'] + */ +$cfg['TablePrimaryKeyOrder'] = 'NONE'; + /** * default display direction (horizontal|vertical|horizontalflipped) * diff --git a/libraries/config.values.php b/libraries/config.values.php index 0a205ff51c..a039bae850 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -57,6 +57,11 @@ $cfg_db['RowActionLinks'] = array( 'right' => __('Right'), 'both' => __('Both') ); +$cfg_db['TablePrimaryKeyOrder'] = array( + 'NONE' => __('None'), + 'ASC' => __('Ascending'), + 'DESC' => __('Descending') +); $cfg_db['ProtectBinary'] = array(false, 'blob', 'noblob', 'all'); $cfg_db['DefaultDisplay'] = array('horizontal', 'vertical', 'horizontalflipped'); $cfg_db['CharEditing'] = array('input', 'textarea'); diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 69004963b3..ac57166629 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -522,6 +522,8 @@ $strConfigRecodingEngine_name = __('Recoding engine'); $strConfigRememberSorting_desc = __('When browsing tables, the sorting of each table is remembered.'); $strConfigRememberSorting_name = __('Remember table\'s sorting'); +$strConfigTablePrimaryKeyOrder_desc = __('Default sort order for tables with primary key.'); +$strConfigTablePrimaryKeyOrder_name = __('The sort order'); $strConfigRepeatCells_desc = __('Repeat the headers every X cells, [kbd]0[/kbd] deactivates this feature.'); $strConfigRepeatCells_name = __('Repeat headers'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index a55fb93911..474731ee85 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -207,6 +207,7 @@ $forms['Main_panel']['Browse'] = array( 'RepeatCells', 'LimitChars', 'RowActionLinks', + 'TablePrimaryKeyOrder', 'DefaultDisplay', 'RememberSorting'); $forms['Main_panel']['Edit'] = array( diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 2e91ecefcd..9b2e312c81 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -117,6 +117,7 @@ $forms['Main_panel']['Browse'] = array( 'RepeatCells', 'LimitChars', 'RowActionLinks', + 'TablePrimaryKeyOrder', 'DefaultDisplay', 'RememberSorting'); $forms['Main_panel']['Edit'] = array( diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 3fb03e3d2c..27e3dfdb4b 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1213,7 +1213,37 @@ function PMA_getDefaultSqlQueryForBrowse($db, $table) ); $sql_query = $book_sql_query; } else { - $sql_query = 'SELECT * FROM ' . PMA_Util::backquote($table); + + $defaultOrderByClause = ''; + + if (isset($GLOBALS['cfg']['TablePrimaryKeyOrder']) + && ($GLOBALS['cfg']['TablePrimaryKeyOrder'] !== 'NONE') + ) { + + $primaryKey = null; + $primary = PMA_Index::getPrimary($table, $db); + + if ($primary !== false) { + + $primarycols = $primary->getColumns(); + + foreach ($primarycols as $col) { + $primaryKey = $col->getName(); + break; + } + + if ($primaryKey != null) { + $defaultOrderByClause = ' ORDER BY ' . PMA_Util::backquote($table) . '.' + . PMA_Util::backquote($primaryKey) . ' ' + . $GLOBALS['cfg']['TablePrimaryKeyOrder']; + } + + } + + } + + $sql_query = 'SELECT * FROM ' . PMA_Util::backquote($table) . $defaultOrderByClause; + } unset($book_sql_query);