]> git.joonet.de Git - adminer.git/commitdiff
Add helper for <input type=hidden>
authorJakub Vrana <jakub@vrana.cz>
Tue, 18 Mar 2025 16:15:10 +0000 (17:15 +0100)
committerJakub Vrana <jakub@vrana.cz>
Tue, 18 Mar 2025 16:15:10 +0000 (17:15 +0100)
13 files changed:
adminer/foreign.inc.php
adminer/include/adminer.inc.php
adminer/include/connect.inc.php
adminer/include/editing.inc.php
adminer/include/html.inc.php
adminer/privileges.inc.php
adminer/select.inc.php
adminer/sql.inc.php
adminer/user.inc.php
compile.php
editor/include/adminer.inc.php
plugins/designs.php
plugins/email-table.php

index c01856c20a56d6d1acba24b263283afc1d69b00a..3685d057ad30b06d32157de176b33061a507356a 100644 (file)
@@ -85,8 +85,8 @@ if (support("scheme")) {
        }
        echo lang('DB') . ": " . html_select("db", $dbs, $row["db"] != "" ? $row["db"] : $_GET["db"], $onchange);
 }
+echo input_hidden("change-js");
 ?>
-<input type="hidden" name="change-js" value="">
 <noscript><p><input type="submit" name="change" value="<?php echo lang('Change'); ?>"></noscript>
 <table>
 <thead><tr><th id="label-source"><?php echo lang('Source'); ?><th id="label-target"><?php echo lang('Target'); ?></thead>
index 778b1fa41ed82624726f6657facb8bced21672ea..6eb039af95add1beb2cc250c55ba2b59c47a03b6 100644 (file)
@@ -1097,7 +1097,7 @@ class Adminer {
                }
                foreach (array("import", "sql", "schema", "dump", "privileges") as $val) {
                        if (isset($_GET[$val])) {
-                               echo "<input type='hidden' name='$val' value=''>";
+                               echo input_hidden($val);
                                break;
                        }
                }
index e69b51e86a4d305e3574002654534c1dd5e1c201..1a47d37fa5923e46702b096143f22ec0b09acaae 100644 (file)
@@ -78,7 +78,7 @@ if (
                        echo (support("database")
                                ? "<div class='footer'><div>\n"
                                        . "<fieldset><legend>" . lang('Selected') . " <span id='selected'></span></legend><div>\n"
-                                       . "<input type='hidden' name='all' value=''>" . script("qsl('input').onclick = function () { selectCount('selected', formChecked(this, /^db/)); };") // used by trCheck()
+                                       . input_hidden("all") . script("qsl('input').onclick = function () { selectCount('selected', formChecked(this, /^db/)); };") // used by trCheck()
                                        . "<input type='submit' name='drop' value='" . lang('Drop') . "'>" . confirm() . "\n"
                                        . "</div></fieldset>\n"
                                        . "</div></div>\n"
index ca3c49cc4e898b4a6e779e57c9016394a1cd954e..e3db6035086dc51d318dd6e7e2d4fdfad623ea9f 100644 (file)
@@ -357,7 +357,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
                if ($display) {
                        echo "<input name='fields[$i][field]' value='" . h($field["field"]) . "' data-maxlength='64' autocapitalize='off' aria-labelledby='label-name'>\n";
                }
-               echo "<input type='hidden' name='fields[$i][orig]' value='" . h($orig) . "'>";
+               echo input_hidden("fields[$i][orig]", $orig);
                edit_type("fields[$i]", $field, $collations, $foreign_keys);
                if ($type == "TABLE") {
                        echo "<td>" . checkbox("fields[$i][null]", 1, $field["null"], "", "", "block", "label-null");
index 14b10e584399cd0f5c12815a8fd2be1258364507..51d65c29c46c1401848361ca2a522749580a646c 100644 (file)
@@ -25,13 +25,22 @@ function nonce() {
        return ' nonce="' . get_nonce() . '"';
 }
 
+/** Get <input type="hidden">
+* @param string
+* @param string
+* @return string HTML
+*/
+function input_hidden($name, $value = "") {
+       return "<input type='hidden' name='" . h($name) . "' value='" . h($value) . "'>\n";
+}
+
 /** Get <input type="hidden" name="token">
 * @param string token to use instead of global $token
 * @return string HTML
 */
 function input_token($special = "") {
        global $token;
-       return "<input type='hidden' name='token' value='" . ($special ?: $token) . "'>\n";
+       return input_hidden("token", ($special ?: $token));
 }
 
 /** Get a target="_blank" attribute
@@ -201,7 +210,7 @@ function hidden_fields($process, $ignore = array(), $prefix = '') {
                                hidden_fields($val, array(), $key);
                        } else {
                                $return = true;
-                               echo '<input type="hidden" name="' . h($prefix ? $prefix . "[$key]" : $key) . '" value="' . h($val) . '">';
+                               echo input_hidden(($prefix ? $prefix . "[$key]" : $key), $val);
                        }
                }
        }
@@ -212,9 +221,9 @@ function hidden_fields($process, $ignore = array(), $prefix = '') {
 * @return null
 */
 function hidden_fields_get() {
-       echo (sid() ? '<input type="hidden" name="' . session_name() . '" value="' . h(session_id()) . '">' : '');
-       echo (SERVER !== null ? '<input type="hidden" name="' . DRIVER . '" value="' . h(SERVER) . '">' : "");
-       echo '<input type="hidden" name="username" value="' . h($_GET["username"]) . '">';
+       echo (sid() ? input_hidden(session_name(), session_id()) : '');
+       echo (SERVER !== null ? input_hidden(DRIVER, SERVER) : "");
+       echo input_hidden("username", $_GET["username"]);
 }
 
 /** Print enum input field
@@ -520,8 +529,8 @@ function edit_form($table, $fields, $row, $update) {
        if (isset($_GET["select"])) {
                hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
        }
-       echo "<input type='hidden' name='referer' value='" . h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]) . "'>\n";
-       echo "<input type='hidden' name='save' value='1'>\n";
+       echo input_hidden("referer", (isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]));
+       echo input_hidden("save", 1);
        echo input_token();
        echo "</form>\n";
 }
index d3cd6142bb42b85c45b979b9461392e183e10f77..975548adb85ef2ffe7946786a049a0e9bdec0680 100644 (file)
@@ -14,8 +14,8 @@ if (!$result) {
 
 echo "<form action=''><p>\n";
 hidden_fields_get();
-echo "<input type='hidden' name='db' value='" . h(DB) . "'>\n";
-echo ($grant ? "" : "<input type='hidden' name='grant' value=''>\n");
+echo input_hidden("db", DB);
+echo ($grant ? "" : input_hidden("grant"));
 echo "<table class='odds'>\n";
 echo "<thead><tr><th>" . lang('Username') . "<th>" . lang('Server') . "<th></thead>\n";
 
index 7dcf7a87c153069abde7739d582f16390dc134df..6f51b8ffdbdf7b759527ac3cdcb6d78cc0b1a4bf 100644 (file)
@@ -258,8 +258,8 @@ if (!$columns && support("table")) {
        echo "<form action='' id='form'>\n";
        echo "<div style='display: none;'>";
        hidden_fields_get();
-       echo (DB != "" ? '<input type="hidden" name="db" value="' . h(DB) . '">' . (isset($_GET["ns"]) ? '<input type="hidden" name="ns" value="' . h($_GET["ns"]) . '">' : "") : ""); // not used in Editor
-       echo '<input type="hidden" name="select" value="' . h($TABLE) . '">';
+       echo (DB != "" ? input_hidden("db", DB) . (isset($_GET["ns"]) ? input_hidden("ns", $_GET["ns"]) : "") : ""); // not used in Editor
+       echo input_hidden("select", $TABLE);
        echo "</div>\n";
        $adminer->selectColumnsPrint($select, $columns);
        $adminer->selectSearchPrint($where, $search_columns, $indexes);
index 34b30e60d3f7a8304a51d9183026fb8d9f3733a9..8f2020c521b3845e3096d94982622b2cb5ac060c 100644 (file)
@@ -168,8 +168,8 @@ if (!$error && $_POST) {
                                                                                        echo ", <a href='#$id'>" . lang('Export') . "</a>" . script("qsl('a').onclick = partial(toggle, '$id');", "") . "<span id='$id' class='hidden'>: "
                                                                                                . html_select("output", $adminer->dumpOutput(), $adminer_export["output"]) . " "
                                                                                                . html_select("format", $dump_format, $adminer_export["format"])
-                                                                                               . "<input type='hidden' name='query' value='" . h($q) . "'>"
-                                                                                               . " <input type='submit' name='export' value='" . lang('Export') . "'>" . input_token() . "</span>\n"
+                                                                                               . input_hidden("query", $q)
+                                                                                               . "<input type='submit' name='export' value='" . lang('Export') . "'>" . input_token() . "</span>\n"
                                                                                                . "</form>\n"
                                                                                        ;
                                                                                }
index 9b6b959463714064f1150796987650fc0938f8fc..3a70f3b2596105d3d95b1f052a7968bd17615300 100644 (file)
@@ -150,7 +150,7 @@ $i = 0;
 foreach ($grants as $object => $grant) {
        echo '<th>' . ($object != "*.*"
                ? "<input name='objects[$i]' value='" . h($object) . "' size='10' autocapitalize='off'>"
-               : "<input type='hidden' name='objects[$i]' value='*.*' size='10'>*.*"
+               : input_hidden("objects[$i]", "*.*") . "*.*"
        ); //! separate db, table, columns, PROCEDURE|FUNCTION, routine
        $i++;
 }
index 53561ce2586ecddfe6814efc4b7f9503e4a1ee86..7425f4cac42f387a460dfd2189e618b4babafb8d 100755 (executable)
@@ -307,7 +307,7 @@ if ($vendor) {
                }
        }
        if ($project != "editor" && count($drivers) == 1) {
-               $file = str_replace('html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);")', "\"<input type='hidden' name='auth[driver]' value='" . ($vendor == "mysql" ? "server" : $vendor) . "'>" . reset($drivers) . "\"", $file, $count);
+               $file = str_replace('html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);")', 'input_hidden("auth[driver]", "' . ($vendor == "mysql" ? "server" : $vendor) . '") . "' . reset($drivers) . '"', $file, $count);
                if (!$count) {
                        echo "auth[driver] form field not found\n";
                }
index 17fbbca0b972f2f5a99d6c76cece73c83c81cf61..304cffaf10e3aa600bdfc898a3e03d701baf1ab4 100644 (file)
@@ -76,7 +76,7 @@ class Adminer {
 
        function loginForm() {
                echo "<table class='layout'>\n";
-               echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input type="hidden" name="auth[driver]" value="server"><input name="auth[username]" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">');
+               echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', input_hidden("auth[driver]", "server") . '<input name="auth[username]" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">');
                echo $this->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
                echo "</table>\n";
                echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
@@ -245,7 +245,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
                        if (preg_match("~enum~", $field["type"]) || like_bool($field)) { //! set - uses 1 << $i and FIND_IN_SET()
                                $key = $keys[$name];
                                $i--;
-                               echo "<div>" . h($desc) . "<input type='hidden' name='where[$i][col]' value='" . h($name) . "'>:";
+                               echo "<div>" . h($desc) . input_hidden("where[$i][col]", $name) . ":";
                                echo (like_bool($field)
                                        ? " <select name='where[$i][val]'>" . optionlist(array("" => "", lang('no'), lang('yes')), $where[$key]["val"], true) . "</select>"
                                        : enum_input("checkbox", " name='where[$i][val][]'", $field, (array) $where[$key]["val"], ($field["null"] ? 0 : null))
@@ -258,7 +258,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
                                }
                                $key = $keys[$name];
                                $i--;
-                               echo "<div>" . h($desc) . "<input type='hidden' name='where[$i][col]' value='" . h($name) . "'><input type='hidden' name='where[$i][op]' value='='>: <select name='where[$i][val]'>" . optionlist($options, $where[$key]["val"], true) . "</select></div>\n";
+                               echo "<div>" . h($desc) . input_hidden("where[$i][col]", $name) . input_hidden("where[$i][op]", "=") . ": <select name='where[$i][val]'>" . optionlist($options, $where[$key]["val"], true) . "</select></div>\n";
                                unset($columns[$name]);
                        }
                }
@@ -337,7 +337,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
                        echo "<p><textarea name='email_message' rows='15' cols='75'>" . h($_POST["email_message"] . ($_POST["email_append"] ? '{$' . "$_POST[email_addition]}" : "")) . "</textarea>\n";
                        echo "<p>" . script("qsl('p').onkeydown = partialArg(bodyKeydown, 'email_append');", "") . html_select("email_addition", $columns, $_POST["email_addition"]) . "<input type='submit' name='email_append' value='" . lang('Insert') . "'>\n"; //! JavaScript
                        echo "<p>" . lang('Attachments') . ": <input type='file' name='email_files[]'>" . script("qsl('input').onchange = emailFileChange;");
-                       echo "<p>" . (count($emailFields) == 1 ? '<input type="hidden" name="email_field" value="' . h(key($emailFields)) . '">' : html_select("email_field", $emailFields));
+                       echo "<p>" . (count($emailFields) == 1 ? input_hidden("email_field", key($emailFields)) : html_select("email_field", $emailFields));
                        echo "<input type='submit' name='email' value='" . lang('Send') . "'>" . confirm();
                        echo "</div>\n";
                        echo "</div></fieldset>\n";
index 29e69d0714be882f9e8d57cce055b672ea91fc18..202fcef0fbb4e82256177fd2a93c2c786cee4cc2 100644 (file)
@@ -35,7 +35,7 @@ class AdminerDesigns {
        function navigation($missing) {
                echo "<form action='' method='post' style='position: fixed; bottom: .5em; right: .5em;'>";
                echo Adminer\html_select("design", array("" => "(design)") + $this->designs, $_SESSION["design"], "this.form.submit();");
-               echo '<input type="hidden" name="token" value="' . Adminer\get_token() . '">';
+               echo Adminer\input_token();
                echo "</form>\n";
        }
 }
index d5bc22b156634642694c3de375a33d429d132869..57c8216966422092442eb04e69c1d3470ad1ce0f 100644 (file)
@@ -38,7 +38,7 @@ class AdminerEmailTable {
        el.value = '';
        this.parentNode.appendChild(el);
 };");
-                       echo "<p>" . (count($emailFields) == 1 ? '<input type="hidden" name="email_field" value="' . Adminer\h(key($emailFields)) . '">' : Adminer\html_select("email_field", $emailFields));
+                       echo "<p>" . (count($emailFields) == 1 ? Adminer\input_hidden("email_field", key($emailFields)) : Adminer\html_select("email_field", $emailFields));
                        echo "<input type='submit' name='email' value='" . ('Send') . "'>" . Adminer\confirm();
                        echo "</div>\n";
                        echo "</div></fieldset>\n";