Preprocessor.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * @ingroup Parser
  4. */
  5. interface Preprocessor {
  6. /** Create a new preprocessor object based on an initialised Parser object */
  7. function __construct( $parser );
  8. /** Create a new top-level frame for expansion of a page */
  9. function newFrame();
  10. /** Create a new custom frame for programmatic use of parameter replacement as used in some extensions */
  11. function newCustomFrame( $args );
  12. /** Preprocess text to a PPNode */
  13. function preprocessToObj( $text, $flags = 0 );
  14. }
  15. /**
  16. * @ingroup Parser
  17. */
  18. interface PPFrame {
  19. const NO_ARGS = 1;
  20. const NO_TEMPLATES = 2;
  21. const STRIP_COMMENTS = 4;
  22. const NO_IGNORE = 8;
  23. const RECOVER_COMMENTS = 16;
  24. const RECOVER_ORIG = 27; // = 1|2|8|16 no constant expression support in PHP yet
  25. /**
  26. * Create a child frame
  27. */
  28. function newChild( $args = false, $title = false );
  29. /**
  30. * Expand a document tree node
  31. */
  32. function expand( $root, $flags = 0 );
  33. /**
  34. * Implode with flags for expand()
  35. */
  36. function implodeWithFlags( $sep, $flags /*, ... */ );
  37. /**
  38. * Implode with no flags specified
  39. */
  40. function implode( $sep /*, ... */ );
  41. /**
  42. * Makes an object that, when expand()ed, will be the same as one obtained
  43. * with implode()
  44. */
  45. function virtualImplode( $sep /*, ... */ );
  46. /**
  47. * Virtual implode with brackets
  48. */
  49. function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
  50. /**
  51. * Returns true if there are no arguments in this frame
  52. */
  53. function isEmpty();
  54. /**
  55. * Get an argument to this frame by name
  56. */
  57. function getArgument( $name );
  58. /**
  59. * Returns true if the infinite loop check is OK, false if a loop is detected
  60. */
  61. function loopCheck( $title );
  62. /**
  63. * Return true if the frame is a template frame
  64. */
  65. function isTemplate();
  66. }
  67. /**
  68. * There are three types of nodes:
  69. * * Tree nodes, which have a name and contain other nodes as children
  70. * * Array nodes, which also contain other nodes but aren't considered part of a tree
  71. * * Leaf nodes, which contain the actual data
  72. *
  73. * This interface provides access to the tree structure and to the contents of array nodes,
  74. * but it does not provide access to the internal structure of leaf nodes. Access to leaf
  75. * data is provided via two means:
  76. * * PPFrame::expand(), which provides expanded text
  77. * * The PPNode::split*() functions, which provide metadata about certain types of tree node
  78. * @ingroup Parser
  79. */
  80. interface PPNode {
  81. /**
  82. * Get an array-type node containing the children of this node.
  83. * Returns false if this is not a tree node.
  84. */
  85. function getChildren();
  86. /**
  87. * Get the first child of a tree node. False if there isn't one.
  88. */
  89. function getFirstChild();
  90. /**
  91. * Get the next sibling of any node. False if there isn't one
  92. */
  93. function getNextSibling();
  94. /**
  95. * Get all children of this tree node which have a given name.
  96. * Returns an array-type node, or false if this is not a tree node.
  97. */
  98. function getChildrenOfType( $type );
  99. /**
  100. * Returns the length of the array, or false if this is not an array-type node
  101. */
  102. function getLength();
  103. /**
  104. * Returns an item of an array-type node
  105. */
  106. function item( $i );
  107. /**
  108. * Get the name of this node. The following names are defined here:
  109. *
  110. * h A heading node.
  111. * template A double-brace node.
  112. * tplarg A triple-brace node.
  113. * title The first argument to a template or tplarg node.
  114. * part Subsequent arguments to a template or tplarg node.
  115. * #nodelist An array-type node
  116. *
  117. * The subclass may define various other names for tree and leaf nodes.
  118. */
  119. function getName();
  120. /**
  121. * Split a <part> node into an associative array containing:
  122. * name PPNode name
  123. * index String index
  124. * value PPNode value
  125. */
  126. function splitArg();
  127. /**
  128. * Split an <ext> node into an associative array containing name, attr, inner and close
  129. * All values in the resulting array are PPNodes. Inner and close are optional.
  130. */
  131. function splitExt();
  132. /**
  133. * Split an <h> node
  134. */
  135. function splitHeading();
  136. }