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