3 * Interfaces for preprocessors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
27 interface Preprocessor
{
29 * Create a new preprocessor object based on an initialised Parser object
31 * @param $parser Parser
33 function __construct( $parser );
36 * Create a new top-level frame for expansion of a page
43 * Create a new custom frame for programmatic use of parameter replacement as used in some extensions
49 function newCustomFrame( $args );
52 * Create a new custom node for programmatic use of parameter replacement as used in some extensions
56 function newPartNodeArray( $values );
59 * Preprocess text to a PPNode
66 function preprocessToObj( $text, $flags = 0 );
74 const NO_TEMPLATES
= 2;
75 const STRIP_COMMENTS
= 4;
77 const RECOVER_COMMENTS
= 16;
79 const RECOVER_ORIG
= 27; // = 1|2|8|16 no constant expression support in PHP yet
81 /** This constant exists when $indexOffset is supported in newChild() */
82 const SUPPORTS_INDEX_OFFSET
= 1;
85 * Create a child frame
89 * @param int $indexOffset A number subtracted from the index attributes of the arguments
93 function newChild( $args = false, $title = false, $indexOffset = 0 );
96 * Expand a document tree node
98 function expand( $root, $flags = 0 );
101 * Implode with flags for expand()
103 function implodeWithFlags( $sep, $flags /*, ... */ );
106 * Implode with no flags specified
108 function implode( $sep /*, ... */ );
111 * Makes an object that, when expand()ed, will be the same as one obtained
114 function virtualImplode( $sep /*, ... */ );
117 * Virtual implode with brackets
119 function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
122 * Returns true if there are no arguments in this frame
129 * Returns all arguments of this frame
131 function getArguments();
134 * Returns all numbered arguments of this frame
136 function getNumberedArguments();
139 * Returns all named arguments of this frame
141 function getNamedArguments();
144 * Get an argument to this frame by name
146 function getArgument( $name );
149 * Returns true if the infinite loop check is OK, false if a loop is detected
155 function loopCheck( $title );
158 * Return true if the frame is a template frame
160 function isTemplate();
163 * Get a title of frame
171 * There are three types of nodes:
172 * * Tree nodes, which have a name and contain other nodes as children
173 * * Array nodes, which also contain other nodes but aren't considered part of a tree
174 * * Leaf nodes, which contain the actual data
176 * This interface provides access to the tree structure and to the contents of array nodes,
177 * but it does not provide access to the internal structure of leaf nodes. Access to leaf
178 * data is provided via two means:
179 * * PPFrame::expand(), which provides expanded text
180 * * The PPNode::split*() functions, which provide metadata about certain types of tree node
185 * Get an array-type node containing the children of this node.
186 * Returns false if this is not a tree node.
188 function getChildren();
191 * Get the first child of a tree node. False if there isn't one.
195 function getFirstChild();
198 * Get the next sibling of any node. False if there isn't one
200 function getNextSibling();
203 * Get all children of this tree node which have a given name.
204 * Returns an array-type node, or false if this is not a tree node.
206 function getChildrenOfType( $type );
209 * Returns the length of the array, or false if this is not an array-type node
211 function getLength();
214 * Returns an item of an array-type node
219 * Get the name of this node. The following names are defined here:
222 * template A double-brace node.
223 * tplarg A triple-brace node.
224 * title The first argument to a template or tplarg node.
225 * part Subsequent arguments to a template or tplarg node.
226 * #nodelist An array-type node
228 * The subclass may define various other names for tree and leaf nodes.
233 * Split a "<part>" node into an associative array containing:
241 * Split an "<ext>" node into an associative array containing name, attr, inner and close
242 * All values in the resulting array are PPNodes. Inner and close are optional.
247 * Split an "<h>" node
249 function splitHeading();