MDL-22537 new html purifier backported to stable, unfortunately PHP5 only
This commit is contained in:
@@ -1,58 +1,60 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/LanguageFactory.php';
|
||||
|
||||
/**
|
||||
* Represents a language and defines localizable string formatting and
|
||||
* other functions, as well as the localized messages for HTML Purifier.
|
||||
*/
|
||||
class HTMLPurifier_Language
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* ISO 639 language code of language. Prefers shortest possible version
|
||||
*/
|
||||
var $code = 'en';
|
||||
|
||||
public $code = 'en';
|
||||
|
||||
/**
|
||||
* Fallback language code
|
||||
*/
|
||||
var $fallback = false;
|
||||
|
||||
public $fallback = false;
|
||||
|
||||
/**
|
||||
* Array of localizable messages
|
||||
*/
|
||||
var $messages = array();
|
||||
|
||||
public $messages = array();
|
||||
|
||||
/**
|
||||
* Array of localizable error codes
|
||||
*/
|
||||
var $errorNames = array();
|
||||
|
||||
public $errorNames = array();
|
||||
|
||||
/**
|
||||
* True if no message file was found for this language, so English
|
||||
* is being used instead. Check this if you'd like to notify the
|
||||
* user that they've used a non-supported language.
|
||||
*/
|
||||
var $error = false;
|
||||
|
||||
public $error = false;
|
||||
|
||||
/**
|
||||
* Has the language object been loaded yet?
|
||||
* @private
|
||||
* @todo Make it private, fix usage in HTMLPurifier_LanguageTest
|
||||
*/
|
||||
var $_loaded = false;
|
||||
|
||||
public $_loaded = false;
|
||||
|
||||
/**
|
||||
* Instances of HTMLPurifier_Config and HTMLPurifier_Context
|
||||
*/
|
||||
var $config, $context;
|
||||
|
||||
function HTMLPurifier_Language($config, &$context) {
|
||||
protected $config, $context;
|
||||
|
||||
public function __construct($config, $context) {
|
||||
$this->config = $config;
|
||||
$this->context =& $context;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads language object with necessary info from factory cache
|
||||
* @note This is a lazy loader
|
||||
*/
|
||||
function load() {
|
||||
public function load() {
|
||||
if ($this->_loaded) return;
|
||||
$factory = HTMLPurifier_LanguageFactory::instance();
|
||||
$factory->loadLanguage($this->code);
|
||||
@@ -61,34 +63,34 @@ class HTMLPurifier_Language
|
||||
}
|
||||
$this->_loaded = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a localised message.
|
||||
* @param $key string identifier of message
|
||||
* @return string localised message
|
||||
*/
|
||||
function getMessage($key) {
|
||||
public function getMessage($key) {
|
||||
if (!$this->_loaded) $this->load();
|
||||
if (!isset($this->messages[$key])) return "[$key]";
|
||||
return $this->messages[$key];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a localised error name.
|
||||
* @param $int integer error number, corresponding to PHP's error
|
||||
* reporting
|
||||
* @return string localised message
|
||||
*/
|
||||
function getErrorName($int) {
|
||||
public function getErrorName($int) {
|
||||
if (!$this->_loaded) $this->load();
|
||||
if (!isset($this->errorNames[$int])) return "[Error: $int]";
|
||||
return $this->errorNames[$int];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts an array list into a string readable representation
|
||||
*/
|
||||
function listify($array) {
|
||||
public function listify($array) {
|
||||
$sep = $this->getMessage('Item separator');
|
||||
$sep_last = $this->getMessage('Item separator last');
|
||||
$ret = '';
|
||||
@@ -103,7 +105,7 @@ class HTMLPurifier_Language
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formats a localised message with passed parameters
|
||||
* @param $key string identifier of message
|
||||
@@ -112,7 +114,7 @@ class HTMLPurifier_Language
|
||||
* @todo Implement conditionals? Right now, some messages make
|
||||
* reference to line numbers, but those aren't always available
|
||||
*/
|
||||
function formatMessage($key, $args = array()) {
|
||||
public function formatMessage($key, $args = array()) {
|
||||
if (!$this->_loaded) $this->load();
|
||||
if (!isset($this->messages[$key])) return "[$key]";
|
||||
$raw = $this->messages[$key];
|
||||
@@ -120,18 +122,18 @@ class HTMLPurifier_Language
|
||||
$generator = false;
|
||||
foreach ($args as $i => $value) {
|
||||
if (is_object($value)) {
|
||||
if (is_a($value, 'HTMLPurifier_Token')) {
|
||||
if ($value instanceof HTMLPurifier_Token) {
|
||||
// factor this out some time
|
||||
if (!$generator) $generator = $this->context->get('Generator');
|
||||
if (isset($value->name)) $subst['$'.$i.'.Name'] = $value->name;
|
||||
if (isset($value->data)) $subst['$'.$i.'.Data'] = $value->data;
|
||||
$subst['$'.$i.'.Compact'] =
|
||||
$subst['$'.$i.'.Compact'] =
|
||||
$subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value);
|
||||
// a more complex algorithm for compact representation
|
||||
// could be introduced for all types of tokens. This
|
||||
// may need to be factored out into a dedicated class
|
||||
if (!empty($value->attr)) {
|
||||
$stripped_token = $value->copy();
|
||||
$stripped_token = clone $value;
|
||||
$stripped_token->attr = array();
|
||||
$subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token);
|
||||
}
|
||||
@@ -155,6 +157,7 @@ class HTMLPurifier_Language
|
||||
}
|
||||
return strtr($raw, $subst);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
||||
Reference in New Issue
Block a user