` vs `
`).
* @property string|null $srcTagName
*
* UnpackDomFragments sets this on misnested elements
* @property bool|null $misnested
*
* This is set by MarkFosteredContent to indicate fostered content and content
* wrappers.
* @property bool|null $fostered
*
* == Links ==
*
* Link trail source (Ex: the "l" in `[[Foo]]l`)
* Porting note: this can be '0', handle emptiness checks with care
* @property string|null $tail
*
* Link prefix source
* Porting note: this can be '0', handle emptiness checks with care
* @property string|null $prefix
*
* True if the link was a pipetrick (`[[Foo|]]`).
* @note This will likely be removed soon since this should not show up in saved wikitext since
* this is a pre-save transformation trick.
* @property bool|null $pipeTrick
*
* Did the link use interwiki syntax?
* Probably redundant with the rel=mw:WikiLink/Interwiki
* @property bool|null $isIW
*
* == Tables ==
*
* Source for start-text separators in table wikitext.
* @property string|null $startTagSrc
*
* Source for end-text separators in table wikitext.
* @property string|null $endTagSrc
*
* Source for attribute-text separators in table wikitext.
* @property string|null $attrSepSrc
*
* 'row' for td/th cells that show up on the same line, null otherwise
* @property string|null $stx_v
*
* == Language variant token properties ==
*
* @property array|null $flags Flags with their human-readable names
* @property array|null $variants The variant names
* @property array|null $original Original flags
* @property array|null $flagSp Spaces around flags, uncompressed
*
* An array of associative arrays describing the parts of the variant rule.
* - text: (string) The text
* - semi: (bool) A semicolon marker
* - sp: (array|string) An array of strings containing spaces
* - oneway: (bool) A one-way rule definition
* - twoway: (bool) A two-way rule definition
* - from: (array) An associative array:
* - tokens: (array) A token array
* - srcOffsets: SourceRange
* - to: (array) An associative array same as "from"
* - lang: (string)
* @property array|null $texts
*
* == Language variant data-parsoid properties ==
*
* @property array|null $flSp Spaces around flags, compressed with compressSpArray().
* @property array|null $tSp Spaces around texts, compressed with compressSpArray().
* @property array|null $fl Original flags, copied from $this->original on the token.
*/
#[\AllowDynamicProperties]
class DataParsoid implements JsonCodecable {
use JsonCodecableTrait;
/**
* Holds a number of transient properties in the wt->html pipeline to pass information between
* stages. Dropped before serialization.
* @var TempData|null
*/
public $tmp;
/**
* Deeply clone this object
*
* @return DataParsoid
*/
public function clone(): self {
$dp = clone $this;
// Properties that need deep cloning
if ( isset( $dp->tmp ) ) {
$dp->tmp = Utils::clone( $dp->tmp );
}
if ( isset( $dp->linkTk ) ) {
$dp->linkTk = Utils::clone( $dp->linkTk );
}
if ( isset( $dp->tokens ) ) {
$dp->tokens = Utils::clone( $dp->tokens );
}
// Properties that need shallow cloning
if ( isset( $dp->tsr ) ) {
$dp->tsr = clone $dp->tsr;
}
if ( isset( $dp->dsr ) ) {
$dp->dsr = clone $dp->dsr;
}
if ( isset( $dp->extTagOffsets ) ) {
$dp->extTagOffsets = clone $dp->extTagOffsets;
}
// The remaining properties were sufficiently handled by the clone operator
return $dp;
}
public function isModified(): bool {
// NOTE: strict equality will not work in this comparison
// @phan-suppress-next-line PhanPluginComparisonObjectEqualityNotStrict
return $this != new self;
}
/**
* Get a lazy-initialized object to which temporary properties can be written.
* @return TempData
*/
public function getTemp(): TempData {
// tmp can be unset despite being declared
$this->tmp ??= new TempData();
return $this->tmp;
}
/**
* Check whether a bit is set in $this->tmp->bits
*
* @param int $flag
* @return bool
*/
public function getTempFlag( $flag ): bool {
return isset( $this->tmp ) && ( $this->tmp->bits & $flag );
}
/**
* Set a bit in $this->tmp->bits
*
* @param int $flag
* @param bool $value
*/
public function setTempFlag( $flag, $value = true ): void {
if ( $value ) {
if ( !isset( $this->tmp ) ) {
$tmp = new TempData;
$tmp->bits = $flag;
$this->tmp = $tmp;
} else {
$this->tmp->bits |= $flag;
}
} elseif ( isset( $this->tmp ) ) {
$this->tmp->bits &= ~$flag;
}
}
/** @inheritDoc */
public function toJsonArray(): array {
static $clearNullsFrom = [
'dsr', 'tsr', 'extTagOffsets',
];
$result = (array)$this;
unset( $result['tmp'] );
// Conciseness: don't include `null` values from certain properties.
foreach ( $clearNullsFrom as $prop ) {
if ( !isset( $result[$prop] ) ) {
unset( $result[$prop] );
}
}
return $result;
}
/** @inheritDoc */
public static function jsonClassHintFor( string $keyname ) {
static $hints = null;
if ( $hints === null ) {
$dsr = Hint::build( DomSourceRange::class, Hint::USE_SQUARE );
$sr = Hint::build( SourceRange::class, Hint::USE_SQUARE );
$hints = [
'dsr' => $dsr,
'extTagOffsets' => $dsr,
'tsr' => $sr,
'pi' => Hint::build( ParamInfo::class, Hint::LIST, Hint::LIST ),
'linkTk' => Token::class,
];
}
return $hints[$keyname] ?? null;
}
/** @inheritDoc */
public static function newFromJsonArray( array $json ): DataParsoid {
$dp = new DataParsoid;
foreach ( $json as $key => $value ) {
switch ( $key ) {
case 'dsr':
case 'extTagOffsets':
case 'tsr':
// For backward compatibility, leave these unset if null.
if ( $value !== null ) {
$dp->$key = $value;
}
break;
case 'tmp':
// This isn't serialized, but we can deserialize it
// for tests.
$tmp = new TempData;
foreach ( $value as $key2 => $value2 ) {
$tmp->$key2 = $value2;
}
$dp->$key = $tmp;
break;
default:
$dp->$key = $value;
break;
}
}
return $dp;
}
}