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