Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / parser / Preprocessor.php
blob3d2f2f869a905a5bd6d2881e22232547154d3244
1 <?php
2 /**
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
20 * @file
21 * @ingroup Parser
24 /**
25 * @ingroup Parser
27 interface Preprocessor {
28 /**
29 * Create a new preprocessor object based on an initialised Parser object
31 * @param $parser Parser
33 function __construct( $parser );
35 /**
36 * Create a new top-level frame for expansion of a page
38 * @return PPFrame
40 function newFrame();
42 /**
43 * Create a new custom frame for programmatic use of parameter replacement as used in some extensions
45 * @param $args array
47 * @return PPFrame
49 function newCustomFrame( $args );
51 /**
52 * Create a new custom node for programmatic use of parameter replacement as used in some extensions
54 * @param $values
56 function newPartNodeArray( $values );
58 /**
59 * Preprocess text to a PPNode
61 * @param $text
62 * @param $flags
64 * @return PPNode
66 function preprocessToObj( $text, $flags = 0 );
69 /**
70 * @ingroup Parser
72 interface PPFrame {
73 const NO_ARGS = 1;
74 const NO_TEMPLATES = 2;
75 const STRIP_COMMENTS = 4;
76 const NO_IGNORE = 8;
77 const RECOVER_COMMENTS = 16;
79 const RECOVER_ORIG = 27; // = 1|2|8|16 no constant expression support in PHP yet
81 /**
82 * Create a child frame
84 * @param $args array
85 * @param $title Title
87 * @return PPFrame
89 function newChild( $args = false, $title = false );
91 /**
92 * Expand a document tree node
94 function expand( $root, $flags = 0 );
96 /**
97 * Implode with flags for expand()
99 function implodeWithFlags( $sep, $flags /*, ... */ );
102 * Implode with no flags specified
104 function implode( $sep /*, ... */ );
107 * Makes an object that, when expand()ed, will be the same as one obtained
108 * with implode()
110 function virtualImplode( $sep /*, ... */ );
113 * Virtual implode with brackets
115 function virtualBracketedImplode( $start, $sep, $end /*, ... */ );
118 * Returns true if there are no arguments in this frame
120 * @return bool
122 function isEmpty();
125 * Returns all arguments of this frame
127 function getArguments();
130 * Returns all numbered arguments of this frame
132 function getNumberedArguments();
135 * Returns all named arguments of this frame
137 function getNamedArguments();
140 * Get an argument to this frame by name
142 function getArgument( $name );
145 * Returns true if the infinite loop check is OK, false if a loop is detected
147 * @param $title
149 * @return bool
151 function loopCheck( $title );
154 * Return true if the frame is a template frame
156 function isTemplate();
159 * Get a title of frame
161 * @return Title
163 function getTitle();
167 * There are three types of nodes:
168 * * Tree nodes, which have a name and contain other nodes as children
169 * * Array nodes, which also contain other nodes but aren't considered part of a tree
170 * * Leaf nodes, which contain the actual data
172 * This interface provides access to the tree structure and to the contents of array nodes,
173 * but it does not provide access to the internal structure of leaf nodes. Access to leaf
174 * data is provided via two means:
175 * * PPFrame::expand(), which provides expanded text
176 * * The PPNode::split*() functions, which provide metadata about certain types of tree node
177 * @ingroup Parser
179 interface PPNode {
181 * Get an array-type node containing the children of this node.
182 * Returns false if this is not a tree node.
184 function getChildren();
187 * Get the first child of a tree node. False if there isn't one.
189 * @return PPNode
191 function getFirstChild();
194 * Get the next sibling of any node. False if there isn't one
196 function getNextSibling();
199 * Get all children of this tree node which have a given name.
200 * Returns an array-type node, or false if this is not a tree node.
202 function getChildrenOfType( $type );
206 * Returns the length of the array, or false if this is not an array-type node
208 function getLength();
211 * Returns an item of an array-type node
213 function item( $i );
216 * Get the name of this node. The following names are defined here:
218 * h A heading node.
219 * template A double-brace node.
220 * tplarg A triple-brace node.
221 * title The first argument to a template or tplarg node.
222 * part Subsequent arguments to a template or tplarg node.
223 * #nodelist An array-type node
225 * The subclass may define various other names for tree and leaf nodes.
227 function getName();
230 * Split a <part> node into an associative array containing:
231 * name PPNode name
232 * index String index
233 * value PPNode value
235 function splitArg();
238 * Split an <ext> node into an associative array containing name, attr, inner and close
239 * All values in the resulting array are PPNodes. Inner and close are optional.
241 function splitExt();
244 * Split an <h> node
246 function splitHeading();