r74344 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74343‎ | r74344 | r74345 >
Date:10:29, 6 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - support multiple names for a parser hook
Modified paths:
  • /trunk/extensions/Validator/includes/ParserHook.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/ParserHook.php
@@ -32,7 +32,7 @@
3333 *
3434 * @since 0.4
3535 *
36 - * @return string
 36+ * @return string or array of string
3737 */
3838 protected abstract function getName();
3939
@@ -66,14 +66,60 @@
6767 * @return true
6868 */
6969 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+ }
7376
7477 return true;
7578 }
7679
7780 /**
 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+ /**
78124 * Function to add the magic word in pre MW 1.16.
79125 *
80126 * @since 0.4
@@ -84,7 +130,10 @@
85131 * @return true
86132 */
87133 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+ }
89138
90139 return true;
91140 }
@@ -110,7 +159,7 @@
111160 if ( !is_null( $defaultParam ) && !is_null( $input ) ) {
112161 $args[$defaultParam] = $input;
113162 }
114 -
 163+
115164 return $this->validateAndRender( $args, true );
116165 }
117166

Status & tagging log