Follow up to r89419:
[mediawiki.git] / includes / parser / Preprocessor.php
blobd6328aa738f3738a50ad9f8e7fe1d76c0f28e61a
1 <?php
2 /**
3 * Interfaces for preprocessors
5 * @file
6 */
8 /**
9 * @ingroup Parser
11 interface Preprocessor {
12 /**
13 * Create a new preprocessor object based on an initialised Parser object
15 * @param $parser Parser
17 function __construct( $parser );
19 /**
20 * Create a new top-level frame for expansion of a page
22 * @return PPFrame
24 function newFrame();
26 /**
27 * Create a new custom frame for programmatic use of parameter replacement as used in some extensions
29 * @param $args array
31 * @return PPFrame
33 function newCustomFrame( $args );
35 /**
36 * Create a new custom node for programmatic use of parameter replacement as used in some extensions
38 * @param $values
40 function newPartNodeArray( $values );
42 /**
43 * Preprocess text to a PPNode
45 * @param $text
46 * @param $flags
48 * @return PPNode
50 function preprocessToObj( $text, $flags = 0 );
53 /**
54 * @ingroup Parser
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;
63 const RECOVER_ORIG = 27; // = 1|2|8|16 no constant expression support in PHP yet
65 /**
66 * Create a child frame
68 * @param $args array
69 * @param $title Title
71 * @return PPFrame
73 function newChild( $args = false, $title = false );
75 /**
76 * Expand a document tree node
78 function expand( $root, $flags = 0 );
80 /**
81 * Implode with flags for expand()
83 function implodeWithFlags( $sep, $flags /*, ... */ );
85 /**
86 * Implode with no flags specified
88 function implode( $sep /*, ... */ );
90 /**
91 * Makes an object that, when expand()ed, will be the same as one obtained
92 * with implode()
94 function virtualImplode( $sep /*, ... */ );
96 /**
97 * Virtual implode with brackets
99 function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
102 * Returns true if there are no arguments in this frame
104 * @return bool
106 function isEmpty();
109 * Returns all arguments of this frame
111 function getArguments();
114 * Returns all numbered arguments of this frame
116 function getNumberedArguments();
119 * Returns all named arguments of this frame
121 function getNamedArguments();
124 * Get an argument to this frame by name
126 function getArgument( $name );
129 * Returns true if the infinite loop check is OK, false if a loop is detected
131 * @param $title
133 * @return bool
135 function loopCheck( $title );
138 * Return true if the frame is a template frame
140 function isTemplate();
144 * There are three types of nodes:
145 * * Tree nodes, which have a name and contain other nodes as children
146 * * Array nodes, which also contain other nodes but aren't considered part of a tree
147 * * Leaf nodes, which contain the actual data
149 * This interface provides access to the tree structure and to the contents of array nodes,
150 * but it does not provide access to the internal structure of leaf nodes. Access to leaf
151 * data is provided via two means:
152 * * PPFrame::expand(), which provides expanded text
153 * * The PPNode::split*() functions, which provide metadata about certain types of tree node
154 * @ingroup Parser
156 interface PPNode {
158 * Get an array-type node containing the children of this node.
159 * Returns false if this is not a tree node.
161 function getChildren();
164 * Get the first child of a tree node. False if there isn't one.
166 * @return PPNode
168 function getFirstChild();
171 * Get the next sibling of any node. False if there isn't one
173 function getNextSibling();
176 * Get all children of this tree node which have a given name.
177 * Returns an array-type node, or false if this is not a tree node.
179 function getChildrenOfType( $type );
183 * Returns the length of the array, or false if this is not an array-type node
185 function getLength();
188 * Returns an item of an array-type node
190 function item( $i );
193 * Get the name of this node. The following names are defined here:
195 * h A heading node.
196 * template A double-brace node.
197 * tplarg A triple-brace node.
198 * title The first argument to a template or tplarg node.
199 * part Subsequent arguments to a template or tplarg node.
200 * #nodelist An array-type node
202 * The subclass may define various other names for tree and leaf nodes.
204 function getName();
207 * Split a <part> node into an associative array containing:
208 * name PPNode name
209 * index String index
210 * value PPNode value
212 function splitArg();
215 * Split an <ext> node into an associative array containing name, attr, inner and close
216 * All values in the resulting array are PPNodes. Inner and close are optional.
218 function splitExt();
221 * Split an <h> node
223 function splitHeading();