Several tweaks to the install.php script
[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 as used in some extensions
44 *
45 * @param array $args
46 *
47 * @return PPFrame
48 */
49 function newCustomFrame( $args );
50
51 /**
52 * Create a new custom node for programmatic use of parameter replacement as used in some extensions
53 *
54 * @param array $values
55 */
56 function newPartNodeArray( $values );
57
58 /**
59 * Preprocess text to a PPNode
60 *
61 * @param string $text
62 * @param int $flags
63 *
64 * @return PPNode
65 */
66 function preprocessToObj( $text, $flags = 0 );
67 }
68
69 /**
70 * @ingroup Parser
71 */
72 interface PPFrame {
73 const NO_ARGS = 1;
74 const NO_TEMPLATES = 2;
75 const STRIP_COMMENTS = 4;
76 const NO_IGNORE = 8;
77 const RECOVER_COMMENTS = 16;
78
79 const RECOVER_ORIG = 27; // = 1|2|8|16 no constant expression support in PHP yet
80
81 /** This constant exists when $indexOffset is supported in newChild() */
82 const SUPPORTS_INDEX_OFFSET = 1;
83
84 /**
85 * Create a child frame
86 *
87 * @param array $args
88 * @param Title $title
89 * @param int $indexOffset A number subtracted from the index attributes of the arguments
90 *
91 * @return PPFrame
92 */
93 function newChild( $args = false, $title = false, $indexOffset = 0 );
94
95 /**
96 * Expand a document tree node
97 */
98 function expand( $root, $flags = 0 );
99
100 /**
101 * Implode with flags for expand()
102 */
103 function implodeWithFlags( $sep, $flags /*, ... */ );
104
105 /**
106 * Implode with no flags specified
107 */
108 function implode( $sep /*, ... */ );
109
110 /**
111 * Makes an object that, when expand()ed, will be the same as one obtained
112 * with implode()
113 */
114 function virtualImplode( $sep /*, ... */ );
115
116 /**
117 * Virtual implode with brackets
118 */
119 function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
120
121 /**
122 * Returns true if there are no arguments in this frame
123 *
124 * @return bool
125 */
126 function isEmpty();
127
128 /**
129 * Returns all arguments of this frame
130 */
131 function getArguments();
132
133 /**
134 * Returns all numbered arguments of this frame
135 */
136 function getNumberedArguments();
137
138 /**
139 * Returns all named arguments of this frame
140 */
141 function getNamedArguments();
142
143 /**
144 * Get an argument to this frame by name
145 */
146 function getArgument( $name );
147
148 /**
149 * Returns true if the infinite loop check is OK, false if a loop is detected
150 *
151 * @param Title $title
152 * @return bool
153 */
154 function loopCheck( $title );
155
156 /**
157 * Return true if the frame is a template frame
158 */
159 function isTemplate();
160
161 /**
162 * Get a title of frame
163 *
164 * @return Title
165 */
166 function getTitle();
167 }
168
169 /**
170 * There are three types of nodes:
171 * * Tree nodes, which have a name and contain other nodes as children
172 * * Array nodes, which also contain other nodes but aren't considered part of a tree
173 * * Leaf nodes, which contain the actual data
174 *
175 * This interface provides access to the tree structure and to the contents of array nodes,
176 * but it does not provide access to the internal structure of leaf nodes. Access to leaf
177 * data is provided via two means:
178 * * PPFrame::expand(), which provides expanded text
179 * * The PPNode::split*() functions, which provide metadata about certain types of tree node
180 * @ingroup Parser
181 */
182 interface PPNode {
183 /**
184 * Get an array-type node containing the children of this node.
185 * Returns false if this is not a tree node.
186 */
187 function getChildren();
188
189 /**
190 * Get the first child of a tree node. False if there isn't one.
191 *
192 * @return PPNode
193 */
194 function getFirstChild();
195
196 /**
197 * Get the next sibling of any node. False if there isn't one
198 */
199 function getNextSibling();
200
201 /**
202 * Get all children of this tree node which have a given name.
203 * Returns an array-type node, or false if this is not a tree node.
204 */
205 function getChildrenOfType( $type );
206
207 /**
208 * Returns the length of the array, or false if this is not an array-type node
209 */
210 function getLength();
211
212 /**
213 * Returns an item of an array-type node
214 */
215 function item( $i );
216
217 /**
218 * Get the name of this node. The following names are defined here:
219 *
220 * h A heading node.
221 * template A double-brace node.
222 * tplarg A triple-brace node.
223 * title The first argument to a template or tplarg node.
224 * part Subsequent arguments to a template or tplarg node.
225 * #nodelist An array-type node
226 *
227 * The subclass may define various other names for tree and leaf nodes.
228 */
229 function getName();
230
231 /**
232 * Split a "<part>" node into an associative array containing:
233 * name PPNode name
234 * index String index
235 * value PPNode value
236 */
237 function splitArg();
238
239 /**
240 * Split an "<ext>" node into an associative array containing name, attr, inner and close
241 * All values in the resulting array are PPNodes. Inner and close are optional.
242 */
243 function splitExt();
244
245 /**
246 * Split an "<h>" node
247 */
248 function splitHeading();
249 }