75 'processing_instruction_handler' =>
'',
91 $this->filterCallback = $filterCallback;
92 $this->parserOptions = array_merge( $this->parserOptions,
$options );
108 return new self(
$fname, $filterCallback,
true );
123 return new self( $string, $filterCallback,
false );
139 $reader =
new XMLReader();
141 $s = $reader->open( $xml, null, LIBXML_NOERROR | LIBXML_NOWARNING );
143 $s = $reader->XML( $xml, null, LIBXML_NOERROR | LIBXML_NOWARNING );
147 $this->wellFormed =
false;
149 $oldDisable = libxml_disable_entity_loader(
true );
150 $reader->setParserProperty( XMLReader::SUBST_ENTITIES,
true );
156 $this->wellFormed =
false;
158 libxml_disable_entity_loader( $oldDisable );
162 libxml_disable_entity_loader( $oldDisable );
167 set_error_handler( [ $this,
'XmlErrorHandler' ] );
168 $ret = $reader->read();
169 restore_error_handler();
174 $this->wellFormed =
false;
182 if ( !$this->
readNext( $reader ) ) {
184 $this->wellFormed =
false;
187 if ( $reader->nodeType === XMLReader::PI ) {
190 }
while ( $reader->nodeType != XMLReader::ELEMENT );
194 switch ( $reader->nodeType ) {
195 case XMLReader::ELEMENT:
198 $reader->namespaceURI
200 if ( $this->rootElement ===
'' ) {
201 $this->rootElement =
$name;
203 $empty = $reader->isEmptyElement;
211 case XMLReader::END_ELEMENT:
215 case XMLReader::WHITESPACE:
216 case XMLReader::SIGNIFICANT_WHITESPACE:
217 case XMLReader::CDATA:
218 case XMLReader::TEXT:
222 case XMLReader::ENTITY_REF:
227 case XMLReader::COMMENT:
244 }
while ( $this->
readNext( $reader ) );
246 if ( $this->stackDepth !== 0 ) {
247 $this->wellFormed =
false;
248 } elseif ( $this->wellFormed === null ) {
249 $this->wellFormed =
true;
261 while ( $r->moveToNextAttribute() ) {
262 if ( $r->namespaceURI ===
'http://www.w3.org/2000/xmlns/' ) {
268 $attrs[
$name] = $r->value;
279 if ( $namespaceURI ) {
280 $parts = explode(
':',
$name );
281 $localname = array_pop( $parts );
282 return "$namespaceURI:$localname";
303 $callbackReturn =
false;
305 if ( is_callable( $this->filterCallback ) ) {
306 $callbackReturn = call_user_func(
307 $this->filterCallback,
313 if ( $callbackReturn ) {
315 $this->filterMatch =
true;
316 $this->filterMatchType = $callbackReturn;
325 $this->
elementData[ $this->stackDepth - 1 ] .= trim( $data );
333 $callbackReturn =
false;
334 if ( $this->parserOptions[
'processing_instruction_handler'] ) {
335 $callbackReturn = call_user_func(
336 $this->parserOptions[
'processing_instruction_handler'],
341 if ( $callbackReturn ) {
343 $this->filterMatch =
true;
344 $this->filterMatchType = $callbackReturn;
readNext(XMLReader $reader)
$parserOptions
Additional parsing options.
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
static newFromString($string, $filterCallback=null)
Alternative constructor: from string.
processing should stop and the error should be shown to the user * false
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
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
validateFromInput($xml, $isFile)
expandNS($name, $namespaceURI)
getRootElement()
Get the root element.
processingInstructionHandler($target, $data)
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
XmlErrorHandler($errno, $errstr)
$stackDepth
Current depth of the data stack.
elementOpen($name, $attribs)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
mixed $filterMatchType
Will contain the type of filter hit if the optional element filter returned a match at some point...
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
static newFromFilename($fname, $filterCallback=null)
Alternative constructor: from filename.
$rootElement
Name of the document's root element, including any namespace as an expanded URL.
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
__construct($input, $filterCallback=null, $isFile=true, $options=[])
$elementData
A stack of strings containing the data of each xml element as it's processed.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
$filterMatch
Will be set to true if the optional element filter returned a match at some point.
getAttributesArray(XMLReader $r)
Get all of the attributes for an XMLReader's current node.
$elementDataContext
A stack of element names and attributes, as we process them.
$wellFormed
Will be set to true or false to indicate whether the file is well-formed XML.
Allows to change the fields on the form that will be generated $name