Mwjames has uploaded a new change for review.

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


Change subject: Support Lua/Scribunto framework in SMW
......................................................................

Support Lua/Scribunto framework in SMW

No idea about Lua but I used the Wikibase/Lua as reference framework
to get a general SMW/Lua/Scribunto interface working [1]

## Library
smw.property.lua is supported by SMW\Lua\PropertyLibrary which inlcudes
getPropertyType()

[1] http://www.semantic-mediawiki.org/wiki/Help:Writing_Lua_modules

Change-Id: I8cd37150c5eaeaddbd6cf5495a0b5eecd52a279f
---
M SemanticMediaWiki.hooks.php
M includes/Setup.php
A includes/lua/PropertyLibrary.php
A includes/lua/smw.property.lua
4 files changed, 140 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/93/56393/1

diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 1a6315a..3a2c1c2 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -418,4 +418,19 @@
 
                return true;
        }
+
+       /**
+        * External library for Scribunto
+        *
+        * @since 1.9
+        *
+        * @param $engine
+        * @param array $extraLibraries
+        * @return bool
+        */
+       public static function onScribuntoExternalLibraries ( $engine, array 
&$extraLibraries ) {
+               $extraLibraries['smw.property'] = 'SMW\Lua\PropertyLibrary';
+               return true;
+       }
+
 }
diff --git a/includes/Setup.php b/includes/Setup.php
index 9d600f4..19ef141 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -85,6 +85,9 @@
        $wgHooks['SkinGetPoweredBy'][] = 'SMWHooks::addPoweredBySMW';
 
        $wgHooks['ExtensionTypes'][] = 'SMWHooks::addSemanticExtensionType';
+
+       // Scribunto support
+       $wgHooks['ScribuntoExternalLibraries'][] = 
'SMWHooks::onScribuntoExternalLibraries';
 }
 
 /**
@@ -111,6 +114,10 @@
        $wgAutoloadClasses['SMWSemanticData']           = $incDir . 
'SMW_SemanticData.php';
        $wgAutoloadClasses['SMWPageLister']             = $incDir . 
'SMW_PageLister.php';
 
+       // Lua support
+       $luaDir = $smwgIP . 'includes/lua/';
+       $wgAutoloadClasses['SMW\Lua\PropertyLibrary']   = $luaDir . 
'PropertyLibrary.php';
+
        // Article pages
        $apDir = $smwgIP . 'includes/articlepages/';
        $wgAutoloadClasses['SMWOrderedListPage']        = $apDir . 
'SMW_OrderedListPage.php';
diff --git a/includes/lua/PropertyLibrary.php b/includes/lua/PropertyLibrary.php
new file mode 100644
index 0000000..26bd69c
--- /dev/null
+++ b/includes/lua/PropertyLibrary.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace SMW\Lua;
+
+/**
+ * Registers methods that can be accessed through the Scribunto extension
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA
+ *
+ * @since 1.9
+ *
+ * @file
+ * @ingroup SMW
+ *
+ * @author mwjames
+ */
+
+/**
+ * Registers property methods that can be accessed through the Scribunto 
extension
+ * @ingroup SMW
+ */
+class PropertyLibrary extends \Scribunto_LuaLibraryBase {
+
+       /**
+        * Register smw.library.lua
+        *
+        * @since 1.9
+        */
+       public function register() {
+               global $smwgIP;
+               $lib = array(
+                       'getPropertyType' => array( $this, 'getPropertyType' ),
+               );
+
+//             $this->getEngine()->registerInterface( dirname( __FILE__ ) . 
'/' . 'smw.property.lua', $lib, array() );
+               $this->getEngine()->registerInterface( 'smw.property.lua', 
$lib, array() );
+       }
+
+       /**
+        * Returns property type
+        *
+        * @since 1.9
+        *
+        * @param string $propertyName
+        *
+        * @return array
+        */
+       public function getPropertyType( $propertyName = null ) {
+               $this->checkType( 'getPropertyType', 1, $propertyName, 'string' 
);
+               $propertyName = trim( $propertyName );
+
+               if ( $propertyName === null ) {
+                       return array( null );
+               }
+
+               $property = \SMWDIProperty::newFromUserLabel( $propertyName );
+
+               if ( $property === null ) {
+                       return array( null );
+               }
+
+               return array( $property->findPropertyTypeID() );
+       }
+
+}
diff --git a/includes/lua/smw.property.lua b/includes/lua/smw.property.lua
new file mode 100644
index 0000000..adb6dce
--- /dev/null
+++ b/includes/lua/smw.property.lua
@@ -0,0 +1,41 @@
+--[[
+    Registers methods that can be accessed through the Scribunto extension
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+    http://www.gnu.org/copyleft/gpl.html
+
+    @since 1.9
+
+    @licence GNU GPL v2+
+    @author mwjames
+]]
+
+local property = {}
+
+function property.setupInterface()
+  local php = mw_interface
+  mw_interface = nil
+  property.getPropertyType = function ( name )
+    local propertyType = php.getPropertyType( name )
+    if propertyType == nil then return nil end
+    return propertyType
+  end
+  smw = smw or {}
+  smw.property = property
+  package.loaded['smw.property'] = property
+  property.setupInterface = nil
+end
+
+return property

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8cd37150c5eaeaddbd6cf5495a0b5eecd52a279f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
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