Debian Codegraph @

vendor/wikimedia/parsoid/src/NodeData/TempData.php

raw
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Wikimedia\Parsoid\NodeData;
5
6 use Wikimedia\Parsoid\Core\DomSourceRange;
7 use Wikimedia\Parsoid\Tokens\SourceRange;
8
9 /**
10 * A class for temporary node-related data, stored in DataParsoid->tmp
11 *
12 * We use undeclared properties to reduce memory usage, since there are
13 * typically very many instances of this class.
14 *
15 * An associative array with keys "key" and "params", set on span typeof=mw:I18n
16 * elements to carry wfMessage() parameters.
17 * @property array|null $i18n
18 *
19 * The original DSR for a quote (b/i) element prior to its adjustment by ComputeDSR.
20 * @property DomSourceRange|null $origDSR
21 *
22 * Offsets of external link content.
23 * @property SourceRange|null $extLinkContentOffsets
24 *
25 * This is set on h1-h6 tokens to track section numbers.
26 * @property int|null $headingIndex
27 *
28 * This is an array of key-value pairs [[k,v], [k,v]] set by AttributeExpander
29 * on template tokens. It filters through to data-mw attribs.
30 * @property array|null $templatedAttribs
31 *
32 * Information about a template invocation
33 * @property TemplateInfo|null $tplarginfo
34 *
35 * The TSR of the end tag
36 * @property SourceRange|null $endTSR
37 *
38 * Used to shuttle tokens to the end of a stage in the TTM
39 * @property array|null $shuttleTokens
40 *
41 * Section data associated with a heading
42 * @property array|null $section
43 */
44 #[\AllowDynamicProperties]
45 class TempData {
46 /**
47 * Whether a DOM node is a new node added during an edit session. figureHandler()
48 * sets this on synthetic div elements.
49 */
50 public const IS_NEW = 1 << 0;
51
52 /**
53 * The tokenizer sets this on table cells originating in wikitext-style syntax
54 * with no attributes set in the input.
55 */
56 public const NO_ATTRS = 1 << 1;
57
58 /**
59 * The tokenizer sets this on table cells that use "||" or "!!" style syntax for
60 * th/td cells. While the tokenizer sets this on all cells, we are only interested
61 * in this info for td/th cells in "SOF" context (modulo comments & whtespace)
62 * in templates. Since Parsoid processes templates in independent parsing contexts,
63 * td/dh cells with this flag set cannot be merged with preceding cells. But cells
64 * without this flag and coming from a template are viable candidates for merging.
65 */
66 public const NON_MERGEABLE_TABLE_CELL = 1 << 2;
67
68 /**
69 * This is set on cell elements that could not be combined with the previous
70 * cell. Private to TableFixups.
71 */
72 public const FAILED_REPARSE = 1 << 3;
73
74 /**
75 * This is set on span tags that are created by PipelineUtils::addSpanWrappers().
76 */
77 public const WRAPPER = 1 << 4;
78
79 /**
80 * This is set on wrapper tokens created by PipelineUtils::encapsulateExpansionHTML()
81 * to propagate the setDSR option to that function.
82 */
83 public const SET_DSR = 1 << 5;
84
85 /**
86 * This is set on wrapper tokens created by PipelineUtils::encapsulateExpansionHTML()
87 * to propagate the fromCache option to that function.
88 */
89 public const FROM_CACHE = 1 << 6;
90
91 /**
92 * A flag private to Linter, used to suppress duplicate messages.
93 */
94 public const LINTED = 1 << 7;
95
96 /**
97 * A flag private to Linter to help it traverse a DOM
98 */
99 public const PROCESSED_TIDY_WS_BUG = 1 << 8;
100
101 /**
102 * This is set on all elements that originate in a template. It controls
103 * the insertion of mw:Transclusion markers in MarkFosteredContent.
104 */
105 public const IN_TRANSCLUSION = 1 << 9;
106
107 /**
108 * MarkFosteredContent sets this on meta mw:Transclusion tags. It is only used
109 * in an assertion.
110 */
111 public const FROM_FOSTER = 1 << 10;
112
113 /**
114 * Used to indicate that media dimensions have redundant units.
115 */
116 public const BOGUS_PX = 1 << 11;
117
118 /**
119 * All elements inserted by TreeBuilderStage receive an integer ID. It is used
120 * in findAutoInsertedTags() in conjunction with data-stag to identify
121 * auto-inserted tags, and for debugging.
122 * @var int|null
123 */
124 public $tagId;
125
126 /**
127 * A combination of flags combined from consts on this class.
128 * @var int
129 */
130 public $bits = 0;
131
132 /**
133 * Node temporary attribute key-value pair to be processed in post-process steps.
134 * Some extensions need to store data to be post-processed due to custom state
135 * implementation.
136 *
137 * Make this property private and leave for ParsoidExtensionAPI to manipulate its
138 * content.
139 *
140 * @var array|null
141 */
142 private ?array $tagData;
143
144 /**
145 * Check whether a bit is set in $this->bits
146 *
147 * @param int $flag
148 * @return bool
149 */
150 public function getFlag( int $flag ): bool {
151 return (bool)( $this->bits & $flag );
152 }
153
154 /**
155 * Set a bit in $this->bits
156 *
157 * @param int $flag
158 * @param bool $value
159 */
160 public function setFlag( int $flag, bool $value = true ): void {
161 if ( $value ) {
162 $this->bits |= $flag;
163 } else {
164 $this->bits &= ~$flag;
165 }
166 }
167
168 /**
169 * Set a tag attribute for a specific extension with a given key
170 *
171 * @param string $key identifier to support a map for multiple extensions
172 * @param mixed $data
173 */
174 public function setTagData( string $key, $data ) {
175 $this->tagData ??= [];
176 $this->tagData[$key] = $data;
177 }
178
179 /**
180 * Get a tag attribute for a specific extension tag with a given key
181 *
182 * @param string $key identifier to support a map for multiple tags
183 * @return mixed
184 */
185 public function getTagData( string $key ) {
186 return $this->tagData[$key] ?? null;
187 }
188 }