Compatibility with iconv charset names on AIX (patch #1420704, thanks to Bj��rn Wiberg - bwiberg).

This commit is contained in:
Michal Čihař
2006-02-21 18:14:44 +00:00
parent c438a35ac8
commit c69bebb25b
4 changed files with 112 additions and 8 deletions

View File

@@ -11,8 +11,11 @@ $Source$
- XHTML fixes (patch #1435772, thanks to Matt LaPlante - cyberdog3k).
* libraries/export/sql.php: New line before values (RFE #1435919).
* libraries/Config.class.php: Trim spaces from config file to avoid
unwanted outpu (path #1431566, thanks to Piotr_Skowronek -
unwanted outpu (patch #1431566, thanks to Piotr_Skowronek -
piotr_skowronek).
* libraries/iconv_wrapper.lib.php, libraries/charset_conversion.lib.php,
libraries/database_interface.lib.php: Compatibility with iconv charset
names on AIX (patch #1420704, thanks to Björn Wiberg - bwiberg).
2006-02-21 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* libraries/common.lib.php PMA_getUvaCondition():

View File

@@ -59,6 +59,7 @@ define('PMA_CHARSET_NONE', 0);
define('PMA_CHARSET_ICONV', 1);
define('PMA_CHARSET_LIBICONV', 2);
define('PMA_CHARSET_RECODE', 3);
define('PMA_CHARSET_ICONV_AIX', 4);
if (!isset($cfg['IconvExtraParams'])) {
$cfg['IconvExtraParams'] = '';
@@ -74,7 +75,11 @@ if (isset($cfg['AllowAnywhereRecoding'])
}
if ($PMA_recoding_engine == 'iconv') {
if (@function_exists('iconv')) {
$PMA_recoding_engine = PMA_CHARSET_ICONV;
if ((@stristr(PHP_OS, 'AIX')) && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) {
$PMA_recoding_engine = PMA_CHARSET_ICONV_AIX;
} else {
$PMA_recoding_engine = PMA_CHARSET_ICONV;
}
} elseif (@function_exists('libiconv')) {
$PMA_recoding_engine = PMA_CHARSET_LIBICONV;
} else {
@@ -100,7 +105,11 @@ if (isset($cfg['AllowAnywhereRecoding'])
}
} else {
if (@function_exists('iconv')) {
$PMA_recoding_engine = PMA_CHARSET_ICONV;
if ((@stristr(PHP_OS, 'AIX')) && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) {
$PMA_recoding_engine = PMA_CHARSET_ICONV_AIX;
} else {
$PMA_recoding_engine = PMA_CHARSET_ICONV;
}
} elseif (@function_exists('libiconv')) {
$PMA_recoding_engine = PMA_CHARSET_LIBICONV;
} elseif (@function_exists('recode_string')) {
@@ -118,6 +127,10 @@ if (isset($cfg['AllowAnywhereRecoding'])
$PMA_recoding_engine = PMA_CHARSET_NONE;
}
/* Load AIX iconv wrapper if needed */
if ($PMA_recoding_engine == PMA_CHARSET_ICONV_AIX) {
require_once('./liraries/iconv_wrapper.lib.php');
}
/**
* Converts encoding according to current settings.
@@ -164,8 +177,10 @@ function PMA_convert_display_charset($what) {
return recode_string($convcharset . '..' . $charset, $what);
case PMA_CHARSET_ICONV:
return iconv($convcharset, $charset . $cfg['IconvExtraParams'], $what);
case PMA_CHARSET_ICONV_AIX:
return PMA_aix_iconv_wrapper($convcharset, $charset . $cfg['IconvExtraParams'], $what);
case PMA_CHARSET_LIBICONV:
return libiconv($convcharset, $charset, $what);
return libiconv($convcharset, $charset . $GLOBALS['cfg']['IconvExtraParams'], $what);
default:
return $what;
}
@@ -216,8 +231,10 @@ function PMA_convert_charset($what) {
return recode_string($charset . '..' . $convcharset, $what);
case PMA_CHARSET_ICONV:
return iconv($charset, $convcharset . $cfg['IconvExtraParams'], $what);
case PMA_CHARSET_ICONV_AIX:
return PMA_aix_iconv_wrapper($charset, $convcharset . $cfg['IconvExtraParams'], $what);
case PMA_CHARSET_LIBICONV:
return libiconv($charset, $convcharset, $what);
return libiconv($charset, $convcharset . $GLOBALS['cfg']['IconvExtraParams'], $what);
default:
return $what;
}
@@ -247,6 +264,8 @@ function PMA_convert_string($src_charset, $dest_charset, $what) {
return recode_string($src_charset . '..' . $dest_charset, $what);
case PMA_CHARSET_ICONV:
return iconv($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what);
case PMA_CHARSET_ICONV_AIX:
return PMA_aix_iconv_wrapper($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what);
case PMA_CHARSET_LIBICONV:
return libiconv($src_charset, $dest_charset, $what);
default:
@@ -285,8 +304,10 @@ function PMA_convert_file($src_charset, $dest_charset, $file) {
$line = fgets($fin, 4096);
if ($GLOBALS['PMA_recoding_engine'] == PMA_CHARSET_ICONV) {
$dist = iconv($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $line);
} elseif ($GLOBALS['PMA_recoding_engine'] == PMA_CHARSET_ICONV_AIX) {
$dist = PMA_aix_iconv_wrapper($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $line);
} else {
$dist = libiconv($src_charset, $dest_charset, $line);
$dist = libiconv($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $line);
}
fputs($fout, $dist);
} // end while

View File

@@ -144,8 +144,14 @@ function PMA_DBI_convert_message( $message ) {
if ( ! empty( $server_language ) && isset( $encodings[$server_language] ) ) {
if ( function_exists( 'iconv' ) ) {
$message = iconv( $encodings[$server_language],
$GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message);
if ((@stristr(PHP_OS, 'AIX')) && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) {
require_once('./liraries/iconv_wrapper.lib.php');
$message = PMA_aix_iconv_wrapper( $encodings[$server_language],
$GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message);
} else {
$message = iconv( $encodings[$server_language],
$GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message);
}
} elseif ( function_exists( 'recode_string' ) ) {
$message = recode_string( $encodings[$server_language] . '..' . $GLOBALS['charset'],
$message );

View File

@@ -0,0 +1,74 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
# GNU iconv code set to IBM AIX libiconv code set table
# Keys of this table should be in lowercase, and searches should be performed using lowercase!
$gnu_iconv_to_aix_iconv_codepage_map = array (
// "iso-8859-[1-9]" --> "ISO8859-[1-9]" according to http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/libs/basetrf2/setlocale.htm
'iso-8859-1' => 'ISO8859-1',
'iso-8859-2' => 'ISO8859-2',
'iso-8859-3' => 'ISO8859-3',
'iso-8859-4' => 'ISO8859-4',
'iso-8859-5' => 'ISO8859-5',
'iso-8859-6' => 'ISO8859-6',
'iso-8859-7' => 'ISO8859-7',
'iso-8859-8' => 'ISO8859-8',
'iso-8859-9' => 'ISO8859-9',
// "big5" --> "IBM-eucTW" according to http://kadesh.cepba.upc.es/mancpp/classref/ref/ITranscoder_DSC.htm
'big5' => 'IBM-eucTW',
// Other mappings corresponding to the phpMyAdmin dropdown box when using the AllowAnywhereRecoding feature
'euc-jp' => 'IBM-eucJP',
'koi8-r' => 'IBM-eucKR',
'ks_c_5601-1987' => 'KSC5601.1987-0',
'tis-620' => 'TIS-620',
'utf-8' => 'UTF-8'
);
/**
* Wrapper around IBM AIX iconv(), whose character set naming differs
* from the GNU version of iconv().
*
* @param string input character set
* @param string output character set
* @param string the string to convert
*
* @return mixed converted string or FALSE on failure
*
* @access public
*
* @author bwiberg Björn Wiberg <Bjorn.Wiberg@its.uu.se>
*/
function PMA_aix_iconv_wrapper($in_charset, $out_charset, $str) {
// Check for transliteration argument at the end of output character set name
$translit_search = strpos(strtolower($out_charset), '//translit');
$using_translit = (!($translit_search === FALSE));
// Extract "plain" output character set name (without any transliteration argument)
$out_charset_plain = ( $using_translit ? substr($out_charset, 0, $translit_search) : $out_charset );
// Transform name of input character set (if found)
if (array_key_exists(strtolower($in_charset), $gnu_iconv_to_aix_iconv_codepage_map)) {
$in_charset = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($in_charset)];
}
// Transform name of "plain" output character set (if found)
if (array_key_exists(strtolower($out_charset_plain), $gnu_iconv_to_aix_iconv_codepage_map)) {
$out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($out_charset_plain)];
}
// Add transliteration argument again (exactly as specified by user) if used
// Build the output character set name that we will use
$out_charset = ( $using_translit ? $out_charset_plain . substr($out_charset, $translit_search) : $out_charset_plain );
// NOTE: Transliteration not supported; we will use the "plain" output character set name
$out_charset = $out_charset_plain;
// Call iconv() with the possibly modified parameters
$result = iconv($in_charset, $out_charset, $str);
return $result;
} // end of the "PMA_aix_iconv_wrapper()" function
?>