MDL-10937 upgraded html purifier to 2.1.1
This commit is contained in:
@@ -3,6 +3,14 @@
|
||||
require_once 'HTMLPurifier/Language.php';
|
||||
require_once 'HTMLPurifier/AttrDef/Lang.php';
|
||||
|
||||
HTMLPurifier_ConfigSchema::define(
|
||||
'Core', 'Language', 'en', 'string', '
|
||||
ISO 639 language code for localizable things in HTML Purifier to use,
|
||||
which is mainly error reporting. There is currently only an English (en)
|
||||
translation, so this directive is currently useless.
|
||||
This directive has been available since 2.0.0.
|
||||
');
|
||||
|
||||
/**
|
||||
* Class responsible for generating HTMLPurifier_Language objects, managing
|
||||
* caching and fallbacks.
|
||||
@@ -24,7 +32,7 @@ class HTMLPurifier_LanguageFactory
|
||||
* variables to slurp out of a message file.
|
||||
* @value array list
|
||||
*/
|
||||
var $keys = array('fallback', 'messages');
|
||||
var $keys = array('fallback', 'messages', 'errorNames');
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_AttrDef_Lang to validate language codes
|
||||
@@ -43,7 +51,7 @@ class HTMLPurifier_LanguageFactory
|
||||
* Keys whose contents are a hash map and can be merged
|
||||
* @value array lookup
|
||||
*/
|
||||
var $mergeable_keys_map = array('messages' => true);
|
||||
var $mergeable_keys_map = array('messages' => true, 'errorNames' => true);
|
||||
|
||||
/**
|
||||
* Keys whose contents are a list and can be merged
|
||||
@@ -74,17 +82,20 @@ class HTMLPurifier_LanguageFactory
|
||||
*/
|
||||
function setup() {
|
||||
$this->validator = new HTMLPurifier_AttrDef_Lang();
|
||||
$this->dir = dirname(__FILE__);
|
||||
$this->dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a language object, handles class fallbacks
|
||||
* @param $code string language code
|
||||
* @param $config Instance of HTMLPurifier_Config
|
||||
* @param $context Instance of HTMLPurifier_Context
|
||||
*/
|
||||
function create($code) {
|
||||
function create($config, &$context) {
|
||||
|
||||
$config = $context = false; // hope it doesn't use these!
|
||||
$code = $this->validator->validate($code, $config, $context);
|
||||
// validate language code
|
||||
$code = $this->validator->validate(
|
||||
$config->get('Core', 'Language'), $config, $context
|
||||
);
|
||||
if ($code === false) $code = 'en'; // malformed code becomes English
|
||||
|
||||
$pcode = str_replace('-', '_', $code); // make valid PHP classname
|
||||
@@ -100,18 +111,18 @@ class HTMLPurifier_LanguageFactory
|
||||
// you can bypass the conditional include by loading the
|
||||
// file yourself
|
||||
if (file_exists($file) && !class_exists($class)) {
|
||||
include_once $file;
|
||||
}
|
||||
include_once $file;
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
// go fallback
|
||||
$fallback = HTMLPurifier_Language::getFallbackFor($code);
|
||||
$fallback = HTMLPurifier_LanguageFactory::getFallbackFor($code);
|
||||
$depth++;
|
||||
$lang = Language::factory( $fallback );
|
||||
$lang = HTMLPurifier_LanguageFactory::factory( $fallback );
|
||||
$depth--;
|
||||
} else {
|
||||
$lang = new $class;
|
||||
$lang = new $class($config, $context);
|
||||
}
|
||||
$lang->code = $code;
|
||||
|
||||
@@ -172,15 +183,15 @@ class HTMLPurifier_LanguageFactory
|
||||
|
||||
// merge fallback with current language
|
||||
foreach ( $this->keys as $key ) {
|
||||
if (isset($cache[$key]) && isset($fallback_cache[$key])) {
|
||||
if (isset($cache[$key]) && isset($fallback_cache[$key])) {
|
||||
if (isset($this->mergeable_keys_map[$key])) {
|
||||
$cache[$key] = $cache[$key] + $fallback_cache[$key];
|
||||
} elseif (isset($this->mergeable_keys_list[$key])) {
|
||||
$cache[$key] = array_merge( $fallback_cache[$key], $cache[$key] );
|
||||
}
|
||||
} else {
|
||||
$cache[$key] = $fallback_cache[$key];
|
||||
}
|
||||
} else {
|
||||
$cache[$key] = $fallback_cache[$key];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -193,4 +204,3 @@ class HTMLPurifier_LanguageFactory
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user