Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / tidy / RemexMungerData.php
blob1d0be6a4fd155012a1314fe847039f3e252a9f16
1 <?php
3 namespace MediaWiki\Tidy;
5 use InvalidArgumentException;
6 use Wikimedia\RemexHtml\Serializer\SerializerNode;
7 use Wikimedia\RemexHtml\TreeBuilder\Element;
9 /**
10 * @internal
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.
18 * @var Element|null
20 public $childPElement;
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.
26 * @var SerializerNode|null
28 public $ancestorPNode;
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.
36 * @var SerializerNode|null
38 public $wrapBaseNode;
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.
47 * @var Element|null
49 public $currentCloneElement;
51 /**
52 * Is the node a p-wrapper, with name mw:p-wrap?
54 * @var bool
56 public $isPWrapper = false;
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.
63 * @var bool
65 public $isSplittable = false;
67 /**
68 * This is true if the node is a body or blockquote, which activates
69 * p-wrapping of child nodes.
71 * @var bool
73 public $needsPWrapping = false;
75 /**
76 * The number of child nodes, not counting whitespace-only text nodes or
77 * comments.
79 * @var int
81 public $nonblankNodeCount = 0;
83 public function __set( $name, $value ) {
84 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
85 throw new InvalidArgumentException( "Cannot set property \"$name\"" );
88 /**
89 * Get a text representation of the current state of the serializer, for
90 * debugging.
92 * @return string
94 public function dump() {
95 $parts = [];
97 if ( $this->childPElement ) {
98 $parts[] = 'childPElement=' . $this->childPElement->getDebugTag();
100 if ( $this->ancestorPNode ) {
101 $parts[] = "ancestorPNode=<{$this->ancestorPNode->name}>";
103 if ( $this->wrapBaseNode ) {
104 $parts[] = "wrapBaseNode=<{$this->wrapBaseNode->name}>";
106 if ( $this->currentCloneElement ) {
107 $parts[] = "currentCloneElement=" . $this->currentCloneElement->getDebugTag();
109 if ( $this->isPWrapper ) {
110 $parts[] = 'isPWrapper';
112 if ( $this->isSplittable ) {
113 $parts[] = 'isSplittable';
115 if ( $this->needsPWrapping ) {
116 $parts[] = 'needsPWrapping';
118 if ( $this->nonblankNodeCount ) {
119 $parts[] = "nonblankNodeCount={$this->nonblankNodeCount}";
121 $s = "RemexMungerData {\n";
122 foreach ( $parts as $part ) {
123 $s .= " $part\n";
125 $s .= "}\n";
126 return $s;