MediaWiki  master
PPNode_DOM.php
Go to the documentation of this file.
1 <?php
26 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
27 class PPNode_DOM implements PPNode {
28 
32  public $node;
33  public $xpath;
34 
35  public function __construct( $node, $xpath = false ) {
36  $this->node = $node;
37  }
38 
42  public function getXPath() {
43  if ( $this->xpath === null ) {
44  $this->xpath = new DOMXPath( $this->node->ownerDocument );
45  }
46  return $this->xpath;
47  }
48 
49  public function __toString() {
50  if ( $this->node instanceof DOMNodeList ) {
51  $s = '';
52  foreach ( $this->node as $node ) {
53  $s .= $node->ownerDocument->saveXML( $node );
54  }
55  } else {
56  $s = $this->node->ownerDocument->saveXML( $this->node );
57  }
58  return $s;
59  }
60 
64  public function getChildren() {
65  return $this->node->childNodes ? new self( $this->node->childNodes ) : false;
66  }
67 
71  public function getFirstChild() {
72  return $this->node->firstChild ? new self( $this->node->firstChild ) : false;
73  }
74 
78  public function getNextSibling() {
79  return $this->node->nextSibling ? new self( $this->node->nextSibling ) : false;
80  }
81 
87  public function getChildrenOfType( $type ) {
88  return new self( $this->getXPath()->query( $type, $this->node ) );
89  }
90 
94  public function getLength() {
95  if ( $this->node instanceof DOMNodeList ) {
96  return $this->node->length;
97  } else {
98  return false;
99  }
100  }
101 
106  public function item( $i ) {
107  $item = $this->node->item( $i );
108  return $item ? new self( $item ) : false;
109  }
110 
114  public function getName() {
115  if ( $this->node instanceof DOMNodeList ) {
116  return '#nodelist';
117  } else {
118  return $this->node->nodeName;
119  }
120  }
121 
131  public function splitArg() {
132  $xpath = $this->getXPath();
133  $names = $xpath->query( 'name', $this->node );
134  $values = $xpath->query( 'value', $this->node );
135  if ( !$names->length || !$values->length ) {
136  throw new MWException( 'Invalid brace node passed to ' . __METHOD__ );
137  }
138  $name = $names->item( 0 );
139  $index = $name->getAttribute( 'index' );
140  return [
141  'name' => new self( $name ),
142  'index' => $index,
143  'value' => new self( $values->item( 0 ) ) ];
144  }
145 
153  public function splitExt() {
154  $xpath = $this->getXPath();
155  $names = $xpath->query( 'name', $this->node );
156  $attrs = $xpath->query( 'attr', $this->node );
157  $inners = $xpath->query( 'inner', $this->node );
158  $closes = $xpath->query( 'close', $this->node );
159  if ( !$names->length || !$attrs->length ) {
160  throw new MWException( 'Invalid ext node passed to ' . __METHOD__ );
161  }
162  $parts = [
163  'name' => new self( $names->item( 0 ) ),
164  'attr' => new self( $attrs->item( 0 ) ) ];
165  if ( $inners->length ) {
166  $parts['inner'] = new self( $inners->item( 0 ) );
167  }
168  if ( $closes->length ) {
169  $parts['close'] = new self( $closes->item( 0 ) );
170  }
171  return $parts;
172  }
173 
179  public function splitHeading() {
180  if ( $this->getName() !== 'h' ) {
181  throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
182  }
183  return [
184  'i' => $this->node->getAttribute( 'i' ),
185  'level' => $this->node->getAttribute( 'level' ),
186  'contents' => $this->getChildren()
187  ];
188  }
189 }
DOMElement DOMNodeList $node
Definition: PPNode_DOM.php:32
getNextSibling()
Definition: PPNode_DOM.php:78
There are three types of nodes:
Definition: PPNode.php:35
__construct( $node, $xpath=false)
Definition: PPNode_DOM.php:35
splitHeading()
Split a "<h>" node.
Definition: PPNode_DOM.php:179
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
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
Definition: distributors.txt:9
getChildrenOfType( $type)
Definition: PPNode_DOM.php:87
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
Definition: injection.txt:35
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
splitArg()
Split a "<part>" node into an associative array containing:
Definition: PPNode_DOM.php:131
splitExt()
Split an "<ext>" node into an associative array containing name, attr, inner and close All values in ...
Definition: PPNode_DOM.php:153