| 1 |
<?php |
| 2 |
declare( strict_types = 1 ); |
| 3 |
|
| 4 |
namespace Wikimedia\Parsoid\Wt2Html\TreeBuilder; |
| 5 |
|
| 6 |
use Wikimedia\Parsoid\DOM\Document; |
| 7 |
use Wikimedia\Parsoid\Utils\DOMDataUtils; |
| 8 |
use Wikimedia\RemexHtml\Tokenizer\PlainAttributes; |
| 9 |
|
| 10 |
class Attributes extends PlainAttributes { |
| 11 |
private $document; |
| 12 |
|
| 13 |
/** |
| 14 |
* @param Document $document |
| 15 |
* @param array $data |
| 16 |
*/ |
| 17 |
public function __construct( Document $document, $data = [] ) { |
| 18 |
$this->document = $document; |
| 19 |
parent::__construct( $data ); |
| 20 |
} |
| 21 |
|
| 22 |
public function clone() { |
| 23 |
if ( isset( $this->data[DOMDataUtils::DATA_OBJECT_ATTR_NAME] ) ) { |
| 24 |
$newAttrs = $this->data; |
| 25 |
$data = DOMDataUtils::getBag( $this->document )->getObject( |
| 26 |
(int)$this->data[DOMDataUtils::DATA_OBJECT_ATTR_NAME] ); |
| 27 |
$newData = $data->cloneNodeData( ( $newAttrs['typeof'] ?? null ) === 'mw:ExpandedAttrs' ); |
| 28 |
|
| 29 |
// - If autoInserted(Start|End)Token flags are set, set the corresponding |
| 30 |
// autoInserted(Start|End) flag. Clear the token flags on the |
| 31 |
// already-processed nodes but let them propagate further down |
| 32 |
// so that autoInserted(Start|End) flags can be set on all clones. |
| 33 |
// - If not, clear autoInserted* flags since TreeEventStage needs |
| 34 |
// to set them again based on the HTML token stream. |
| 35 |
if ( isset( $data->parsoid->autoInsertedStartToken ) ) { |
| 36 |
unset( $data->parsoid->autoInsertedStartToken ); |
| 37 |
$newData->parsoid->autoInsertedStart = true; |
| 38 |
} else { |
| 39 |
unset( $newData->parsoid->autoInsertedStart ); |
| 40 |
} |
| 41 |
if ( isset( $data->parsoid->autoInsertedEndToken ) ) { |
| 42 |
unset( $data->parsoid->autoInsertedEndToken ); |
| 43 |
$newData->parsoid->autoInsertedEnd = true; |
| 44 |
} else { |
| 45 |
unset( $newData->parsoid->autoInsertedEnd ); |
| 46 |
} |
| 47 |
|
| 48 |
$newAttrs[DOMDataUtils::DATA_OBJECT_ATTR_NAME] = |
| 49 |
DOMDataUtils::stashObjectInDoc( $this->document, $newData ); |
| 50 |
return new self( $this->document, $newAttrs ); |
| 51 |
} else { |
| 52 |
return $this; |
| 53 |
} |
| 54 |
} |
| 55 |
} |