RemexMungerData.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace MediaWiki\Tidy;
  3. /**
  4. * @internal
  5. */
  6. class RemexMungerData {
  7. /**
  8. * The Element for the mw:p-wrap which is a child of the current node. If
  9. * this is set, inline insertions into this node will be diverted so that
  10. * they insert into the p-wrap.
  11. *
  12. * @var \RemexHtml\TreeBuilder\Element|null
  13. */
  14. public $childPElement;
  15. /**
  16. * This tracks the mw:p-wrap node in the Serializer stack which is an
  17. * ancestor of this node. If there is no mw:p-wrap ancestor, it is null.
  18. *
  19. * @var \RemexHtml\Serializer\SerializerNode|null
  20. */
  21. public $ancestorPNode;
  22. /**
  23. * The wrap base node is the body or blockquote node which is the parent
  24. * of active p-wrappers. This is set if there is an ancestor p-wrapper,
  25. * or if a p-wrapper was closed due to a block element being encountered
  26. * inside it.
  27. *
  28. * @var \RemexHtml\Serializer\SerializerNode|null
  29. */
  30. public $wrapBaseNode;
  31. /**
  32. * Stack splitting (essentially our idea of AFE reconstruction) can clone
  33. * formatting elements which are split over multiple paragraphs.
  34. * TreeBuilder is not aware of the cloning, and continues to insert into
  35. * the original element. This is set to the newer clone if this node was
  36. * cloned, i.e. if there is an active diversion of the insertion location.
  37. *
  38. * @var \RemexHtml\TreeBuilder\Element|null
  39. */
  40. public $currentCloneElement;
  41. /**
  42. * Is the node a p-wrapper, with name mw:p-wrap?
  43. *
  44. * @var bool
  45. */
  46. public $isPWrapper = false;
  47. /**
  48. * Is the node splittable, i.e. a formatting element or a node with a
  49. * formatting element ancestor which is under an active or deactivated
  50. * p-wrapper.
  51. *
  52. * @var bool
  53. */
  54. public $isSplittable = false;
  55. /**
  56. * This is true if the node is a body or blockquote, which activates
  57. * p-wrapping of child nodes.
  58. */
  59. public $needsPWrapping = false;
  60. /**
  61. * The number of child nodes, not counting whitespace-only text nodes or
  62. * comments.
  63. */
  64. public $nonblankNodeCount = 0;
  65. public function __set( $name, $value ) {
  66. throw new \Exception( "Cannot set property \"$name\"" );
  67. }
  68. /**
  69. * Get a text representation of the current state of the serializer, for
  70. * debugging.
  71. *
  72. * @return string
  73. */
  74. public function dump() {
  75. $parts = [];
  76. if ( $this->childPElement ) {
  77. $parts[] = 'childPElement=' . $this->childPElement->getDebugTag();
  78. }
  79. if ( $this->ancestorPNode ) {
  80. $parts[] = "ancestorPNode=<{$this->ancestorPNode->name}>";
  81. }
  82. if ( $this->wrapBaseNode ) {
  83. $parts[] = "wrapBaseNode=<{$this->wrapBaseNode->name}>";
  84. }
  85. if ( $this->currentCloneElement ) {
  86. $parts[] = "currentCloneElement=" . $this->currentCloneElement->getDebugTag();
  87. }
  88. if ( $this->isPWrapper ) {
  89. $parts[] = 'isPWrapper';
  90. }
  91. if ( $this->isSplittable ) {
  92. $parts[] = 'isSplittable';
  93. }
  94. if ( $this->needsPWrapping ) {
  95. $parts[] = 'needsPWrapping';
  96. }
  97. if ( $this->nonblankNodeCount ) {
  98. $parts[] = "nonblankNodeCount={$this->nonblankNodeCount}";
  99. }
  100. $s = "RemexMungerData {\n";
  101. foreach ( $parts as $part ) {
  102. $s .= " $part\n";
  103. }
  104. $s .= "}\n";
  105. return $s;
  106. }
  107. }