Merge "Remove Vector from the default LESS import path"
[lhc/web/wiklou.git] / includes / parser / Preprocessor.php
1 <?php
2 /**
3 * Interfaces for preprocessors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Parser
22 */
23
24 /**
25 * @ingroup Parser
26 */
27 interface Preprocessor {
28 /**
29 * Create a new preprocessor object based on an initialised Parser object
30 *
31 * @param Parser $parser
32 */
33 function __construct( $parser );
34
35 /**
36 * Create a new top-level frame for expansion of a page
37 *
38 * @return PPFrame
39 */
40 function newFrame();
41
42 /**
43 * Create a new custom frame for programmatic use of parameter replacement
44 * as used in some extensions.
45 *
46 * @param array $args
47 *
48 * @return PPFrame
49 */
50 function newCustomFrame( $args );
51
52 /**
53 * Create a new custom node for programmatic use of parameter replacement
54 * as used in some extensions.
55 *
56 * @param array $values
57 */
58 function newPartNodeArray( $values );
59
60 /**
61 * Preprocess text to a PPNode
62 *
63 * @param string $text
64 * @param int $flags
65 *
66 * @return PPNode
67 */
68 function preprocessToObj( $text, $flags = 0 );
69 }
70
71 /**
72 * @ingroup Parser
73 */
74 interface PPFrame {
75 const NO_ARGS = 1;
76 const NO_TEMPLATES = 2;
77 const STRIP_COMMENTS = 4;
78 const NO_IGNORE = 8;
79 const RECOVER_COMMENTS = 16;
80
81 const RECOVER_ORIG = 27; // = 1|2|8|16 no constant expression support in PHP yet
82
83 /** This constant exists when $indexOffset is supported in newChild() */
84 const SUPPORTS_INDEX_OFFSET = 1;
85
86 /**
87 * Create a child frame
88 *
89 * @param array|bool $args
90 * @param bool|Title $title
91 * @param int $indexOffset A number subtracted from the index attributes of the arguments
92 *
93 * @return PPFrame
94 */
95 function newChild( $args = false, $title = false, $indexOffset = 0 );
96
97 /**
98 * Expand a document tree node
99 */
100 function expand( $root, $flags = 0 );
101
102 /**
103 * Implode with flags for expand()
104 */
105 function implodeWithFlags( $sep, $flags /*, ... */ );
106
107 /**
108 * Implode with no flags specified
109 */
110 function implode( $sep /*, ... */ );
111
112 /**
113 * Makes an object that, when expand()ed, will be the same as one obtained
114 * with implode()
115 */
116 function virtualImplode( $sep /*, ... */ );
117
118 /**
119 * Virtual implode with brackets
120 */
121 function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
122
123 /**
124 * Returns true if there are no arguments in this frame
125 *
126 * @return bool
127 */
128 function isEmpty();
129
130 /**
131 * Returns all arguments of this frame
132 */
133 function getArguments();
134
135 /**
136 * Returns all numbered arguments of this frame
137 */
138 function getNumberedArguments();
139
140 /**
141 * Returns all named arguments of this frame
142 */
143 function getNamedArguments();
144
145 /**
146 * Get an argument to this frame by name
147 */
148 function getArgument( $name );
149
150 /**
151 * Returns true if the infinite loop check is OK, false if a loop is detected
152 *
153 * @param Title $title
154 * @return bool
155 */
156 function loopCheck( $title );
157
158 /**
159 * Return true if the frame is a template frame
160 */
161 function isTemplate();
162
163 /**
164 * Get a title of frame
165 *
166 * @return Title
167 */
168 function getTitle();
169 }
170
171 /**
172 * There are three types of nodes:
173 * * Tree nodes, which have a name and contain other nodes as children
174 * * Array nodes, which also contain other nodes but aren't considered part of a tree
175 * * Leaf nodes, which contain the actual data
176 *
177 * This interface provides access to the tree structure and to the contents of array nodes,
178 * but it does not provide access to the internal structure of leaf nodes. Access to leaf
179 * data is provided via two means:
180 * * PPFrame::expand(), which provides expanded text
181 * * The PPNode::split*() functions, which provide metadata about certain types of tree node
182 * @ingroup Parser
183 */
184 interface PPNode {
185 /**
186 * Get an array-type node containing the children of this node.
187 * Returns false if this is not a tree node.
188 */
189 function getChildren();
190
191 /**
192 * Get the first child of a tree node. False if there isn't one.
193 *
194 * @return PPNode
195 */
196 function getFirstChild();
197
198 /**
199 * Get the next sibling of any node. False if there isn't one
200 */
201 function getNextSibling();
202
203 /**
204 * Get all children of this tree node which have a given name.
205 * Returns an array-type node, or false if this is not a tree node.
206 */
207 function getChildrenOfType( $type );
208
209 /**
210 * Returns the length of the array, or false if this is not an array-type node
211 */
212 function getLength();
213
214 /**
215 * Returns an item of an array-type node
216 */
217 function item( $i );
218
219 /**
220 * Get the name of this node. The following names are defined here:
221 *
222 * h A heading node.
223 * template A double-brace node.
224 * tplarg A triple-brace node.
225 * title The first argument to a template or tplarg node.
226 * part Subsequent arguments to a template or tplarg node.
227 * #nodelist An array-type node
228 *
229 * The subclass may define various other names for tree and leaf nodes.
230 */
231 function getName();
232
233 /**
234 * Split a "<part>" node into an associative array containing:
235 * name PPNode name
236 * index String index
237 * value PPNode value
238 */
239 function splitArg();
240
241 /**
242 * Split an "<ext>" node into an associative array containing name, attr, inner and close
243 * All values in the resulting array are PPNodes. Inner and close are optional.
244 */
245 function splitExt();
246
247 /**
248 * Split an "<h>" node
249 */
250 function splitHeading();
251 }