r74262 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74261‎ | r74262 | r74263 >
Date:17:03, 4 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 1.5.3 - split the parser function code from the ParserExtensions class to individual classes and added resource loader code to the light setup
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Ask.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Concept.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Declare.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Info.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Set.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Show.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php
@@ -1,18 +1,14 @@
22 <?php
33 /**
4 - * This file contains essentially all SMW code that affects parsing by reading some
5 - * special SMW syntax.
6 - * @file
 4+ * Static class to collect all functions related to parsing wiki text in SMW.
 5+ * It includes all parser function declarations and hooks.
 6+ *
 7+ * @file SMW_ParserExtensions.php
78 * @ingroup SMW
 9+ *
810 * @author Markus Krötzsch
911 * @author Denny Vrandecic
1012 */
11 -
12 -/**
13 - * Static class to collect all functions related to parsing wiki text in SMW.
14 - * It includes all parser function declarations and hooks.
15 - * @ingroup SMW
16 - */
1713 class SMWParserExtensions {
1814
1915 /// Temporarily store parser as it cannot be passed to call-back functions otherwise.
@@ -180,476 +176,4 @@
181177 return $result;
182178 }
183179
184 - /**
185 - * This hook registers parser functions and hooks to the given parser. It is
186 - * called during SMW initialisation. Note that parser hooks are something different
187 - * than MW hooks in general, which explains the two-level registration.
188 - */
189 - public static function registerParserFunctions( Parser &$parser ) {
190 - $parser->setFunctionHook( 'ask', array( 'SMWParserExtensions', 'doAsk' ) );
191 - $parser->setFunctionHook( 'show', array( 'SMWParserExtensions', 'doShow' ) );
192 - $parser->setFunctionHook( 'info', array( 'SMWParserExtensions', 'doInfo' ) );
193 - $parser->setFunctionHook( 'concept', array( 'SMWParserExtensions', 'doConcept' ) );
194 - $parser->setFunctionHook( 'set', array( 'SMWParserExtensions', 'doSet' ) );
195 - $parser->setFunctionHook( 'set_recurring_event', array( 'SMWParserExtensions', 'doSetRecurringEvent' ) );
196 - $parser->setFunctionHook( 'declare', array( 'SMWParserExtensions', 'doDeclare' ), SFH_OBJECT_ARGS );
197 -
198 - return true; // Always return true, in order not to stop MW's hook processing!
199 - }
200 -
201 - /**
202 - * Function for handling the {{\#ask }} parser function. It triggers the execution of inline
203 - * query processing and checks whether (further) inline queries are allowed.
204 - */
205 - static public function doAsk( &$parser ) {
206 - global $smwgQEnabled, $smwgIQRunningNumber;
207 -
208 - if ( $smwgQEnabled ) {
209 - $smwgIQRunningNumber++;
210 -
211 - $params = func_get_args();
212 - array_shift( $params ); // We already know the $parser ...
213 -
214 - $result = SMWQueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI );
215 - } else {
216 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
217 - $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) );
218 - }
219 -
220 - SMWOutputs::commitToParser( $parser );
221 -
222 - return $result;
223 - }
224 -
225 - /**
226 - * Function for handling the {{\#show }} parser function. The \#show function is
227 - * similar to \#ask but merely prints some property value for a specified page.
228 - */
229 - static public function doShow( &$parser ) {
230 - global $smwgQEnabled, $smwgIQRunningNumber;
231 -
232 - if ( $smwgQEnabled ) {
233 - $smwgIQRunningNumber++;
234 -
235 - $params = func_get_args();
236 - array_shift( $params ); // We already know the $parser ...
237 -
238 - $result = SMWQueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, true );
239 - } else {
240 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
241 - $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) );
242 - }
243 -
244 - SMWOutputs::commitToParser( $parser );
245 - return $result;
246 - }
247 -
248 - /**
249 - * Function for handling the {{\#concept }} parser function. This parser function provides a special input
250 - * facility for defining concepts, and it displays the resulting concept description.
251 - */
252 - static public function doConcept( &$parser ) {
253 - global $smwgQDefaultNamespaces, $smwgQMaxSize, $smwgQMaxDepth, $wgContLang;
254 -
255 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
256 -
257 - $title = $parser->getTitle();
258 - $pconc = SMWPropertyValue::makeProperty( '_CONC' );
259 -
260 - if ( $title->getNamespace() != SMW_NS_CONCEPT ) {
261 - $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_no_concept_namespace' ) ) );
262 - SMWOutputs::commitToParser( $parser );
263 - return $result;
264 - } elseif ( count( SMWParseData::getSMWdata( $parser )->getPropertyValues( $pconc ) ) > 0 ) {
265 - $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_multiple_concepts' ) ) );
266 - SMWOutputs::commitToParser( $parser );
267 - return $result;
268 - }
269 -
270 - // process input:
271 - $params = func_get_args();
272 - array_shift( $params ); // We already know the $parser ...
273 -
274 - // Use first parameter as concept (query) string.
275 - $concept_input = str_replace( array( '&gt;', '&lt;' ), array( '>', '<' ), array_shift( $params ) );
276 -
277 - // second parameter, if any, might be a description
278 - $concept_docu = array_shift( $params );
279 -
280 - // NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14
281 - $query = SMWQueryProcessor::createQuery( $concept_input, array( 'limit' => 20, 'format' => 'list' ), SMWQueryProcessor::CONCEPT_DESC );
282 - $concept_text = $query->getDescription()->getQueryString();
283 -
284 - $dv = SMWDataValueFactory::newPropertyObjectValue( $pconc );
285 - $dv->setValues( $concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth() );
286 -
287 - if ( SMWParseData::getSMWData( $parser ) !== null ) {
288 - SMWParseData::getSMWData( $parser )->addPropertyObjectValue( $pconc, $dv );
289 - }
290 -
291 - // display concept box:
292 - $rdflink = SMWInfolink::newInternalLink( wfMsgForContent( 'smw_viewasrdf' ), $wgContLang->getNsText( NS_SPECIAL ) . ':ExportRDF/' . $title->getPrefixedText(), 'rdflink' );
293 - SMWOutputs::requireHeadItem( SMW_HEADER_STYLE );
294 -
295 - // TODO: escape output, preferably via Html or Xml class.
296 - $result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent( 'smw_concept_description', $title->getText() ) .
297 - ( count( $query->getErrors() ) > 0 ? ' ' . smwfEncodeMessages( $query->getErrors() ) : '' ) .
298 - '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' .
299 - ( $concept_docu ? "<p>$concept_docu</p>" : '' ) .
300 - '<pre>' . str_replace( '[', '&#x005B;', $concept_text ) . "</pre>\n</div>";
301 -
302 - SMWOutputs::commitToParser( $parser );
303 - return $result;
304 - }
305 -
306 - /**
307 - * Function for handling the {{\#info }} parser function. This function creates a tooltip like
308 - * the one used by SMW for giving hints.
309 - * @note This feature is at risk and may vanish or change in future versions.
310 - */
311 - static public function doInfo( &$parser ) {
312 - $params = func_get_args();
313 - array_shift( $params ); // We already know the $parser ...
314 -
315 - $content = array_shift( $params ); // Use only first parameter, ignore the rest (may get meaning later).
316 - $result = smwfEncodeMessages( array( $content ), 'info' );
317 -
318 - SMWOutputs::commitToParser( $parser );
319 - return $result;
320 - }
321 -
322 - /**
323 - * Function for handling the {{\#set }} parser function. This is used for adding annotations
324 - * silently.
325 - *
326 - * Usage:
327 - * {{\#set:
328 - * population = 13000
329 - * | area = 396 km²
330 - * | sea = Adria
331 - * }}
332 - *
333 - * This creates annotations with the properties as stated on the left side, and the
334 - * values on the right side.
335 - *
336 - * @param Parser &$parser The current parser
337 - *
338 - * @return empty string
339 - */
340 - static public function doSet( &$parser ) {
341 - $params = func_get_args();
342 - array_shift( $params ); // We already know the $parser ...
343 -
344 - foreach ( $params as $param ) {
345 - $parts = explode( '=', trim( $param ), 2 );
346 -
347 - // Only add the property when there is both a name and a value.
348 - if ( count( $parts ) == 2 ) {
349 - SMWParseData::addProperty( $parts[0], $parts[1], false, $parser, true );
350 - }
351 - }
352 -
353 - SMWOutputs::commitToParser( $parser ); // not obviously required, but let us be sure
354 - return '';
355 - }
356 -
357 - /**
358 - * Helper function used by doSetRecurringEvent(), as well as the
359 - * Semantic Internal Objects extension
360 - *
361 - * @param Parser &$parser The current parser
362 - * @return either null, or an array of main property name, set of
363 - * all date strings, and the unused params
364 - */
365 - static public function getDatesForRecurringEvent( $params ) {
366 - // Initialize variables.
367 - $all_date_strings = array();
368 - $unused_params = array();
369 - $property_name = $start_date = $end_date = $unit = $period = $week_num = null;
370 - $included_dates = array();
371 - $excluded_dates_jd = array();
372 -
373 - // Set values from the parameters.
374 - foreach ( $params as $param ) {
375 - $parts = explode( '=', trim( $param ) );
376 -
377 - if ( count( $parts ) != 2 ) {
378 - continue;
379 - }
380 -
381 - list( $name, $value ) = $parts;
382 -
383 - switch( $name ) {
384 - case 'property':
385 - $property_name = $value;
386 - break;
387 - case 'start':
388 - $start_date = SMWDataValueFactory::newTypeIDValue( '_dat', $value );
389 - break;
390 - case 'end':
391 - $end_date = SMWDataValueFactory::newTypeIDValue( '_dat', $value );
392 - break;
393 - case 'unit':
394 - $unit = $value;
395 - break;
396 - case 'period':
397 - $period = (int)$value;
398 - break;
399 - case 'week number':
400 - $week_num = (int)$value;
401 - break;
402 - case 'include':
403 - $included_dates = explode( ';', $value );
404 - break;
405 - case 'exclude':
406 - $excluded_dates = explode( ';', $value );
407 -
408 - foreach ( $excluded_dates as $date_str ) {
409 - $date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str );
410 - $excluded_dates_jd[] = $date->getValueKey();
411 - }
412 - break;
413 - default:
414 - $unused_params[] = $param;
415 - }
416 - }
417 -
418 - // We need at least a property and start date - if either one is null, exit here.
419 - if ( is_null( $property_name ) || is_null( $start_date ) ) {
420 - return;
421 - }
422 -
423 - // If the period is null, or outside of normal bounds, set it to 1.
424 - if ( is_null( $period ) || $period < 1 || $period > 500 ) {
425 - $period = 1;
426 - }
427 -
428 - // Handle 'week number', but only if it's of unit 'month'.
429 - if ( $unit == 'month' && ! is_null( $week_num ) ) {
430 - $unit = 'dayofweekinmonth';
431 -
432 - if ( $week_num < -4 || $week_num > 5 || $week_num == 0 ) {
433 - $week_num = null;
434 - }
435 - }
436 -
437 - if ( $unit == 'dayofweekinmonth' && is_null( $week_num ) ) {
438 - $week_num = ceil( $start_date->getDay() / 7 );
439 - }
440 -
441 - // Get the Julian day value for both the start and end date.
442 - $start_date_jd = $start_date->getValueKey();
443 -
444 - if ( !is_null( $end_date ) ) {
445 - $end_date_jd = $end_date->getValueKey();
446 - }
447 -
448 - $cur_date = $start_date;
449 - $cur_date_jd = $start_date->getValueKey();
450 - $i = 0;
451 - $reached_end_date = false;
452 -
453 - do {
454 - $i++;
455 - $exclude_date = ( in_array( $cur_date_jd, $excluded_dates_jd ) );
456 -
457 - if ( !$exclude_date ) {
458 - $all_date_strings[] = $cur_date->getLongWikiText();
459 - }
460 -
461 - // Now get the next date.
462 - // Handling is different depending on whether it's
463 - // month/year or week/day since the latter is a set
464 - // number of days while the former isn't.
465 - if ( $unit === 'year' || $unit == 'month' ) {
466 - $cur_year = $cur_date->getYear();
467 - $cur_month = $cur_date->getMonth();
468 - $cur_day = $cur_date->getDay();
469 - $cur_time = $cur_date->getTimeString();
470 -
471 - if ( $unit == 'year' ) {
472 - $cur_year += $period;
473 - $display_month = $cur_month;
474 - } else { // $unit === 'month'
475 - $cur_month += $period;
476 - $cur_year += (int)( ( $cur_month - 1 ) / 12 );
477 - $cur_month %= 12;
478 - $display_month = ( $cur_month == 0 ) ? 12 : $cur_month;
479 - }
480 -
481 - $date_str = "$cur_year-$display_month-$cur_day $cur_time";
482 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str );
483 - $cur_date_jd = $cur_date->getValueKey();
484 - } elseif ( $unit == 'dayofweekinmonth' ) {
485 - // e.g., "3rd Monday of every month"
486 - $prev_month = $cur_date->getMonth();
487 - $prev_year = $cur_date->getYear();
488 -
489 - $new_month = ( $prev_month + $period ) % 12;
490 - if ( $new_month == 0 ) $new_month = 12;
491 -
492 - $new_year = $prev_year + floor( ( $prev_month + $period - 1 ) / 12 );
493 - $cur_date_jd += ( 28 * $period ) - 7;
494 -
495 - // We're sometime before the actual date now -
496 - // keep incrementing by a week, until we get there.
497 - do {
498 - $cur_date_jd += 7;
499 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
500 - $right_month = ( $cur_date->getMonth() == $new_month );
501 -
502 - if ( $week_num < 0 ) {
503 - $next_week_jd = $cur_date_jd;
504 -
505 - do {
506 - $next_week_jd += 7;
507 - $next_week_date = SMWDataValueFactory::newTypeIDValue( '_dat', $next_week_jd );
508 - $right_week = ( $next_week_date->getMonth() != $new_month ) || ( $next_week_date->getYear() != $new_year );
509 - } while ( !$right_week );
510 -
511 - $cur_date_jd = $next_week_jd + ( 7 * $week_num );
512 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
513 - } else {
514 - $cur_week_num = ceil( $cur_date->getDay() / 7 );
515 - $right_week = ( $cur_week_num == $week_num );
516 -
517 - if ( $week_num == 5 && ( $cur_date->getMonth() % 12 == ( $new_month + 1 ) % 12 ) ) {
518 - $cur_date_jd -= 7;
519 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
520 - $right_month = $right_week = true;
521 - }
522 - }
523 - } while ( !$right_month || !$right_week);
524 - } else { // $unit == 'day' or 'week'
525 - // Assume 'day' if it's none of the above.
526 - $cur_date_jd += ( $unit === 'week' ) ? 7 * $period : $period;
527 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
528 - }
529 -
530 - // should we stop?
531 - if ( is_null( $end_date ) ) {
532 - global $smwgDefaultNumRecurringEvents;
533 - $reached_end_date = $i > $smwgDefaultNumRecurringEvents;
534 - } else {
535 - global $smwgMaxNumRecurringEvents;
536 - $reached_end_date = ( $cur_date_jd > $end_date_jd ) || ( $i > $smwgMaxNumRecurringEvents );
537 - }
538 - } while ( !$reached_end_date );
539 -
540 - // Handle the 'include' dates as well.
541 - $all_date_strings = array_merge( $all_date_strings, $included_dates);
542 - return array( $property_name, $all_date_strings, $unused_params );
543 - }
544 -
545 - /**
546 - * Function for handling the {{\#set_recurring_event }} parser function.
547 - * This is used for defining a set of date values for a page that
548 - * represents a recurring event.
549 - * Like with the #set function, all annotations happen silently.
550 - *
551 - * Usage:
552 - * {{\#set_recurring_event:
553 - * property = Has date
554 - * | start = January 4, 2010
555 - * | end = June 7, 2010
556 - * | unit = week
557 - * | period = 1
558 - * | include = March 16, 2010;March 23, 2010
559 - * | exclude = March 15, 2010;March 22, 2010
560 - * }}
561 - * This sets a "Has date" value for every Monday within the specified
562 - * six-month period, except for two Mondays which are excluded and
563 - * two Tuesdays that are saved in their place.
564 - *
565 - * There's also a 'week number' parameter, which is only valid when
566 - * the 'unit' parameter is set to 'month'. This one dictates that the
567 - * event should always happen on the n-th week of each month, instead
568 - * of a specific numbered date. Negative values for 'week number'
569 - * indicate the n-th last week of a month instead.
570 - *
571 - * @param Parser &$parser The current parser
572 - * @return nothing
573 - */
574 - static public function doSetRecurringEvent( &$parser ) {
575 - $params = func_get_args();
576 - array_shift( $params ); // We already know the $parser ...
577 -
578 - // Almost all of the work gets done by
579 - // getDatesForRecurringEvent().
580 - $results = self::getDatesForRecurringEvent( $params );
581 - if ( $results == null ) {
582 - return null;
583 - }
584 -
585 - list( $property, $all_date_strings, $unused_params ) = $results;
586 -
587 - // Do the actual saving of the data.
588 - foreach ( $all_date_strings as $date_str ) {
589 - SMWParseData::addProperty( $property_name, $date_str, false, $parser, true );
590 - }
591 -
592 - SMWOutputs::commitToParser( $parser ); // Not obviously required, but let us be sure.
593 - }
594 -
595 - /**
596 - * Function for handling the {{\#declare }} parser function. It is used for declaring template parameters
597 - * that should automagically be annotated when the template is used.
598 - *
599 - * Usage:
600 - * {{\#declare:Author|Publisher=editor}}
601 - */
602 - static public function doDeclare( &$parser, PPFrame $frame, $args ) {
603 - if ( $frame->isTemplate() ) {
604 - foreach ( $args as $arg )
605 - if ( trim( $arg ) != '' ) {
606 - $expanded = trim( $frame->expand( $arg ) );
607 - $parts = explode( '=', $expanded, 2 );
608 -
609 - if ( count( $parts ) == 1 ) {
610 - $propertystring = $expanded;
611 - $argumentname = $expanded;
612 - } else {
613 - $propertystring = $parts[0];
614 - $argumentname = $parts[1];
615 - }
616 -
617 - $property = SMWPropertyValue::makeUserProperty( $propertystring );
618 - $argument = $frame->getArgument( $argumentname );
619 - $valuestring = $frame->expand( $argument );
620 -
621 - if ( $property->isValid() ) {
622 - $type = $property->getPropertyTypeID();
623 -
624 - if ( $type == '_wpg' ) {
625 - $matches = array();
626 - preg_match_all( '/\[\[([^\[\]]*)\]\]/', $valuestring, $matches );
627 - $objects = $matches[1];
628 -
629 - if ( count( $objects ) == 0 ) {
630 - if ( trim( $valuestring ) != '' ) {
631 - SMWParseData::addProperty( $propertystring, $valuestring, false, $parser, true );
632 - }
633 - } else {
634 - foreach ( $objects as $object ) {
635 - SMWParseData::addProperty( $propertystring, $object, false, $parser, true );
636 - }
637 - }
638 - } else {
639 - if ( trim( $valuestring ) != '' ) {
640 - SMWParseData::addProperty( $propertystring, $valuestring, false, $parser, true );
641 - }
642 - }
643 -
644 - $value = SMWDataValueFactory::newPropertyObjectValue( $property, $valuestring );
645 - // if (!$value->isValid()) continue;
646 - }
647 - }
648 - } else {
649 - // @todo Save as metadata
650 - }
651 -
652 - SMWOutputs::commitToParser( $parser ); // Not obviously required, but let us be sure.
653 - return '';
654 - }
655 -
656180 }
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Concept.php
@@ -0,0 +1,78 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'concept' parser functions.
 6+ *
 7+ * @since 1.5.3
 8+ *
 9+ * @file SMW_Concept.php
 10+ * @ingroup SMW
 11+ * @ingroup ParserHooks
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @author Jeroen De Dauw
 15+ */
 16+class SMWConcept {
 17+
 18+ /**
 19+ * Method for handling the ask concept function.
 20+ *
 21+ * @since 1.5.3
 22+ *
 23+ * @param Parser $parser
 24+ */
 25+ public static function render( Parser &$parser ) {
 26+ global $smwgQDefaultNamespaces, $smwgQMaxSize, $smwgQMaxDepth, $wgContLang;
 27+
 28+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 29+
 30+ $title = $parser->getTitle();
 31+ $pconc = SMWPropertyValue::makeProperty( '_CONC' );
 32+
 33+ if ( $title->getNamespace() != SMW_NS_CONCEPT ) {
 34+ $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_no_concept_namespace' ) ) );
 35+ SMWOutputs::commitToParser( $parser );
 36+ return $result;
 37+ } elseif ( count( SMWParseData::getSMWdata( $parser )->getPropertyValues( $pconc ) ) > 0 ) {
 38+ $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_multiple_concepts' ) ) );
 39+ SMWOutputs::commitToParser( $parser );
 40+ return $result;
 41+ }
 42+
 43+ // process input:
 44+ $params = func_get_args();
 45+ array_shift( $params ); // We already know the $parser ...
 46+
 47+ // Use first parameter as concept (query) string.
 48+ $concept_input = str_replace( array( '&gt;', '&lt;' ), array( '>', '<' ), array_shift( $params ) );
 49+
 50+ // second parameter, if any, might be a description
 51+ $concept_docu = array_shift( $params );
 52+
 53+ // NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14
 54+ $query = SMWQueryProcessor::createQuery( $concept_input, array( 'limit' => 20, 'format' => 'list' ), SMWQueryProcessor::CONCEPT_DESC );
 55+ $concept_text = $query->getDescription()->getQueryString();
 56+
 57+ $dv = SMWDataValueFactory::newPropertyObjectValue( $pconc );
 58+ $dv->setValues( $concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth() );
 59+
 60+ if ( SMWParseData::getSMWData( $parser ) !== null ) {
 61+ SMWParseData::getSMWData( $parser )->addPropertyObjectValue( $pconc, $dv );
 62+ }
 63+
 64+ // display concept box:
 65+ $rdflink = SMWInfolink::newInternalLink( wfMsgForContent( 'smw_viewasrdf' ), $wgContLang->getNsText( NS_SPECIAL ) . ':ExportRDF/' . $title->getPrefixedText(), 'rdflink' );
 66+ SMWOutputs::requireHeadItem( SMW_HEADER_STYLE );
 67+
 68+ // TODO: escape output, preferably via Html or Xml class.
 69+ $result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent( 'smw_concept_description', $title->getText() ) .
 70+ ( count( $query->getErrors() ) > 0 ? ' ' . smwfEncodeMessages( $query->getErrors() ) : '' ) .
 71+ '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' .
 72+ ( $concept_docu ? "<p>$concept_docu</p>" : '' ) .
 73+ '<pre>' . str_replace( '[', '&#x005B;', $concept_text ) . "</pre>\n</div>";
 74+
 75+ SMWOutputs::commitToParser( $parser );
 76+ return $result;
 77+ }
 78+
 79+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Concept.php
___________________________________________________________________
Added: svn:eol-style
180 + native
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Info.php
@@ -0,0 +1,35 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'info' parser functions.
 6+ *
 7+ * @since 1.5.3
 8+ *
 9+ * @file SMW_Info.php
 10+ * @ingroup SMW
 11+ * @ingroup ParserHooks
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @author Jeroen De Dauw
 15+ */
 16+class SMWInfo {
 17+
 18+ /**
 19+ * Method for handling the info parser function.
 20+ *
 21+ * @since 1.5.3
 22+ *
 23+ * @param Parser $parser
 24+ */
 25+ public static function render( Parser &$parser ) {
 26+ $params = func_get_args();
 27+ array_shift( $params ); // We already know the $parser ...
 28+
 29+ $content = array_shift( $params ); // Use only first parameter, ignore the rest (may get meaning later).
 30+ $result = smwfEncodeMessages( array( $content ), 'info' );
 31+
 32+ SMWOutputs::commitToParser( $parser );
 33+ return $result;
 34+ }
 35+
 36+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Info.php
___________________________________________________________________
Added: svn:eol-style
137 + native
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Set.php
@@ -0,0 +1,41 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'set' parser functions.
 6+ *
 7+ * @since 1.5.3
 8+ *
 9+ * @file SMW_Set.php
 10+ * @ingroup SMW
 11+ * @ingroup ParserHooks
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @author Jeroen De Dauw
 15+ */
 16+class SMWSet {
 17+
 18+ /**
 19+ * Method for handling the set parser function.
 20+ *
 21+ * @since 1.5.3
 22+ *
 23+ * @param Parser $parser
 24+ */
 25+ public static function render( Parser &$parser ) {
 26+ $params = func_get_args();
 27+ array_shift( $params ); // We already know the $parser ...
 28+
 29+ foreach ( $params as $param ) {
 30+ $parts = explode( '=', trim( $param ), 2 );
 31+
 32+ // Only add the property when there is both a name and a value.
 33+ if ( count( $parts ) == 2 ) {
 34+ SMWParseData::addProperty( $parts[0], $parts[1], false, $parser, true );
 35+ }
 36+ }
 37+
 38+ SMWOutputs::commitToParser( $parser ); // not obviously required, but let us be sure
 39+ return '';
 40+ }
 41+
 42+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Set.php
___________________________________________________________________
Added: svn:eol-style
143 + native
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Ask.php
@@ -0,0 +1,44 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'ask' parser functions.
 6+ *
 7+ * @since 1.5.3
 8+ *
 9+ * @file SMW_Ask.php
 10+ * @ingroup SMW
 11+ * @ingroup ParserHooks
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @author Jeroen De Dauw
 15+ */
 16+class SMWAsk {
 17+
 18+ /**
 19+ * Method for handling the ask parser function.
 20+ *
 21+ * @since 1.5.3
 22+ *
 23+ * @param Parser $parser
 24+ */
 25+ public static function render( Parser &$parser ) {
 26+ global $smwgQEnabled, $smwgIQRunningNumber;
 27+
 28+ if ( $smwgQEnabled ) {
 29+ $smwgIQRunningNumber++;
 30+
 31+ $params = func_get_args();
 32+ array_shift( $params ); // We already know the $parser ...
 33+
 34+ $result = SMWQueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI );
 35+ } else {
 36+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 37+ $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) );
 38+ }
 39+
 40+ SMWOutputs::commitToParser( $parser );
 41+
 42+ return $result;
 43+ }
 44+
 45+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Ask.php
___________________________________________________________________
Added: svn:eol-style
146 + native
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php
@@ -0,0 +1,233 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'set_recurring_event' parser functions.
 6+ *
 7+ * @since 1.5.3
 8+ *
 9+ * @file SMW_SetRecurringEvent.php
 10+ * @ingroup SMW
 11+ * @ingroup ParserHooks
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @author Jeroen De Dauw
 15+ */
 16+class SMWSetRecurringEvent {
 17+
 18+ /**
 19+ * Method for handling the set_recurring_event parser function.
 20+ *
 21+ * @since 1.5.3
 22+ *
 23+ * @param Parser $parser
 24+ */
 25+ public static function render( Parser &$parser ) {
 26+ $params = func_get_args();
 27+ array_shift( $params ); // We already know the $parser ...
 28+
 29+ // Almost all of the work gets done by
 30+ // getDatesForRecurringEvent().
 31+ $results = self::getDatesForRecurringEvent( $params );
 32+ if ( $results == null ) {
 33+ return null;
 34+ }
 35+
 36+ list( $property, $all_date_strings, $unused_params ) = $results;
 37+
 38+ // Do the actual saving of the data.
 39+ foreach ( $all_date_strings as $date_str ) {
 40+ SMWParseData::addProperty( $property_name, $date_str, false, $parser, true );
 41+ }
 42+
 43+ SMWOutputs::commitToParser( $parser ); // Not obviously required, but let us be sure.
 44+ }
 45+
 46+ /**
 47+ * Helper function used by doSetRecurringEvent(), as well as the
 48+ * Semantic Internal Objects extension
 49+ *
 50+ * @param Parser &$parser The current parser
 51+ * @return either null, or an array of main property name, set of
 52+ * all date strings, and the unused params
 53+ */
 54+ static public function getDatesForRecurringEvent( $params ) {
 55+ // Initialize variables.
 56+ $all_date_strings = array();
 57+ $unused_params = array();
 58+ $property_name = $start_date = $end_date = $unit = $period = $week_num = null;
 59+ $included_dates = array();
 60+ $excluded_dates_jd = array();
 61+
 62+ // Set values from the parameters.
 63+ foreach ( $params as $param ) {
 64+ $parts = explode( '=', trim( $param ) );
 65+
 66+ if ( count( $parts ) != 2 ) {
 67+ continue;
 68+ }
 69+
 70+ list( $name, $value ) = $parts;
 71+
 72+ switch( $name ) {
 73+ case 'property':
 74+ $property_name = $value;
 75+ break;
 76+ case 'start':
 77+ $start_date = SMWDataValueFactory::newTypeIDValue( '_dat', $value );
 78+ break;
 79+ case 'end':
 80+ $end_date = SMWDataValueFactory::newTypeIDValue( '_dat', $value );
 81+ break;
 82+ case 'unit':
 83+ $unit = $value;
 84+ break;
 85+ case 'period':
 86+ $period = (int)$value;
 87+ break;
 88+ case 'week number':
 89+ $week_num = (int)$value;
 90+ break;
 91+ case 'include':
 92+ $included_dates = explode( ';', $value );
 93+ break;
 94+ case 'exclude':
 95+ $excluded_dates = explode( ';', $value );
 96+
 97+ foreach ( $excluded_dates as $date_str ) {
 98+ $date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str );
 99+ $excluded_dates_jd[] = $date->getValueKey();
 100+ }
 101+ break;
 102+ default:
 103+ $unused_params[] = $param;
 104+ }
 105+ }
 106+
 107+ // We need at least a property and start date - if either one is null, exit here.
 108+ if ( is_null( $property_name ) || is_null( $start_date ) ) {
 109+ return;
 110+ }
 111+
 112+ // If the period is null, or outside of normal bounds, set it to 1.
 113+ if ( is_null( $period ) || $period < 1 || $period > 500 ) {
 114+ $period = 1;
 115+ }
 116+
 117+ // Handle 'week number', but only if it's of unit 'month'.
 118+ if ( $unit == 'month' && ! is_null( $week_num ) ) {
 119+ $unit = 'dayofweekinmonth';
 120+
 121+ if ( $week_num < -4 || $week_num > 5 || $week_num == 0 ) {
 122+ $week_num = null;
 123+ }
 124+ }
 125+
 126+ if ( $unit == 'dayofweekinmonth' && is_null( $week_num ) ) {
 127+ $week_num = ceil( $start_date->getDay() / 7 );
 128+ }
 129+
 130+ // Get the Julian day value for both the start and end date.
 131+ $start_date_jd = $start_date->getValueKey();
 132+
 133+ if ( !is_null( $end_date ) ) {
 134+ $end_date_jd = $end_date->getValueKey();
 135+ }
 136+
 137+ $cur_date = $start_date;
 138+ $cur_date_jd = $start_date->getValueKey();
 139+ $i = 0;
 140+ $reached_end_date = false;
 141+
 142+ do {
 143+ $i++;
 144+ $exclude_date = ( in_array( $cur_date_jd, $excluded_dates_jd ) );
 145+
 146+ if ( !$exclude_date ) {
 147+ $all_date_strings[] = $cur_date->getLongWikiText();
 148+ }
 149+
 150+ // Now get the next date.
 151+ // Handling is different depending on whether it's
 152+ // month/year or week/day since the latter is a set
 153+ // number of days while the former isn't.
 154+ if ( $unit === 'year' || $unit == 'month' ) {
 155+ $cur_year = $cur_date->getYear();
 156+ $cur_month = $cur_date->getMonth();
 157+ $cur_day = $cur_date->getDay();
 158+ $cur_time = $cur_date->getTimeString();
 159+
 160+ if ( $unit == 'year' ) {
 161+ $cur_year += $period;
 162+ $display_month = $cur_month;
 163+ } else { // $unit === 'month'
 164+ $cur_month += $period;
 165+ $cur_year += (int)( ( $cur_month - 1 ) / 12 );
 166+ $cur_month %= 12;
 167+ $display_month = ( $cur_month == 0 ) ? 12 : $cur_month;
 168+ }
 169+
 170+ $date_str = "$cur_year-$display_month-$cur_day $cur_time";
 171+ $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str );
 172+ $cur_date_jd = $cur_date->getValueKey();
 173+ } elseif ( $unit == 'dayofweekinmonth' ) {
 174+ // e.g., "3rd Monday of every month"
 175+ $prev_month = $cur_date->getMonth();
 176+ $prev_year = $cur_date->getYear();
 177+
 178+ $new_month = ( $prev_month + $period ) % 12;
 179+ if ( $new_month == 0 ) $new_month = 12;
 180+
 181+ $new_year = $prev_year + floor( ( $prev_month + $period - 1 ) / 12 );
 182+ $cur_date_jd += ( 28 * $period ) - 7;
 183+
 184+ // We're sometime before the actual date now -
 185+ // keep incrementing by a week, until we get there.
 186+ do {
 187+ $cur_date_jd += 7;
 188+ $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 189+ $right_month = ( $cur_date->getMonth() == $new_month );
 190+
 191+ if ( $week_num < 0 ) {
 192+ $next_week_jd = $cur_date_jd;
 193+
 194+ do {
 195+ $next_week_jd += 7;
 196+ $next_week_date = SMWDataValueFactory::newTypeIDValue( '_dat', $next_week_jd );
 197+ $right_week = ( $next_week_date->getMonth() != $new_month ) || ( $next_week_date->getYear() != $new_year );
 198+ } while ( !$right_week );
 199+
 200+ $cur_date_jd = $next_week_jd + ( 7 * $week_num );
 201+ $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 202+ } else {
 203+ $cur_week_num = ceil( $cur_date->getDay() / 7 );
 204+ $right_week = ( $cur_week_num == $week_num );
 205+
 206+ if ( $week_num == 5 && ( $cur_date->getMonth() % 12 == ( $new_month + 1 ) % 12 ) ) {
 207+ $cur_date_jd -= 7;
 208+ $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 209+ $right_month = $right_week = true;
 210+ }
 211+ }
 212+ } while ( !$right_month || !$right_week);
 213+ } else { // $unit == 'day' or 'week'
 214+ // Assume 'day' if it's none of the above.
 215+ $cur_date_jd += ( $unit === 'week' ) ? 7 * $period : $period;
 216+ $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 217+ }
 218+
 219+ // should we stop?
 220+ if ( is_null( $end_date ) ) {
 221+ global $smwgDefaultNumRecurringEvents;
 222+ $reached_end_date = $i > $smwgDefaultNumRecurringEvents;
 223+ } else {
 224+ global $smwgMaxNumRecurringEvents;
 225+ $reached_end_date = ( $cur_date_jd > $end_date_jd ) || ( $i > $smwgMaxNumRecurringEvents );
 226+ }
 227+ } while ( !$reached_end_date );
 228+
 229+ // Handle the 'include' dates as well.
 230+ $all_date_strings = array_merge( $all_date_strings, $included_dates);
 231+ return array( $property_name, $all_date_strings, $unused_params );
 232+ }
 233+
 234+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php
___________________________________________________________________
Added: svn:eol-style
1235 + native
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Declare.php
@@ -0,0 +1,78 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'declare' parser functions.
 6+ *
 7+ * @since 1.5.3
 8+ *
 9+ * @file SMW_Declare.php
 10+ * @ingroup SMW
 11+ * @ingroup ParserHooks
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @author Jeroen De Dauw
 15+ */
 16+class SMWDeclare {
 17+
 18+ /**
 19+ * Method for handling the declare parser function.
 20+ *
 21+ * @since 1.5.3
 22+ *
 23+ * @param Parser $parser
 24+ */
 25+ public static function render( Parser &$parser ) {
 26+ if ( $frame->isTemplate() ) {
 27+ foreach ( $args as $arg )
 28+ if ( trim( $arg ) != '' ) {
 29+ $expanded = trim( $frame->expand( $arg ) );
 30+ $parts = explode( '=', $expanded, 2 );
 31+
 32+ if ( count( $parts ) == 1 ) {
 33+ $propertystring = $expanded;
 34+ $argumentname = $expanded;
 35+ } else {
 36+ $propertystring = $parts[0];
 37+ $argumentname = $parts[1];
 38+ }
 39+
 40+ $property = SMWPropertyValue::makeUserProperty( $propertystring );
 41+ $argument = $frame->getArgument( $argumentname );
 42+ $valuestring = $frame->expand( $argument );
 43+
 44+ if ( $property->isValid() ) {
 45+ $type = $property->getPropertyTypeID();
 46+
 47+ if ( $type == '_wpg' ) {
 48+ $matches = array();
 49+ preg_match_all( '/\[\[([^\[\]]*)\]\]/', $valuestring, $matches );
 50+ $objects = $matches[1];
 51+
 52+ if ( count( $objects ) == 0 ) {
 53+ if ( trim( $valuestring ) != '' ) {
 54+ SMWParseData::addProperty( $propertystring, $valuestring, false, $parser, true );
 55+ }
 56+ } else {
 57+ foreach ( $objects as $object ) {
 58+ SMWParseData::addProperty( $propertystring, $object, false, $parser, true );
 59+ }
 60+ }
 61+ } else {
 62+ if ( trim( $valuestring ) != '' ) {
 63+ SMWParseData::addProperty( $propertystring, $valuestring, false, $parser, true );
 64+ }
 65+ }
 66+
 67+ $value = SMWDataValueFactory::newPropertyObjectValue( $property, $valuestring );
 68+ // if (!$value->isValid()) continue;
 69+ }
 70+ }
 71+ } else {
 72+ // @todo Save as metadata
 73+ }
 74+
 75+ SMWOutputs::commitToParser( $parser ); // Not obviously required, but let us be sure.
 76+ return '';
 77+ }
 78+
 79+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Declare.php
___________________________________________________________________
Added: svn:eol-style
180 + native
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Show.php
@@ -0,0 +1,43 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'show' parser functions.
 6+ *
 7+ * @since 1.5.3
 8+ *
 9+ * @file SMW_Show.php
 10+ * @ingroup SMW
 11+ * @ingroup ParserHooks
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @author Jeroen De Dauw
 15+ */
 16+class SMWShow {
 17+
 18+ /**
 19+ * Method for handling the show parser function.
 20+ *
 21+ * @since 1.5.3
 22+ *
 23+ * @param Parser $parser
 24+ */
 25+ public static function render( Parser &$parser ) {
 26+ global $smwgQEnabled, $smwgIQRunningNumber;
 27+
 28+ if ( $smwgQEnabled ) {
 29+ $smwgIQRunningNumber++;
 30+
 31+ $params = func_get_args();
 32+ array_shift( $params ); // We already know the $parser ...
 33+
 34+ $result = SMWQueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, true );
 35+ } else {
 36+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 37+ $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) );
 38+ }
 39+
 40+ SMWOutputs::commitToParser( $parser );
 41+ return $result;
 42+ }
 43+
 44+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Show.php
___________________________________________________________________
Added: svn:eol-style
145 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php
@@ -107,6 +107,17 @@
108108 // $wgAutoloadClasses['SMWExpElement'] = $smwgIP . 'includes/export/SMW_Exp_Element.php';
109109 // $wgAutoloadClasses['SMWExpLiteral'] = $smwgIP . 'includes/export/SMW_Exp_Element.php';
110110 // $wgAutoloadClasses['SMWExpResource'] = $smwgIP . 'includes/export/SMW_Exp_Element.php';
 111+
 112+ // Parser hooks
 113+ $phDir = $smwgIP . 'includes/parserhooks/';
 114+ $wgAutoloadClasses['SMWAsk'] = $phDir . 'SMW_Ask.php';
 115+ $wgAutoloadClasses['SMWShow'] = $phDir . 'SMW_Show.php';
 116+ $wgAutoloadClasses['SMWInfo'] = $phDir . 'SMW_Info.php';
 117+ $wgAutoloadClasses['SMWConcept'] = $phDir . 'SMW_Concept.php';
 118+ $wgAutoloadClasses['SMWSet'] = $phDir . 'SMW_Set.php';
 119+ $wgAutoloadClasses['SMWSetRecurringEvent'] = $phDir . 'SMW_SetRecurringEvent.php';
 120+ $wgAutoloadClasses['SMWDeclare'] = $phDir . 'SMW_Declare.php';
 121+
111122 // Stores & queries
112123 // $wgAutoloadClasses['SMWQueryProcessor'] = $smwgIP . 'includes/SMW_QueryProcessor.php';
113124 // $wgAutoloadClasses['SMWQueryParser'] = $smwgIP . 'includes/SMW_QueryParser.php';
@@ -220,8 +231,10 @@
221232 $wgHooks['NewRevisionFromEditComplete'][] = 'SMWParseData::onNewRevisionFromEditComplete'; // fetch some MediaWiki data for replication in SMW's store
222233 // $wgHooks['OutputPageParserOutput'][] = 'SMWFactbox::onOutputPageParserOutput'; // copy some data for later Factbox display
223234 $wgHooks['ArticleFromTitle'][] = 'smwfOnArticleFromTitle'; // special implementations for property/type articles
224 - $wgHooks['ParserFirstCallInit'][] = 'SMWParserExtensions::registerParserFunctions';
 235+ $wgHooks['ParserFirstCallInit'][] = 'smwfRegisterParserFunctions';
225236
 237+ $wgHooks['ResourceLoaderRegisterModules'][] = 'smwfRegisterResourceLoaderModules';
 238+
226239 $smwgMW_1_14 = true; // assume latest 1.14 API
227240
228241 ///// credits (see "Special:Version") /////
@@ -415,3 +428,60 @@
416429
417430 wfProfileOut( 'smwfInitContentLanguage (SMW)' );
418431 }
 432+
 433+/**
 434+ * Register the resource modules for the resource loader.
 435+ *
 436+ * @since 1.5.3
 437+ *
 438+ * @param ResourceLoader $resourceLoader
 439+ *
 440+ * @return true
 441+ */
 442+function smwfRegisterResourceLoaderModules( ResourceLoader &$resourceLoader ) {
 443+ global $smwgScriptPath, $wgContLang;
 444+
 445+ $modules = array(
 446+ 'ext.smw.style' => array(
 447+ 'styles' => $smwgScriptPath . ( $wgContLang->isRTL() ? '/skins/SMW_custom_rtl.css' : '/skins/SMW_custom.css' )
 448+ ),
 449+ 'ext.smw.tooltips' => array(
 450+ 'scripts' => $smwgScriptPath . '/skins/SMW_tooltip.js',
 451+ 'dependencies' => array(
 452+ 'mediawiki.legacy.wikibits',
 453+ 'ext.smw.style'
 454+ )
 455+ ),
 456+ 'ext.smw.sorttable' => array(
 457+ 'scripts' => $smwgScriptPath . '/skins/SMW_sorttable.js',
 458+ 'dependencies' => 'ext.smw.style'
 459+ )
 460+ );
 461+
 462+ foreach ( $modules as $name => $resources ) {
 463+ $resourceLoader->register( $name, new ResourceLoaderFileModule(
 464+ array_merge_recursive( $resources, array( 'group' => 'ext.smw' ) )
 465+ ) );
 466+ }
 467+
 468+ return true;
 469+}
 470+
 471+/**
 472+ * This hook registers parser functions and hooks to the given parser. It is
 473+ * called during SMW initialisation. Note that parser hooks are something different
 474+ * than MW hooks in general, which explains the two-level registration.
 475+ *
 476+ * @since 1.5.3
 477+ */
 478+function smwfRegisterParserFunctions( Parser &$parser ) {
 479+ $parser->setFunctionHook( 'ask', array( 'SMWAsk', 'render' ) );
 480+ $parser->setFunctionHook( 'show', array( 'SMWShow', 'render' ) );
 481+ $parser->setFunctionHook( 'info', array( 'SMWInfo', 'render' ) );
 482+ $parser->setFunctionHook( 'concept', array( 'SMWConcept', 'render' ) );
 483+ $parser->setFunctionHook( 'set', array( 'SMWSet', 'render' ) );
 484+ $parser->setFunctionHook( 'set_recurring_event', array( 'SMWSetRecurringEvent', 'render' ) );
 485+ $parser->setFunctionHook( 'declare', array( 'SMWDeclare', 'render' ), SFH_OBJECT_ARGS );
 486+
 487+ return true; // Always return true, in order not to stop MW's hook processing!
 488+}
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -126,6 +126,16 @@
127127 $wgAutoloadClasses['SMWExpLiteral'] = $expDir . 'SMW_Exp_Element.php';
128128 $wgAutoloadClasses['SMWExpResource'] = $expDir . 'SMW_Exp_Element.php';
129129
 130+ // Parser hooks
 131+ $phDir = $smwgIP . 'includes/parserhooks/';
 132+ $wgAutoloadClasses['SMWAsk'] = $phDir . 'SMW_Ask.php';
 133+ $wgAutoloadClasses['SMWShow'] = $phDir . 'SMW_Show.php';
 134+ $wgAutoloadClasses['SMWInfo'] = $phDir . 'SMW_Info.php';
 135+ $wgAutoloadClasses['SMWConcept'] = $phDir . 'SMW_Concept.php';
 136+ $wgAutoloadClasses['SMWSet'] = $phDir . 'SMW_Set.php';
 137+ $wgAutoloadClasses['SMWSetRecurringEvent'] = $phDir . 'SMW_SetRecurringEvent.php';
 138+ $wgAutoloadClasses['SMWDeclare'] = $phDir . 'SMW_Declare.php';
 139+
130140 // Stores & queries
131141 $wgAutoloadClasses['SMWQueryProcessor'] = $smwgIP . 'includes/SMW_QueryProcessor.php';
132142 $wgAutoloadClasses['SMWQueryParser'] = $smwgIP . 'includes/SMW_QueryParser.php';
@@ -241,7 +251,7 @@
242252 $wgHooks['NewRevisionFromEditComplete'][] = 'SMWParseData::onNewRevisionFromEditComplete'; // fetch some MediaWiki data for replication in SMW's store
243253 $wgHooks['OutputPageParserOutput'][] = 'SMWFactbox::onOutputPageParserOutput'; // copy some data for later Factbox display
244254 $wgHooks['ArticleFromTitle'][] = 'smwfOnArticleFromTitle'; // special implementations for property/type articles
245 - $wgHooks['ParserFirstCallInit'][] = 'SMWParserExtensions::registerParserFunctions';
 255+ $wgHooks['ParserFirstCallInit'][] = 'smwfRegisterParserFunctions';
246256
247257 if ( $smwgToolboxBrowseLink ) {
248258 if ( version_compare( $wgVersion, '1.13', '>=' ) ) {
@@ -538,4 +548,23 @@
539549 }
540550
541551 return true;
 552+}
 553+
 554+/**
 555+ * This hook registers parser functions and hooks to the given parser. It is
 556+ * called during SMW initialisation. Note that parser hooks are something different
 557+ * than MW hooks in general, which explains the two-level registration.
 558+ *
 559+ * @since 1.5.3
 560+ */
 561+function smwfRegisterParserFunctions( Parser &$parser ) {
 562+ $parser->setFunctionHook( 'ask', array( 'SMWAsk', 'render' ) );
 563+ $parser->setFunctionHook( 'show', array( 'SMWShow', 'render' ) );
 564+ $parser->setFunctionHook( 'info', array( 'SMWInfo', 'render' ) );
 565+ $parser->setFunctionHook( 'concept', array( 'SMWConcept', 'render' ) );
 566+ $parser->setFunctionHook( 'set', array( 'SMWSet', 'render' ) );
 567+ $parser->setFunctionHook( 'set_recurring_event', array( 'SMWSetRecurringEvent', 'render' ) );
 568+ $parser->setFunctionHook( 'declare', array( 'SMWDeclare', 'render' ), SFH_OBJECT_ARGS );
 569+
 570+ return true; // Always return true, in order not to stop MW's hook processing!
542571 }
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r74264Follow up to r74262 - added links to the docs and fixed author for set_recurr...jeroendedauw17:24, 4 October 2010
r74280multiple issues fixed relating to comment/followup revision r74262, r74263neilk22:02, 4 October 2010

Status & tagging log