Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/57077


Change subject: SMW 1.9 compatibility
......................................................................

SMW 1.9 compatibility

#set_internal_recurring_event and #set_recurring_event are now
interchangeable

Difference between #set_internal and #subobject are
* #list vs +sep=
* auto in-page reference (which would be rather easy to implement because
'SMW\RecurringEventsParserFunction' already does it )

SIO has no unit tests, so I used the following for verfication:

{{#set_internal:Some hunger
|property1=value1
|property2=value2
}}

{{#set_internal:Part of recipe
|Has quantity=1
|Has unit=cup
|Has ingredient=flour
}}

{{#set_internal:Is president of
|Has name=Ulysses S. Grant
|Has vice president#list=Schuyler Colfax, Henry Wilson
}}

{{#ask:[[Part of recipe::+]][[Has ingredient::flour]][[Has unit::cup]][[Has 
quantity::>.5]]
|mainlabel=-
|? Part of recipe
|? Has quantity
}}

{{#set_internal_recurring_event:Is instance of
|property=Has sio date
|start=January 4, 2010
|end=June 8, 2011
|unit=week
|period=1
}}

{{#ask:[[Has sio date::>February 1, 2010]][[Has sio date::<February 7, 2010]]
|mainlabel=-
|?Is instance of
|?Has sio date
}}

Change-Id: I8923ca50fbb0dd3515801aaf38052624f45cb3b8
---
M SIO_SubobjectAlias.php
1 file changed, 34 insertions(+), 26 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticInternalObjects 
refs/changes/77/57077/1

diff --git a/SIO_SubobjectAlias.php b/SIO_SubobjectAlias.php
index 0b749b0..bd50b25 100644
--- a/SIO_SubobjectAlias.php
+++ b/SIO_SubobjectAlias.php
@@ -54,15 +54,14 @@
                                $subobjectArgs[] = $origArgs[$i];
                        }
                }
-               if ( class_exists( 'SMW\SubobjectHandler' ) ) {
-                       // SMW 1.9+
-                       call_user_func_array( array( 'SMW\SubobjectHandler', 
'render' ), $subobjectArgs );
-               } elseif ( class_exists( 'SMW\SubobjectParser' ) ) {
-                       // SMW 1.9
-                       call_user_func_array( array( 'SMW\SubobjectParser', 
'render' ), $subobjectArgs );
-               } elseif ( class_exists( 'SMW\Subobject' ) ) {
-                       // SMW 1.9
-                       call_user_func_array( array( 'SMW\Subobject', 'render' 
), $subobjectArgs );
+
+               // Use SMW\SubobjectParserFunction class
+               if ( class_exists( 'SMW\SubobjectParserFunction' ) ) {
+                       $instance = new SMW\SubobjectParserFunction(
+                               new SMW\ParserData( $parser->getTitle(), 
$parser->getOutput() ),
+                               new SMW\Subobject( $parser->getTitle() )
+                       );
+                       return $instance->parse( new 
SMW\ParserParameterFormatter( $subobjectArgs ) );
                } else {
                        // SMW 1.8
                        call_user_func_array( array( 'SMWSubobject', 'render' 
), $subobjectArgs );
@@ -83,24 +82,33 @@
                // First param should be a standalone property name.
                $objToPagePropName = array_shift( $params );
 
-               $results = SMWSetRecurringEvent::getDatesForRecurringEvent( 
$params );
-               if ( $results == null ) {
-                       return null;
-               }
-
-               list( $property, $all_date_strings, $unused_params ) = $results;
-
-               // Mimic a call to #subobject for each date.
-               foreach ( $all_date_strings as $date_string ) {
-                       $first_params = array(
-                               &$parser,
-                               '',
-                               $objToPagePropName . '=' . 
$parser->getTitle()->getText(),
-                               "$property=$date_string"
+               // Use RecurringEventsParserFunction class
+               if ( class_exists( 'SMW\RecurringEventsParserFunction' ) ) {
+                       $instance = new SMW\RecurringEventsParserFunction(
+                               new SMW\ParserData( $parser->getTitle(), 
$parser->getOutput() ),
+                               new SMW\Subobject( $parser->getTitle() )
                        );
-                       
-                       $cur_params = array_merge( $first_params, 
$unused_params );
-                       call_user_func_array( array( 'SMWSubobject', 'render' 
), $cur_params );
+                       return $instance->parse( new 
SMW\ParserParameterFormatter( $params ) );
+               } else {
+                       $results = 
SMWSetRecurringEvent::getDatesForRecurringEvent( $params );
+                       if ( $results == null ) {
+                               return null;
+                       }
+
+                       list( $property, $all_date_strings, $unused_params ) = 
$results;
+
+                       // Mimic a call to #subobject for each date.
+                       foreach ( $all_date_strings as $date_string ) {
+                               $first_params = array(
+                                       &$parser,
+                                       '',
+                                       $objToPagePropName . '=' . 
$parser->getTitle()->getText(),
+                                       "$property=$date_string"
+                               );
+
+                               $cur_params = array_merge( $first_params, 
$unused_params );
+                               call_user_func_array( array( 'SMWSubobject', 
'render' ), $cur_params );
+                       }
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/57077
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8923ca50fbb0dd3515801aaf38052624f45cb3b8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticInternalObjects
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to