Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
TempData
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 getFlag
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setFlag
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 setTagData
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getTagData
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\NodeData;
5
6use Wikimedia\Parsoid\Core\DomSourceRange;
7use 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 TokenHandlerPipeline
35 * @property array|null $shuttleTokens
36 *
37 * Section data associated with a heading
38 * @property array|null $section
39 *
40 * For td/th tokens, wikitext source for attributes
41 * This is needed to reparse this as content when tokenization is incorrect
42 * @property string|null $attrSrc
43 */
44#[\AllowDynamicProperties]
45class 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 cell is a merge of two cells in TableFixups.
76     * For now, this prevents additional merges.
77     */
78    public const MERGED_TABLE_CELL = 1 << 4;
79
80    /**
81     * Indicates a cell is from the start of template source.
82     * Used in TableFixups.
83     */
84    public const AT_SRC_START = 1 << 5;
85
86    /**
87     * This is set on span tags that are created by PipelineUtils::addSpanWrappers().
88     */
89    public const WRAPPER = 1 << 6;
90
91    /**
92     * This is set on wrapper tokens created by PipelineUtils::encapsulateExpansionHTML()
93     * to propagate the setDSR option to that function.
94     */
95    public const SET_DSR = 1 << 7;
96
97    /**
98     * A flag private to Linter, used to suppress duplicate messages.
99     */
100    public const LINTED = 1 << 8;
101
102    /**
103     * A flag private to Linter to help it traverse a DOM
104     */
105    public const PROCESSED_TIDY_WS_BUG = 1 << 9;
106
107    /**
108     * This is set on all elements that originate in a template. It controls
109     * the insertion of mw:Transclusion markers in MarkFosteredContent.
110     */
111    public const IN_TRANSCLUSION = 1 << 10;
112
113    /**
114     * MarkFosteredContent sets this on meta mw:Transclusion tags. It is only used
115     * in an assertion.
116     */
117    public const FROM_FOSTER = 1 << 11;
118
119    /**
120     * Used to indicate that media dimensions have redundant units.
121     */
122    public const BOGUS_PX = 1 << 12;
123
124    /**
125     * This is set on wrapper tokens created by PipelineUtils::encapsulateExpansionHTML()
126     * to propagate the fromCache option to that function.
127     */
128    public const FROM_CACHE = 1 << 13;
129
130    /**
131     * All elements inserted by TreeBuilderStage receive an integer ID. It is used
132     * in findAutoInsertedTags() in conjunction with data-stag to identify
133     * auto-inserted tags, and for debugging.
134     */
135    public ?int $tagId;
136
137    /**
138     * A combination of flags combined from consts on this class.
139     */
140    public int $bits = 0;
141
142    /**
143     * Node temporary attribute key-value pair to be processed in post-process steps.
144     * Some extensions need to store data to be post-processed due to custom state
145     * implementation.
146     *
147     * Make this property private and leave for ParsoidExtensionAPI to manipulate its
148     * content.
149     */
150    private ?array $tagData;
151
152    /**
153     * Check whether a bit is set in $this->bits
154     */
155    public function getFlag( int $flag ): bool {
156        return (bool)( $this->bits & $flag );
157    }
158
159    /**
160     * Set a bit in $this->bits
161     */
162    public function setFlag( int $flag, bool $value = true ): void {
163        if ( $value ) {
164            $this->bits |= $flag;
165        } else {
166            $this->bits &= ~$flag;
167        }
168    }
169
170    /**
171     * Set a tag attribute for a specific extension with a given key
172     *
173     * @param string $key identifier to support a map for multiple extensions
174     * @param mixed $data
175     */
176    public function setTagData( string $key, $data ): void {
177        $this->tagData ??= [];
178        $this->tagData[$key] = $data;
179    }
180
181    /**
182     * Get a tag attribute for a specific extension tag with a given key
183     *
184     * @param string $key identifier to support a map for multiple tags
185     * @return mixed
186     */
187    public function getTagData( string $key ) {
188        return $this->tagData[$key] ?? null;
189    }
190}