From 97f25269009927b7c33df69e83c4356862a4f5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 28 Nov 2005 15:08:06 +0000 Subject: [PATCH] document all functions --- ChangeLog | 2 +- scripts/setup.php | 365 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 298 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47b0fef7d..6aa2079a8 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10,7 +10,7 @@ $Source$ 2005-11-28 Michal Čihař * scripts/setup.php: Don't allow loading of configuration if there is no - write permission on config. + write permission on config, document all functions. * libraries/auth/cookie.auth.lib.php: Display PMA_errors on login form. * Documentation.html: Add anchors to configuration directives. * scripts/setup.php: Add links to documentation. diff --git a/scripts/setup.php b/scripts/setup.php index 7a0979784..3403f8317 100644 --- a/scripts/setup.php +++ b/scripts/setup.php @@ -4,10 +4,6 @@ // phpMyAdmin setup script by Michal Čihař -// TODO: -// - links to documentation -// - document functions - // Grab phpMyAdmin version and PMA_dl function $cfg['GD2Available'] = 'auto'; require('../libraries/defines.lib.php'); @@ -22,6 +18,13 @@ require('../config.default.php'); $default_cfg = $cfg; unset($cfg); +/** + * Removes slashes from string if needed (eg. magic quotes are enabled) + * + * @param string prossibly escaped string + * + * @return string unsescaped string + */ function remove_slashes($val) { if (get_magic_quotes_gpc()) { return stripslashes($val); @@ -30,7 +33,7 @@ function remove_slashes($val) { } -// Grab some variables +// Grab action if (isset($_POST['action'])) { $action = $_POST['action']; } else { @@ -38,23 +41,30 @@ if (isset($_POST['action'])) { } if (isset($_POST['cfg']) && $action != 'clear' ) { + // Grab previous configuration, if it should not be cleared $cfg = unserialize(remove_slashes($_POST['cfg'])); } else { + // Start with empty configuration $cfg = array(); } + +// We rely on Servers array to exist, so create it here if (!isset($cfg['Servers']) || !is_array($cfg['Servers'])) { $cfg['Servers'] = array(); } +// Used later $now = gmdate('D, d M Y H:i:s') . ' GMT'; -// whether to show html header? -if ($action != 'download') { - +// General header for no caching header('Expires: ' . $now); // rfc2616 - Section 14.21 header('Last-Modified: ' . $now); header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header('Pragma: no-cache'); // HTTP/1.0 + +// whether to show html header? +if ($action != 'download') { + // Define the charset to be used header('Content-Type: text/html; charset=utf-8'); @@ -225,10 +235,26 @@ echo '' . "\n"; Documentation'; } +/** + * Displays message + * + * @param string type of message (notice/warning/error) + * @param string text of message + * @param title optional title of message + * + * @return nothing + */ function message($type, $text, $title = '') { echo '
' . "\n"; if (!empty($title)) { @@ -240,16 +266,26 @@ function message($type, $text, $title = '') { echo '
' . "\n"; } +/** + * Creates hidden input required for keeping current configuraion + * + * @return string HTML with hidden inputs + */ function get_hidden_cfg() { global $cfg; return '' . "\n"; } -function show_hidden_cfg() { - echo get_hidden_cfg(); -} - +/** + * Creates form for some action + * + * @param string action name + * @param string form title + * @param string optional additional inputs + * + * @return string HTML with form + */ function get_action($name, $title, $added = '') { $ret = ''; $ret .= '
'; @@ -262,15 +298,23 @@ function get_action($name, $title, $added = '') { return $ret; } -function show_action($name, $title, $added = '') { - echo get_action($name, $title, $added); -} - +/** + * Terminates script and ends HTML + * + * @return nothing + */ function footer() { echo ''; exit; } +/** + * Creates string describing server authentication method + * + * @param array server configuration + * + * @return string authentication method description + */ function get_server_auth($val) { global $default_cfg; @@ -290,6 +334,14 @@ function get_server_auth($val) { return $ret; } +/** + * Creates nice string with server name + * + * @param array server configuration + * @param int optional server id + * + * @return string fancy server name + */ function get_server_name($val, $id = FALSE) { if (!empty($val['verbose'])) { $ret = htmlspecialchars($val['verbose']); @@ -303,8 +355,15 @@ function get_server_name($val, $id = FALSE) { return $ret; } -function get_cfg_string() { - global $cfg, $script_info, $script_version, $now; +/** + * Creates configuration PHP code + * + * @param array configuration + * + * @return string PHP code containing configuration + */ +function get_cfg_string($cfg) { + global $script_info, $script_version, $now; $c = $cfg; $ret = " 0) { $res[$v[0]] = remove_slashes($_POST[$v[0]]); @@ -411,9 +488,19 @@ function grab_values($list) { return $res; } -function show_overview($legend, $list, $buttons = '') { +/** + * Displays overview + * + * @param string title of oveview + * @param array list of values to display (each element is array of two + * values - name and value) + * @param string optional buttons to be displayed + * + * @return nothing + */ +function show_overview($title, $list, $buttons = '') { echo '
' . "\n"; - echo '' . $legend . '' . "\n"; + echo '' . $title . '' . "\n"; foreach($list as $val) { echo '
'; echo '
'; @@ -434,6 +521,22 @@ function show_overview($legend, $list, $buttons = '') { echo "\n"; } +/** + * Displays configration, fallback defaults are taken from global $default_cfg + * + * @param array list of values to display (each element is array of two or + * three values - desription, name and optional type + * indicator). Type is determined by type of this parameter, + * array means select and array elements are items, + * 'password' means password input. + * @param string title of configuration + * @param string help string for this configuration + * @param array optional first level defaults + * @param string optional title for save button + * @param string optional prefix for documentation links + * + * @return nothing + */ function show_config_form($list, $legend, $help, $defaults = array(), $save = '', $prefix = '') { global $default_cfg; @@ -518,12 +621,19 @@ function show_config_form($list, $legend, $help, $defaults = array(), $save = '' echo "\n"; } +/** + * Shows security options configuration form + * + * @param array optional defaults + * + * @return nothing + */ function show_security_form($defaults = array()) { ?> '; } @@ -677,12 +829,19 @@ function show_server_form($defaults = array(), $number = FALSE) { '; foreach ($cfg['Servers'] as $key => $val) { @@ -835,21 +1035,23 @@ if ($action != 'download') { } } +/** + * @var boolean whether to show configuration overview + */ $show_info = FALSE; +// Do the main work depending on selected action switch ($action) { case 'download': header('Content-Type: text/plain'); - header('Expires: ' . $now); header('Content-Disposition: attachment; filename="config.inc.php"'); - header('Pragma: no-cache'); - echo get_cfg_string(); + echo get_cfg_string($cfg); exit; break; case 'display': echo '' . "\n"; ?>