Index: trunk/extensions/Validator/includes/ParserHook.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | * |
34 | 34 | * @since 0.4 |
35 | 35 | * |
36 | | - * @return string |
| 36 | + * @return string or array of string |
37 | 37 | */ |
38 | 38 | protected abstract function getName(); |
39 | 39 | |
— | — | @@ -66,14 +66,60 @@ |
67 | 67 | * @return true |
68 | 68 | */ |
69 | 69 | public function init( Parser &$wgParser ) { |
70 | | - $name = get_class( $this ); |
71 | | - $wgParser->setHook( $this->getName(), array( new ParserHookCaller( $name, 'renderTag' ), 'runHook' ) ); |
72 | | - $wgParser->setFunctionHook( $this->getName(), array( new ParserHookCaller( $name, 'renderFunction' ), 'runHook' ) ); |
| 70 | + $className = get_class( $this ); |
| 71 | + |
| 72 | + foreach ( $this->getNames() as $name ) { |
| 73 | + $wgParser->setHook( $this->getTagName( $name ), array( new ParserHookCaller( $className, 'renderTag' ), 'runHook' ) ); |
| 74 | + $wgParser->setFunctionHook( $name, array( new ParserHookCaller( $className, 'renderFunction' ), 'runHook' ) ); |
| 75 | + } |
73 | 76 | |
74 | 77 | return true; |
75 | 78 | } |
76 | 79 | |
77 | 80 | /** |
| 81 | + * returns an array with the names for the parser hook. |
| 82 | + * |
| 83 | + * @since 0.4 |
| 84 | + * |
| 85 | + * @return array |
| 86 | + */ |
| 87 | + protected function getNames() { |
| 88 | + $names = $this->getName(); |
| 89 | + |
| 90 | + if ( !is_array( $names ) ) { |
| 91 | + $names = array( $names ); |
| 92 | + } |
| 93 | + |
| 94 | + return $names; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Returns the tag extension version of the name. |
| 99 | + * |
| 100 | + * @since 0.4 |
| 101 | + * |
| 102 | + * @param string $rawName |
| 103 | + * |
| 104 | + * @return string |
| 105 | + */ |
| 106 | + protected function getTagName( $rawName ) { |
| 107 | + return str_replace( '_', ' ', $rawName ); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Returns the parser function version of the name. |
| 112 | + * |
| 113 | + * @since 0.4 |
| 114 | + * |
| 115 | + * @param string $rawName |
| 116 | + * |
| 117 | + * @return string |
| 118 | + */ |
| 119 | + protected function getFunctionName( $rawName ) { |
| 120 | + return str_replace( ' ', '_', $rawName ); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
78 | 124 | * Function to add the magic word in pre MW 1.16. |
79 | 125 | * |
80 | 126 | * @since 0.4 |
— | — | @@ -84,7 +130,10 @@ |
85 | 131 | * @return true |
86 | 132 | */ |
87 | 133 | public function magic( array &$magicWords, $langCode ) { |
88 | | - $magicWords[$this->getName()] = array( 0, $this->getName() ); |
| 134 | + foreach ( $this->getNames() as $name ) { |
| 135 | + $name = $this->getFunctionName( $name ); |
| 136 | + $magicWords[$name] = array( 0, $name ); |
| 137 | + } |
89 | 138 | |
90 | 139 | return true; |
91 | 140 | } |
— | — | @@ -110,7 +159,7 @@ |
111 | 160 | if ( !is_null( $defaultParam ) && !is_null( $input ) ) { |
112 | 161 | $args[$defaultParam] = $input; |
113 | 162 | } |
114 | | - |
| 163 | + |
115 | 164 | return $this->validateAndRender( $args, true ); |
116 | 165 | } |
117 | 166 | |