summaryrefslogtreecommitdiff
path: root/config/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'config/index.php')
-rw-r--r--config/index.php79
1 files changed, 78 insertions, 1 deletions
diff --git a/config/index.php b/config/index.php
index a0d7f4fb..e76e6c7e 100644
--- a/config/index.php
+++ b/config/index.php
@@ -598,7 +598,6 @@ print "<li style='font-weight:bold;color:green;font-size:110%'>Environment check
$conf->RootPW = importPost( "RootPW", "" );
$useRoot = importCheck( 'useroot', false );
$conf->LanguageCode = importPost( "LanguageCode", "en" );
-
## MySQL specific:
$conf->DBprefix = importPost( "DBprefix" );
$conf->setSchema(
@@ -617,6 +616,7 @@ print "<li style='font-weight:bold;color:green;font-size:110%'>Environment check
// We need a second field so it doesn't overwrite the MySQL one
$conf->DBprefix2 = importPost( "DBprefix2" );
+ $conf->ShellLocale = getShellLocale( $conf->LanguageCode );
/* Check for validity */
$errs = array();
@@ -1521,6 +1521,13 @@ function writeLocalSettings( $conf ) {
$rights = ($conf->RightsUrl) ? "" : "# ";
$hashedUploads = $conf->safeMode ? '' : '# ';
+ if ( $conf->ShellLocale ) {
+ $locale = '';
+ } else {
+ $locale = '# ';
+ $conf->ShellLocale = 'en_US.UTF-8';
+ }
+
switch ( $conf->Shm ) {
case 'memcached':
$cacheType = 'CACHE_MEMCACHED';
@@ -1692,6 +1699,11 @@ if ( \$wgCommandLineMode ) {
{$magic}\$wgUseImageMagick = true;
{$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
+## If you use ImageMagick (or any other shell command) on a
+## Linux server, this will need to be set to the name of an
+## available UTF-8 locale
+{$locale}\$wgShellLocale = \"{$slconf['ShellLocale']}\";
+
## If you want to use image uploads under safe mode,
## create the directories images/archive, images/thumb and
## images/temp, and make them all writable. Then uncomment
@@ -1934,6 +1946,71 @@ function printListItem( $item ) {
print "<li>$item</li>";
}
+# Determine a suitable value for $wgShellLocale
+function getShellLocale( $wikiLanguage ) {
+ # Give up now if we're in safe mode or open_basedir
+ # It's theoretically possible but tricky to work with
+ if ( wfIniGetBool( "safe_mode" ) || ini_get( 'open_basedir' ) ) {
+ return false;
+ }
+
+ $os = php_uname( 's' );
+ $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
+ if ( !in_array( $os, $supported ) ) {
+ return false;
+ }
+
+ # Get a list of available locales
+ $lines = $ret = false;
+ exec( '/usr/bin/locale -a', $lines, $ret );
+ if ( $ret ) {
+ return false;
+ }
+
+ $lines = array_map( 'trim', $lines );
+ $candidatesByLocale = array();
+ $candidatesByLang = array();
+ foreach ( $lines as $line ) {
+ if ( $line === '' ) {
+ continue;
+ }
+ if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
+ continue;
+ }
+ list( $all, $lang, $territory, $charset, $modifier ) = $m;
+ $candidatesByLocale[$m[0]] = $m;
+ $candidatesByLang[$lang][] = $m;
+ }
+
+ # Try the current value of LANG
+ if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
+ return getenv( 'LANG' );
+ }
+
+ # Try the most common ones
+ $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
+ foreach ( $commonLocales as $commonLocale ) {
+ if ( isset( $candidatesByLocale[$commonLocale] ) ) {
+ return $commonLocale;
+ }
+ }
+
+ # Is there an available locale in the Wiki's language?
+ if ( isset( $candidatesByLang[$wikiLang] ) ) {
+ $m = reset( $candidatesByLang[$wikiLang] );
+ return $m[0];
+ }
+
+ # Are there any at all?
+ if ( count( $candidatesByLocale ) ) {
+ $m = reset( $candidatesByLocale );
+ return $m[0];
+ }
+
+ # Give up
+ return false;
+}
+
?>
<div class="license">