75 'processing_instruction_handler' =>
'',
76 'external_dtd_handler' =>
'',
78 'require_safe_dtd' =>
true
108 $this->filterCallback = $filterCallback;
109 $this->parserOptions = array_merge( $this->parserOptions,
$options );
125 return new self(
$fname, $filterCallback,
true );
140 return new self( $string, $filterCallback,
false );
156 $reader =
new XMLReader();
158 $s = $reader->open( $xml,
null, LIBXML_NOERROR | LIBXML_NOWARNING );
160 $s = $reader->XML( $xml,
null, LIBXML_NOERROR | LIBXML_NOWARNING );
164 $this->wellFormed =
false;
166 $oldDisable = libxml_disable_entity_loader(
true );
167 $reader->setParserProperty( XMLReader::SUBST_ENTITIES,
true );
170 }
catch ( Exception
$e ) {
173 $this->wellFormed =
false;
175 libxml_disable_entity_loader( $oldDisable );
179 libxml_disable_entity_loader( $oldDisable );
184 set_error_handler( [ $this,
'XmlErrorHandler' ] );
185 $ret = $reader->read();
186 restore_error_handler();
191 $this->wellFormed =
false;
198 if ( !$this->
readNext( $reader ) ) {
200 $this->wellFormed =
false;
203 if ( $reader->nodeType === XMLReader::PI ) {
206 if ( $reader->nodeType === XMLReader::DOC_TYPE ) {
209 }
while ( $reader->nodeType != XMLReader::ELEMENT );
213 switch ( $reader->nodeType ) {
214 case XMLReader::ELEMENT:
217 $reader->namespaceURI
219 if ( $this->rootElement ===
'' ) {
220 $this->rootElement =
$name;
222 $empty = $reader->isEmptyElement;
230 case XMLReader::END_ELEMENT:
234 case XMLReader::WHITESPACE:
235 case XMLReader::SIGNIFICANT_WHITESPACE:
236 case XMLReader::CDATA:
237 case XMLReader::TEXT:
241 case XMLReader::ENTITY_REF:
246 case XMLReader::COMMENT:
257 case XMLReader::DOC_TYPE:
260 $this->wellFormed =
false;
267 }
while ( $this->
readNext( $reader ) );
269 if ( $this->stackDepth !== 0 ) {
270 $this->wellFormed =
false;
271 } elseif ( $this->wellFormed ===
null ) {
272 $this->wellFormed =
true;
283 while ( $r->moveToNextAttribute() ) {
284 if ( $r->namespaceURI ===
'http://www.w3.org/2000/xmlns/' ) {
290 $attrs[
$name] = $r->value;
300 private function expandNS( $name, $namespaceURI ) {
301 if ( $namespaceURI ) {
302 $parts = explode(
':',
$name );
303 $localname = array_pop( $parts );
304 return "$namespaceURI:$localname";
323 $callbackReturn =
false;
325 if ( is_callable( $this->filterCallback ) ) {
326 $callbackReturn = call_user_func(
327 $this->filterCallback,
333 if ( $callbackReturn ) {
335 $this->filterMatch =
true;
336 $this->filterMatchType = $callbackReturn;
345 $this->
elementData[ $this->stackDepth - 1 ] .= trim( $data );
353 $callbackReturn =
false;
354 if ( $this->parserOptions[
'processing_instruction_handler'] ) {
355 $callbackReturn = call_user_func(
356 $this->parserOptions[
'processing_instruction_handler'],
361 if ( $callbackReturn ) {
363 $this->filterMatch =
true;
364 $this->filterMatchType = $callbackReturn;
373 $externalCallback = $this->parserOptions[
'external_dtd_handler'];
374 $generalCallback = $this->parserOptions[
'dtd_handler'];
375 $checkIfSafe = $this->parserOptions[
'require_safe_dtd'];
376 if ( !$externalCallback && !$generalCallback && !$checkIfSafe ) {
379 $dtd = $reader->readOuterXML();
380 $callbackReturn =
false;
382 if ( $generalCallback ) {
383 $callbackReturn = call_user_func( $generalCallback, $dtd );
385 if ( $callbackReturn ) {
387 $this->filterMatch =
true;
388 $this->filterMatchType = $callbackReturn;
389 $callbackReturn =
false;
392 $parsedDTD = $this->
parseDTD( $dtd );
393 if ( $externalCallback && isset( $parsedDTD[
'type'] ) ) {
394 $callbackReturn = call_user_func(
397 isset( $parsedDTD[
'publicid'] ) ? $parsedDTD[
'publicid'] :
null,
398 isset( $parsedDTD[
'systemid'] ) ? $parsedDTD[
'systemid'] : null
401 if ( $callbackReturn ) {
403 $this->filterMatch =
true;
404 $this->filterMatchType = $callbackReturn;
405 $callbackReturn =
false;
408 if ( $checkIfSafe && isset( $parsedDTD[
'internal'] ) ) {
410 $this->wellFormed =
false;
438 '/^(?:\s*<!ENTITY\s+\S+\s+' .
439 '(?:"(?:&[^"%&;]{1,64};|(?:[^"%&]|&|"){0,255})"' .
440 '|\'(?:&[^"%&;]{1,64};|(?:[^\'%&]|&|'){0,255})\')\s*>' .
441 '|\s*<!--(?:[^-]|-[^-])*-->' .
442 '|\s*<!ATTLIST svg xmlns:xlink CDATA #FIXED ' .
443 '"http:\/\/www.w3.org\/1999\/xlink">)*\s*$/',
461 '/^<!DOCTYPE\s*\S+\s*' .
462 '(?:(?P<typepublic>PUBLIC)\s*' .
463 '(?:"(?P<pubquote>[^"]*)"|\'(?P<pubapos>[^\']*)\')' .
464 '\s*"(?P<pubsysquote>[^"]*)"|\'(?P<pubsysapos>[^\']*)\'' .
465 '|(?P<typesystem>SYSTEM)\s*' .
466 '(?:"(?P<sysquote>[^"]*)"|\'(?P<sysapos>[^\']*)\')' .
468 '(?:\[\s*(?P<internal>.*)\])?\s*>$/s',
473 $this->wellFormed =
false;
477 foreach ( $m
as $field =>
$value ) {
478 if (
$value ===
'' || is_numeric( $field ) ) {
488 $parsed[
'publicid'] =
$value;
494 $parsed[
'systemid'] =
$value;
497 $parsed[
'internal'] =
$value;
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
getRootElement()
Get the root element.
__construct( $input, $filterCallback=null, $isFile=true, $options=[])
Allow filtering an XML file.
parseDTD( $dtd)
Parse DTD into parts.
$elementDataContext
A stack of element names and attributes, as we process them.
$rootElement
Name of the document's root element, including any namespace as an expanded URL.
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.
static newFromFilename( $fname, $filterCallback=null)
Alternative constructor: from filename.
readNext(XMLReader $reader)
$elementData
A stack of strings containing the data of each xml element as it's processed.
elementOpen( $name, $attribs)
validateFromInput( $xml, $isFile)
mixed $filterMatchType
Will contain the type of filter hit if the optional element filter returned a match at some point.
XmlErrorHandler( $errno, $errstr)
$filterMatch
Will be set to true if the optional element filter returned a match at some point.
expandNS( $name, $namespaceURI)
static newFromString( $string, $filterCallback=null)
Alternative constructor: from string.
processingInstructionHandler( $target, $data)
$parserOptions
Additional parsing options.
checkDTDIsSafe( $internalSubset)
Check if the internal subset of the DTD is safe.
$stackDepth
Current depth of the data stack.
getAttributesArray(XMLReader $r)
Get all of the attributes for an XMLReader's current node.
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
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
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
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
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
Allows to change the fields on the form that will be generated $name
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
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
if(is_array($mode)) switch( $mode) $input