<?php
/**
- * Internationalisation code
+ * Internationalisation code.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Language
global $wgLanguageNames;
require_once( dirname( __FILE__ ) . '/Names.php' );
-mb_internal_encoding( 'UTF-8' );
+if ( function_exists( 'mb_strtoupper' ) ) {
+ mb_internal_encoding( 'UTF-8' );
+}
/**
* a fake language converter
}
if ( !defined( 'MW_COMPILED' ) ) {
- // Preload base classes to work around APC/PHP5 bug
- if ( file_exists( "$IP/languages/classes/$class.deps.php" ) ) {
- include_once( "$IP/languages/classes/$class.deps.php" );
- }
if ( file_exists( "$IP/languages/classes/$class.php" ) ) {
include_once( "$IP/languages/classes/$class.php" );
}
*/
public function setNamespaces( array $namespaces ) {
$this->namespaceNames = $namespaces;
+ $this->mNamespaceIds = null;
+ }
+
+ /**
+ * Resets all of the namespace caches. Mainly used for testing
+ */
+ public function resetNamespaces( ) {
+ $this->namespaceNames = null;
+ $this->mNamespaceIds = null;
+ $this->namespaceAliases = null;
}
/**
$mwNames = $wgExtraLanguageNames + $coreLanguageNames;
foreach ( $mwNames as $mwCode => $mwName ) {
# - Prefer own MediaWiki native name when not using the hook
- # TODO: prefer it always to make it consistent, but casing is different in CLDR
# - For other names just add if not added through the hook
- if ( ( $mwCode === $inLanguage && !$inLanguage ) || !isset( $names[$mwCode] ) ) {
+ if ( $mwCode === $inLanguage || !isset( $names[$mwCode] ) ) {
$names[$mwCode] = $mwName;
}
}
return mb_strtoupper( $matches[0] );
}
+ /**
+ * @param $matches array
+ * @return string
+ */
+ function ucCallback( $matches ) {
+ list( $wikiUpperChars ) = self::getCaseMaps();
+ return strtr( $matches[1], $wikiUpperChars );
+ }
+
+ /**
+ * @param $matches array
+ * @return string
+ */
+ function lcCallback( $matches ) {
+ list( , $wikiLowerChars ) = self::getCaseMaps();
+ return strtr( $matches[1], $wikiLowerChars );
+ }
+
/**
* @param $matches array
* @return string
return mb_strtoupper( $matches[0] );
}
+ /**
+ * @param $matches array
+ * @return string
+ */
+ function ucwordsCallbackWiki( $matches ) {
+ list( $wikiUpperChars ) = self::getCaseMaps();
+ return strtr( $matches[0], $wikiUpperChars );
+ }
+
/**
* Make a string's first character uppercase
*
* @return string
*/
function uc( $str, $first = false ) {
- if ( $first ) {
- if ( $this->isMultibyte( $str ) ) {
- return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
+ if ( function_exists( 'mb_strtoupper' ) ) {
+ if ( $first ) {
+ if ( $this->isMultibyte( $str ) ) {
+ return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
+ } else {
+ return ucfirst( $str );
+ }
} else {
- return ucfirst( $str );
+ return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
}
} else {
- return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
+ if ( $this->isMultibyte( $str ) ) {
+ $x = $first ? '^' : '';
+ return preg_replace_callback(
+ "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
+ array( $this, 'ucCallback' ),
+ $str
+ );
+ } else {
+ return $first ? ucfirst( $str ) : strtoupper( $str );
+ }
}
}
* @return mixed|string
*/
function lc( $str, $first = false ) {
- if ( $first ) {
- if ( $this->isMultibyte( $str ) ) {
- return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
+ if ( function_exists( 'mb_strtolower' ) ) {
+ if ( $first ) {
+ if ( $this->isMultibyte( $str ) ) {
+ return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
+ } else {
+ return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
+ }
} else {
- return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
+ return $this->isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
}
} else {
- return $this->isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
+ if ( $this->isMultibyte( $str ) ) {
+ $x = $first ? '^' : '';
+ return preg_replace_callback(
+ "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
+ array( $this, 'lcCallback' ),
+ $str
+ );
+ } else {
+ return $first ? strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 ) : strtolower( $str );
+ }
}
}
$replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
// function to use to capitalize a single char
- return preg_replace_callback(
- $replaceRegexp,
- array( $this, 'ucwordsCallbackMB' ),
- $str
- );
+ if ( function_exists( 'mb_strtoupper' ) ) {
+ return preg_replace_callback(
+ $replaceRegexp,
+ array( $this, 'ucwordsCallbackMB' ),
+ $str
+ );
+ } else {
+ return preg_replace_callback(
+ $replaceRegexp,
+ array( $this, 'ucwordsCallbackWiki' ),
+ $str
+ );
+ }
} else {
return ucwords( strtolower( $str ) );
}
// find first letter after word break
$replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
- return preg_replace_callback(
- $replaceRegexp,
- array( $this, 'ucwordbreaksCallbackMB' ),
- $str
- );
+ if ( function_exists( 'mb_strtoupper' ) ) {
+ return preg_replace_callback(
+ $replaceRegexp,
+ array( $this, 'ucwordbreaksCallbackMB' ),
+ $str
+ );
+ } else {
+ return preg_replace_callback(
+ $replaceRegexp,
+ array( $this, 'ucwordsCallbackWiki' ),
+ $str
+ );
+ }
} else {
return preg_replace_callback(
'/\b([\w\x80-\xff]+)\b/',
return $s;
}
- $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
- '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
+ if ( function_exists( 'mb_check_encoding' ) ) {
+ $isutf8 = mb_check_encoding( $s, 'UTF-8' );
+ } else {
+ $isutf8 = preg_match( '/^(?>[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
+ '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
+ }
if ( $isutf8 ) {
return $s;
}