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