Merge remote-tracking branch 'origin/master'

This commit is contained in:
Michal Čihař 2012-05-11 15:17:43 +02:00
commit 835029e8e8
8 changed files with 144 additions and 88 deletions

View File

@ -1599,9 +1599,6 @@ class PMA_Config
function setCookie($cookie, $value, $default = null, $validity = null,
$httponly = true
) {
if ($validity == null) {
$validity = 2592000;
}
if (strlen($value) && null !== $default && $value === $default) {
// default value is used
if (isset($_COOKIE[$cookie])) {
@ -1619,10 +1616,12 @@ class PMA_Config
if (! isset($_COOKIE[$cookie]) || $_COOKIE[$cookie] !== $value) {
// set cookie with new value
/* Calculate cookie validity */
if ($validity == 0) {
$v = 0;
if ($validity == null) {
$validity = time() + 2592000;
} elseif ($validity == 0) {
$validity = 0;
} else {
$v = time() + $validity;
$validity = time() + $validity;
}
if (defined('TESTSUITE')) {
$_COOKIE[$cookie] = $value;
@ -1631,7 +1630,7 @@ class PMA_Config
return setcookie(
$cookie,
$value,
$v,
$validity,
$this->getCookiePath(),
'',
$this->isHttps(),

View File

@ -239,7 +239,7 @@ class PMA_File
}
/**
*
* Loads uploaded file from table change request.
*
* @param string $key the md5 hash of the column name
* @param string $rownumber
@ -252,7 +252,11 @@ class PMA_File
if (! isset($_FILES['fields_upload']) || empty($_FILES['fields_upload']['name']['multi_edit'][$rownumber][$key])) {
return false;
}
$file = PMA_File::fetchUploadedFromTblChangeRequestMultiple($_FILES['fields_upload'], $rownumber, $key);
$file = PMA_File::fetchUploadedFromTblChangeRequestMultiple(
$_FILES['fields_upload'],
$rownumber,
$key
);
// check for file upload errors
switch ($file['error']) {
@ -344,13 +348,17 @@ class PMA_File
&& is_string($_REQUEST['fields_uploadlocal']['multi_edit'][$rownumber][$key])
) {
// ... whether with multiple rows ...
return $this->setLocalSelectedFile($_REQUEST['fields_uploadlocal']['multi_edit'][$rownumber][$key]);
return $this->setLocalSelectedFile(
$_REQUEST['fields_uploadlocal']['multi_edit'][$rownumber][$key]
);
} else {
return false;
}
}
/**
* Returns possible error message.
*
* @access public
* @return string error message
*/
@ -360,6 +368,8 @@ class PMA_File
}
/**
* Checks whether there was any error.
*
* @access public
* @return boolean whether an error occured or not
*/
@ -395,6 +405,7 @@ class PMA_File
}
/**
* Sets named file to be read from UploadDir.
*
* @param string $name
*
@ -407,7 +418,9 @@ class PMA_File
return false;
}
$this->setName(PMA_userDir($GLOBALS['cfg']['UploadDir']) . PMA_securePath($name));
$this->setName(
PMA_userDir($GLOBALS['cfg']['UploadDir']) . PMA_securePath($name)
);
if (! $this->isReadable()) {
$this->_error_message = __('File could not be read');
$this->setName(null);
@ -418,6 +431,8 @@ class PMA_File
}
/**
* Checks whether file can be read.
*
* @access public
* @return boolean whether the file is readable or not
*/
@ -452,12 +467,18 @@ class PMA_File
return false;
}
$new_file_to_upload = tempnam(realpath($GLOBALS['cfg']['TempDir']), basename($this->getName()));
$new_file_to_upload = tempnam(
realpath($GLOBALS['cfg']['TempDir']),
basename($this->getName())
);
// suppress warnings from being displayed, but not from being logged
// any file access outside of open_basedir will issue a warning
ob_start();
$move_uploaded_file_result = move_uploaded_file($this->getName(), $new_file_to_upload);
$move_uploaded_file_result = move_uploaded_file(
$this->getName(),
$new_file_to_upload
);
ob_end_clean();
if (! $move_uploaded_file_result) {
$this->_error_message = __('Error while moving uploaded file.');
@ -559,6 +580,8 @@ class PMA_File
}
/**
* Attempts to open the file.
*
* @return bool
*/
function open()
@ -625,6 +648,8 @@ class PMA_File
}
/**
* Returns compression used by file.
*
* @return string MIME type of compression, none for none
* @access public
*/

View File

@ -576,18 +576,14 @@ function PMA_auth_set_user()
$url_params['target'] = $GLOBALS['target'];
}
/**
* whether we come from a fresh cookie login
*/
define('PMA_COMING_FROM_COOKIE_LOGIN', true);
/**
* Clear user cache.
*/
PMA_clearUserCache();
PMA_sendHeaderLocation(
$redirect_url . PMA_generate_common_url($url_params, '&')
$redirect_url . PMA_generate_common_url($url_params, '&'),
true
);
exit();
} // end if

View File

@ -531,7 +531,7 @@ function PMA_showPHPDocu($target)
* returns HTML for a footnote marker and add the messsage to the footnotes
*
* @param string $message the error message
* @param bool $bbcode
* @param bool $bbcode whether to interpret BB code
* @param string $type message types
*
* @return string html code for a footnote marker
@ -600,7 +600,7 @@ function PMA_mysqlDie(
*/
include_once './libraries/header.inc.php';
$error_msg_output = '';
$error_msg = '';
if (! $error_message) {
$error_message = PMA_DBI_getError();
@ -625,8 +625,8 @@ function PMA_mysqlDie(
}
}
// ---
$error_msg_output .= "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
$error_msg_output .= ' <div class="error"><h1>' . __('Error')
$error_msg .= "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
$error_msg .= ' <div class="error"><h1>' . __('Error')
. '</h1>' . "\n";
// if the config password is wrong, or the MySQL server does not
// respond, do not show the query that would reveal the
@ -634,15 +634,15 @@ function PMA_mysqlDie(
if (! empty($the_query) && ! strstr($the_query, 'connect')) {
// --- Added to solve bug #641765
if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
$error_msg_output .= PMA_SQP_getErrorString() . "\n";
$error_msg_output .= '<br />' . "\n";
$error_msg .= PMA_SQP_getErrorString() . "\n";
$error_msg .= '<br />' . "\n";
}
// ---
// modified to show the help on sql errors
$error_msg_output .= ' <p><strong>' . __('SQL query') . ':</strong>' . "\n";
$error_msg .= '<p><strong>' . __('SQL query') . ':</strong>' . "\n";
if (strstr(strtolower($formatted_sql), 'select')) {
// please show me help to the error on select
$error_msg_output .= PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
$error_msg .= PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
}
if ($is_modify_link) {
$_url_params = array(
@ -663,14 +663,14 @@ function PMA_mysqlDie(
. PMA_generate_common_url($_url_params) . '">';
}
$error_msg_output .= $doedit_goto
$error_msg .= $doedit_goto
. PMA_getIcon('b_edit.png', __('Edit'))
. '</a>';
} // end if
$error_msg_output .= ' </p>' . "\n"
.' <p>' . "\n"
.' ' . $formatted_sql . "\n"
.' </p>' . "\n";
$error_msg .= ' </p>' . "\n"
.'<p>' . "\n"
. $formatted_sql . "\n"
. '</p>' . "\n";
} // end if
if (! empty($error_message)) {
@ -682,7 +682,7 @@ function PMA_mysqlDie(
}
// modified to show the help on error-returns
// (now error-messages-server)
$error_msg_output .= '<p>' . "\n"
$error_msg .= '<p>' . "\n"
. ' <strong>' . __('MySQL said: ') . '</strong>'
. PMA_showMySQLDocu('Error-messages-server', 'Error-messages-server')
. "\n"
@ -699,12 +699,12 @@ function PMA_mysqlDie(
// Replace linebreaks
$error_message = nl2br($error_message);
$error_msg_output .= '<code>' . "\n"
$error_msg .= '<code>' . "\n"
. $error_message . "\n"
. '</code><br />' . "\n";
$error_msg_output .= '</div>';
$error_msg .= '</div>';
$_SESSION['Import_message']['message'] = $error_msg_output;
$_SESSION['Import_message']['message'] = $error_msg;
if ($exit) {
/**
@ -713,7 +713,7 @@ function PMA_mysqlDie(
* - use PMA_ajaxResponse() to transmit the message and exit
*/
if ($GLOBALS['is_ajax_request'] == true) {
PMA_ajaxResponse($error_msg_output, false);
PMA_ajaxResponse($error_msg, false);
}
if (! empty($back_url)) {
if (strstr($back_url, '?')) {
@ -724,18 +724,18 @@ function PMA_mysqlDie(
$_SESSION['Import_message']['go_back_url'] = $back_url;
$error_msg_output .= '<fieldset class="tblFooters">';
$error_msg_output .= '[ <a href="' . $back_url . '">' . __('Back') . '</a> ]';
$error_msg_output .= '</fieldset>' . "\n\n";
$error_msg .= '<fieldset class="tblFooters">';
$error_msg .= '[ <a href="' . $back_url . '">' . __('Back') . '</a> ]';
$error_msg .= '</fieldset>' . "\n\n";
}
echo $error_msg_output;
echo $error_msg;
/**
* display footer and exit
*/
include './libraries/footer.inc.php';
} else {
echo $error_msg_output;
echo $error_msg;
}
} // end of the 'PMA_mysqlDie()' function
@ -791,7 +791,12 @@ function PMA_getTableList($db, $tables = null, $limit_offset = 0,
$tbl_is_view = $table['TABLE_TYPE'] == 'VIEW';
if ($tbl_is_view || PMA_is_system_schema($db)) {
$table['Rows'] = PMA_Table::countRecords($db, $table['Name'], false, true);
$table['Rows'] = PMA_Table::countRecords(
$db,
$table['Name'],
false,
true
);
}
}
@ -933,7 +938,7 @@ function PMA_whichCrlf()
*
* @access public
*/
function PMA_reloadNavigation($jsonly=false)
function PMA_reloadNavigation($jsonly = false)
{
// Reloads the navigation frame via JavaScript if required
if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
@ -943,19 +948,21 @@ function PMA_reloadNavigation($jsonly=false)
// and the offset becomes greater than the total number of tables
unset($_SESSION['tmp_user_values']['table_limit_offset']);
echo "\n";
$reload_url = './navigation.php?' . PMA_generate_common_url($GLOBALS['db'], '', '&');
$reload_url = './navigation.php?' . PMA_generate_common_url(
$GLOBALS['db'],
'',
'&'
);
if (!$jsonly) {
echo '<script type="text/javascript">' . PHP_EOL;
}
?>
//<![CDATA[
if (typeof(window.parent) != 'undefined'
&& typeof(window.parent.frame_navigation) != 'undefined'
&& window.parent.goTo) {
window.parent.goTo('<?php echo $reload_url; ?>');
}
//]]>
<?php
echo '//<![CDATA[' . PHP_EOL;
echo 'if (typeof(window.parent) != "undefined"' . PHP_EOL;
echo ' && typeof(window.parent.frame_navigation) != "undefined"' . PHP_EOL;
echo ' && window.parent.goTo) {' . PHP_EOL;
echo ' window.parent.goTo("' . $reload_url . '");' . PHP_EOL;
echo '}' . PHP_EOL;
echo '//]]>' . PHP_EOL;
if (!$jsonly) {
echo '</script>' . PHP_EOL;
}
@ -1013,25 +1020,14 @@ function PMA_showMessage(
$retval .= "\n";
$retval .= '<script type="text/javascript">' . "\n";
$retval .= '//<![CDATA[' . "\n";
$retval .= "if (window.parent.updateTableTitle) window.parent.updateTableTitle('"
$retval .= 'if (window.parent.updateTableTitle) {' . "\n";
$retval .= " window.parent.updateTableTitle('";
. $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
$retval .= '}' . "\n";
$retval .= '//]]>' . "\n";
$retval .= '</script>' . "\n";
} // end if ... elseif
// Checks if the table needs to be repaired after a TRUNCATE query.
// @todo what about $GLOBALS['display_query']???
// @todo this is REALLY the wrong place to do this - very unexpected here
if (strlen($GLOBALS['table'])
&& $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])
) {
if (PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Index_length') > 1024
&& ! PMA_DRIZZLE
) {
PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
}
}
// In an Ajax request, $GLOBALS['cell_align_left'] may not be defined. Hence,
// check for it's presence before using it
$retval .= '<div id="result_query"'
@ -1507,7 +1503,7 @@ function PMA_formatNumber(
$value, $digits_left = 3, $digits_right = 0,
$only_down = false, $noTrailingZero = true
) {
if ($value==0) {
if ($value == 0) {
return '0';
}
@ -1565,11 +1561,11 @@ function PMA_formatNumber(
*/
$cur_digits = floor(log10($value / PMA_pow(1000, $d, 'pow'))+1);
if ($digits_left > $cur_digits) {
$d-= floor(($digits_left - $cur_digits)/3);
$d -= floor(($digits_left - $cur_digits)/3);
}
if ($d<0 && $only_down) {
$d=0;
if ($d < 0 && $only_down) {
$d = 0;
}
$value = round($value / (PMA_pow(1000, $d, 'pow') / $dh)) /$dh;
@ -1585,7 +1581,7 @@ function PMA_formatNumber(
$value = PMA_localizeNumber(number_format($value, $digits_right));
}
if ($originalValue!=0 && floatval($value) == 0) {
if ($originalValue != 0 && floatval($value) == 0) {
return ' <' . (1 / PMA_pow(10, $digits_right)) . ' ' . $unit;
}

View File

@ -506,11 +506,12 @@ function PMA_getenv($var_name)
/**
* Send HTTP header, taking IIS limits into account (600 seems ok)
*
* @param string $uri the header to send
* @param string $uri the header to send
* @param bool $use_refresh whether to use Refresh: header when running on IIS
*
* @return boolean always true
*/
function PMA_sendHeaderLocation($uri)
function PMA_sendHeaderLocation($uri, $use_refresh = false)
{
if (PMA_IS_IIS && strlen($uri) > 600) {
include_once './libraries/js_escape.lib.php';
@ -557,7 +558,7 @@ function PMA_sendHeaderLocation($uri)
// bug #1523784: IE6 does not like 'Refresh: 0', it
// results in a blank page
// but we need it when coming from the cookie login panel)
if (PMA_IS_IIS && defined('PMA_COMING_FROM_COOKIE_LOGIN')) {
if (PMA_IS_IIS && $use_refresh) {
header('Refresh: 0; ' . $uri);
} else {
header('Location: ' . $uri);

View File

@ -3,7 +3,6 @@
/**
* Test for PMA_Config class
*
*
* @package PhpMyAdmin-test
* @group current
*/
@ -272,8 +271,10 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @covers PMA_Config::get
* @covers PMA_Config::set
*
* @return void
*/
public function testGetAndSet()
@ -308,6 +309,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @depends testCheckPmaAbsoluteUriEmpty
*/
public function testCheckPmaAbsoluteUriNormal()
@ -323,6 +325,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @depends testCheckPmaAbsoluteUriNormal
*/
public function testCheckPmaAbsoluteUriScheme()
@ -339,6 +342,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @depends testCheckPmaAbsoluteUriScheme
*/
public function testCheckPmaAbsoluteUriUser()
@ -398,6 +402,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @depends testDetectHttps
*/
public function testCheckCookiePath()
@ -408,6 +413,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @depends testCheckSystem
* @depends testCheckWebServer
* @depends testLoadDefaults
@ -438,6 +444,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testSave().
*/
public function testSave()
@ -449,6 +456,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testGetFontsizeForm().
*/
public function testGetFontsizeForm()
@ -460,6 +468,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testRemoveCookie().
*/
public function testRemoveCookie()
@ -469,7 +478,8 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
'This test has not been implemented yet.'
);
}
/**
/**
*
* @todo Implement testCheckFontsize().
*/
public function testCheckFontsize()
@ -481,6 +491,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testCheckUpload().
*/
public function testCheckUpload()
@ -492,6 +503,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testCheckUploadSize().
*/
public function testCheckUploadSize()
@ -503,6 +515,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testCheckIsHttps().
*/
public function testCheckIsHttps()
@ -514,6 +527,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testGetCookiePath().
*/
public function testGetCookiePath()
@ -525,6 +539,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo finish implementing test + dependencies
*/
public function testLoad()
@ -535,6 +550,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testLoadUserPreferences().
*/
public function testLoadUserPreferences()
@ -545,6 +561,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testSetUserValue().
*/
public function testSetUserValue()
@ -555,6 +572,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testGetUserValue().
*/
public function testGetUserValue()
@ -563,6 +581,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testGetThemeUniqueValue().
*/
public function testGetThemeUniqueValue()
@ -574,6 +593,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testCheckPermissions().
*/
public function testCheckPermissions()
@ -586,6 +606,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
/**
*
* @todo Implement testSetCookie().
*/
public function testSetCookie()
@ -602,6 +623,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase
}
/**
*
* @dataProvider sslUris
*/
public function testSSLUri($original, $expected)

View File

@ -5,7 +5,6 @@ require_once 'libraries/Theme.class.php';
/**
* Test class for PMA_Theme.
* Generated by PHPUnit on 2011-07-18 at 03:19:13.
*/
class PMA_ThemeTest extends PHPUnit_Framework_TestCase
{
@ -40,7 +39,10 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
public function testCheckImgPathIncorrect()
{
$this->object->setPath('./test/classes/_data/incorrect_theme');
$this->assertFalse($this->object->loadInfo(), 'Theme name is not properly set');
$this->assertFalse(
$this->object->loadInfo(),
'Theme name is not properly set'
);
}
public function testCheckImgPathFull()
@ -54,12 +56,16 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
public function testLoadInfo()
{
$this->object->setPath('./themes/original');
$infofile = $this->object->getPath().'/info.inc.php';
$this->assertTrue($this->object->loadInfo());
$this->assertEquals(filemtime($this->object->getPath().'/info.inc.php'), $this->object->mtime_info);
$this->assertEquals(
filemtime($infofile),
$this->object->mtime_info
);
$this->object->setPath('./themes/original');
$this->object->mtime_info = filemtime($this->object->getPath().'/info.inc.php');
$this->object->mtime_info = filemtime($infofile);
$this->assertTrue($this->object->loadInfo());
$this->assertEquals('Original', $this->object->getName());
}
@ -76,6 +82,7 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @expectedException PHPUnit_Framework_Error
*/
public function testCheckImgPathBad()
@ -101,6 +108,7 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @expectedException PHPUnit_Framework_Error
*/
public function testCheckImgPathGlobalsWrongPath()
@ -115,6 +123,7 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @covers PMA_Theme::setPath
* @covers PMA_Theme::getPath
*/
@ -132,11 +141,16 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @depends testLoadInfo
*/
public function testGetSetCheckVersion()
{
$this->assertEquals('0.0.0.0', $this->object->getVersion(), 'Version 0.0.0.0 by default');
$this->assertEquals(
'0.0.0.0',
$this->object->getVersion(),
'Version 0.0.0.0 by default'
);
$this->object->setVersion("1.2.3.4");
$this->assertEquals('1.2.3.4', $this->object->getVersion());
@ -146,6 +160,7 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @covers PMA_Theme::getName
* @covers PMA_Theme::setName
*/
@ -158,6 +173,7 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @covers PMA_Theme::getId
* @covers PMA_Theme::setId
*/
@ -170,12 +186,16 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @covers PMA_Theme::getImgPath
* @covers PMA_Theme::setImgPath
*/
public function testGetSetImgPath()
{
$this->assertEmpty($this->object->getImgPath(), 'ImgPath is empty by default');
$this->assertEmpty(
$this->object->getImgPath(),
'ImgPath is empty by default'
);
$this->object->setImgPath('/new/path');
$this->assertEquals('/new/path', $this->object->getImgPath());
@ -194,6 +214,7 @@ class PMA_ThemeTest extends PHPUnit_Framework_TestCase
}
/**
*
* @todo Implement testPrintPreview().
*/
public function testPrintPreview()

View File

@ -196,7 +196,6 @@ class PMA_headerLocation_test extends PHPUnit_Framework_TestCase
if ($this->runkitExt && $this->apdExt) {
runkit_constant_redefine('PMA_IS_IIS', true);
runkit_constant_add('PMA_COMING_FROM_COOKIE_LOGIN', true);
$testUri = 'http://testurl.com/test.php';
$separator = PMA_get_arg_separator();
@ -205,9 +204,6 @@ class PMA_headerLocation_test extends PHPUnit_Framework_TestCase
PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
// cleaning constant
runkit_constant_remove('PMA_COMING_FROM_COOKIE_LOGIN');
$this->assertEquals($header, $GLOBALS['header']);
} else {