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