Debian Codegraph @

includes/tidy/RemexMungerData.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tidy;
4
5 use InvalidArgumentException;
6 use Wikimedia\RemexHtml\Serializer\SerializerNode;
7 use Wikimedia\RemexHtml\TreeBuilder\Element;
8
9 /**
10 * @internal
11 */
12 class RemexMungerData {
13 /**
14 * The Element for the mw:p-wrap which is a child of the current node. If
15 * this is set, inline insertions into this node will be diverted so that
16 * they insert into the p-wrap.
17 *
18 * @var Element|null
19 */
20 public $childPElement;
21
22 /**
23 * This tracks the mw:p-wrap node in the Serializer stack which is an
24 * ancestor of this node. If there is no mw:p-wrap ancestor, it is null.
25 *
26 * @var SerializerNode|null
27 */
28 public $ancestorPNode;
29
30 /**
31 * The wrap base node is the body or blockquote node which is the parent
32 * of active p-wrappers. This is set if there is an ancestor p-wrapper,
33 * or if a p-wrapper was closed due to a block element being encountered
34 * inside it.
35 *
36 * @var SerializerNode|null
37 */
38 public $wrapBaseNode;
39
40 /**
41 * Stack splitting (essentially our idea of AFE reconstruction) can clone
42 * formatting elements which are split over multiple paragraphs.
43 * TreeBuilder is not aware of the cloning, and continues to insert into
44 * the original element. This is set to the newer clone if this node was
45 * cloned, i.e. if there is an active diversion of the insertion location.
46 *
47 * @var Element|null
48 */
49 public $currentCloneElement;
50
51 /**
52 * Is the node a p-wrapper, with name mw:p-wrap?
53 *
54 * @var bool
55 */
56 public $isPWrapper = false;
57
58 /**
59 * Is the node splittable, i.e. a formatting element or a node with a
60 * formatting element ancestor which is under an active or deactivated
61 * p-wrapper.
62 *
63 * @var bool
64 */
65 public $isSplittable = false;
66
67 /**
68 * This is true if the node is a body or blockquote, which activates
69 * p-wrapping of child nodes.
70 *
71 * @var bool
72 */
73 public $needsPWrapping = false;
74
75 /**
76 * The number of child nodes, not counting whitespace-only text nodes or
77 * comments.
78 *
79 * @var int
80 */
81 public $nonblankNodeCount = 0;
82
83 public function __set( $name, $value ) {
84 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
85 throw new InvalidArgumentException( "Cannot set property \"$name\"" );
86 }
87
88 /**
89 * Get a text representation of the current state of the serializer, for
90 * debugging.
91 *
92 * @return string
93 */
94 public function dump() {
95 $parts = [];
96
97 if ( $this->childPElement ) {
98 $parts[] = 'childPElement=' . $this->childPElement->getDebugTag();
99 }
100 if ( $this->ancestorPNode ) {
101 $parts[] = "ancestorPNode=<{$this->ancestorPNode->name}>";
102 }
103 if ( $this->wrapBaseNode ) {
104 $parts[] = "wrapBaseNode=<{$this->wrapBaseNode->name}>";
105 }
106 if ( $this->currentCloneElement ) {
107 $parts[] = "currentCloneElement=" . $this->currentCloneElement->getDebugTag();
108 }
109 if ( $this->isPWrapper ) {
110 $parts[] = 'isPWrapper';
111 }
112 if ( $this->isSplittable ) {
113 $parts[] = 'isSplittable';
114 }
115 if ( $this->needsPWrapping ) {
116 $parts[] = 'needsPWrapping';
117 }
118 if ( $this->nonblankNodeCount ) {
119 $parts[] = "nonblankNodeCount={$this->nonblankNodeCount}";
120 }
121 $s = "RemexMungerData {\n";
122 foreach ( $parts as $part ) {
123 $s .= " $part\n";
124 }
125 $s .= "}\n";
126 return $s;
127 }
128 }