Skip to content

Commit d356091

Browse files
committed
Hide unsupported alter table links
1 parent a5ec07a commit d356091

2 files changed

Lines changed: 35 additions & 31 deletions

File tree

adminer/db.inc.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,27 @@
8080
echo '<thead><tr class="wrap">';
8181
echo '<td><input id="check-all" type="checkbox" class="jsonly">' . script("qs('#check-all').onclick = partial(formCheck, /^(tables|views)\[/);", "");
8282
echo '<th>' . lang('Table');
83-
echo '<td>' . lang('Engine') . doc_link(array('sql' => 'storage-engines.html'));
84-
echo '<td>' . lang('Collation') . doc_link(array('sql' => 'charset-charsets.html', 'mariadb' => 'supported-character-sets-and-collations/'));
85-
echo '<td>' . lang('Data Length') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT', 'oracle' => 'REFRN20286'));
86-
echo '<td>' . lang('Index Length') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT'));
87-
echo '<td>' . lang('Data Free') . doc_link(array('sql' => 'show-table-status.html'));
88-
echo '<td>' . lang('Auto Increment') . doc_link(array('sql' => 'example-auto-increment.html', 'mariadb' => 'auto_increment/'));
89-
echo '<td>' . lang('Rows') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'catalog-pg-class.html#CATALOG-PG-CLASS', 'oracle' => 'REFRN20286'));
90-
echo (support("comment") ? '<td>' . lang('Comment') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'functions-info.html#FUNCTIONS-INFO-COMMENT-TABLE')) : '');
83+
$columns = array("Engine" => array(lang('Engine') . doc_link(array('sql' => 'storage-engines.html'))));
84+
if (collations()) {
85+
$columns["Collation"] = array(lang('Collation') . doc_link(array('sql' => 'charset-charsets.html', 'mariadb' => 'supported-character-sets-and-collations/')));
86+
}
87+
if (function_exists('Adminer\alter_table')) {
88+
$columns["Data_length"] = array(lang('Data Length') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT', 'oracle' => 'REFRN20286')), "create", lang('Alter table'));
89+
}
90+
if (support('indexes')) {
91+
$columns["Index_length"] = array(lang('Index Length') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT')), "indexes", lang('Alter indexes'));
92+
}
93+
$columns["Data_free"] = array(lang('Data Free') . doc_link(array('sql' => 'show-table-status.html')), "edit", lang('New item'));
94+
if (function_exists('Adminer\alter_table')) {
95+
$columns["Auto_increment"] = array(lang('Auto Increment') . doc_link(array('sql' => 'example-auto-increment.html', 'mariadb' => 'auto_increment/')), "auto_increment=1&create", lang('Alter table'));
96+
}
97+
$columns["Rows"] = array(lang('Rows') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'catalog-pg-class.html#CATALOG-PG-CLASS', 'oracle' => 'REFRN20286')), "select", lang('Select data'));
98+
if (support("comment")) {
99+
$columns["Comment"] = array(lang('Comment') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'functions-info.html#FUNCTIONS-INFO-COMMENT-TABLE')));
100+
}
101+
foreach ($columns as $column) {
102+
echo "<td>$column[0]";
103+
}
91104
echo "</thead>\n";
92105

93106
$tables = 0;
@@ -101,34 +114,23 @@
101114
echo '<td colspan="6">' . (support("view") ? "<a href='" . h(ME) . "view=" . urlencode($name) . "' title='" . lang('Alter view') . "'>$title</a>" : $title);
102115
echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
103116
} else {
104-
foreach (
105-
array(
106-
"Engine" => array(),
107-
"Collation" => array(),
108-
"Data_length" => array("create", lang('Alter table')),
109-
"Index_length" => array("indexes", lang('Alter indexes')),
110-
"Data_free" => array("edit", lang('New item')),
111-
"Auto_increment" => array("auto_increment=1&create", lang('Alter table')),
112-
"Rows" => array("select", lang('Select data')),
113-
) as $key => $link
114-
) {
117+
foreach ($columns as $key => $column) {
115118
$id = " id='$key-" . h($name) . "'";
116-
echo ($link ? "<td align='right'>" . (support("table") || $key == "Rows" || (support("indexes") && $key != "Data_length")
117-
? "<a href='" . h(ME . "$link[0]=") . urlencode($name) . "'$id title='$link[1]'>?</a>"
118-
: "<span$id>?</span>"
119-
) : "<td id='$key-" . h($name) . "'>");
119+
echo ($column[1]
120+
? "<td align='right'><a href='" . h(ME . "$column[1]=") . urlencode($name) . "'$id title='$column[2]'>?</a>"
121+
: "<td id='$key-" . h($name) . "'>"
122+
);
120123
}
121124
$tables++;
122125
}
123-
echo (support("comment") ? "<td id='Comment-" . h($name) . "'>" : "");
124126
echo "\n";
125127
}
126128

127129
echo "<tr><td><th>" . lang('%d in total', count($tables_list));
128130
echo "<td>" . h(JUSH == "sql" ? get_val("SELECT @@default_storage_engine") : "");
129131
echo "<td>" . h(db_collation(DB, collations()));
130132
foreach (array("Data_length", "Index_length", "Data_free") as $key) {
131-
echo "<td align='right' id='sum-$key'>";
133+
echo ($columns[$key] ? "<td align='right' id='sum-$key'>" : "");
132134
}
133135
echo "\n";
134136

@@ -173,7 +175,7 @@
173175
echo script("tableCheck();");
174176
}
175177

176-
echo "<p class='links'><a href='" . h(ME) . "create='>" . lang('Create table') . "</a>\n";
178+
echo (function_exists('Adminer\alter_table') ? "<p class='links'><a href='" . h(ME) . "create='>" . lang('Create table') . "</a>\n" : '');
177179
echo (support("view") ? "<a href='" . h(ME) . "view='>" . lang('Create view') . "</a>\n" : "");
178180

179181
if (support("routine")) {

adminer/include/adminer.inc.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,12 @@ function selectLinks(array $tableStatus, ?string $set = ""): void {
201201
$is_view = false;
202202
if (support("table")) {
203203
$is_view = is_view($tableStatus);
204-
if (!$is_view) {
204+
if ($is_view) {
205+
if (support("view")) {
206+
$links["view"] = lang('Alter view');
207+
}
208+
} elseif (function_exists('Adminer\alter_table')) {
205209
$links["create"] = lang('Alter table');
206-
} elseif (support("view")) {
207-
$links["view"] = lang('Alter view');
208210
}
209211
}
210212
if ($set !== null) {
@@ -423,7 +425,7 @@ function selectSearchPrint(array $where, array $columns, array $indexes): void {
423425
echo "<div>(<i>" . implode("</i>, <i>", array_map('Adminer\h', $index["columns"])) . "</i>) AGAINST";
424426
echo " <input type='search' name='fulltext[$i]' value='" . h(idx($_GET["fulltext"], $i)) . "'>";
425427
echo script("qsl('input').oninput = selectFieldChange;", "");
426-
echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
428+
echo (JUSH == 'sql' ? checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL") : '');
427429
echo "</div>\n";
428430
}
429431
}
@@ -1020,7 +1022,7 @@ function navigation(string $missing): void {
10201022
$actions[] = "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Export') . "</a>";
10211023
}
10221024
$in_db = $_GET["ns"] !== "" && !$missing && DB != "";
1023-
if ($in_db) {
1025+
if ($in_db && function_exists('Adminer\alter_table')) {
10241026
$actions[] = '<a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . ">" . lang('Create table') . "</a>";
10251027
}
10261028
echo ($actions ? "<p class='links'>\n" . implode("\n", $actions) . "\n" : "");

0 commit comments

Comments
 (0)