Jens Ohlig has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53570
Change subject: Lua support to access the repo data and implement getEntity
......................................................................
Lua support to access the repo data and implement getEntity
Change-Id: I9fd05c36f32bffdeb15fb793e7c3332032b3541e
---
M client/WikibaseClient.hooks.php
M client/WikibaseClient.php
A client/includes/WikibaseLibrary.php
A client/resources/mw.wikibase.lua
4 files changed, 47 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/70/53570/1
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index f2b005e..7538650 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -398,6 +398,16 @@
return true;
}
+ /**
+ * External library for Scribunto
+ *
+ * @return bool
+ */
+ public static function onScribuntoExternalLibraries ( $engine, array
&$extraLibraries ) {
+ $extraLibraries['mw.wikibase'] = 'Scribunto_LuaWikibaseLibrary';
+ return true;
+ }
+
/**
* Hook for modifying the query for fetching recent changes
* @see
https://www.mediawiki.org/wiki/Manual:Hooks/SpecialRecentChangesQuery
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index 2345169..e86ac06 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -65,6 +65,7 @@
$wgAutoloadClasses['Wikibase\LangLinkHandler'] = $dir .
'includes/LangLinkHandler.php';
$wgAutoloadClasses['Wikibase\ChangeHandler'] = $dir .
'includes/ChangeHandler.php';
$wgAutoloadClasses['Wikibase\NamespaceChecker'] = $dir .
'includes/NamespaceChecker.php';
+$wgAutoloadClasses['Scribunto_LuaWikibaseLibrary'] = $dir .
'includes/WikibaseLibrary.php';
// includes/api
$wgAutoloadClasses['Wikibase\ApiClientInfo'] = $dir .
'includes/api/ApiClientInfo.php';
@@ -114,7 +115,7 @@
$wgHooks['GetPreferences'][] =
'\Wikibase\ClientHooks::onGetPreferences';
$wgHooks['BeforePageDisplay'][] =
'\Wikibase\ClientHooks::onBeforePageDisplay';
$wgHooks['SpecialPageBeforeExecute'][] =
'\Wikibase\ClientHooks::onSpecialPageBeforeExecute';
-
+$wgHooks['ScribuntoExternalLibraries'][] =
'\Wikibase\ClientHooks::onScribuntoExternalLibraries';
// extension hooks
$wgHooks['WikibasePollHandle'][] =
'\Wikibase\ClientHooks::onWikibasePollHandle';
$wgHooks['WikibaseDeleteData'][] =
'\Wikibase\ClientHooks::onWikibaseDeleteData';
diff --git a/client/includes/WikibaseLibrary.php
b/client/includes/WikibaseLibrary.php
new file mode 100644
index 0000000..4e2cfe1
--- /dev/null
+++ b/client/includes/WikibaseLibrary.php
@@ -0,0 +1,23 @@
+<?php
+class Scribunto_LuaWikibaseLibrary extends Scribunto_LuaLibraryBase {
+ protected static $moduleName = 'wikibase';
+ public function register() {
+ $lib = array( 'getEntity' => array( $this, 'getEntity' ) );
+ $this->getEngine()->registerInterface( dirname( __FILE__ ) .
'/../resources/' . 'mw.wikibase.lua', $lib, array() );
+ }
+
+ public function getEntity( $entity ) {
+ $this->checkType( 'getEntity', 1, $entity, 'string' );
+ $entityObject =
Wikibase\ClientStoreFactory::getStore()->newEntityLookup()->getEntity(
Wikibase\EntityId::newFromPrefixedId( $entity ) );
+
+ $serializerFactory = new \Wikibase\Lib\Serializers\SerializerFactory();
+ $serializer =$serializerFactory->newSerializerForObject( $entityObject
);
+
+ $opt = new \Wikibase\Lib\Serializers\EntitySerializationOptions();
+ $serializer->setOptions( $opt );
+
+ $entityArr = $serializer->getSerialized( $entityObject );
+ MWDebug::log( serialize($entityArr) );
+ return array( $entityArr );
+ }
+}
diff --git a/client/resources/mw.wikibase.lua b/client/resources/mw.wikibase.lua
new file mode 100644
index 0000000..4c54835
--- /dev/null
+++ b/client/resources/mw.wikibase.lua
@@ -0,0 +1,12 @@
+wikibase = {}
+
+function wikibase.setupInterface()
+ for k, v in pairs( mw_interface ) do
+ wikibase[k] = v
+ end
+ mw = mw or {}
+ mw.wikibase = wikibase
+ package.loaded['mw.wikibase'] = wikibase
+end
+
+return wikibase
--
To view, visit https://gerrit.wikimedia.org/r/53570
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9fd05c36f32bffdeb15fb793e7c3332032b3541e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jens Ohlig <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits