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