Merge "Optimize HashRing to avoid hashing for the common single-location case"
[lhc/web/wiklou.git] / includes / parser / PPFrame.php
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 /**
23 * @ingroup Parser
24 */
25 interface PPFrame {
26 const NO_ARGS = 1;
27 const NO_TEMPLATES = 2;
28 const STRIP_COMMENTS = 4;
29 const NO_IGNORE = 8;
30 const RECOVER_COMMENTS = 16;
31 const NO_TAGS = 32;
32
33 const RECOVER_ORIG = self::NO_ARGS | self::NO_TEMPLATES | self::NO_IGNORE |
34 self::RECOVER_COMMENTS | self::NO_TAGS;
35
36 /** This constant exists when $indexOffset is supported in newChild() */
37 const SUPPORTS_INDEX_OFFSET = 1;
38
39 /**
40 * Create a child frame
41 *
42 * @param array|bool $args
43 * @param bool|Title $title
44 * @param int $indexOffset A number subtracted from the index attributes of the arguments
45 *
46 * @return PPFrame
47 */
48 public function newChild( $args = false, $title = false, $indexOffset = 0 );
49
50 /**
51 * Expand a document tree node, caching the result on its parent with the given key
52 * @param string|int $key
53 * @param string|PPNode $root
54 * @param int $flags
55 * @return string
56 */
57 public function cachedExpand( $key, $root, $flags = 0 );
58
59 /**
60 * Expand a document tree node
61 * @param string|PPNode $root
62 * @param int $flags
63 * @return string
64 */
65 public function expand( $root, $flags = 0 );
66
67 /**
68 * Implode with flags for expand()
69 * @param string $sep
70 * @param int $flags
71 * @param string|PPNode $args,...
72 * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847
73 * @return string
74 */
75 public function implodeWithFlags( $sep, $flags /*, ... */ );
76
77 /**
78 * Implode with no flags specified
79 * @param string $sep
80 * @param string|PPNode $args,...
81 * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847
82 * @return string
83 */
84 public function implode( $sep /*, ... */ );
85
86 /**
87 * Makes an object that, when expand()ed, will be the same as one obtained
88 * with implode()
89 * @param string $sep
90 * @param string|PPNode ...$args
91 * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847
92 * @return PPNode
93 */
94 public function virtualImplode( $sep /* ...$args */ );
95
96 /**
97 * Virtual implode with brackets
98 * @param string $start
99 * @param string $sep
100 * @param string $end
101 * @param string|PPNode ...$args
102 * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847
103 * @return PPNode
104 */
105 public function virtualBracketedImplode( $start, $sep, $end /* ...$args */ );
106
107 /**
108 * Returns true if there are no arguments in this frame
109 *
110 * @return bool
111 */
112 public function isEmpty();
113
114 /**
115 * Returns all arguments of this frame
116 * @return array
117 */
118 public function getArguments();
119
120 /**
121 * Returns all numbered arguments of this frame
122 * @return array
123 */
124 public function getNumberedArguments();
125
126 /**
127 * Returns all named arguments of this frame
128 * @return array
129 */
130 public function getNamedArguments();
131
132 /**
133 * Get an argument to this frame by name
134 * @param int|string $name
135 * @return string|bool
136 */
137 public function getArgument( $name );
138
139 /**
140 * Returns true if the infinite loop check is OK, false if a loop is detected
141 *
142 * @param Title $title
143 * @return bool
144 */
145 public function loopCheck( $title );
146
147 /**
148 * Return true if the frame is a template frame
149 * @return bool
150 */
151 public function isTemplate();
152
153 /**
154 * Set the "volatile" flag.
155 *
156 * Note that this is somewhat of a "hack" in order to make extensions
157 * with side effects (such as Cite) work with the PHP parser. New
158 * extensions should be written in a way that they do not need this
159 * function, because other parsers (such as Parsoid) are not guaranteed
160 * to respect it, and it may be removed in the future.
161 *
162 * @param bool $flag
163 */
164 public function setVolatile( $flag = true );
165
166 /**
167 * Get the "volatile" flag.
168 *
169 * Callers should avoid caching the result of an expansion if it has the
170 * volatile flag set.
171 *
172 * @see self::setVolatile()
173 * @return bool
174 */
175 public function isVolatile();
176
177 /**
178 * Get the TTL of the frame's output.
179 *
180 * This is the maximum amount of time, in seconds, that this frame's
181 * output should be cached for. A value of null indicates that no
182 * maximum has been specified.
183 *
184 * Note that this TTL only applies to caching frames as parts of pages.
185 * It is not relevant to caching the entire rendered output of a page.
186 *
187 * @return int|null
188 */
189 public function getTTL();
190
191 /**
192 * Set the TTL of the output of this frame and all of its ancestors.
193 * Has no effect if the new TTL is greater than the one already set.
194 * Note that it is the caller's responsibility to change the cache
195 * expiry of the page as a whole, if such behavior is desired.
196 *
197 * @see self::getTTL()
198 * @param int $ttl
199 */
200 public function setTTL( $ttl );
201
202 /**
203 * Get a title of frame
204 *
205 * @return Title
206 */
207 public function getTitle();
208 }