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
44 * as used in some extensions.
50 function newCustomFrame( $args );
53 * Create a new custom node for programmatic use of parameter replacement
54 * as used in some extensions.
56 * @param array $values
58 function newPartNodeArray( $values );
61 * Preprocess text to a PPNode
68 function preprocessToObj( $text, $flags = 0 );
76 const NO_TEMPLATES
= 2;
77 const STRIP_COMMENTS
= 4;
79 const RECOVER_COMMENTS
= 16;
81 const RECOVER_ORIG
= 27; // = 1|2|8|16 no constant expression support in PHP yet
83 /** This constant exists when $indexOffset is supported in newChild() */
84 const SUPPORTS_INDEX_OFFSET
= 1;
87 * Create a child frame
89 * @param array|bool $args
90 * @param bool|Title $title
91 * @param int $indexOffset A number subtracted from the index attributes of the arguments
95 function newChild( $args = false, $title = false, $indexOffset = 0 );
98 * Expand a document tree node, caching the result on its parent with the given key
100 function cachedExpand( $key, $root, $flags = 0 );
103 * Expand a document tree node
105 function expand( $root, $flags = 0 );
108 * Implode with flags for expand()
110 function implodeWithFlags( $sep, $flags /*, ... */ );
113 * Implode with no flags specified
115 function implode( $sep /*, ... */ );
118 * Makes an object that, when expand()ed, will be the same as one obtained
121 function virtualImplode( $sep /*, ... */ );
124 * Virtual implode with brackets
126 function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
129 * Returns true if there are no arguments in this frame
136 * Returns all arguments of this frame
138 function getArguments();
141 * Returns all numbered arguments of this frame
143 function getNumberedArguments();
146 * Returns all named arguments of this frame
148 function getNamedArguments();
151 * Get an argument to this frame by name
153 function getArgument( $name );
156 * Returns true if the infinite loop check is OK, false if a loop is detected
158 * @param Title $title
161 function loopCheck( $title );
164 * Return true if the frame is a template frame
166 function isTemplate();
169 * Get a title of frame
177 * There are three types of nodes:
178 * * Tree nodes, which have a name and contain other nodes as children
179 * * Array nodes, which also contain other nodes but aren't considered part of a tree
180 * * Leaf nodes, which contain the actual data
182 * This interface provides access to the tree structure and to the contents of array nodes,
183 * but it does not provide access to the internal structure of leaf nodes. Access to leaf
184 * data is provided via two means:
185 * * PPFrame::expand(), which provides expanded text
186 * * The PPNode::split*() functions, which provide metadata about certain types of tree node
191 * Get an array-type node containing the children of this node.
192 * Returns false if this is not a tree node.
194 function getChildren();
197 * Get the first child of a tree node. False if there isn't one.
201 function getFirstChild();
204 * Get the next sibling of any node. False if there isn't one
206 function getNextSibling();
209 * Get all children of this tree node which have a given name.
210 * Returns an array-type node, or false if this is not a tree node.
212 function getChildrenOfType( $type );
215 * Returns the length of the array, or false if this is not an array-type node
217 function getLength();
220 * Returns an item of an array-type node
225 * Get the name of this node. The following names are defined here:
228 * template A double-brace node.
229 * tplarg A triple-brace node.
230 * title The first argument to a template or tplarg node.
231 * part Subsequent arguments to a template or tplarg node.
232 * #nodelist An array-type node
234 * The subclass may define various other names for tree and leaf nodes.
239 * Split a "<part>" node into an associative array containing:
247 * Split an "<ext>" node into an associative array containing name, attr, inner and close
248 * All values in the resulting array are PPNodes. Inner and close are optional.
253 * Split an "<h>" node
255 function splitHeading();