MDL-22537 new html purifier backported to stable, unfortunately PHP5 only
This commit is contained in:
@@ -5,16 +5,18 @@
|
||||
* HTMLPurifier_HTMLDefinition and HTMLPurifier_HTMLModule.
|
||||
* @note This class is inspected by HTMLPurifier_Printer_HTMLDefinition.
|
||||
* Please update that class too.
|
||||
* @warning If you add new properties to this class, you MUST update
|
||||
* the mergeIn() method.
|
||||
*/
|
||||
class HTMLPurifier_ElementDef
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Does the definition work by itself, or is it created solely
|
||||
* for the purpose of merging into another definition?
|
||||
*/
|
||||
var $standalone = true;
|
||||
|
||||
public $standalone = true;
|
||||
|
||||
/**
|
||||
* Associative array of attribute name to HTMLPurifier_AttrDef
|
||||
* @note Before being processed by HTMLPurifier_AttrCollections
|
||||
@@ -25,68 +27,58 @@ class HTMLPurifier_ElementDef
|
||||
* contain string indentifiers in lieu of HTMLPurifier_AttrDef,
|
||||
* see HTMLPurifier_AttrTypes on how they are expanded during
|
||||
* HTMLPurifier_HTMLDefinition->setup() processing.
|
||||
* @public
|
||||
*/
|
||||
var $attr = array();
|
||||
|
||||
public $attr = array();
|
||||
|
||||
/**
|
||||
* Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation
|
||||
* @public
|
||||
*/
|
||||
var $attr_transform_pre = array();
|
||||
|
||||
public $attr_transform_pre = array();
|
||||
|
||||
/**
|
||||
* Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation
|
||||
* @public
|
||||
*/
|
||||
var $attr_transform_post = array();
|
||||
|
||||
|
||||
|
||||
public $attr_transform_post = array();
|
||||
|
||||
/**
|
||||
* HTMLPurifier_ChildDef of this tag.
|
||||
* @public
|
||||
*/
|
||||
var $child;
|
||||
|
||||
public $child;
|
||||
|
||||
/**
|
||||
* Abstract string representation of internal ChildDef rules. See
|
||||
* HTMLPurifier_ContentSets for how this is parsed and then transformed
|
||||
* into an HTMLPurifier_ChildDef.
|
||||
* @warning This is a temporary variable that is not available after
|
||||
* being processed by HTMLDefinition
|
||||
* @public
|
||||
*/
|
||||
var $content_model;
|
||||
|
||||
public $content_model;
|
||||
|
||||
/**
|
||||
* Value of $child->type, used to determine which ChildDef to use,
|
||||
* used in combination with $content_model.
|
||||
* @warning This must be lowercase
|
||||
* @warning This is a temporary variable that is not available after
|
||||
* being processed by HTMLDefinition
|
||||
* @public
|
||||
*/
|
||||
var $content_model_type;
|
||||
|
||||
|
||||
|
||||
public $content_model_type;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Does the element have a content model (#PCDATA | Inline)*? This
|
||||
* is important for chameleon ins and del processing in
|
||||
* is important for chameleon ins and del processing in
|
||||
* HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't
|
||||
* have to worry about this one.
|
||||
* @public
|
||||
*/
|
||||
var $descendants_are_inline = false;
|
||||
|
||||
public $descendants_are_inline = false;
|
||||
|
||||
/**
|
||||
* List of the names of required attributes this element has. Dynamically
|
||||
* populated by HTMLPurifier_HTMLDefinition::getElement
|
||||
* @public
|
||||
*/
|
||||
var $required_attr = array();
|
||||
|
||||
public $required_attr = array();
|
||||
|
||||
/**
|
||||
* Lookup table of tags excluded from all descendants of this tag.
|
||||
* @note SGML permits exclusions for all descendants, but this is
|
||||
@@ -97,35 +89,45 @@ class HTMLPurifier_ElementDef
|
||||
* all descendants and not just children. Note that the XHTML
|
||||
* Modularization Abstract Modules are blithely unaware of such
|
||||
* distinctions.
|
||||
* @public
|
||||
*/
|
||||
var $excludes = array();
|
||||
|
||||
public $excludes = array();
|
||||
|
||||
/**
|
||||
* Is this element safe for untrusted users to use?
|
||||
* This tag is explicitly auto-closed by the following tags.
|
||||
*/
|
||||
var $safe;
|
||||
|
||||
public $autoclose = array();
|
||||
|
||||
/**
|
||||
* If a foreign element is found in this element, test if it is
|
||||
* allowed by this sub-element; if it is, instead of closing the
|
||||
* current element, place it inside this element.
|
||||
*/
|
||||
public $wrap;
|
||||
|
||||
/**
|
||||
* Whether or not this is a formatting element affected by the
|
||||
* "Active Formatting Elements" algorithm.
|
||||
*/
|
||||
public $formatting;
|
||||
|
||||
/**
|
||||
* Low-level factory constructor for creating new standalone element defs
|
||||
* @static
|
||||
*/
|
||||
function create($safe, $content_model, $content_model_type, $attr) {
|
||||
public static function create($content_model, $content_model_type, $attr) {
|
||||
$def = new HTMLPurifier_ElementDef();
|
||||
$def->safe = (bool) $safe;
|
||||
$def->content_model = $content_model;
|
||||
$def->content_model_type = $content_model_type;
|
||||
$def->attr = $attr;
|
||||
return $def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merges the values of another element definition into this one.
|
||||
* Values from the new element def take precedence if a value is
|
||||
* not mergeable.
|
||||
*/
|
||||
function mergeIn($def) {
|
||||
|
||||
public function mergeIn($def) {
|
||||
|
||||
// later keys takes precedence
|
||||
foreach($def->attr as $k => $v) {
|
||||
if ($k === 0) {
|
||||
@@ -145,9 +147,10 @@ class HTMLPurifier_ElementDef
|
||||
$this->_mergeAssocArray($this->attr_transform_pre, $def->attr_transform_pre);
|
||||
$this->_mergeAssocArray($this->attr_transform_post, $def->attr_transform_post);
|
||||
$this->_mergeAssocArray($this->excludes, $def->excludes);
|
||||
|
||||
|
||||
if(!empty($def->content_model)) {
|
||||
$this->content_model .= ' | ' . $def->content_model;
|
||||
$this->content_model =
|
||||
str_replace("#SUPER", $this->content_model, $def->content_model);
|
||||
$this->child = false;
|
||||
}
|
||||
if(!empty($def->content_model_type)) {
|
||||
@@ -155,17 +158,17 @@ class HTMLPurifier_ElementDef
|
||||
$this->child = false;
|
||||
}
|
||||
if(!is_null($def->child)) $this->child = $def->child;
|
||||
if(!is_null($def->formatting)) $this->formatting = $def->formatting;
|
||||
if($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline;
|
||||
if(!is_null($def->safe)) $this->safe = $def->safe;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merges one array into another, removes values which equal false
|
||||
* @param $a1 Array by reference that is merged into
|
||||
* @param $a2 Array that merges into $a1
|
||||
*/
|
||||
function _mergeAssocArray(&$a1, $a2) {
|
||||
private function _mergeAssocArray(&$a1, $a2) {
|
||||
foreach ($a2 as $k => $v) {
|
||||
if ($v === false) {
|
||||
if (isset($a1[$k])) unset($a1[$k]);
|
||||
@@ -174,14 +177,7 @@ class HTMLPurifier_ElementDef
|
||||
$a1[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a copy of the element definition
|
||||
*/
|
||||
function copy() {
|
||||
return unserialize(serialize($this));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
||||
Reference in New Issue
Block a user