$url = Sanitizer::decodeCharReferences( $url );
# Escape any control characters introduced by the above step
- $url = preg_replace( '/[\][<>"\\x00-\\x20\\x7F\|]/e', "urlencode('\\0')", $url );
+ $url = preg_replace_callback( '/[\][<>"\\x00-\\x20\\x7F\|]/',
+ array( __CLASS__, 'cleanUrlCallback' ), $url );
# Validate hostname portion
$matches = array();
}
}
+ static function cleanUrlCallback( $matches ) {
+ return urlencode( $matches[0] );
+ }
}
return $string;
}
$out = "=?$charset?Q?";
- $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
+ $out .= preg_replace_callback( "/([$replace])/",
+ array( __CLASS__, 'quotedPrintableCallback' ), $string );
$out .= '?=';
return $out;
}
+
+ protected static function quotedPrintableCallback( $matches ) {
+ return sprintf( "=%02X", ord( $matches[1] ) );
+ }
}
/**
* @ingroup Parser
*/
class PPNode_DOM implements PPNode {
- var $node;
+ var $node, $xpath;
function __construct( $node, $xpath = false ) {
$this->node = $node;
}
- function __get( $name ) {
- if ( $name == 'xpath' ) {
+ function getXPath() {
+ if ( $this->xpath === null ) {
$this->xpath = new DOMXPath( $this->node->ownerDocument );
}
return $this->xpath;
}
function getChildrenOfType( $type ) {
- return new self( $this->xpath->query( $type, $this->node ) );
+ return new self( $this->getXPath()->query( $type, $this->node ) );
}
function getLength() {
* value PPNode value
*/
function splitArg() {
- $names = $this->xpath->query( 'name', $this->node );
- $values = $this->xpath->query( 'value', $this->node );
+ $xpath = $this->getXPath();
+ $names = $xpath->query( 'name', $this->node );
+ $values = $xpath->query( 'value', $this->node );
if ( !$names->length || !$values->length ) {
throw new MWException( 'Invalid brace node passed to ' . __METHOD__ );
}
* All values in the resulting array are PPNodes. Inner and close are optional.
*/
function splitExt() {
- $names = $this->xpath->query( 'name', $this->node );
- $attrs = $this->xpath->query( 'attr', $this->node );
- $inners = $this->xpath->query( 'inner', $this->node );
- $closes = $this->xpath->query( 'close', $this->node );
+ $xpath = $this->getXPath();
+ $names = $xpath->query( 'name', $this->node );
+ $attrs = $xpath->query( 'attr', $this->node );
+ $inners = $xpath->query( 'inner', $this->node );
+ $closes = $xpath->query( 'close', $this->node );
if ( !$names->length || !$attrs->length ) {
throw new MWException( 'Invalid ext node passed to ' . __METHOD__ );
}
* Split a <h> node
*/
function splitHeading() {
- if ( !$this->nodeName == 'h' ) {
+ if ( $this->getName() !== 'h' ) {
throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
}
return array(