Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php |
— | — | @@ -357,43 +357,21 @@ |
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
361 | | - * Function for handling the {{\#set_recurring_event }} parser function. |
362 | | - * This is used for defining a set of date values for a page that |
363 | | - * represents a recurring event. |
364 | | - * Like with the #set function, all annotations happen silently. |
| 361 | + * Helper function used by doSetRecurringEvent(), as well as the |
| 362 | + * Semantic Internal Objects extension |
365 | 363 | * |
366 | | - * Usage: |
367 | | - * {{\#set_recurring_event: |
368 | | - * property = Has date |
369 | | - * | start = January 4, 2010 |
370 | | - * | end = June 7, 2010 |
371 | | - * | unit = week |
372 | | - * | period = 1 |
373 | | - * | include = March 16, 2010;March 23, 2010 |
374 | | - * | exclude = March 15, 2010;March 22, 2010 |
375 | | - * }} |
376 | | - * This sets a "Has date" value for every Monday within the specified |
377 | | - * six-month period, except for two Mondays which are excluded and |
378 | | - * two Tuesdays that are saved in their place. |
379 | | - * |
380 | | - * There's also a 'week number' parameter, which is only valid when |
381 | | - * the 'unit' parameter is set to 'month'. This one dictates that the |
382 | | - * event should always happen on the n-th week of each month, instead |
383 | | - * of a specific numbered date. Negative values for 'week number' |
384 | | - * indicate the n-th last week of a month instead. |
385 | | - * |
386 | 364 | * @param Parser &$parser The current parser |
387 | | - * @return nothing |
| 365 | + * @return either null, or an array of main property name, set of |
| 366 | + * all date strings, and the unused params |
388 | 367 | */ |
389 | | - static public function doSetRecurringEvent( &$parser ) { |
390 | | - $params = func_get_args(); |
391 | | - array_shift( $params ); // We already know the $parser ... |
392 | | - |
| 368 | + static public function getDatesForRecurringEvent( $params ) { |
393 | 369 | // Initialize variables. |
| 370 | + $all_date_strings = array(); |
| 371 | + $unused_params = array(); |
394 | 372 | $property_name = $start_date = $end_date = $unit = $period = $week_num = null; |
395 | 373 | $included_dates = array(); |
396 | 374 | $excluded_dates_jd = array(); |
397 | | - |
| 375 | + |
398 | 376 | // Set values from the parameters. |
399 | 377 | foreach ( $params as $param ) { |
400 | 378 | $parts = explode( '=', trim( $param ) ); |
— | — | @@ -432,6 +410,8 @@ |
433 | 411 | $excluded_dates_jd[] = $date->getValueKey(); |
434 | 412 | } |
435 | 413 | break; |
| 414 | + default: |
| 415 | + $unused_params[] = $param; |
436 | 416 | } |
437 | 417 | } |
438 | 418 | |
— | — | @@ -470,13 +450,13 @@ |
471 | 451 | $exclude_date = ( in_array( $cur_date_jd, $excluded_dates_jd ) ); |
472 | 452 | |
473 | 453 | if ( !$exclude_date ) { |
474 | | - $cur_date_str = $cur_date->getLongWikiText(); |
475 | | - SMWParseData::addProperty( $property_name, $cur_date_str, false, $parser, true ); |
| 454 | + $all_date_strings[] = $cur_date->getLongWikiText(); |
476 | 455 | } |
477 | 456 | |
478 | 457 | // Now get the next date. |
479 | | - // Handling is different depending on whether it's month/year or week/day |
480 | | - // since the latter is a set number of days while the former isn't. |
| 458 | + // Handling is different depending on whether it's |
| 459 | + // month/year or week/day since the latter is a set |
| 460 | + // number of days while the former isn't. |
481 | 461 | if ( $unit === 'year' || $unit == 'month' ) { |
482 | 462 | $cur_year = $cur_date->getYear(); |
483 | 463 | $cur_month = $cur_date->getMonth(); |
— | — | @@ -537,7 +517,7 @@ |
538 | 518 | } |
539 | 519 | } while ( !$right_month || !$right_week); |
540 | 520 | } else { // $unit == 'day' or 'week' |
541 | | - // Sssume 'day' if it's none of the above. |
| 521 | + // Assume 'day' if it's none of the above. |
542 | 522 | $cur_date_jd += ( $unit === 'week' ) ? 7 * $period : $period; |
543 | 523 | $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd ); |
544 | 524 | } |
— | — | @@ -553,10 +533,57 @@ |
554 | 534 | } while ( !$reached_end_date ); |
555 | 535 | |
556 | 536 | // Handle the 'include' dates as well. |
557 | | - foreach ( $included_dates as $date_str ) { |
| 537 | + $all_date_strings = array_merge( $all_date_strings, $included_dates); |
| 538 | + return array( $property_name, $all_date_strings, $unused_params ); |
| 539 | + } |
| 540 | + |
| 541 | + /** |
| 542 | + * Function for handling the {{\#set_recurring_event }} parser function. |
| 543 | + * This is used for defining a set of date values for a page that |
| 544 | + * represents a recurring event. |
| 545 | + * Like with the #set function, all annotations happen silently. |
| 546 | + * |
| 547 | + * Usage: |
| 548 | + * {{\#set_recurring_event: |
| 549 | + * property = Has date |
| 550 | + * | start = January 4, 2010 |
| 551 | + * | end = June 7, 2010 |
| 552 | + * | unit = week |
| 553 | + * | period = 1 |
| 554 | + * | include = March 16, 2010;March 23, 2010 |
| 555 | + * | exclude = March 15, 2010;March 22, 2010 |
| 556 | + * }} |
| 557 | + * This sets a "Has date" value for every Monday within the specified |
| 558 | + * six-month period, except for two Mondays which are excluded and |
| 559 | + * two Tuesdays that are saved in their place. |
| 560 | + * |
| 561 | + * There's also a 'week number' parameter, which is only valid when |
| 562 | + * the 'unit' parameter is set to 'month'. This one dictates that the |
| 563 | + * event should always happen on the n-th week of each month, instead |
| 564 | + * of a specific numbered date. Negative values for 'week number' |
| 565 | + * indicate the n-th last week of a month instead. |
| 566 | + * |
| 567 | + * @param Parser &$parser The current parser |
| 568 | + * @return nothing |
| 569 | + */ |
| 570 | + static public function doSetRecurringEvent( &$parser ) { |
| 571 | + $params = func_get_args(); |
| 572 | + array_shift( $params ); // We already know the $parser ... |
| 573 | + |
| 574 | + // Almost all of the work gets done by |
| 575 | + // getDatesForRecurringEvent(). |
| 576 | + $results = self::getDatesForRecurringEvent( $params ); |
| 577 | + if ( $results == null ) { |
| 578 | + return null; |
| 579 | + } |
| 580 | + |
| 581 | + list( $property, $all_date_strings, $unused_params ) = $results; |
| 582 | + |
| 583 | + // Do the actual saving of the data. |
| 584 | + foreach ( $all_date_strings as $date_str ) { |
558 | 585 | SMWParseData::addProperty( $property_name, $date_str, false, $parser, true ); |
559 | 586 | } |
560 | | - |
| 587 | + |
561 | 588 | SMWOutputs::commitToParser( $parser ); // Not obviously required, but let us be sure. |
562 | 589 | } |
563 | 590 | |
— | — | @@ -621,4 +648,4 @@ |
622 | 649 | return ''; |
623 | 650 | } |
624 | 651 | |
625 | | -} |
\ No newline at end of file |
| 652 | +} |