Go to the documentation of this file.
68 'processing_instruction_handler' =>
'',
69 'external_dtd_handler' =>
'',
71 'require_safe_dtd' =>
true
101 $this->filterCallback = $filterCallback;
102 $this->parserOptions = array_merge( $this->parserOptions,
$options );
118 return new self(
$fname, $filterCallback,
true );
133 return new self( $string, $filterCallback,
false );
150 $reader =
new XMLReader();
152 $s = $reader->open( $xml,
null, LIBXML_NOERROR | LIBXML_NOWARNING );
154 $s = $reader->XML( $xml,
null, LIBXML_NOERROR | LIBXML_NOWARNING );
158 $this->wellFormed =
false;
160 $oldDisable = libxml_disable_entity_loader(
true );
161 $reader->setParserProperty( XMLReader::SUBST_ENTITIES,
true );
164 }
catch ( Exception
$e ) {
167 $this->wellFormed =
false;
169 libxml_disable_entity_loader( $oldDisable );
173 libxml_disable_entity_loader( $oldDisable );
178 set_error_handler(
array( $this,
'XmlErrorHandler' ) );
179 $ret = $reader->read();
180 restore_error_handler();
185 $this->wellFormed =
false;
195 $this->wellFormed =
false;
198 if ( $reader->nodeType === XMLReader::PI ) {
201 if ( $reader->nodeType === XMLReader::DOC_TYPE ) {
204 }
while ( $reader->nodeType != XMLReader::ELEMENT );
208 switch ( $reader->nodeType ) {
209 case XMLReader::ELEMENT:
212 $reader->namespaceURI
214 if ( $this->rootElement ===
'' ) {
215 $this->rootElement =
$name;
217 $empty = $reader->isEmptyElement;
225 case XMLReader::END_ELEMENT:
230 case XMLReader::SIGNIFICANT_WHITESPACE:
231 case XMLReader::CDATA:
232 case XMLReader::TEXT:
236 case XMLReader::ENTITY_REF:
252 case XMLReader::DOC_TYPE:
255 $this->wellFormed =
false;
263 }
while ( $this->
readNext( $reader ) );
265 if ( $this->stackDepth !== 0 ) {
266 $this->wellFormed =
false;
267 } elseif ( $this->wellFormed ===
null ) {
268 $this->wellFormed =
true;
280 while ( $r->moveToNextAttribute() ) {
281 if ( $r->namespaceURI ===
'http://www.w3.org/2000/xmlns/' ) {
287 $attrs[
$name] = $r->value;
298 if ( $namespaceURI ) {
299 $parts = explode(
':',
$name );
300 $localname = array_pop( $parts );
301 return "$namespaceURI:$localname";
323 if ( is_callable( $this->filterCallback )
325 $this->filterCallback,
332 $this->filterMatch =
true;
341 $this->
elementData[ $this->stackDepth - 1 ] .= trim( $data );
349 if ( $this->parserOptions[
'processing_instruction_handler'] ) {
351 $this->parserOptions[
'processing_instruction_handler'],
356 $this->filterMatch =
true;
366 $externalCallback = $this->parserOptions[
'external_dtd_handler'];
367 $generalCallback = $this->parserOptions[
'dtd_handler'];
368 $checkIfSafe = $this->parserOptions[
'require_safe_dtd'];
369 if ( !$externalCallback && !$generalCallback && !$checkIfSafe ) {
372 $dtd = $reader->readOuterXML();
373 $callbackReturn =
false;
375 if ( $generalCallback ) {
376 $callbackReturn = call_user_func( $generalCallback, $dtd );
378 if ( $callbackReturn ) {
380 $this->filterMatch =
true;
381 $this->filterMatchType = $callbackReturn;
382 $callbackReturn =
false;
385 $parsedDTD = $this->
parseDTD( $dtd );
386 if ( $externalCallback && isset( $parsedDTD[
'type'] ) ) {
387 $callbackReturn = call_user_func(
390 isset( $parsedDTD[
'publicid'] ) ? $parsedDTD[
'publicid'] :
null,
391 isset( $parsedDTD[
'systemid'] ) ? $parsedDTD[
'systemid'] :
null
394 if ( $callbackReturn ) {
396 $this->filterMatch =
true;
397 $this->filterMatchType = $callbackReturn;
398 $callbackReturn =
false;
401 if ( $checkIfSafe && isset( $parsedDTD[
'internal'] ) ) {
403 $this->wellFormed =
false;
431 '/^(?:\s*<!ENTITY\s+\S+\s+' .
432 '(?:"(?:&[^"%&;]{1,64};|(?:[^"%&]|&|"){0,255})"' .
433 '|\'(?:&[^"%&;]{1,64};|(?:[^\'%&]|&|'){0,255})\')\s*>' .
434 '|\s*<!--(?:[^-]|-[^-])*-->' .
435 '|\s*<!ATTLIST svg xmlns:xlink CDATA #FIXED ' .
436 '"http:\/\/www.w3.org\/1999\/xlink">)*\s*$/',
454 '/^<!DOCTYPE\s*\S+\s*' .
455 '(?:(?P<typepublic>PUBLIC)\s*' .
456 '(?:"(?P<pubquote>[^"]*)"|\'(?P<pubapos>[^\']*)\')' .
457 '\s*"(?P<pubsysquote>[^"]*)"|\'(?P<pubsysapos>[^\']*)\'' .
458 '|(?P<typesystem>SYSTEM)\s*' .
459 '(?:"(?P<sysquote>[^"]*)"|\'(?P<sysapos>[^\']*)\')' .
461 '(?:\[\s*(?P<internal>.*)\])?\s*>$/s',
466 $this->wellFormed =
false;
470 foreach ( $m
as $field =>
$value ) {
471 if (
$value ===
'' || is_numeric( $field ) ) {
481 $parsed[
'publicid'] =
$value;
487 $parsed[
'systemid'] =
$value;
490 $parsed[
'internal'] =
$value;
$filterMatch
Will be set to true if the optional element filter returned a match at some point.
parseDTD( $dtd)
Parse DTD into parts.
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
static newFromString( $string, $filterCallback=null)
Alternative constructor: from string.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
__construct( $input, $filterCallback=null, $isFile=true, $options=array())
Allow filtering an XML file.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
static newFromFilename( $fname, $filterCallback=null)
Alternative constructor: from filename.
$rootElement
Name of the document's root element, including any namespace as an expanded URL.
expandNS( $name, $namespaceURI)
getAttributesArray(XMLReader $r)
Get all of the attributes for an XMLReader's current node.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
$elementData
A stack of strings containing the data of each xml element as it's processed.
$elementDataContext
A stack of element names and attributes, as we process them.
XmlErrorHandler( $errno, $errstr)
DTDHandler(XMLReader $reader)
Handle coming across a <!DOCTYPE declaration.
$wellFormed
Will be set to true or false to indicate whether the file is well-formed XML.
readNext(XMLReader $reader)
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
processing should stop and the error should be shown to the user * false
$parserOptions
Additional parsing options.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
$stackDepth
Current depth of the data stack.
Allows to change the fields on the form that will be generated $name
getRootElement()
Get the root element.
elementOpen( $name, $attribs)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
processingInstructionHandler( $target, $data)
validateFromInput( $xml, $isFile)
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
checkDTDIsSafe( $internalSubset)
Check if the internal subset of the DTD is safe.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e