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