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