| 1 | <?php |
| 2 | /** |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | * http://www.gnu.org/copyleft/gpl.html |
| 17 | * |
| 18 | * @file |
| 19 | * @ingroup Parser |
| 20 | */ |
| 21 | |
| 22 | namespace MediaWiki\Parser; |
| 23 | |
| 24 | /** |
| 25 | * There are three types of nodes: |
| 26 | * * Tree nodes, which have a name and contain other nodes as children |
| 27 | * * Array nodes, which also contain other nodes but aren't considered part of a tree |
| 28 | * * Leaf nodes, which contain the actual data |
| 29 | * |
| 30 | * This interface provides access to the tree structure and to the contents of array nodes, |
| 31 | * but it does not provide access to the internal structure of leaf nodes. Access to leaf |
| 32 | * data is provided via two means: |
| 33 | * * PPFrame::expand(), which provides expanded text |
| 34 | * * The PPNode::split*() functions, which provide metadata about certain types of tree node |
| 35 | * @ingroup Parser |
| 36 | */ |
| 37 | interface PPNode { |
| 38 | /** |
| 39 | * Get an array-type node containing the children of this node. |
| 40 | * Returns false if this is not a tree node. |
| 41 | * @return false|PPNode |
| 42 | */ |
| 43 | public function getChildren(); |
| 44 | |
| 45 | /** |
| 46 | * Get the first child of a tree node. False if there isn't one. |
| 47 | * |
| 48 | * @return false|PPNode |
| 49 | */ |
| 50 | public function getFirstChild(); |
| 51 | |
| 52 | /** |
| 53 | * Get the next sibling of any node. False if there isn't one |
| 54 | * @return false|PPNode |
| 55 | */ |
| 56 | public function getNextSibling(); |
| 57 | |
| 58 | /** |
| 59 | * Get all children of this tree node which have a given name. |
| 60 | * Returns an array-type node, or false if this is not a tree node. |
| 61 | * @param string $type |
| 62 | * @return false|PPNode |
| 63 | */ |
| 64 | public function getChildrenOfType( $type ); |
| 65 | |
| 66 | /** |
| 67 | * Returns the length of the array, or false if this is not an array-type node |
| 68 | */ |
| 69 | public function getLength(); |
| 70 | |
| 71 | /** |
| 72 | * Returns an item of an array-type node |
| 73 | * @param int $i |
| 74 | * @return PPNode|false |
| 75 | */ |
| 76 | public function item( $i ); |
| 77 | |
| 78 | /** |
| 79 | * Get the name of this node. The following names are defined here: |
| 80 | * |
| 81 | * h A heading node. |
| 82 | * template A double-brace node. |
| 83 | * tplarg A triple-brace node. |
| 84 | * title The first argument to a template or tplarg node. |
| 85 | * part Subsequent arguments to a template or tplarg node. |
| 86 | * #nodelist An array-type node |
| 87 | * |
| 88 | * The subclass may define various other names for tree and leaf nodes. |
| 89 | * @return string |
| 90 | */ |
| 91 | public function getName(); |
| 92 | |
| 93 | /** |
| 94 | * Split a "<part>" node into an associative array containing: |
| 95 | * name PPNode name |
| 96 | * index String index |
| 97 | * value PPNode value |
| 98 | * @return array |
| 99 | */ |
| 100 | public function splitArg(); |
| 101 | |
| 102 | /** |
| 103 | * Split an "<ext>" node into an associative array containing name, attr, inner and close |
| 104 | * All values in the resulting array are PPNodes. Inner and close are optional. |
| 105 | * @return array |
| 106 | */ |
| 107 | public function splitExt(); |
| 108 | |
| 109 | /** |
| 110 | * Split an "<h>" node |
| 111 | * @return array |
| 112 | */ |
| 113 | public function splitHeading(); |
| 114 | } |
| 115 | |
| 116 | /** @deprecated class alias since 1.43 */ |
| 117 | class_alias( PPNode::class, 'PPNode' ); |