Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
TempData | |
0.00% |
0 / 7 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
getFlag | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setFlag | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
setTagData | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getTagData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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 | * Information about a template invocation |
29 | * @property TemplateInfo|null $tplarginfo |
30 | * |
31 | * The TSR of the end tag |
32 | * @property SourceRange|null $endTSR |
33 | * |
34 | * Used to shuttle tokens to the end of a stage in the TTM |
35 | * @property array|null $shuttleTokens |
36 | * |
37 | * Section data associated with a heading |
38 | * @property array|null $section |
39 | */ |
40 | #[\AllowDynamicProperties] |
41 | class TempData { |
42 | /** |
43 | * Whether a DOM node is a new node added during an edit session. figureHandler() |
44 | * sets this on synthetic div elements. |
45 | */ |
46 | public const IS_NEW = 1 << 0; |
47 | |
48 | /** |
49 | * The tokenizer sets this on table cells originating in wikitext-style syntax |
50 | * with no attributes set in the input. |
51 | */ |
52 | public const NO_ATTRS = 1 << 1; |
53 | |
54 | /** |
55 | * The tokenizer sets this on table cells that use "||" or "!!" style syntax for |
56 | * th/td cells. While the tokenizer sets this on all cells, we are only interested |
57 | * in this info for td/th cells in "SOF" context (modulo comments & whtespace) |
58 | * in templates. Since Parsoid processes templates in independent parsing contexts, |
59 | * td/dh cells with this flag set cannot be merged with preceding cells. But cells |
60 | * without this flag and coming from a template are viable candidates for merging. |
61 | */ |
62 | public const NON_MERGEABLE_TABLE_CELL = 1 << 2; |
63 | |
64 | /** |
65 | * This is set on cell elements that could not be combined with the previous |
66 | * cell. Private to TableFixups. |
67 | */ |
68 | public const FAILED_REPARSE = 1 << 3; |
69 | |
70 | /** |
71 | * This is set on span tags that are created by PipelineUtils::addSpanWrappers(). |
72 | */ |
73 | public const WRAPPER = 1 << 4; |
74 | |
75 | /** |
76 | * This is set on wrapper tokens created by PipelineUtils::encapsulateExpansionHTML() |
77 | * to propagate the setDSR option to that function. |
78 | */ |
79 | public const SET_DSR = 1 << 5; |
80 | |
81 | /** |
82 | * This is set on wrapper tokens created by PipelineUtils::encapsulateExpansionHTML() |
83 | * to propagate the fromCache option to that function. |
84 | */ |
85 | public const FROM_CACHE = 1 << 6; |
86 | |
87 | /** |
88 | * A flag private to Linter, used to suppress duplicate messages. |
89 | */ |
90 | public const LINTED = 1 << 7; |
91 | |
92 | /** |
93 | * A flag private to Linter to help it traverse a DOM |
94 | */ |
95 | public const PROCESSED_TIDY_WS_BUG = 1 << 8; |
96 | |
97 | /** |
98 | * This is set on all elements that originate in a template. It controls |
99 | * the insertion of mw:Transclusion markers in MarkFosteredContent. |
100 | */ |
101 | public const IN_TRANSCLUSION = 1 << 9; |
102 | |
103 | /** |
104 | * MarkFosteredContent sets this on meta mw:Transclusion tags. It is only used |
105 | * in an assertion. |
106 | */ |
107 | public const FROM_FOSTER = 1 << 10; |
108 | |
109 | /** |
110 | * Used to indicate that media dimensions have redundant units. |
111 | */ |
112 | public const BOGUS_PX = 1 << 11; |
113 | |
114 | /** |
115 | * All elements inserted by TreeBuilderStage receive an integer ID. It is used |
116 | * in findAutoInsertedTags() in conjunction with data-stag to identify |
117 | * auto-inserted tags, and for debugging. |
118 | */ |
119 | public ?int $tagId; |
120 | |
121 | /** |
122 | * A combination of flags combined from consts on this class. |
123 | */ |
124 | public int $bits = 0; |
125 | |
126 | /** |
127 | * Node temporary attribute key-value pair to be processed in post-process steps. |
128 | * Some extensions need to store data to be post-processed due to custom state |
129 | * implementation. |
130 | * |
131 | * Make this property private and leave for ParsoidExtensionAPI to manipulate its |
132 | * content. |
133 | */ |
134 | private ?array $tagData; |
135 | |
136 | /** |
137 | * Check whether a bit is set in $this->bits |
138 | */ |
139 | public function getFlag( int $flag ): bool { |
140 | return (bool)( $this->bits & $flag ); |
141 | } |
142 | |
143 | /** |
144 | * Set a bit in $this->bits |
145 | */ |
146 | public function setFlag( int $flag, bool $value = true ): void { |
147 | if ( $value ) { |
148 | $this->bits |= $flag; |
149 | } else { |
150 | $this->bits &= ~$flag; |
151 | } |
152 | } |
153 | |
154 | /** |
155 | * Set a tag attribute for a specific extension with a given key |
156 | * |
157 | * @param string $key identifier to support a map for multiple extensions |
158 | * @param mixed $data |
159 | */ |
160 | public function setTagData( string $key, $data ): void { |
161 | $this->tagData ??= []; |
162 | $this->tagData[$key] = $data; |
163 | } |
164 | |
165 | /** |
166 | * Get a tag attribute for a specific extension tag with a given key |
167 | * |
168 | * @param string $key identifier to support a map for multiple tags |
169 | * @return mixed |
170 | */ |
171 | public function getTagData( string $key ) { |
172 | return $this->tagData[$key] ?? null; |
173 | } |
174 | } |