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