<pre>
<?php
/** Format string as table row
-* @param string $s
* @return string HTML
*/
-function pre_tr($s) {
+function pre_tr(string $s) {
return preg_replace('~^~m', '<tr>', preg_replace('~\|~', '<td>', preg_replace('~\|$~m', "", rtrim($s))));
}
}
/** Set the client character set
- * @param string $charset
* @return bool
*/
- function set_charset($charset) {
+ function set_charset(string $charset) {
if (function_exists('mysql_set_charset')) {
if (mysql_set_charset($charset, $this->link)) {
return true;
/** @var int */ private $offset = 0;
/** Constructor
- * @param resource $result
*/
- function __construct($result) {
+ function __construct(resource $result) {
$this->result = $result;
$this->num_rows = mysql_num_rows($result);
}
/** Escape database identifier
- * @param string $idf
* @return string
*/
- function idf_escape($idf) {
+ function idf_escape(string $idf) {
return "`" . str_replace("`", "``", $idf) . "`";
}
/** Get escaped table name
- * @param string $idf
* @return string
*/
- function table($idf) {
+ function table(string $idf) {
return idf_escape($idf);
}
* @param array{string, string, string} $credentials [$server, $username, $password]
* @return string|Db string for error
*/
- function connect($credentials) {
+ function connect(array $credentials) {
global $drivers;
$connection = new Db;
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
}
/** Get cached list of databases
- * @param bool $flush
* @return list<string>
*/
- function get_databases($flush) {
+ function get_databases(bool $flush) {
// SHOW DATABASES can take a very long time so it is cached
$return = get_session("dbs");
if ($return === null) {
/** Formulate SQL query with limit
* @param string $query everything after SELECT
* @param string $where including WHERE
- * @param int $limit
- * @param int $offset
- * @param string $separator
* @return string
*/
- function limit($query, $where, $limit, $offset = 0, $separator = " ") {
+ function limit(string $query, string $where, int $limit, int $offset = 0, string $separator = " ") {
return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
}
/** Formulate SQL modification query with limit 1
- * @param string $table
* @param string $query everything after UPDATE or DELETE
- * @param string $where
- * @param string $separator
* @return string
*/
- function limit1($table, $query, $where, $separator = "\n") {
+ function limit1(string $table, string $query, string $where, string $separator = "\n") {
return limit($query, $where, 1, 0, $separator);
}
/** Get database collation
- * @param string $db
* @param string[][] $collations result of collations()
* @return string
*/
- function db_collation($db, $collations) {
+ function db_collation(string $db, array $collations) {
$return = null;
$create = get_val("SHOW CREATE DATABASE " . idf_escape($db), 1);
if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) {
* @param list<string> $databases
* @return int[] [$db => $tables]
*/
- function count_tables($databases) {
+ function count_tables(array $databases) {
$return = array();
foreach ($databases as $db) {
$return[$db] = count(get_vals("SHOW TABLES IN " . idf_escape($db)));
}
/** Get table status
- * @param string $name
* @param bool $fast return only "Name", "Engine" and "Comment" fields
* @return TableStatus[]
*/
- function table_status($name = "", $fast = false) {
+ function table_status(string $name = "", bool $fast = false) {
$return = array();
foreach (
get_rows(
* @param TableStatus $table_status
* @return bool
*/
- function is_view($table_status) {
+ function is_view(array $table_status) {
return $table_status["Engine"] === null;
}
* @param TableStatus $table_status result of table_status1()
* @return bool
*/
- function fk_support($table_status) {
+ function fk_support(array $table_status) {
return preg_match('~InnoDB|IBMDB2I' . (min_version(5.6) ? '|NDB' : '') . '~i', $table_status["Engine"]);
}
/** Get information about fields
- * @param string $table
* @return Field[]
*/
- function fields($table) {
+ function fields(string $table) {
global $connection;
$maria = ($connection->flavor == 'maria');
$return = array();
}
/** Get table indexes
- * @param string $table
- * @param ?Db $connection2
* @return Index[]
*/
- function indexes($table, $connection2 = null) {
+ function indexes(string $table, ?Db $connection2 = null) {
$return = array();
foreach (get_rows("SHOW INDEX FROM " . table($table), $connection2) as $row) {
$name = $row["Key_name"];
}
/** Get foreign keys in table
- * @param string $table
* @return ForeignKey[]
*/
- function foreign_keys($table) {
+ function foreign_keys(string $table) {
global $driver;
static $pattern = '(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")';
$return = array();
}
/** Get view SELECT
- * @param string $name
* @return array{select:string}
*/
- function view($name) {
+ function view(string $name) {
return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)*\s+AS\s+~isU', '', get_val("SHOW CREATE VIEW " . table($name), 1)));
}
}
/** Find out if database is information_schema
- * @param string $db
* @return bool
*/
- function information_schema($db) {
+ function information_schema(string $db) {
return ($db == "information_schema")
|| (min_version(5.5) && $db == "performance_schema");
}
}
/** Create database
- * @param string $db
- * @param string $collation
* @return Result
*/
- function create_database($db, $collation) {
+ function create_database(string $db, string $collation) {
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . q($collation) : ""));
}
* @param list<string> $databases
* @return bool
*/
- function drop_databases($databases) {
+ function drop_databases(array $databases) {
$return = apply_queries("DROP DATABASE", $databases, 'Adminer\idf_escape');
restart_session();
set_session("dbs", null);
/** Rename database from DB
* @param string $name new name
- * @param string $collation
* @return bool
*/
- function rename_database($name, $collation) {
+ function rename_database(string $name, string $collation) {
$return = false;
if (create_database($name, $collation)) {
$tables = array();
* @param string $name new name
* @param list<array{string, list<string>, string}> $fields of [$orig, $process_field, $after]
* @param string[] $foreign
- * @param string $comment
- * @param string $engine
- * @param string $collation
* @param string $auto_increment number
- * @param string $partitioning
* @return Result|bool
*/
- function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
+ function alter_table(string $table, string $name, array $fields, array $foreign, string $comment, string $engine, string $collation, string $auto_increment, string $partitioning) {
global $connection;
$alter = array();
foreach ($fields as $field) {
* @param list<array{string, string, 'DROP'|list<string>}> $alter of ["index type", "name", ["column definition", ...]] or ["index type", "name", "DROP"]
* @return Result|bool
*/
- function alter_indexes($table, $alter) {
+ function alter_indexes(string $table, $alter) {
$changes = array();
foreach ($alter as $val) {
$changes[] = ($val[2] == "DROP"
* @param list<string> $tables
* @return bool
*/
- function truncate_tables($tables) {
+ function truncate_tables(array $tables) {
return apply_queries("TRUNCATE TABLE", $tables);
}
* @param list<string> $views
* @return Result|bool
*/
- function drop_views($views) {
+ function drop_views(array $views) {
return queries("DROP VIEW " . implode(", ", array_map('Adminer\table', $views)));
}
* @param list<string> $tables
* @return Result|bool
*/
- function drop_tables($tables) {
+ function drop_tables(array $tables) {
return queries("DROP TABLE " . implode(", ", array_map('Adminer\table', $tables)));
}
/** Move tables to other schema
* @param list<string> $tables
* @param list<string> $views
- * @param string $target
* @return bool
*/
- function move_tables($tables, $views, $target) {
+ function move_tables(array $tables, array $views, string $target) {
global $connection;
$rename = array();
foreach ($tables as $table) {
/** Copy tables to other schema
* @param list<string> $tables
* @param list<string> $views
- * @param string $target
* @return bool
*/
- function copy_tables($tables, $views, $target) {
+ function copy_tables(array $tables, array $views, string $target) {
queries("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'");
foreach ($tables as $table) {
$name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table));
/** Get information about trigger
* @param string $name trigger name
- * @param string $table
* @return Trigger
*/
- function trigger($name, $table) {
+ function trigger(string $name, string $table) {
if ($name == "") {
return array();
}
}
/** Get defined triggers
- * @param string $table
* @return array{string, string}[]
*/
- function triggers($table) {
+ function triggers(string $table) {
$return = array();
foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_\\"))) as $row) {
$return[$row["Trigger"]] = array($row["Timing"], $row["Event"]);
}
/** Get information about stored routine
- * @param string $name
* @param 'FUNCTION'|'PROCEDURE' $type
* @return Routine
*/
- function routine($name, $type) {
+ function routine(string $name, $type) {
global $driver;
$aliases = array("bool", "boolean", "integer", "double precision", "real", "dec", "numeric", "fixed", "national char", "national varchar");
$space = "(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";
}
/** Get routine signature
- * @param string $name
* @param Routine $row result of routine()
* @return string
*/
- function routine_id($name, $row) {
+ function routine_id(string $name, array $row) {
return idf_escape($name);
}
}
/** Explain select
- * @param Db $connection
- * @param string $query
* @return Result
*/
- function explain($connection, $query) {
+ function explain(Db $connection, string $query) {
return $connection->query("EXPLAIN " . (min_version(5.1) && !min_version(5.7) ? "PARTITIONS " : "") . $query);
}
* @param list<string> $where
* @return numeric-string|null null if approximate number can't be retrieved
*/
- function found_rows($table_status, $where) {
+ function found_rows(array $table_status, array $where) {
return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]);
}
/** Get SQL command to create table
- * @param string $table
- * @param bool $auto_increment
- * @param string $style
* @return string
*/
- function create_sql($table, $auto_increment, $style) {
+ function create_sql(string $table, bool $auto_increment, string $style) {
$return = get_val("SHOW CREATE TABLE " . table($table), 1);
if (!$auto_increment) {
$return = preg_replace('~ AUTO_INCREMENT=\d+~', '', $return); //! skip comments
}
/** Get SQL command to truncate table
- * @param string $table
* @return string
*/
- function truncate_sql($table) {
+ function truncate_sql(string $table) {
return "TRUNCATE " . table($table);
}
/** Get SQL command to change database
- * @param string $database
* @return string
*/
- function use_sql($database) {
+ function use_sql(string $database) {
return "USE " . idf_escape($database);
}
/** Get SQL commands to create triggers
- * @param string $table
* @return string
*/
- function trigger_sql($table) {
+ function trigger_sql(string $table) {
$return = "";
foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_\\")), null, "-- ") as $row) {
$return .= "\nCREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
* @param Field $field one element from fields()
* @return string|void
*/
- function convert_field($field) {
+ function convert_field(array $field) {
if (preg_match("~binary~", $field["type"])) {
return "HEX(" . idf_escape($field["field"]) . ")";
}
* @param string $return SQL expression
* @return string
*/
- function unconvert_field($field, $return) {
+ function unconvert_field(array $field, string $return) {
if (preg_match("~binary~", $field["type"])) {
$return = "UNHEX($return)";
}
* @param literal-string $feature "check|comment|copy|database|descidx|drop_col|dump|event|indexes|kill|materializedview|partitioning|privileges|procedure|processlist|routine|scheme|sequence|status|table|trigger|type|variables|view|view_trigger"
* @return bool
*/
- function support($feature) {
+ function support(string $feature) {
return !preg_match("~scheme|sequence|type|view_trigger|materializedview" . (min_version(8) ? "" : "|descidx" . (min_version(5.1) ? "" : "|event|partitioning")) . (min_version('8.0.16', '10.2.1') ? "" : "|check") . "~", $feature);
}
* @param numeric-string $val
* @return Result|bool
*/
- function kill_process($val) {
+ function kill_process(string $val) {
return queries("KILL " . number($val));
}
}
/** Get values of user defined type
- * @param int $id
* @return string
*/
- function type_values($id) {
+ function type_values(int $id) {
return "";
}
}
/** Set current schema
- * @param string $schema
- * @param Db $connection2
* @return bool
*/
- function set_schema($schema, $connection2 = null) {
+ function set_schema(string $schema, Db $connection2 = null) {
return true;
}
}
* @param string $add_check CHECK constraint to add
* @return bool
*/
- function recreate_table($table, $name, $fields, $originals, $foreign, $auto_increment = 0, $indexes = array(), $drop_check = "", $add_check = "") {
+ function recreate_table(string $table, string $name, array $fields, array $originals, array $foreign, int $auto_increment = 0, $indexes = array(), string $drop_check = "", string $add_check = "") {
global $driver;
if ($table != "") {
if (!$fields) {
}
/** Get key used for permanent login
- * @param bool $create
* @return string cryptic string which gets combined with password or false in case of an error
*/
- function permanentLogin($create = false) {
+ function permanentLogin(bool $create = false) {
return password_file($create);
}
}
/** Get server name displayed in breadcrumbs
- * @param string $server
* @return string HTML code or null
*/
- function serverName($server) {
+ function serverName(string $server) {
return h($server);
}
}
/** Get cached list of databases
- * @param bool $flush
* @return list<string>
*/
- function databases($flush = true) {
+ function databases(bool $flush = true) {
return get_databases($flush);
}
* @param bool $dark dark CSS: false to disable, true to force, null to base on user preferences
* @return bool true to link favicon.ico
*/
- function head($dark = null) {
+ function head(bool $dark = null) {
// this is matched by compile.php
echo "<link rel='stylesheet' href='../externals/jush/jush.css'>\n";
echo ($dark !== false ? "<link rel='stylesheet'" . ($dark ? "" : " media='(prefers-color-scheme: dark)'") . " href='../externals/jush/jush-dark.css'>\n" : "");
}
/** Get login form field
- * @param string $name
* @param string $heading HTML
* @param string $value HTML
* @return string
*/
- function loginFormField($name, $heading, $value) {
+ function loginFormField(string $name, string $heading, string $value) {
return $heading . $value . "\n";
}
/** Authorize the user
- * @param string $login
- * @param string $password
* @return mixed true for success, string for error message, false for unknown error
*/
- function login($login, $password) {
+ function login(string $login, string $password) {
if ($password == "") {
return lang('Adminer does not support accessing a database without a password, <a href="https://www.adminer.org/en/password/"%s>more information</a>.', target_blank());
}
* @param TableStatus $tableStatus result of table_status1()
* @return string HTML code, "" to ignore table
*/
- function tableName($tableStatus) {
+ function tableName(array $tableStatus) {
return h($tableStatus["Name"]);
}
* @param int $order order of column in select
* @return string HTML code, "" to ignore field
*/
- function fieldName($field, $order = 0) {
+ function fieldName(array $field, int $order = 0) {
$type = $field["full_type"];
$comment = $field["comment"];
return '<span title="' . h($type . ($comment != "" ? ($type ? ": " : "") . $comment : '')) . '">' . h($field["field"]) . '</span>';
* @param string $set new item options, NULL for no new item
* @return void
*/
- function selectLinks($tableStatus, $set = "") {
+ function selectLinks(array $tableStatus, string $set = "") {
global $driver;
echo '<p class="links">';
$links = array("select" => lang('Select data'));
}
/** Get foreign keys for table
- * @param string $table
* @return ForeignKey[] same format as foreign_keys()
*/
- function foreignKeys($table) {
+ function foreignKeys(string $table) {
return foreign_keys($table);
}
/** Find backward keys for table
- * @param string $table
- * @param string $tableName
* @return BackwardKey[]
*/
- function backwardKeys($table, $tableName) {
+ function backwardKeys(string $table, string $tableName) {
return array();
}
* @param string[] $row
* @return void
*/
- function backwardKeysPrint($backwardKeys, $row) {
+ function backwardKeysPrint(array $backwardKeys, array $row) {
}
/** Query printed in select before execution
* @param string $query query to be executed
* @param float $start start time of the query
- * @param bool $failed
* @return string
*/
- function selectQuery($query, $start, $failed = false) {
+ function selectQuery(string $query, float $start, bool $failed = false) {
global $driver;
$return = "</p>\n"; // required for IE9 inline edit
if (!$failed && ($warnings = $driver->warnings())) {
* @param string $query query to be executed
* @return string escaped query to be printed
*/
- function sqlCommandQuery($query) {
+ function sqlCommandQuery(string $query) {
return shorten_utf8(trim($query), 1000);
}
}
/** Description of a row in a table
- * @param string $table
* @return string SQL expression, empty string for no description
*/
- function rowDescription($table) {
+ function rowDescription(string $table) {
return "";
}
* @param ForeignKey[] $foreignKeys
* @return list<string[]>
*/
- function rowDescriptions($rows, $foreignKeys) {
+ function rowDescriptions(array $rows, array $foreignKeys) {
return $rows;
}
* @param Field $field single field returned from fields()
* @return string|void null to create the default link
*/
- function selectLink($val, $field) {
+ function selectLink(string $val, array $field) {
}
/** Value printed in select table
* @param string $original original value before applying editVal() and escaping
* @return string
*/
- function selectVal($val, $link, $field, $original) {
+ function selectVal(string $val, string $link, array $field, string $original) {
$return = ($val === null ? "<i>NULL</i>"
: (preg_match("~char|binary|boolean~", $field["type"]) && !preg_match("~var~", $field["type"]) ? "<code>$val</code>"
: (preg_match('~json~', $field["type"]) ? "<code class='jush-js'>$val</code>"
}
/** Value conversion used in select and edit
- * @param string $val
* @param Field $field single field returned from fields()
* @return string
*/
- function editVal($val, $field) {
+ function editVal(string $val, array $field) {
return $val;
}
* @param TableStatus $tableStatus
* @return void
*/
- function tableStructurePrint($fields, $tableStatus = null) {
+ function tableStructurePrint(array $fields, array $tableStatus = null) {
global $driver;
echo "<div class='scrollable'>\n";
echo "<table class='nowrap odds'>\n";
* @param Index[] $indexes data about all indexes on a table
* @return void
*/
- function tableIndexesPrint($indexes) {
+ function tableIndexesPrint(array $indexes) {
echo "<table>\n";
foreach ($indexes as $name => $index) {
ksort($index["columns"]); // enforce correct columns order
* @param string[] $columns selectable columns
* @return void
*/
- function selectColumnsPrint($select, $columns) {
+ function selectColumnsPrint(array $select, array $columns) {
global $driver;
print_fieldset("select", lang('Select'), $select);
$i = 0;
* @param Index[] $indexes
* @return void
*/
- function selectSearchPrint($where, $columns, $indexes) {
+ function selectSearchPrint(array $where, array $columns, array $indexes) {
print_fieldset("search", lang('Search'), $where);
foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT") {
* @param Index[] $indexes
* @return void
*/
- function selectOrderPrint($order, $columns, $indexes) {
+ function selectOrderPrint(array $order, array $columns, array $indexes) {
print_fieldset("sort", lang('Sort'), $order);
$i = 0;
foreach ((array) $_GET["order"] as $key => $val) {
* @param string $limit result of selectLimitProcess()
* @return void
*/
- function selectLimitPrint($limit) {
+ function selectLimitPrint(string $limit) {
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
echo "<input type='number' name='limit' class='size' value='" . h($limit) . "'>";
echo script("qsl('input').oninput = selectFieldChange;", "");
* @param string $text_length result of selectLengthProcess()
* @return void
*/
- function selectLengthPrint($text_length) {
+ function selectLengthPrint(string $text_length) {
if ($text_length !== null) {
echo "<fieldset><legend>" . lang('Text length') . "</legend><div>";
echo "<input type='number' name='text_length' class='size' value='" . h($text_length) . "'>";
* @param Index[] $indexes
* @return void
*/
- function selectActionPrint($indexes) {
+ function selectActionPrint(array $indexes) {
echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
echo "<input type='submit' value='" . lang('Select') . "'>";
echo " <span id='noindex' title='" . lang('Full table scan') . "'></span>";
* @param string[] $columns selectable columns
* @return void
*/
- function selectEmailPrint($emailFields, $columns) {
+ function selectEmailPrint(array $emailFields, array $columns) {
}
/** Process columns box in select
* @param Index[] $indexes
* @return list<list<string>> [[select_expressions], [group_expressions]]
*/
- function selectColumnsProcess($columns, $indexes) {
+ function selectColumnsProcess(array $columns, array $indexes) {
global $driver;
$select = array(); // select expressions, empty for *
$group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
* @param Index[] $indexes
* @return list<string> expressions to join by AND
*/
- function selectSearchProcess($fields, $indexes) {
+ function selectSearchProcess(array $fields, array $indexes) {
global $connection, $driver;
$return = array();
foreach ($indexes as $i => $index) {
* @param Index[] $indexes
* @return list<string> expressions to join by comma
*/
- function selectOrderProcess($fields, $indexes) {
+ function selectOrderProcess(array $fields, array $indexes) {
$return = array();
foreach ((array) $_GET["order"] as $key => $val) {
if ($val != "") {
* @param ForeignKey[] $foreignKeys
* @return bool true if processed, false to process other parts of form
*/
- function selectEmailProcess($where, $foreignKeys) {
+ function selectEmailProcess(array $where, array $foreignKeys) {
return false;
}
* @param int $page index of page starting at zero
* @return string empty string to use default query
*/
- function selectQueryBuild($select, $where, $group, $order, $limit, $page) {
+ function selectQueryBuild(array $select, array $where, array $group, array $order, int $limit, int $page) {
return "";
}
/** Query printed after execution in the message
* @param string $query executed query
* @param string $time elapsed time
- * @param bool $failed
* @return string
*/
- function messageQuery($query, $time, $failed = false) {
+ function messageQuery(string $query, string $time, bool $failed = false) {
global $driver;
restart_session();
$history = &get_session("queries");
}
/** Print before edit form
- * @param string $table
* @param Field[] $fields
* @param mixed $row
- * @param bool $update
* @return void
*/
- function editRowPrint($table, $fields, $row, $update) {
+ function editRowPrint(string $table, array $fields, $row, bool $update) {
}
/** Functions displayed in edit form
* @param Field $field single field from fields()
* @return list<string>
*/
- function editFunctions($field) {
+ function editFunctions(array $field) {
global $driver;
$return = ($field["null"] ? "NULL/" : "");
$update = isset($_GET["select"]) || where($_GET);
* @param string $table table name
* @param Field $field single field from fields()
* @param string $attrs attributes to use inside the tag
- * @param string $value
* @return string custom input field or empty string for default
*/
- function editInput($table, $field, $attrs, $value) {
+ function editInput(string $table, array $field, string $attrs, string $value) {
if ($field["type"] == "enum") {
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
. ($field["null"] ? "<label><input type='radio'$attrs value=''" . ($value !== null || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")
/** Get hint for edit field
* @param string $table table name
* @param Field $field single field from fields()
- * @param string $value
* @return string
*/
- function editHint($table, $field, $value) {
+ function editHint(string $table, array $field, string $value) {
return "";
}
/** Process sent input
* @param Field $field single field from fields()
- * @param string $value
- * @param string $function
* @return string expression to use in a query
*/
- function processInput($field, $value, $function = "") {
+ function processInput(array $field, string $value, string $function = "") {
if ($function == "SQL") {
return $value; // SQL injection
}
}
/** Export database structure
- * @param string $db
* @return void prints data
*/
- function dumpDatabase($db) {
+ function dumpDatabase(string $db) {
}
/** Export table structure
- * @param string $table
- * @param string $style
* @param int $is_view 0 table, 1 view, 2 temporary view table
* @return void prints data
*/
- function dumpTable($table, $style, $is_view = 0) {
+ function dumpTable(string $table, string $style, int $is_view = 0) {
if ($_POST["format"] != "sql") {
echo "\xef\xbb\xbf"; // UTF-8 byte order mark
if ($style) {
}
/** Export table data
- * @param string $table
- * @param string $style
- * @param string $query
* @return void prints data
*/
- function dumpData($table, $style, $query) {
+ function dumpData(string $table, string $style, string $query) {
global $connection;
if ($style) {
$max_packet = (JUSH == "sqlite" ? 0 : 1048576); // default, minimum is 1024
}
/** Set export filename
- * @param string $identifier
* @return string filename without extension
*/
- function dumpFilename($identifier) {
+ function dumpFilename(string $identifier) {
return friendly_url($identifier != "" ? $identifier : (SERVER != "" ? SERVER : "localhost"));
}
/** Send headers for export
- * @param string $identifier
- * @param bool $multi_table
* @return string extension
*/
- function dumpHeaders($identifier, $multi_table = false) {
+ function dumpHeaders(string $identifier, bool $multi_table = false) {
$output = $_POST["output"];
$ext = (preg_match('~sql~', $_POST["format"]) ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
header("Content-Type: " .
* @param string $missing can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
* @return void
*/
- function navigation($missing) {
+ function navigation(string $missing) {
global $VERSION, $drivers, $connection;
echo "<h1>" . $this->name() . " <span class='version'>$VERSION";
$new_version = $_COOKIE["adminer_version"];
* @param TableStatus[] $tables result of table_status('', true)
* @return void
*/
- function syntaxHighlighting($tables) {
+ function syntaxHighlighting(array $tables) {
global $connection;
// this is matched by compile.php
echo script_src("../externals/jush/modules/jush.js");
}
/** Print databases list in menu
- * @param string $missing
* @return void
*/
- function databasesPrint($missing) {
+ function databasesPrint(string $missing) {
global $adminer, $connection;
$databases = $this->databases();
if (DB && $databases && !in_array(DB, $databases)) {
* @param TableStatus[] $tables result of table_status('', true)
* @return void
*/
- function tablesPrint($tables) {
+ function tablesPrint(array $tables) {
echo "<ul id='tables'>" . script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
foreach ($tables as $table => $status) {
$name = $this->tableName($status);
* @param string $error plain text
* @return never
*/
-function auth_error($error) {
+function auth_error(string $error) {
global $adminer, $has_token;
$session_name = session_name();
if (isset($_GET["username"])) {
/** @var Result|bool */ protected $multi; // used for multiquery
/** Connect to server
- * @param string $server
- * @param string $username
- * @param string $password
* @return bool
*/
- abstract function connect($server, $username, $password);
+ abstract function connect(string $server, string $username, string $password);
/** Quote string to use in SQL
- * @param string $string
* @return string escaped string enclosed in '
*/
- abstract function quote($string);
+ abstract function quote(string $string);
/** Select database
- * @param string $database
* @return bool
*/
- abstract function select_db($database);
+ abstract function select_db(string $database);
/** Send query
- * @param string $query
- * @param bool $unbuffered
* @return Result|bool
*/
- abstract function query($query, $unbuffered = false);
+ abstract function query(string $query, bool $unbuffered = false);
/** Send query with more resultsets
- * @param string $query
* @return Result|bool
*/
- function multi_query($query) {
+ function multi_query(string $query) {
return $this->multi = $this->query($query);
}
}
/** Get single field from result
- * @param string $query
- * @param int $field
* @return string|bool
*/
- function result($query, $field = 0) {
+ function result(string $query, int $field = 0) {
$result = $this->query($query);
if (!is_object($result)) {
return false;
/** Print HTML header
* @param string $title used in title, breadcrumb and heading, should be HTML escaped
-* @param string $error
* @param mixed $breadcrumb ["key" => "link", "key2" => ["link", "desc"]], null for nothing, false for driver only, true for driver and server
* @param string $title2 used after colon in title and heading, should be HTML escaped
* @return void
*/
-function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
+function page_header(string $title, string $error = "", $breadcrumb = array(), string $title2 = "") {
global $LANG, $VERSION, $adminer, $drivers;
page_headers();
if (is_ajax() && $error) {
}
/** Print flash and error messages
-* @param string $error
* @return void
*/
-function page_messages($error) {
+function page_messages(string $error) {
global $adminer;
$uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
$messages = idx($_SESSION["messages"], $uri);
* @param string $missing "auth", "db", "ns"
* @return void
*/
-function page_footer($missing = "") {
+function page_footer(string $missing = "") {
global $adminer;
echo "</div>\n\n<div id='menu'>\n";
$adminer->navigation($missing);
$drivers = array();
/** Add a driver
-* @param string $id
-* @param string $name
* @return void
*/
-function add_driver($id, $name) {
+function add_driver(string $id, string $name) {
global $drivers;
$drivers[$id] = $name;
}
/** Get driver name
-* @param string $id
* @return string
*/
-function get_driver($id) {
+function get_driver(string $id) {
global $drivers;
return $drivers[$id];
}
/** @var list<string> */ public $generated = array(); // allowed types of generated columns
/** Create object for performing database operations
- * @param Db $connection
*/
- function __construct($connection) {
+ function __construct(Db $connection) {
$this->conn = $connection;
}
* @param Field $field
* @return string|void
*/
- function enumLength($field) {
+ function enumLength(array $field) {
}
/** Function used to convert the value inputted by user
* @param Field $field
* @return string|void
*/
- function unconvertFunction($field) {
+ function unconvertFunction(array $field) {
}
/** Select data from table
- * @param string $table
* @param list<string> $select result of $adminer->selectColumnsProcess()[0]
* @param list<string> $where result of $adminer->selectSearchProcess()
* @param list<string> $group result of $adminer->selectColumnsProcess()[1]
* @param bool $print whether to print the query
* @return Result|false
*/
- function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
+ function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, int $page = 0, bool $print = false) {
global $adminer;
$is_group = (count($group) < count($select));
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
}
/** Delete data from table
- * @param string $table
* @param string $queryWhere " WHERE ..."
* @param int $limit 0 or 1
* @return Result|bool
*/
- function delete($table, $queryWhere, $limit = 0) {
+ function delete(string $table, string $queryWhere, int $limit = 0) {
$query = "FROM " . table($table);
return queries("DELETE" . ($limit ? limit1($table, $query, $queryWhere) : " $query$queryWhere"));
}
/** Update data in table
- * @param string $table
* @param string[] $set escaped columns in keys, quoted data in values
* @param string $queryWhere " WHERE ..."
* @param int $limit 0 or 1
- * @param string $separator
* @return Result|bool
*/
- function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") {
+ function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") {
$values = array();
foreach ($set as $key => $val) {
$values[] = "$key = $val";
}
/** Insert data into table
- * @param string $table
* @param string[] $set escaped columns in keys, quoted data in values
* @return Result|bool
*/
- function insert($table, $set) {
+ function insert(string $table, array $set) {
return queries("INSERT INTO " . table($table) . ($set
? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")"
: " DEFAULT VALUES"
}
/** Get RETURNING clause for INSERT queries (PostgreSQL specific)
- * @param string $table
* @return string
*/
- function insertReturning($table) {
+ function insertReturning(string $table) {
return "";
}
/** Insert or update data in table
- * @param string $table
* @param list<string[]> $rows of arrays with escaped columns in keys and quoted data in values
* @param int[] $primary column names in keys
* @return Result|bool
*/
- function insertUpdate($table, $rows, $primary) {
+ function insertUpdate(string $table, array $rows, array $primary) {
return false;
}
}
/** Return query with a timeout
- * @param string $query
* @param int $timeout seconds
* @return string|void null if the driver doesn't support query timeouts
*/
- function slowQuery($query, $timeout) {
+ function slowQuery(string $query, int $timeout) {
}
/** Convert column to be searchable
* @param Field $field
* @return string
*/
- function convertSearch($idf, $val, $field) {
+ function convertSearch(string $idf, array $val, array $field) {
return $idf;
}
/** Convert operator so it can be used in search
- * @param string $operator
* @return string
*/
- function convertOperator($operator) {
+ function convertOperator(string $operator) {
return $operator;
}
/** Convert value returned by database to actual value
- * @param string $val
* @param Field $field
* @return string
*/
- function value($val, $field) {
+ function value(string $val, array $field) {
return (method_exists($this->conn, 'value')
? $this->conn->value($val, $field)
: (is_resource($val) ? stream_get_contents($val) : $val)
}
/** Quote binary string
- * @param string $s
* @return string
*/
- function quoteBinary($s) {
+ function quoteBinary(string $s) {
return q($s);
}
}
/** Get help link for table
- * @param string $name
- * @param bool $is_view
* @return string|void relative URL
*/
- function tableHelp($name, $is_view = false) {
+ function tableHelp(string $name, bool $is_view = false) {
}
/** Check if C-style escapes are supported
* @param TableStatus $table_status result of table_status1()
* @return bool
*/
- function supportsIndex($table_status) {
+ function supportsIndex(array $table_status) {
return !is_view($table_status);
}
/** Get defined check constraints
- * @param string $table
* @return string[] [$name => $clause]
*/
- function checkConstraints($table) {
+ function checkConstraints(string $table) {
// MariaDB contains CHECK_CONSTRAINTS.TABLE_NAME, MySQL and PostrgreSQL not
return get_key_vals("SELECT c.CONSTRAINT_NAME, CHECK_CLAUSE
FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS c
* @param Result $result
* @param Db $connection2 connection to examine indexes
* @param string[] $orgtables
-* @param int $limit
* @return string[] $orgtables
*/
-function select($result, $connection2 = null, $orgtables = array(), $limit = 0) {
+function select($result, Db $connection2 = null, array $orgtables = array(), int $limit = 0) {
$links = array(); // colno => orgtable - create links from these columns
$indexes = array(); // orgtable => array(column => colno) - primary keys
$columns = array(); // orgtable => array(column => ) - not selected columns in primary key
}
/** Get referencable tables with single column primary key except self
-* @param string $self
* @return array<string, Field> [$table_name => $field]
*/
-function referencable_primary($self) {
+function referencable_primary(string $self) {
$return = array(); // table_name => field
foreach (table_status('', true) as $table_name => $table) {
if ($table_name != $self && fk_support($table)) {
}
/** Print SQL <textarea> tag
-* @param string $name
* @param string|list<array{string}> $value
-* @param int $rows
-* @param int $cols
* @return void
*/
-function textarea($name, $value, $rows = 10, $cols = 80) {
+function textarea(string $name, $value, int $rows = 10, int $cols = 80) {
echo "<textarea name='" . h($name) . "' rows='$rows' cols='$cols' class='sqlarea jush-" . JUSH . "' spellcheck='false' wrap='off'>";
if (is_array($value)) {
foreach ($value as $val) { // not implode() to save memory
}
/** Generate HTML <select> or <input> if $options are empty
-* @param string $attrs
* @param string[] $options
-* @param string $value
-* @param string $onchange
-* @param string $placeholder
* @return string
*/
-function select_input($attrs, $options, $value = "", $onchange = "", $placeholder = "") {
+function select_input(string $attrs, array $options, string $value = "", string $onchange = "", string $placeholder = "") {
$tag = ($options ? "select" : "input");
return "<$tag$attrs" . ($options
? "><option value=''>$placeholder" . optionlist($options, $value, true) . "</select>"
* @param string|int $val
* @return void
*/
-function json_row($key, $val = null) {
+function json_row(string $key, $val = null) {
static $first = true;
if ($first) {
echo "{";
}
/** Print table columns for type edit
-* @param string $key
* @param Field $field
* @param list<string> $collations
* @param string[] $foreign_keys
* @param list<string> $extra_types extra types to prepend
* @return void
*/
-function edit_type($key, $field, $collations, $foreign_keys = array(), $extra_types = array()) {
+function edit_type(string $key, array $field, array $collations, array $foreign_keys = array(), array $extra_types = array()) {
global $driver;
$type = $field["type"];
echo "<td><select name='" . h($key) . "[type]' class='type' aria-labelledby='label-type'>";
}
/** Get partition info
-* @param string $table
* @return array{partition_by:string, partition:string, partitions:string, partition_names:list<string>, partition_values:list<string>}
*/
-function get_partitions_info($table) {
+function get_partitions_info(string $table) {
global $connection;
$from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($table);
$result = $connection->query("SELECT PARTITION_METHOD, PARTITION_EXPRESSION, PARTITION_ORDINAL_POSITION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
}
/** Filter length value including enums
-* @param string $length
* @return string
*/
-function process_length($length) {
+function process_length(string $length) {
global $driver;
$enum_length = $driver->enumLength;
return (preg_match("~^\\s*\\(?\\s*$enum_length(?:\\s*,\\s*$enum_length)*+\\s*\\)?\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches)
/** Create SQL string from field type
* @param FieldType $field
-* @param string $collate
* @return string
*/
-function process_type($field, $collate = "COLLATE") {
+function process_type(array $field, string $collate = "COLLATE") {
global $driver;
return " $field[type]"
. process_length($field["length"])
* @param Field $type_field information about field type
* @return list<string> ["field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT"]
*/
-function process_field($field, $type_field) {
+function process_field(array $field, array $type_field) {
// MariaDB exports CURRENT_TIMESTAMP as a function.
if ($field["on_update"]) {
$field["on_update"] = str_ireplace("current_timestamp()", "CURRENT_TIMESTAMP", $field["on_update"]);
* @param Field $field
* @return string
*/
-function default_value($field) {
+function default_value(array $field) {
global $driver;
$default = $field["default"];
$generated = $field["generated"];
}
/** Get type class to use in CSS
-* @param string $type
* @return string|void class=''
*/
-function type_class($type) {
+function type_class(string $type) {
foreach (
array(
'char' => 'text',
* @param string[] $foreign_keys
* @return void
*/
-function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = array()) {
+function edit_fields(array $fields, array $collations, $type = "TABLE", array $foreign_keys = array()) {
global $driver;
$fields = array_values($fields);
$default_class = (($_POST ? $_POST["defaults"] : get_setting("defaults")) ? "" : " class='hidden'");
* @param Field[] $fields
* @return bool
*/
-function process_fields(&$fields) {
+function process_fields(&array $fields) {
$offset = 0;
if ($_POST["up"]) {
$last = 0;
* @param list<string> $match
* @return string
*/
-function normalize_enum($match) {
+function normalize_enum(array $match) {
$val = $match[0];
return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($val[0] . $val[0], $val[0], substr($val, 1, -1))), '\\')) . "'";
}
/** Issue grant or revoke commands
* @param string $grant GRANT or REVOKE
* @param list<string> $privileges
-* @param string $columns
-* @param string $on
* @return Result|bool
*/
-function grant($grant, $privileges, $columns, $on) {
+function grant(string $grant, array $privileges, string $columns, string $on) {
if (!$privileges) {
return true;
}
* @param string $drop_created drop new object query
* @param string $test create test object query
* @param string $drop_test drop test object query
-* @param string $location
-* @param string $message_drop
-* @param string $message_alter
-* @param string $message_create
-* @param string $old_name
-* @param string $new_name
* @return void redirect on success
*/
-function drop_create($drop, $create, $drop_created, $test, $drop_test, $location, $message_drop, $message_alter, $message_create, $old_name, $new_name) {
+function drop_create(string $drop, string $create, string $drop_created, string $test, string $drop_test, string $location, string $message_drop, string $message_alter, string $message_create, string $old_name, string $new_name) {
if ($_POST["drop"]) {
query_redirect($drop, $location, $message_drop);
} elseif ($old_name == "") {
}
/** Generate SQL query for creating trigger
-* @param string $on
* @param Trigger $row result of trigger()
* @return string
*/
-function create_trigger($on, $row) {
+function create_trigger(string $on, array $row) {
$timing_event = " $row[Timing] $row[Event]" . (preg_match('~ OF~', $row["Event"]) ? " $row[Of]" : ""); // SQL injection
return "CREATE TRIGGER "
. idf_escape($row["Trigger"])
* @param Routine $row result of routine()
* @return string
*/
-function create_routine($routine, $row) {
+function create_routine($routine, array $row) {
global $driver;
$set = array();
$fields = (array) $row["fields"];
}
/** Remove current user definer from SQL command
-* @param string $query
* @return string
*/
-function remove_definer($query) {
+function remove_definer(string $query) {
return preg_replace('~^([A-Z =]+) DEFINER=`' . preg_replace('~@(.*)~', '`@`(%|\1)', logged_user()) . '`~', '\1', $query); //! proper escaping of user
}
* @param ForeignKey $foreign_key
* @return string
*/
-function format_foreign_key($foreign_key) {
+function format_foreign_key(array $foreign_key) {
global $driver;
$db = $foreign_key["db"];
$ns = $foreign_key["ns"];
}
/** Add a file to TAR
-* @param string $filename
* @param TmpFile $tmp_file
* @return void prints the output
*/
-function tar_file($filename, $tmp_file) {
+function tar_file(string $filename, $tmp_file) {
$return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct($tmp_file->size), decoct(time()));
$checksum = 8*32; // space for checksum itself
for ($i=0; $i < strlen($return); $i++) {
}
/** Get INI bytes value
-* @param string $ini
* @return int
*/
-function ini_bytes($ini) {
+function ini_bytes(string $ini) {
$val = ini_get($ini);
switch (strtolower(substr($val, -1))) {
case 'g':
* @param string $text HTML code
* @return string HTML code
*/
-function doc_link($paths, $text = "<sup>?</sup>") {
+function doc_link(array $paths, string $text = "<sup>?</sup>") {
global $connection;
$server_info = $connection->server_info;
$version = preg_replace('~^(\d\.?\d).*~s', '\1', $server_info); // two most significant digits
}
/** Compute size of database
-* @param string $db
* @return string formatted
*/
-function db_size($db) {
+function db_size(string $db) {
global $connection;
if (!$connection->select_db($db)) {
return "?";
}
/** Print SET NAMES if utf8mb4 might be needed
-* @param string $create
* @return void
*/
-function set_utf8mb4($create) {
+function set_utf8mb4(string $create) {
global $connection;
static $set = false;
if (!$set && preg_match('~\butf8mb4~i', $create)) { // possible false positive
* @param string $idf text inside ``
* @return string
*/
-function idf_unescape($idf) {
+function idf_unescape(string $idf) {
if (!preg_match('~^[`\'"[]~', $idf)) {
return $idf;
}
}
/** Shortcut for $connection->quote($string)
-* @param string $string
* @return string
*/
-function q($string) {
+function q(string $string) {
global $connection;
return $connection->quote($string);
}
/** Escape string to use inside ''
-* @param string $val
* @return string
*/
-function escape_string($val) {
+function escape_string(string $val) {
return substr(q($val), 1, -1);
}
* @param mixed $default
* @return mixed
*/
-function idx($array, $key, $default = null) {
+function idx(?array $array, $key, $default = null) {
return ($array && array_key_exists($key, $array) ? $array[$key] : $default);
}
/** Remove non-digits from a string
-* @param string $val
* @return string
*/
-function number($val) {
+function number(string $val) {
return preg_replace('~[^0-9]+~', '', $val);
}
* @param bool $filter whether to leave values as is
* @return void modified in place
*/
-function remove_slashes($process, $filter = false) {
+function remove_slashes(array $process, bool $filter = false) {
if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) {
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
}
/** Escape or unescape string to use inside form []
-* @param string $idf
-* @param bool $back
* @return string
*/
-function bracket_escape($idf, $back = false) {
+function bracket_escape(string $idf, bool $back = false) {
// escape brackets inside name="x[]"
static $trans = array(':' => ':1', ']' => ':2', '[' => ':3', '"' => ':4');
return strtr($idf, ($back ? array_flip($trans) : $trans));
* @param Db $connection2 defaults to $connection
* @return bool
*/
-function min_version($version, $maria_db = "", $connection2 = null) {
+function min_version($version, $maria_db = "", Db $connection2 = null) {
global $connection;
if (!$connection2) {
$connection2 = $connection;
}
/** Get connection charset
-* @param Db $connection
* @return string
*/
-function charset($connection) {
+function charset(Db $connection) {
return (min_version("5.5.3", 0, $connection) ? "utf8mb4" : "utf8"); // SHOW CHARSET would require an extra query
}
/** Get INI boolean value
-* @param string $ini
* @return bool
*/
-function ini_bool($ini) {
+function ini_bool(string $ini) {
$val = ini_get($ini);
return (preg_match('~^(on|true|yes)$~i', $val) || (int) $val); // boolean values set by php_value are strings
}
}
/** Set password to session
-* @param string $vendor
-* @param string $server
-* @param string $username
-* @param ?string $password
* @return void
*/
-function set_password($vendor, $server, $username, $password) {
+function set_password(string $vendor, string $server, string $username, ?string $password) {
$_SESSION["pwds"][$vendor][$server][$username] = ($_COOKIE["adminer_key"] && is_string($password)
? array(encrypt_string($password, $_COOKIE["adminer_key"]))
: $password
}
/** Get single value from database
-* @param string $query
-* @param int $field
* @return string or false if error
*/
-function get_val($query, $field = 0) {
+function get_val(string $query, int $field = 0) {
global $connection;
return $connection->result($query, $field);
}
/** Get list of values from database
-* @param string $query
* @param mixed $column
* @return list<string>
*/
-function get_vals($query, $column = 0) {
+function get_vals(string $query, $column = 0) {
global $connection;
$return = array();
$result = $connection->query($query);
}
/** Get keys from first column and values from second
-* @param string $query
-* @param Db $connection2
-* @param bool $set_keys
* @return string[]
*/
-function get_key_vals($query, $connection2 = null, $set_keys = true) {
+function get_key_vals(string $query, Db $connection2 = null, bool $set_keys = true) {
global $connection;
if (!is_object($connection2)) {
$connection2 = $connection;
}
/** Get all rows of result
-* @param string $query
-* @param Db $connection2
-* @param string $error
* @return list<string[]> of associative arrays
*/
-function get_rows($query, $connection2 = null, $error = "<p class='error'>") {
+function get_rows(string $query, Db $connection2 = null, string $error = "<p class='error'>") {
global $connection;
$conn = (is_object($connection2) ? $connection2 : $connection);
$return = array();
* @param Index[] $indexes result of indexes()
* @return string[]|void null if there is no unique identifier
*/
-function unique_array($row, $indexes) {
+function unique_array(array $row, array $indexes) {
foreach ($indexes as $index) {
if (preg_match("~PRIMARY|UNIQUE~", $index["type"])) {
$return = array();
}
/** Escape column key used in where()
-* @param string $key
* @return string
*/
-function escape_key($key) {
+function escape_key(string $key) {
if (preg_match('(^([\w(]+)(' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . ')([ \w)]+)$)', $key, $match)) { //! columns looking like functions
return $match[1] . idf_escape(idf_unescape($match[2])) . $match[3]; //! SQL injection
}
* @param Field[] $fields
* @return string
*/
-function where($where, $fields = array()) {
+function where(array $where, array $fields = array()) {
global $connection;
$return = array();
foreach ((array) $where["where"] as $key => $val) {
}
/** Create SQL condition from query string
-* @param string $val
* @param Field[] $fields
* @return string
*/
-function where_check($val, $fields = array()) {
+function where_check(string $val, array $fields = array()) {
parse_str($val, $check);
remove_slashes(array(&$check));
return where($check, $fields);
/** Create query string where condition from value
* @param int $i condition order
* @param string $column column identifier
-* @param string $value
-* @param string $operator
* @return string
*/
-function where_link($i, $column, $value, $operator = "=") {
+function where_link(int $i, string $column, string $value, string $operator = "=") {
return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=" . urlencode(($value !== null ? $operator : "IS NULL")) . "&where%5B$i%5D%5Bval%5D=" . urlencode($value);
}
* @param list<string> $select
* @return string
*/
-function convert_fields($columns, $fields, $select = array()) {
+function convert_fields(array $columns, array $fields, array $select = array()) {
$return = "";
foreach ($columns as $key => $val) {
if ($select && !in_array(idf_escape($key), $select)) {
}
/** Set cookie valid on current path
-* @param string $name
-* @param string $value
* @param int $lifetime number of seconds, 0 for session cookie, 2592000 - 30 days
* @return void
*/
-function cookie($name, $value, $lifetime = 2592000) {
+function cookie(string $name, string $value, int $lifetime = 2592000) {
global $HTTPS;
header(
"Set-Cookie: $name=" . urlencode($value)
}
/** Get settings stored in a cookie
-* @param string $cookie
* @return mixed[]
*/
-function get_settings($cookie) {
+function get_settings(string $cookie) {
parse_str($_COOKIE[$cookie], $settings);
return $settings;
}
/** Get setting stored in a cookie
-* @param string $key
-* @param string $cookie
* @return mixed
*/
-function get_setting($key, $cookie = "adminer_settings") {
+function get_setting(string $key, string $cookie = "adminer_settings") {
$settings = get_settings($cookie);
return $settings[$key];
}
/** Store settings to a cookie
* @param mixed[] $settings
-* @param string $cookie
* @return void
*/
-function save_settings($settings, $cookie = "adminer_settings") {
+function save_settings(array $settings, string $cookie = "adminer_settings") {
cookie($cookie, http_build_query($settings + get_settings($cookie)));
}
}
/** Stop session if possible
-* @param bool $force
* @return void
*/
-function stop_session($force = false) {
+function stop_session(bool $force = false) {
$use_cookies = ini_bool("session.use_cookies");
if (!$use_cookies || $force) {
session_write_close(); // improves concurrency if a user opens several pages at once, may be restarted later
}
/** Get session variable for current server
-* @param string $key
* @return mixed
*/
-function &get_session($key) {
+function &get_session(string $key) {
return $_SESSION[$key][DRIVER][SERVER][$_GET["username"]];
}
/** Set session variable for current server
-* @param string $key
* @param mixed $val
* @return mixed
*/
-function set_session($key, $val) {
+function set_session(string $key, $val) {
$_SESSION[$key][DRIVER][SERVER][$_GET["username"]] = $val; // used also in auth.inc.php
}
/** Get authenticated URL
-* @param string $vendor
-* @param string $server
-* @param string $username
-* @param string $db
* @return string
*/
-function auth_url($vendor, $server, $username, $db = null) {
+function auth_url(string $vendor, string $server, string $username, string $db = null) {
global $drivers;
$uri = remove_from_uri(implode("|", array_keys($drivers))
. "|username|ext|"
/** Send Location header and exit
* @param string $location null to only set a message
-* @param string $message
* @return void
*/
-function redirect($location, $message = null) {
+function redirect(string $location, string $message = null) {
if ($message !== null) {
restart_session();
$_SESSION["messages"][preg_replace('~^[^?]*~', '', ($location !== null ? $location : $_SERVER["REQUEST_URI"]))][] = $message;
}
/** Execute query and redirect if successful
-* @param string $query
-* @param string $location
-* @param string $message
-* @param bool $redirect
-* @param bool $execute
-* @param bool $failed
-* @param string $time
* @return bool
*/
-function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false, $time = "") {
+function query_redirect(string $query, string $location, string $message, bool $redirect = true, bool $execute = true, bool $failed = false, string $time = "") {
global $connection, $error, $adminer;
if ($execute) {
$start = microtime(true);
* @param string $query end with ';' to use DELIMITER
* @return Result|bool
*/
-function queries($query) {
+function queries(string $query) {
global $connection;
if (!Queries::$start) {
Queries::$start = microtime(true);
}
/** Apply command to all array items
-* @param string $query
* @param list<string> $tables
* @param callable(string):string $escape
* @return bool
*/
-function apply_queries($query, $tables, $escape = 'Adminer\table') {
+function apply_queries(string $query, array $tables, callable $escape = 'Adminer\table') {
foreach ($tables as $table) {
if (!queries("$query " . $escape($table))) {
return false;
}
/** Redirect by remembered queries
-* @param string $location
-* @param string $message
-* @param bool $redirect
* @return bool
*/
-function queries_redirect($location, $message, $redirect) {
+function queries_redirect(string $location, string $message, bool $redirect) {
$queries = implode("\n", Queries::$queries);
$time = format_time(Queries::$start);
return query_redirect($queries, $location, $message, $redirect, false, !$redirect, $time);
* @param float $start output of microtime(true)
* @return string HTML code
*/
-function format_time($start) {
+function format_time(float $start) {
return lang('%.3f s', max(0, microtime(true) - $start));
}
}
/** Remove parameter from query string
-* @param string $param
* @return string
*/
-function remove_from_uri($param = "") {
+function remove_from_uri(string $param = "") {
return substr(preg_replace("~(?<=[?&])($param" . (SID ? "" : "|" . session_name()) . ")=[^&]*&~", '', relative_uri() . "&"), 0, -1);
}
/** Get file contents from $_FILES
-* @param string $key
-* @param bool $decompress
-* @param string $delimiter
* @return mixed int for error, string otherwise
*/
-function get_file($key, $decompress = false, $delimiter = "") {
+function get_file(string $key, bool $decompress = false, string $delimiter = "") {
$file = $_FILES[$key];
if (!$file) {
return null;
}
/** Determine upload error
-* @param int $error
* @return string
*/
-function upload_error($error) {
+function upload_error(int $error) {
$max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : 0); // post_max_size is checked in index.php
return ($error ? lang('Unable to upload a file.') . ($max_size ? " " . lang('Maximum allowed file size is %sB.', $max_size) : "") : lang('File does not exist.'));
}
/** Create repeat pattern for preg
-* @param string $pattern
-* @param int $length
* @return string
*/
-function repeat_pattern($pattern, $length) {
+function repeat_pattern(string $pattern, int $length) {
// fix for Compilation failed: number too big in {} quantifier
return str_repeat("$pattern{0,65535}", $length / 65535) . "$pattern{0," . ($length % 65535) . "}"; // can create {0,0} which is OK
}
/** Check whether the string is in UTF-8
-* @param string $val
* @return bool
*/
-function is_utf8($val) {
+function is_utf8(string $val) {
// don't print control chars except \t\r\n
return (preg_match('~~u', $val) && !preg_match('~[\0-\x8\xB\xC\xE-\x1F]~', $val));
}
/** Shorten UTF-8 string
-* @param string $string
-* @param int $length
-* @param string $suffix
* @return string escaped string with appended ...
*/
-function shorten_utf8($string, $length = 80, $suffix = "") {
+function shorten_utf8(string $string, int $length = 80, string $suffix = "") {
if (!preg_match("(^(" . repeat_pattern("[\t\r\n -\x{10FFFF}]", $length) . ")($)?)u", $string, $match)) { // ~s causes trash in $match[2] under some PHP versions, (.|\n) is slow
preg_match("(^(" . repeat_pattern("[\t\r\n -~]", $length) . ")($)?)", $string, $match);
}
}
/** Generate friendly URL
-* @param string $val
* @return string
*/
-function friendly_url($val) {
+function friendly_url(string $val) {
// used for blobs and export
return preg_replace('~\W~i', '-', $val);
}
/** Get status of a single table and fall back to name on error
-* @param string $table
-* @param bool $fast
* @return TableStatus one element from table_status()
*/
-function table_status1($table, $fast = false) {
+function table_status1(string $table, bool $fast = false) {
$return = table_status($table, $fast);
return ($return ? reset($return) : array("Name" => $table));
}
/** Find out foreign keys for each column
-* @param string $table
* @return list<ForeignKey>[] [$col => []]
*/
-function column_foreign_keys($table) {
+function column_foreign_keys(string $table) {
global $adminer;
$return = array();
foreach ($adminer->foreignKeys($table) as $foreign_key) {
}
/** Send headers for export
-* @param string $identifier
-* @param bool $multi_table
* @return string extension
*/
-function dump_headers($identifier, $multi_table = false) {
+function dump_headers(string $identifier, bool $multi_table = false) {
global $adminer;
$return = $adminer->dumpHeaders($identifier, $multi_table);
$output = $_POST["output"];
* @param string[] $row
* @return void
*/
-function dump_csv($row) {
+function dump_csv(array $row) {
foreach ($row as $key => $val) {
if (preg_match('~["\n,;\t]|^0|\.\d*0$~', $val) || $val === "") {
$row[$key] = '"' . str_replace('"', '""', $val) . '"';
}
/** Apply SQL function
-* @param string $function
* @param string $column escaped column identifier
* @return string
*/
-function apply_sql_function($function, $column) {
+function apply_sql_function(string $function, string $column) {
return ($function ? ($function == "unixepoch" ? "DATETIME($column, '$function')" : ($function == "count distinct" ? "COUNT(DISTINCT " : strtoupper("$function(")) . "$column)") : $column);
}
}
/** Open and exclusively lock a file
-* @param string $filename
* @return resource|void null for error
*/
-function file_open_lock($filename) {
+function file_open_lock(string $filename) {
if (is_link($filename)) {
return; // https://cwe.mitre.org/data/definitions/61.html
}
}
/** Write and unlock a file
-* @param resource $fp
-* @param string $data
* @return void
*/
-function file_write_unlock($fp, $data) {
+function file_write_unlock(resource $fp, string $data) {
rewind($fp);
fwrite($fp, $data);
ftruncate($fp, strlen($data));
}
/** Unlock and close a file
-* @param resource $fp
* @return void
*/
-function file_unlock($fp) {
+function file_unlock(resource $fp) {
flock($fp, LOCK_UN);
fclose($fp);
}
* @param mixed[] $array
* @return mixed if not found
*/
-function first($array) {
+function first(array $array) {
// reset(f()) triggers a notice
return reset($array);
}
/** Read password from file adminer.key in temporary directory or create one
-* @param bool $create
* @return string|false false if the file can not be created
*/
-function password_file($create) {
+function password_file(bool $create) {
$filename = get_temp_dir() . "/adminer.key";
if (!$create && !file_exists($filename)) {
return false;
/** Format value to use in select
* @param string|string[] $val
-* @param string $link
* @param Field $field
-* @param int $text_length
* @return string HTML
*/
-function select_value($val, $link, $field, $text_length) {
+function select_value($val, string $link, array $field, int $text_length) {
global $adminer;
if (is_array($val)) {
$return = "";
}
/** Check whether the string is e-mail address
-* @param ?string $email
* @return bool
*/
-function is_mail($email) {
+function is_mail(?string $email) {
$atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name
$domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component
$pattern = "$atom+(\\.$atom+)*@($domain?\\.)+$domain";
}
/** Check whether the string is URL address
-* @param string $string
* @return bool
*/
-function is_url($string) {
+function is_url(string $string) {
$domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component //! IDN
return preg_match("~^(https?)://($domain?\\.)+$domain(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i", $string); //! restrict path, query and fragment characters
}
* @param Field $field
* @return bool
*/
-function is_shortable($field) {
+function is_shortable(array $field) {
return preg_match('~char|text|json|lob|geometry|point|linestring|polygon|string|bytea~', $field["type"]);
}
/** Get query to compute number of found rows
-* @param string $table
* @param list<string> $where
-* @param bool $is_group
* @param list<string> $group
* @return string
*/
-function count_rows($table, $where, $is_group, $group) {
+function count_rows(string $table, array $where, bool $is_group, array $group) {
$query = " FROM " . table($table) . ($where ? " WHERE " . implode(" AND ", $where) : "");
return ($is_group && (JUSH == "sql" || count($group) == 1)
? "SELECT COUNT(DISTINCT " . implode(", ", $group) . ")$query"
}
/** Run query which can be killed by AJAX call after timing out
-* @param string $query
* @return string[]
*/
-function slow_query($query) {
+function slow_query(string $query) {
global $adminer, $token, $driver;
$db = $adminer->database();
$timeout = $adminer->queryTimeout();
// used in compiled version
/**
-* @param string $binary
* @return string
*/
-function lzw_decompress($binary) {
+function lzw_decompress(string $binary) {
// convert binary string to codes
$dictionary_count = 256;
$bits = 8; // ceil(log($dictionary_count, 2))
namespace Adminer;
/** Return <script> element
-* @param string $source
-* @param string $trailing
* @return string
*/
-function script($source, $trailing = "\n") {
+function script(string $source, string $trailing = "\n") {
return "<script" . nonce() . ">$source</script>$trailing";
}
/** Return <script src> element
-* @param string $url
* @return string
*/
-function script_src($url) {
+function script_src(string $url) {
return "<script src='" . h($url) . "'" . nonce() . "></script>\n";
}
}
/** Get <input type="hidden">
-* @param string $name
* @param string|int $value
* @return string HTML
*/
-function input_hidden($name, $value = "") {
+function input_hidden(string $name, $value = "") {
return "<input type='hidden' name='" . h($name) . "' value='" . h($value) . "'>\n";
}
* @param string $special token to use instead of global $token
* @return string HTML
*/
-function input_token($special = "") {
+function input_token(string $special = "") {
global $token;
return input_hidden("token", ($special ?: $token));
}
}
/** Escape for HTML
-* @param string $string
* @return string
*/
-function h($string) {
+function h(string $string) {
return str_replace("\0", "�", htmlspecialchars($string, ENT_QUOTES, 'utf-8'));
}
/** Convert \n to <br>
-* @param string $string
* @return string
*/
-function nl_br($string) {
+function nl_br(string $string) {
return str_replace("\n", "<br>", $string); // nl2br() uses XHTML before PHP 5.3
}
/** Generate HTML checkbox
-* @param string $name
* @param string|int $value
-* @param bool $checked
-* @param string $label
-* @param string $onclick
-* @param string $class
-* @param string $labelled_by
* @return string
*/
-function checkbox($name, $value, $checked, $label = "", $onclick = "", $class = "", $labelled_by = "") {
+function checkbox(string $name, $value, bool $checked, string $label = "", string $onclick = "", string $class = "", string $labelled_by = "") {
$return = "<input type='checkbox' name='$name' value='" . h($value) . "'"
. ($checked ? " checked" : "")
. ($labelled_by ? " aria-labelledby='$labelled_by'" : "")
* @param bool $use_keys always use array keys for value="", otherwise only string keys are used
* @return string
*/
-function optionlist($options, $selected = null, $use_keys = false) {
+function optionlist($options, $selected = null, bool $use_keys = false) {
$return = "";
foreach ($options as $k => $v) {
$opts = array($k => $v);
}
/** Generate HTML <select>
-* @param string $name
* @param string[] $options
-* @param string $value
-* @param string $onchange
-* @param string $labelled_by
* @return string
*/
-function html_select($name, $options, $value = "", $onchange = "", $labelled_by = "") {
+function html_select(string $name, array $options, string $value = "", string $onchange = "", string $labelled_by = "") {
return "<select name='" . h($name) . "'"
. ($labelled_by ? " aria-labelledby='$labelled_by'" : "")
. ">" . optionlist($options, $value) . "</select>"
}
/** Generate HTML radio list
-* @param string $name
* @param string[] $options
-* @param string $value
* @return string
*/
-function html_radios($name, $options, $value = "") {
+function html_radios(string $name, array $options, string $value = "") {
$return = "";
foreach ($options as $key => $val) {
$return .= "<label><input type='radio' name='" . h($name) . "' value='" . h($key) . "'" . ($key == $value ? " checked" : "") . ">" . h($val) . "</label>";
}
/** Get onclick confirmation
-* @param string $message
-* @param string $selector
* @return string
*/
-function confirm($message = "", $selector = "qsl('input')") {
+function confirm(string $message = "", string $selector = "qsl('input')") {
return script("$selector.onclick = () => confirm('" . ($message ? js_escape($message) : lang('Are you sure?')) . "');", "");
}
/** Print header for hidden fieldset (close by </div></fieldset>)
-* @param string $id
-* @param string $legend
-* @param bool $visible
* @return void
*/
-function print_fieldset($id, $legend, $visible = false) {
+function print_fieldset(string $id, string $legend, bool $visible = false) {
echo "<fieldset><legend>";
echo "<a href='#fieldset-$id'>$legend</a>";
echo script("qsl('a').onclick = partial(toggle, 'fieldset-$id');", "");
}
/** Return class='active' if $bold is true
-* @param bool $bold
-* @param string $class
* @return string
*/
-function bold($bold, $class = "") {
+function bold(bool $bold, string $class = "") {
return ($bold ? " class='active $class'" : ($class ? " class='$class'" : ""));
}
/** Escape string for JavaScript apostrophes
-* @param string $string
* @return string
*/
-function js_escape($string) {
+function js_escape(string $string) {
return addcslashes($string, "\r\n'\\/"); // slash for <script>
}
/** Generate page number for pagination
-* @param int $page
-* @param int $current
* @return string
*/
-function pagination($page, $current) {
+function pagination(int $page, int $current) {
return " " . ($page == $current
? $page + 1
: '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" . ($_GET["next"] ? "&next=" . urlencode($_GET["next"]) : "") : "")) . '">' . ($page + 1) . "</a>"
/** Print hidden fields
* @param mixed[] $process
* @param list<string> $ignore
-* @param string $prefix
* @return bool
*/
-function hidden_fields($process, $ignore = array(), $prefix = '') {
+function hidden_fields(array $process, array $ignore = array(), string $prefix = '') {
$return = false;
foreach ($process as $key => $val) {
if (!in_array($key, $ignore)) {
/** Print enum or set input field
* @param string $type "radio"|"checkbox"
-* @param string $attrs
* @param Field $field
* @param mixed $value string|array
-* @param string $empty
* @return string
*/
-function enum_input($type, $attrs, $field, $value, $empty = null) {
+function enum_input(string $type, string $attrs, array $field, $value, string $empty = null) {
global $adminer;
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
$return = ($empty !== null ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === $empty) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
/** Print edit input field
* @param Field|RoutineField $field one field from fields()
* @param mixed $value
-* @param string $function
-* @param bool $autofocus
* @return void
*/
-function input($field, $value, $function, $autofocus = false) {
+function input(array $field, $value, string $function, bool $autofocus = false) {
global $driver, $adminer;
$name = h(bracket_escape($field["field"]));
echo "<td class='function'>";
* @param Field|RoutineField $field one field from fields()
* @return mixed false to leave the original value
*/
-function process_input($field) {
+function process_input(array $field) {
global $adminer, $driver;
if (stripos($field["default"], "GENERATED ALWAYS AS ") === 0) {
return;
* @param int $side JS expression
* @return string
*/
-function on_help($command, $side = 0) {
+function on_help(string $command, int $side = 0) {
return script("mixin(qsl('select, input'), {onmouseover: function (event) { helpMouseover.call(this, event, $command, $side) }, onmouseout: helpMouseout});", "");
}
/** Print edit data form
-* @param string $table
* @param Field[] $fields
* @param mixed $row
-* @param bool $update
* @return void
*/
-function edit_form($table, $fields, $row, $update) {
+function edit_form(string $table, array $fields, $row, bool $update) {
global $adminer, $error;
$table_name = $adminer->tableName(table_status1($table, true));
page_header(
}
/** Get button with icon
-* @param string $icon
-* @param string $name
-* @param string $html
-* @param string $title
* @return string
*/
-function icon($icon, $name, $html, $title) {
+function icon(string $icon, string $name, string $html, string $title) {
return "<button type='submit' name='$name' title='" . h($title) . "' class='icon icon-$icon'><span>$html</span></button>";
}
* @param float|string $number
* @return string
*/
-function lang($idf, $number = null) {
+function lang(string $idf, $number = null) {
// this is matched by compile.php
global $LANG, $translations;
$translation = ($translations[$idf] ?: $idf);
/** @var \PDO */ protected $pdo;
/** Connect to server using DSN
- * @param string $dsn
- * @param string $username
- * @param string $password
* @param mixed[] $options
* @return void
*/
- function dsn($dsn, $username, $password, $options = array()) {
+ function dsn(string $dsn, string $username, string $password, array $options = array()) {
$options[\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_SILENT;
$options[\PDO::ATTR_STATEMENT_CLASS] = array('Adminer\PdoResult');
try {
/** Register plugins
* @param ?list<object> $plugins object instances or null to autoload plugins from adminer-plugins/
*/
- function __construct($plugins) {
+ function __construct(?array $plugins) {
if ($plugins === null) {
$plugins = array();
$basename = "adminer-plugins";
* @param mixed[] $args
* @return mixed
*/
- private function callParent($function, $args) {
+ private function callParent(string $function, array $args) {
return call_user_func_array(array('parent', $function), $args);
}
* @param mixed[] $params
* @return mixed
*/
- private function applyPlugin($function, $params) {
+ private function applyPlugin(string $function, array $params) {
$args = array();
foreach ($params as $key => $val) {
// some plugins accept params by reference - we don't need to propage it outside, just to the other plugins
* @param mixed[] $args
* @return mixed
*/
- private function appendPlugin($function, $args) {
+ private function appendPlugin(string $function, array $args) {
$return = $this->callParent($function, $args);
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
}
/**
- * @param string $contents
* @return void
*/
- function write($contents) {
+ function write(string $contents) {
$this->size += strlen($contents);
fwrite($this->handler, $contents);
}
*/
/**
-* @param int $n
* @return int
*/
-function int32($n) {
+function int32(int $n) {
while ($n >= 2147483648) {
$n -= 4294967296;
}
/**
* @param int[] $v
-* @param bool $w
* @return string
*/
-function long2str($v, $w) {
+function long2str(array $v, bool $w) {
$s = '';
foreach ($v as $val) {
$s .= pack('V', $val);
}
/**
-* @param string $s
-* @param bool $w
* @return int[]
*/
-function str2long($s, $w) {
+function str2long(string $s, bool $w) {
$v = array_values(unpack('V*', str_pad($s, 4 * ceil(strlen($s) / 4), "\0")));
if ($w) {
$v[] = strlen($s);
}
/**
-* @param int $z
-* @param int $y
-* @param int $sum
-* @param int $k
* @return int
*/
-function xxtea_mx($z, $y, $sum, $k) {
+function xxtea_mx(int $z, int $y, int $sum, int $k) {
return int32((($z >> 5 & 0x7FFFFFF) ^ $y << 2) + (($y >> 3 & 0x1FFFFFFF) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k ^ $z));
}
/** Cipher
* @param string $str plain-text password
-* @param string $key
* @return string binary cipher
*/
-function encrypt_string($str, $key) {
+function encrypt_string(string $str, string $key) {
if ($str == "") {
return "";
}
/** Decipher
* @param string $str binary cipher
-* @param string $key
* @return string|false plain-text password
*/
-function decrypt_string($str, $key) {
+function decrypt_string(string $str, string $key) {
if ($str == "") {
return "";
}
}
if (basename($match[2]) != "lang.inc.php" || !$_SESSION["lang"]) {
if (basename($match[2]) == "lang.inc.php") {
- $return = str_replace('function lang($idf, $number = null) {', 'function lang($idf, $number = null) {
+ $return = str_replace('function lang(string $idf, $number = null) {', 'function lang($idf, $number = null) {
if (is_string($idf)) { // compiled version uses numbers, string comes from a plugin
// English translation is closest to the original identifiers //! pluralized translations are not found
$pos = array_search($idf, get_translations("en")); //! this should be cached
namespace Adminer;
/** Encode e-mail header in UTF-8
-* @param string $header
* @return string
*/
-function email_header($header) {
+function email_header(string $header) {
// iconv_mime_encode requires iconv, imap_8bit requires IMAP extension
return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
}
/** Send e-mail in UTF-8
-* @param string $email
-* @param string $subject
-* @param string $message
-* @param string $from
* @param array{error?:list<int>, type?:list<string>, name?:list<string>, tmp_name?:list<string>} $files
* @return bool
*/
-function send_mail($email, $subject, $message, $from = "", $files = array()) {
+function send_mail(string $email, string $subject, string $message, string $from = "", array $files = array()) {
$eol = PHP_EOL;
$message = str_replace("\n", $eol, wordwrap(str_replace("\r", "", "$message\n")));
$boundary = uniqid("boundary");
* @param Field $field single field returned from fields()
* @return bool
*/
-function like_bool($field) {
+function like_bool(array $field) {
return preg_match("~bool|(tinyint|bit)\\(1\\)~", $field["full_type"]);
}
/**
* @param list<string> $disabled case insensitive database names in values
*/
- function __construct($disabled) {
+ function __construct(array $disabled) {
$this->disabled = array_map('strtolower', $disabled);
}
/**
* @param list<string> $designs URL in key, name in value
*/
- function __construct($designs) {
+ function __construct(array $designs) {
$this->designs = $designs;
}
private $url;
/**
- * @param string $path
- * @param ?array $content
- * @param string $method
* @return array|false
*/
- function rootQuery($path, array $content = null, $method = 'GET') {
+ function rootQuery(string $path, ?array $content = null, string $method = 'GET') {
$file = @file_get_contents("$this->url/" . ltrim($path, '/'), false, stream_context_create(array('http' => array(
'method' => $method,
'content' => $content !== null ? json_encode($content) : null,
}
/** Perform query relative to actual selected DB
- * @param string $path
- * @param ?array $content
- * @param string $method
* @return array|false
*/
- function query($path, array $content = null, $method = 'GET') {
+ function query(string $path, ?array $content = null, string $method = 'GET') {
// Support for global search through all tables
if ($path != "" && $path[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $path, $matches)) {
$driver = driver();
}
/**
- * @param string $server
- * @param string $username
- * @param string $password
* @return bool
*/
- function connect($server, $username, $password) {
+ function connect(string $server, string $username, string $password) {
preg_match('~^(https?://)?(.*)~', $server, $match);
$this->url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query('');
}
/** Alter type
- * @param array $table
* @return mixed
*/
- function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
+ function alter_table(array $table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$properties = array();
foreach ($fields as $f) {
$field_name = trim($f[1][0]);
* @param list<string> $tables
* @return bool
*/
- function drop_tables($tables) {
+ function drop_tables(array $tables) {
$return = true;
foreach ($tables as $table) { //! convert to bulk api
$return = $return && connection()->query(urlencode($table), null, 'DELETE');
* @param string $prepend text to append before first calendar usage
* @param string $langPath path to language file, %s stands for language code
*/
- function __construct($prepend = null, $langPath = "jquery-ui/i18n/jquery.ui.datepicker-%s.js") {
+ function __construct(string $prepend = null, string $langPath = "jquery-ui/i18n/jquery.ui.datepicker-%s.js") {
$this->prepend = $prepend;
$this->langPath = $langPath;
}
* @param string $subject quoted column name
* @param string $message quoted column name
*/
- function __construct($table = "email", $id = "id", $title = "subject", $subject = "subject", $message = "message") {
+ function __construct(string $table = "email", string $id = "id", string $title = "subject", string $subject = "subject", string $message = "message") {
$this->table = $table;
$this->id = $id;
$this->title = $title;
* @param string $displayPath prefix for displaying data, null stands for $uploadPath
* @param string $extensions regular expression with allowed file extensions
*/
- function __construct($uploadPath = "../static/data/", $displayPath = null, $extensions = "[a-zA-Z0-9]+") {
+ function __construct(string $uploadPath = "../static/data/", string $displayPath = null, string $extensions = "[a-zA-Z0-9]+") {
$this->uploadPath = $uploadPath;
$this->displayPath = ($displayPath !== null ? $displayPath : $uploadPath);
$this->extensions = $extensions;
/**
* @param bool $sameOrigin allow running from the same origin only
*/
- function __construct($sameOrigin = false) {
+ function __construct(bool $sameOrigin = false) {
$this->sameOrigin = $sameOrigin;
}
* @param list<string> $ips IP address prefixes
* @param list<string> $forwarded_for X-Forwarded-For prefixes if IP address matches, empty array means anything
*/
- function __construct($ips, $forwarded_for = array()) {
+ function __construct(array $ips, array $forwarded_for = array()) {
$this->ips = $ips;
$this->forwarded_for= $forwarded_for;
}
/**
* @param string $secret decoded secret, e.g. base64_decode("SECRET")
*/
- function __construct($secret) {
+ function __construct(string $secret) {
$this->secret = $secret;
if ($_POST["auth"]) {
$_SESSION["otp"] = (string) $_POST["auth"]["otp"];
/** Set allowed password
* @param string $password_hash result of password_hash
*/
- function __construct($password_hash) {
+ function __construct(string $password_hash) {
$this->password_hash = $password_hash;
}
/** Set supported servers
* @param array{server:string, driver:string}[] $servers [$description => ["server" => , "driver" => "server|pgsql|sqlite|..."]]
*/
- function __construct($servers) {
+ function __construct(array $servers) {
$this->servers = $servers;
if ($_POST["auth"]) {
$key = $_POST["auth"]["server"];
protected $ssl;
/**
- * @param array{ssl?:string, cert?:string, verify?:bool, mode?:string, Encrypt?:bool, TrustServerCertificate?:bool} $ssl
* MySQL: ["key" => filename, "cert" => filename, "ca" => filename, "verify" => bool]
* PostgresSQL: ["mode" => sslmode] (https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE)
* MSSQL: ["Encrypt" => true, "TrustServerCertificate" => true] (https://learn.microsoft.com/en-us/sql/connect/php/connection-options)
*/
- function __construct($ssl) {
+ function __construct(array $ssl) {
$this->ssl = $ssl;
}
protected $database;
/** Set database of login table
- * @param string $database
*/
- function __construct($database) {
+ function __construct(string $database) {
$this->database = $database;
}
/**
* @param string[] $masters [$slave => $master]
*/
- function __construct($masters) {
+ function __construct(array $masters) {
$this->masters = $masters;
}
* @param string $from find these characters ...
* @param string $to ... and replace them by these
*/
- function __construct($from = 'áčďéěíňóřšťúůýž', $to = 'acdeeinorstuuyz') {
+ function __construct(string $from = 'áčďéěíňóřšťúůýž', string $to = 'acdeeinorstuuyz') {
$this->from = $from;
$this->to = $to;
}
* @param string $apiKey Get API key at: https://aistudio.google.com/apikey
* @param string $model Available models: https://ai.google.dev/gemini-api/docs/models#available-models
*/
- function __construct($apiKey, $model = "gemini-2.0-flash") {
+ function __construct(string $apiKey, string $model = "gemini-2.0-flash") {
$this->apiKey = $apiKey;
$this->model = $model;
}
/**
* @param string $filename defaults to "$database.sql"
*/
- function __construct($filename = "") {
+ function __construct(string $filename = "") {
$this->filename = $filename;
}
* @param Index[] $indexes data about all indexes on a table
* @return bool
*/
- function tableIndexesPrint($indexes) {
+ function tableIndexesPrint(array $indexes) {
echo "<table>\n";
echo "<thead><tr><th>" . Adminer\lang('Name') . "<th>" . Adminer\lang('Type') . "<th>" . Adminer\lang('Columns') . "</thead>\n";
foreach ($indexes as $name => $index) {
* @param Field[] $fields data about individual fields
* @return bool
*/
- function tableStructurePrint($fields, $tableStatus = null) {
+ function tableStructurePrint(array $fields, $tableStatus = null) {
echo "<div class='scrollable'>\n";
echo "<table class='nowrap odds'>\n";
echo "<thead><tr>"
protected $path;
/**
- * @param string $path
*/
- function __construct($path = "tiny_mce/tiny_mce.js") {
+ function __construct(string $path = "tiny_mce/tiny_mce.js") {
$this->path = $path;
}