Index: trunk/extensions/Validator/RELEASE-NOTES |
— | — | @@ -4,6 +4,18 @@ |
5 | 5 | This change log contains a list of completed to-do's (new features, bug fixes, refactoring) for every version of Validator. |
6 | 6 | |
7 | 7 | |
| 8 | +=== Validator 0.4.13 alpha === |
| 9 | +( trunk ) |
| 10 | + |
| 11 | +* ParserHook::$parser now is a reference to the original parser object, as one would suspect. |
| 12 | + Before this has only been the case for tag extension but not for parser function calls. |
| 13 | + |
| 14 | +* if SFH_OBJECT_ARGS and therefore object parser function arguments are available in the MW |
| 15 | + version used with Validator, ParserHook::$frame will not be null anymore. Therefore a new |
| 16 | + function ParserHook::renderFunctionObj() is introduced, handling these SFH_OBJECT_ARGS hooks. |
| 17 | + |
| 18 | +* ParserHook Validation messages will now output text in global content language instead of users interface language. |
| 19 | + |
8 | 20 | === Validator 0.4.12 === |
9 | 21 | (2011-10-15) |
10 | 22 | |
Index: trunk/extensions/Validator/includes/ParserHook.php |
— | — | @@ -11,6 +11,10 @@ |
12 | 12 | * |
13 | 13 | * @licence GNU GPL v3 or later |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + * @author Daniel Werner |
| 16 | + * |
| 17 | + * @ToDo: Add possiblity to use 'functionTagHooks'. See Parser::setFunctionTagHook() for |
| 18 | + * details. There is not much information on this kind of parser funktion hook though. |
15 | 19 | */ |
16 | 20 | abstract class ParserHook { |
17 | 21 | |
— | — | @@ -130,11 +134,11 @@ |
131 | 135 | * |
132 | 136 | * @since 0.4 |
133 | 137 | * |
134 | | - * @param Parser $wgParser |
| 138 | + * @param Parser $parser |
135 | 139 | * |
136 | 140 | * @return true |
137 | 141 | */ |
138 | | - public function init( Parser &$wgParser ) { |
| 142 | + public function init( Parser &$parser ) { |
139 | 143 | $className = get_class( $this ); |
140 | 144 | $first = true; |
141 | 145 | |
— | — | @@ -143,18 +147,30 @@ |
144 | 148 | self::$registeredHooks[$name] = $className; |
145 | 149 | $first = false; |
146 | 150 | } |
147 | | - |
| 151 | + |
148 | 152 | if ( $this->forTagExtensions ) { |
149 | | - $wgParser->setHook( |
| 153 | + $parser->setHook( |
150 | 154 | $name, |
151 | | - array( new ParserHookCaller( $className, 'renderTag' ), 'runHook' ) |
| 155 | + array( new ParserHookCaller( $className, 'renderTag' ), 'runTagHook' ) |
152 | 156 | ); |
153 | 157 | } |
154 | 158 | |
155 | 159 | if ( $this->forParserFunctions ) { |
156 | | - $wgParser->setFunctionHook( |
| 160 | + $flags = 0; |
| 161 | + $function = 'renderFunction'; |
| 162 | + $callerFunction = 'runFunctionHook'; |
| 163 | + |
| 164 | + // use object arguments if available: |
| 165 | + if ( defined( 'SFH_OBJECT_ARGS' ) ) { |
| 166 | + $flags = $flags | SFH_OBJECT_ARGS; |
| 167 | + $function .= 'Obj'; |
| 168 | + $callerFunction .= 'Obj'; |
| 169 | + } |
| 170 | + |
| 171 | + $parser->setFunctionHook( |
157 | 172 | $name, |
158 | | - array( new ParserHookCaller( $className, 'renderFunction' ), 'runHook' ) |
| 173 | + array( new ParserHookCaller( $className, $function ), $callerFunction ), |
| 174 | + $flags |
159 | 175 | ); |
160 | 176 | } |
161 | 177 | } |
— | — | @@ -198,11 +214,11 @@ |
199 | 215 | } |
200 | 216 | |
201 | 217 | /** |
202 | | - * Handler for rendering the tag hook. |
| 218 | + * Handler for rendering the tag hook registered by Parser::setHook() |
203 | 219 | * |
204 | 220 | * @since 0.4 |
205 | 221 | * |
206 | | - * @param minxed $input string or null |
| 222 | + * @param mixed $input string or null |
207 | 223 | * @param array $args |
208 | 224 | * @param Parser $parser |
209 | 225 | * @param PPFrame $frame Available from 1.16 |
— | — | @@ -216,7 +232,7 @@ |
217 | 233 | $defaultParameters = $this->getDefaultParameters( self::TYPE_TAG ); |
218 | 234 | $defaultParam = array_shift( $defaultParameters ); |
219 | 235 | |
220 | | - // If there is a first default parameter, set the tag contents as it's value. |
| 236 | + // If there is a first default parameter, set the tag contents as its value. |
221 | 237 | if ( !is_null( $defaultParam ) && !is_null( $input ) ) { |
222 | 238 | $args[$defaultParam] = $input; |
223 | 239 | } |
— | — | @@ -225,23 +241,28 @@ |
226 | 242 | } |
227 | 243 | |
228 | 244 | /** |
229 | | - * Handler for rendering the function hook. |
| 245 | + * Handler for rendering the function hook registered by Parser::setFunctionHook() |
230 | 246 | * |
231 | 247 | * @since 0.4 |
232 | 248 | * |
233 | | - * @param Parser $parser |
| 249 | + * @param Parser &$parser |
234 | 250 | * ... further arguments ... |
235 | 251 | * |
236 | 252 | * @return array |
237 | 253 | */ |
238 | | - public function renderFunction() { |
| 254 | + public function renderFunction( Parser &$parser /*, n args */ ) { |
239 | 255 | $args = func_get_args(); |
240 | | - |
| 256 | + |
241 | 257 | $this->parser = array_shift( $args ); |
| 258 | + |
242 | 259 | $output = $this->validateAndRender( $args, self::TYPE_FUNCTION ); |
243 | 260 | $options = $this->getFunctionOptions(); |
244 | 261 | |
245 | 262 | if ( array_key_exists( 'isHTML', $options ) && $options['isHTML'] ) { |
| 263 | + /** @ToDo: FIXME: Is this really necessary? The same thing is propably going to |
| 264 | + * happen in Parser::braceSubstitution() if 'isHTML' is set! |
| 265 | + * @ToDo: other options besides 'isHTML' like 'noparse' are ignored here! |
| 266 | + */ |
246 | 267 | return $this->parser->insertStripItem( $output, $this->parser->mStripState ); |
247 | 268 | } |
248 | 269 | |
— | — | @@ -250,6 +271,34 @@ |
251 | 272 | $options |
252 | 273 | ); |
253 | 274 | } |
| 275 | + |
| 276 | + /** |
| 277 | + * Handler for rendering the function hook registered by Parser::setFunctionHook() together |
| 278 | + * with object style arguments (SFH_OBJECT_ARGS flag). |
| 279 | + * |
| 280 | + * @since 0.4.13 |
| 281 | + * |
| 282 | + * @param Parser &$parser |
| 283 | + * @param PPFrame $frame |
| 284 | + * @param type $args |
| 285 | + * @return array |
| 286 | + */ |
| 287 | + public function renderFunctionObj( Parser &$parser, PPFrame $frame, $args ) { |
| 288 | + $this->frame = $frame; |
| 289 | + |
| 290 | + // create non-object args for old style 'renderFunction()' |
| 291 | + $oldStyleArgs = array( &$parser ); |
| 292 | + |
| 293 | + foreach( $args as $arg ) { |
| 294 | + $oldStyleArgs[] = trim( $frame->expand( $arg ) ); |
| 295 | + } |
| 296 | + |
| 297 | + /* |
| 298 | + * since we can't validate un-expandet arguments, we just go on with old-style function |
| 299 | + * handling from here. Only advantage is that we have $this->frame set properly. |
| 300 | + */ |
| 301 | + return call_user_func_array( array( $this, 'renderFunction' ), $oldStyleArgs ); |
| 302 | + } |
254 | 303 | |
255 | 304 | /** |
256 | 305 | * Returns the parser function otpions. |
— | — | @@ -331,9 +380,9 @@ |
332 | 381 | * |
333 | 382 | * @return string |
334 | 383 | */ |
335 | | - protected function renderFatalError( ValidationError $error ) { |
| 384 | + protected function renderFatalError( ValidationError $error ) { |
336 | 385 | return '<div><span class="errorbox">' . |
337 | | - htmlspecialchars( wfMsgExt( 'validator-fatal-error', 'parsemag', $error->getMessage() ) ) . |
| 386 | + htmlspecialchars( wfMsgExt( 'validator-fatal-error', array( 'parsemag', 'content' ), $error->getMessage() ) ) . |
338 | 387 | '</span></div><br /><br />'; |
339 | 388 | } |
340 | 389 | |
— | — | @@ -348,21 +397,21 @@ |
349 | 398 | $displayStuff = $this->getErrorsToDisplay(); |
350 | 399 | |
351 | 400 | if ( count( $displayStuff['errors'] ) > 0 ) { |
352 | | - $output .= wfMsgExt( 'validator_error_parameters', 'parsemag', count( $displayStuff['errors'] ) ); |
| 401 | + $output .= wfMsgExt( 'validator_error_parameters', array( 'parsemag', 'content' ), count( $displayStuff['errors'] ) ); |
353 | 402 | |
354 | 403 | foreach( $displayStuff['errors'] as $error ) { |
355 | 404 | $output .= '<br />* ' . $error->getMessage(); |
356 | 405 | } |
357 | 406 | |
358 | 407 | if ( count( $displayStuff['warnings'] ) > 0 ) { |
359 | | - $output .= '<br />* ' . wfMsgExt( 'validator-warning-adittional-errors', 'parsemag', count( $displayStuff['warnings'] ) ); |
| 408 | + $output .= '<br />* ' . wfMsgExt( 'validator-warning-adittional-errors', array( 'parsemag', 'content' ), count( $displayStuff['warnings'] ) ); |
360 | 409 | } |
361 | 410 | } |
362 | 411 | elseif ( count( $displayStuff['warnings'] ) > 0 ) { |
363 | 412 | $output .= wfMsgExt( |
364 | 413 | 'validator-warning', |
365 | | - 'parsemag', |
366 | | - wfMsgExt( 'validator_warning_parameters', 'parsemag', count( $displayStuff['warnings'] ) ) |
| 414 | + array( 'parsemag', 'content' ), |
| 415 | + wfMsgExt( 'validator_warning_parameters', array( 'parsemag', 'content' ), count( $displayStuff['warnings'] ) ) |
367 | 416 | ); |
368 | 417 | } |
369 | 418 | |
— | — | @@ -505,20 +554,40 @@ |
506 | 555 | * @since 0.4 |
507 | 556 | * |
508 | 557 | * @author Jeroen De Dauw |
| 558 | + * @author Daniel Werner |
509 | 559 | */ |
510 | 560 | class ParserHookCaller { |
511 | | - |
| 561 | + |
512 | 562 | protected $class; |
513 | 563 | protected $method; |
514 | | - |
| 564 | + |
515 | 565 | function __construct( $class, $method ) { |
516 | 566 | $this->class = $class; |
517 | 567 | $this->method = $method; |
518 | 568 | } |
519 | | - |
520 | | - public function runHook() { |
| 569 | + |
| 570 | + /* |
| 571 | + * See Parser::braceSubstitution() and Parser::extensionSubstitution() for details about |
| 572 | + * how the Parser object and other parameters are being passed. Therefore for function |
| 573 | + * hooks &$parser fullfills the same purpos as $parser for the tag hook. |
| 574 | + * functionTagHook (!) calls (if implemented at a later time) are more like function hooks, |
| 575 | + * meaning, they would require &$parser as well. |
| 576 | + */ |
| 577 | + |
| 578 | + public function runTagHook( $input, array $args, Parser $parser, PPFrame $frame = null ) { |
| 579 | + $obj = new $this->class(); |
| 580 | + return $obj->{$this->method}( $input, $args, $parser, $frame ); |
| 581 | + } |
| 582 | + |
| 583 | + public function runFunctionHook( Parser &$parser /*, n args */ ) { |
521 | 584 | $args = func_get_args(); |
| 585 | + $args[0] = &$parser; // with '&' becaus call_user_func_array is being used |
522 | 586 | return call_user_func_array( array( new $this->class(), $this->method ), $args ); |
523 | 587 | } |
| 588 | + |
| 589 | + public function runFunctionHookObj( Parser &$parser, PPFrame $frame, array $args ) { |
| 590 | + $obj = new $this->class(); |
| 591 | + return $obj->{$this->method}( $parser, $frame, $args ); |
| 592 | + } |
524 | 593 | |
525 | 594 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/Validator.i18n.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | * |
10 | 10 | * @licence GNU GPL v3 or later |
11 | 11 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
12 | | -*/ |
| 12 | + */ |
13 | 13 | |
14 | 14 | $messages = array(); |
15 | 15 | |
Index: trunk/extensions/Validator/Validator.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | die( 'Not an entry point.' ); |
27 | 27 | } |
28 | 28 | |
29 | | -define( 'Validator_VERSION', '0.4.12' ); |
| 29 | +define( 'Validator_VERSION', '0.4.13 alpha' ); |
30 | 30 | |
31 | 31 | // Register the internationalization file. |
32 | 32 | $wgExtensionMessagesFiles['Validator'] = dirname( __FILE__ ) . '/Validator.i18n.php'; |