MDL-17099 htmlpurifier: new version from upstream
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
* This enables "formatter-like" functionality such as auto-paragraphing,
|
||||
* smiley-ification and linkification to take place.
|
||||
*
|
||||
* A note on how handlers create changes; this is done by assigning a new
|
||||
* value to the $token reference. These values can take a variety of forms and
|
||||
* are best described HTMLPurifier_Strategy_MakeWellFormed->processToken()
|
||||
* documentation.
|
||||
*
|
||||
* @todo Allow injectors to request a re-run on their output. This
|
||||
* would help if an operation is recursive.
|
||||
*/
|
||||
@@ -16,13 +21,6 @@ abstract class HTMLPurifier_Injector
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Amount of tokens the injector needs to skip + 1. Because
|
||||
* the decrement is the first thing that happens, this needs to
|
||||
* be one greater than the "real" skip count.
|
||||
*/
|
||||
public $skip = 1;
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_HTMLDefinition
|
||||
*/
|
||||
@@ -54,6 +52,32 @@ abstract class HTMLPurifier_Injector
|
||||
*/
|
||||
public $needed = array();
|
||||
|
||||
/**
|
||||
* Index of inputTokens to rewind to.
|
||||
*/
|
||||
protected $rewind = false;
|
||||
|
||||
/**
|
||||
* Rewind to a spot to re-perform processing. This is useful if you
|
||||
* deleted a node, and now need to see if this change affected any
|
||||
* earlier nodes. Rewinding does not affect other injectors, and can
|
||||
* result in infinite loops if not used carefully.
|
||||
* @warning HTML Purifier will prevent you from fast-forwarding with this
|
||||
* function.
|
||||
*/
|
||||
public function rewind($index) {
|
||||
$this->rewind = $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves rewind, and then unsets it.
|
||||
*/
|
||||
public function getRewind() {
|
||||
$r = $this->rewind;
|
||||
$this->rewind = false;
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the injector by giving it the config and context objects:
|
||||
* this allows references to important variables to be made within
|
||||
@@ -116,6 +140,69 @@ abstract class HTMLPurifier_Injector
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator function, which starts with the next token and continues until
|
||||
* you reach the end of the input tokens.
|
||||
* @warning Please prevent previous references from interfering with this
|
||||
* functions by setting $i = null beforehand!
|
||||
* @param &$i Current integer index variable for inputTokens
|
||||
* @param &$current Current token variable. Do NOT use $token, as that variable is also a reference
|
||||
*/
|
||||
protected function forward(&$i, &$current) {
|
||||
if ($i === null) $i = $this->inputIndex + 1;
|
||||
else $i++;
|
||||
if (!isset($this->inputTokens[$i])) return false;
|
||||
$current = $this->inputTokens[$i];
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to _forward, but accepts a third parameter $nesting (which
|
||||
* should be initialized at 0) and stops when we hit the end tag
|
||||
* for the node $this->inputIndex starts in.
|
||||
*/
|
||||
protected function forwardUntilEndToken(&$i, &$current, &$nesting) {
|
||||
$result = $this->forward($i, $current);
|
||||
if (!$result) return false;
|
||||
if ($nesting === null) $nesting = 0;
|
||||
if ($current instanceof HTMLPurifier_Token_Start) $nesting++;
|
||||
elseif ($current instanceof HTMLPurifier_Token_End) {
|
||||
if ($nesting <= 0) return false;
|
||||
$nesting--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator function, starts with the previous token and continues until
|
||||
* you reach the beginning of input tokens.
|
||||
* @warning Please prevent previous references from interfering with this
|
||||
* functions by setting $i = null beforehand!
|
||||
* @param &$i Current integer index variable for inputTokens
|
||||
* @param &$current Current token variable. Do NOT use $token, as that variable is also a reference
|
||||
*/
|
||||
protected function backward(&$i, &$current) {
|
||||
if ($i === null) $i = $this->inputIndex - 1;
|
||||
else $i--;
|
||||
if ($i < 0) return false;
|
||||
$current = $this->inputTokens[$i];
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the iterator at the current position. Use in a do {} while;
|
||||
* loop to force the _forward and _backward functions to start at the
|
||||
* current location.
|
||||
* @warning Please prevent previous references from interfering with this
|
||||
* functions by setting $i = null beforehand!
|
||||
* @param &$i Current integer index variable for inputTokens
|
||||
* @param &$current Current token variable. Do NOT use $token, as that variable is also a reference
|
||||
*/
|
||||
protected function current(&$i, &$current) {
|
||||
if ($i === null) $i = $this->inputIndex;
|
||||
$current = $this->inputTokens[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler that is called when a text token is processed
|
||||
*/
|
||||
@@ -126,9 +213,17 @@ abstract class HTMLPurifier_Injector
|
||||
*/
|
||||
public function handleElement(&$token) {}
|
||||
|
||||
/**
|
||||
* Handler that is called when an end token is processed
|
||||
*/
|
||||
public function handleEnd(&$token) {
|
||||
$this->notifyEnd($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifier that is called when an end token is processed
|
||||
* @note This differs from handlers in that the token is read-only
|
||||
* @deprecated
|
||||
*/
|
||||
public function notifyEnd($token) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user