PPFrame.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. * @ingroup Parser
  20. */
  21. /**
  22. * @ingroup Parser
  23. *
  24. * @property int $depth
  25. * @property PPFrame $parent
  26. */
  27. interface PPFrame {
  28. const NO_ARGS = 1;
  29. const NO_TEMPLATES = 2;
  30. const STRIP_COMMENTS = 4;
  31. const NO_IGNORE = 8;
  32. const RECOVER_COMMENTS = 16;
  33. const NO_TAGS = 32;
  34. const RECOVER_ORIG = self::NO_ARGS | self::NO_TEMPLATES | self::NO_IGNORE |
  35. self::RECOVER_COMMENTS | self::NO_TAGS;
  36. /** This constant exists when $indexOffset is supported in newChild() */
  37. const SUPPORTS_INDEX_OFFSET = 1;
  38. /**
  39. * Create a child frame
  40. *
  41. * @param array|bool $args
  42. * @param bool|Title $title
  43. * @param int $indexOffset A number subtracted from the index attributes of the arguments
  44. *
  45. * @return PPFrame
  46. */
  47. public function newChild( $args = false, $title = false, $indexOffset = 0 );
  48. /**
  49. * Expand a document tree node, caching the result on its parent with the given key
  50. * @param string|int $key
  51. * @param string|PPNode $root
  52. * @param int $flags
  53. * @return string
  54. */
  55. public function cachedExpand( $key, $root, $flags = 0 );
  56. /**
  57. * Expand a document tree node
  58. * @param string|PPNode $root
  59. * @param int $flags
  60. * @return string
  61. */
  62. public function expand( $root, $flags = 0 );
  63. /**
  64. * Implode with flags for expand()
  65. * @param string $sep
  66. * @param int $flags
  67. * @param string|PPNode ...$params
  68. * @return string
  69. */
  70. public function implodeWithFlags( $sep, $flags, ...$params );
  71. /**
  72. * Implode with no flags specified
  73. * @param string $sep
  74. * @param string|PPNode ...$params
  75. * @return string
  76. */
  77. public function implode( $sep, ...$params );
  78. /**
  79. * Makes an object that, when expand()ed, will be the same as one obtained
  80. * with implode()
  81. * @param string $sep
  82. * @param string|PPNode ...$params
  83. * @return PPNode
  84. */
  85. public function virtualImplode( $sep, ...$params );
  86. /**
  87. * Virtual implode with brackets
  88. * @param string $start
  89. * @param string $sep
  90. * @param string $end
  91. * @param string|PPNode ...$params
  92. * @return PPNode
  93. */
  94. public function virtualBracketedImplode( $start, $sep, $end, ...$params );
  95. /**
  96. * Returns true if there are no arguments in this frame
  97. *
  98. * @return bool
  99. */
  100. public function isEmpty();
  101. /**
  102. * Returns all arguments of this frame
  103. * @return array
  104. */
  105. public function getArguments();
  106. /**
  107. * Returns all numbered arguments of this frame
  108. * @return array
  109. */
  110. public function getNumberedArguments();
  111. /**
  112. * Returns all named arguments of this frame
  113. * @return array
  114. */
  115. public function getNamedArguments();
  116. /**
  117. * Get an argument to this frame by name
  118. * @param int|string $name
  119. * @return string|bool
  120. */
  121. public function getArgument( $name );
  122. /**
  123. * Returns true if the infinite loop check is OK, false if a loop is detected
  124. *
  125. * @param Title $title
  126. * @return bool
  127. */
  128. public function loopCheck( $title );
  129. /**
  130. * Return true if the frame is a template frame
  131. * @return bool
  132. */
  133. public function isTemplate();
  134. /**
  135. * Set the "volatile" flag.
  136. *
  137. * Note that this is somewhat of a "hack" in order to make extensions
  138. * with side effects (such as Cite) work with the PHP parser. New
  139. * extensions should be written in a way that they do not need this
  140. * function, because other parsers (such as Parsoid) are not guaranteed
  141. * to respect it, and it may be removed in the future.
  142. *
  143. * @param bool $flag
  144. */
  145. public function setVolatile( $flag = true );
  146. /**
  147. * Get the "volatile" flag.
  148. *
  149. * Callers should avoid caching the result of an expansion if it has the
  150. * volatile flag set.
  151. *
  152. * @see self::setVolatile()
  153. * @return bool
  154. */
  155. public function isVolatile();
  156. /**
  157. * Get the TTL of the frame's output.
  158. *
  159. * This is the maximum amount of time, in seconds, that this frame's
  160. * output should be cached for. A value of null indicates that no
  161. * maximum has been specified.
  162. *
  163. * Note that this TTL only applies to caching frames as parts of pages.
  164. * It is not relevant to caching the entire rendered output of a page.
  165. *
  166. * @return int|null
  167. */
  168. public function getTTL();
  169. /**
  170. * Set the TTL of the output of this frame and all of its ancestors.
  171. * Has no effect if the new TTL is greater than the one already set.
  172. * Note that it is the caller's responsibility to change the cache
  173. * expiry of the page as a whole, if such behavior is desired.
  174. *
  175. * @see self::getTTL()
  176. * @param int $ttl
  177. */
  178. public function setTTL( $ttl );
  179. /**
  180. * Get a title of frame
  181. *
  182. * @return Title
  183. */
  184. public function getTitle();
  185. }