Yaron Koren has uploaded a new change for review.

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


Change subject: Moved #subobject alias methods into their own class/file
......................................................................

Moved #subobject alias methods into their own class/file

Change-Id: Ia13e9d3e9fa7d539b6ffbbbfff4a6beebe58ed43
---
A SIO_SubobjectAlias.php
M SemanticInternalObjects.php
M SemanticInternalObjects_body.php
3 files changed, 105 insertions(+), 97 deletions(-)


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

diff --git a/SIO_SubobjectAlias.php b/SIO_SubobjectAlias.php
new file mode 100644
index 0000000..9790c9e
--- /dev/null
+++ b/SIO_SubobjectAlias.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * Class that holds methods used to call Semantic MediaWiki's #subobject
+ * parser function to store data when #set_internal or
+ * #set_internal_recurring_event are called.
+ *
+ * @author Yaron Koren
+ */
+class SIOSubobjectAlias {
+
+       public static function doSetInternal( &$parser ) {
+               // This is a hack, since SMW's SMWSubobject::render() call is
+               // not meant to be called outside of SMW. However, this seemed
+               // like the better solution than copying over all of that
+               // method's code. Ideally, a true public function can be
+               // added to SMW, that handles a subobject creation, that this
+               // code can then call.
+
+               $origArgs = func_get_args();
+               // $parser is also $origArgs[0].
+               $subobjectArgs = array( &$parser );
+               // Blank first argument, so that subobject ID will be
+               // an automatically-generated random number.
+               $subobjectArgs[1] = '';
+               // "main" property, pointing back to the page.
+               $mainPageName = $parser->getTitle()->getText();
+               $mainPageNamespace = $parser->getTitle()->getNsText();
+               if ( $mainPageNamespace != '' ) {
+                       $mainPageName = $mainPageNamespace . ':' . 
$mainPageName;
+               }
+               if ( $origArgs[1] == '' ) {
+                       die( "Error: first argument to #set_internal cannot be 
blank." );
+               }
+               $subobjectArgs[2] = $origArgs[1] . '=' . $mainPageName;
+
+               for ( $i = 2; $i < count( $origArgs ); $i++ ) {
+                       $propAndValue = explode( '=', $origArgs[$i] );
+                       if ( count( $propAndValue ) != 2 ) continue;
+
+                       list( $prop, $value ) = $propAndValue;
+                       // If the property name ends with '#list', it's
+                       // a comma-delimited group of values.
+                       if ( substr( $prop, - 5 ) == '#list' ) {
+                               $prop = substr( $prop, 0, strlen( $prop ) - 5 );
+                               // #subobject has a different syntax for lists
+                               $actualValues = explode( ',', $value );
+                               $subobjectArgs[] = "$prop=" . $actualValues[0];
+                               for ( $j = 1; $j < count( $actualValues ); $j++ 
) {
+                                       $subobjectArgs[] = $actualValues[$j];
+                               }
+                       } else {
+                               $subobjectArgs[] = $origArgs[$i];
+                       }
+               }
+               if ( 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 );
+               } else {
+                       // SMW 1.8
+                       call_user_func_array( array( 'SMWSubobject', 'render' 
), $subobjectArgs );
+               }
+               return;
+       }
+
+       /**
+        * Just calls SMW's own #subobject for each instance of this
+        * recurring event.
+        */
+       public static function doSetInternalRecurringEvent( &$parser ) {
+               // This is a hack, as is doSetInternal() - see comments
+               // in that method.
+               $params = func_get_args();
+               array_shift( $params ); // We already know the $parser ...
+
+               // 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"
+                       );
+                       
+                       $cur_params = array_merge( $first_params, 
$unused_params );
+                       call_user_func_array( array( 'SMWSubobject', 'render' 
), $cur_params );
+               }
+       }
+
+}
diff --git a/SemanticInternalObjects.php b/SemanticInternalObjects.php
index 18ca33a..2d518d0 100644
--- a/SemanticInternalObjects.php
+++ b/SemanticInternalObjects.php
@@ -52,6 +52,7 @@
 $wgExtensionMessagesFiles['SemanticInternalObjects'] = $siogIP . 
'/SemanticInternalObjects.i18n.php';
 $wgExtensionMessagesFiles['SemanticInternalObjectsMagic'] = $siogIP . 
'/SemanticInternalObjects.i18n.magic.php';
 $wgAutoloadClasses['SIOHandler'] = $siogIP . 
'/SemanticInternalObjects_body.php';
+$wgAutoloadClasses['SIOSubobjectAlias'] = $siogIP . '/SIO_SubobjectAlias.php';
 $wgAutoloadClasses['SIOPageSchemas'] = $siogIP . '/SIO_PageSchemas.php';
 
 function siofRegisterParserFunctions( &$parser ) {
@@ -61,7 +62,7 @@
 }
 
 function siofRegisterAliasParserFunctions( &$parser ) {
-       $parser->setFunctionHook( 'set_internal', array( 'SIOHandler', 
'doSetInternalAsAlias' ) );
-       $parser->setFunctionHook( 'set_internal_recurring_event', array( 
'SIOHandler', 'doSetInternalRecurringEventAsAlias' ) );
+       $parser->setFunctionHook( 'set_internal', array( 'SIOSubobjectAlias', 
'doSetInternal' ) );
+       $parser->setFunctionHook( 'set_internal_recurring_event', array( 
'SIOSubobjectAlias', 'doSetInternalRecurringEvent' ) );
        return true; // always return true, in order not to stop MW's hook 
processing!
 }
diff --git a/SemanticInternalObjects_body.php b/SemanticInternalObjects_body.php
index 008eef2..a2c86f2 100644
--- a/SemanticInternalObjects_body.php
+++ b/SemanticInternalObjects_body.php
@@ -333,67 +333,6 @@
        }
 
        /**
-        * Just calls SMW's own #subobject, which does essentially the
-        * same thing but with a different syntax.
-        */
-       public static function doSetInternalAsAlias( &$parser ) {
-               // This is a hack, since SMW's SMWSubobject::render() call is
-               // not meant to be called outside of SMW. However, this seemed
-               // like the better solution than copying over all of that
-               // method's code. Ideally, a true public function can be
-               // added to SMW, that handles a subobject creation, that this
-               // code can then call.
-
-               $origArgs = func_get_args();
-               // $parser is also $origArgs[0].
-               $subobjectArgs = array( &$parser );
-               // Blank first argument, so that subobject ID will be
-               // an automatically-generated random number.
-               $subobjectArgs[1] = '';
-               // "main" property, pointing back to the page.
-               $mainPageName = $parser->getTitle()->getText();
-               $mainPageNamespace = $parser->getTitle()->getNsText();
-               if ( $mainPageNamespace != '' ) {
-                       $mainPageName = $mainPageNamespace . ':' . 
$mainPageName;
-               }
-               if ( $origArgs[1] == '' ) {
-                       die( "Error: first argument to #set_internal cannot be 
blank." );
-               }
-               $subobjectArgs[2] = $origArgs[1] . '=' . $mainPageName;
-
-               for ( $i = 2; $i < count( $origArgs ); $i++ ) {
-                       $propAndValue = explode( '=', $origArgs[$i] );
-                       if ( count( $propAndValue ) != 2 ) continue;
-
-                       list( $prop, $value ) = $propAndValue;
-                       // If the property name ends with '#list', it's
-                       // a comma-delimited group of values.
-                       if ( substr( $prop, - 5 ) == '#list' ) {
-                               $prop = substr( $prop, 0, strlen( $prop ) - 5 );
-                               // #subobject has a different syntax for lists
-                               $actualValues = explode( ',', $value );
-                               $subobjectArgs[] = "$prop=" . $actualValues[0];
-                               for ( $j = 1; $j < count( $actualValues ); $j++ 
) {
-                                       $subobjectArgs[] = $actualValues[$j];
-                               }
-                       } else {
-                               $subobjectArgs[] = $origArgs[$i];
-                       }
-               }
-               if ( 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 );
-               } else {
-                       // SMW 1.8
-                       call_user_func_array( array( 'SMWSubobject', 'render' 
), $subobjectArgs );
-               }
-               return;
-       }
-
-       /**
         * Handles the #set_internal_recurring_event parser function.
         */
        public static function doSetInternalRecurringEvent( &$parser ) {
@@ -421,40 +360,6 @@
                        
                        $cur_params = array_merge( $first_params, 
$unused_params );
                        call_user_func_array( 'SIOHandler::doSetInternal', 
$cur_params );
-               }
-       }
-
-       /**
-        * Just calls SMW's own #subobject for each instance of this
-        * recurring event.
-        */
-       public static function doSetInternalRecurringEventAsAlias( &$parser ) {
-               // This is a hack, as is doSetInternalAsAlias() - see comments
-               // in that method.
-               $params = func_get_args();
-               array_shift( $params ); // We already know the $parser ...
-
-               // 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"
-                       );
-                       
-                       $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/50170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

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

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

Reply via email to