Daniel Kinzler has submitted this change and it was merged.

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.i18n.php
M client/WikibaseClient.php
A client/includes/WikibaseLibrary.php
A client/resources/mw.wikibase.lua
5 files changed, 131 insertions(+), 3 deletions(-)

Approvals:
  Daniel Kinzler: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 6908b36..65007ec 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -397,6 +397,20 @@
        }
 
        /**
+        * External library for Scribunto
+        *
+        * @since 0.4
+        *
+        * @param $engine
+        * @param array $extraLibraries
+        * @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
         *
@@ -710,7 +724,7 @@
                if ( $special->getName() === 'Watchlist' ) {
                        $context = $special->getContext();
 
-                       if ( $context->getRequest()->getBool( 'enhanced', 
$context->getUser()->getOption( 'usenewrc' ) ) === false ) {
+                       if ( $context->getRequest()->getBool( 'enhanced', 
$context->getUser()->getOption( 'usenewrc' ) ) === false ) {
                                $special->getOutput()->addModules( array(
                                        'wbclient.watchlist.css',
                                        'wbclient.watchlist',
diff --git a/client/WikibaseClient.i18n.php b/client/WikibaseClient.i18n.php
index 74885e5..876ccf7 100644
--- a/client/WikibaseClient.i18n.php
+++ b/client/WikibaseClient.i18n.php
@@ -53,7 +53,8 @@
        'wikibase-property-notsupportedyet' => 'Wikibase does not yet support 
property type for $1 property.',
        'wikibase-rc-hide-wikidata' => '$1 Wikidata',
        'wikibase-rc-show-wikidata-pref' => 'Show Wikidata edits in recent 
changes',
-       'wikibase-watchlist-show-changes-pref' => 'Show Wikidata edits in my 
watchlist',
+       'wikibase-watchlist-show-changes-pref' => 'Show Wikidata edits in your 
watchlist',
+       'wikibase-error-invalid-entity-id' => 'The ID entered is unknown to the 
system. Please use a valid entity ID.',
 );
 
 /** Message documentation (Message documentation)
@@ -136,6 +137,7 @@
 * $1 - a link with the text {{msg-mw|show}} or {{msg-mw|hide}}',
        'wikibase-rc-show-wikidata-pref' => 'Option in the recent changes 
section of preferences to show wikibase changes by default in recent changes.',
        'wikibase-watchlist-show-changes-pref' => 'Option in the watchlist 
section of preferences to always show wikibase edits by default in the 
watchlist.',
+       'wikibase-error-invalid-entity-id' => 'Generic error message when an 
invalid entity ID was entered.',
 );
 
 /** Afrikaans (Afrikaans)
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index 1f80e62..59dd8bf 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';
@@ -111,7 +112,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..3b276fe
--- /dev/null
+++ b/client/includes/WikibaseLibrary.php
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * Registers and defines functions to access Wikibase 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 0.4
+ *
+ * @licence GNU GPL v2+
+ * @author Jens Ohlig < [email protected] >
+ */
+
+class Scribunto_LuaWikibaseLibrary extends Scribunto_LuaLibraryBase {
+
+       /**
+        * Register mw.wikibase.lua library
+        *
+        * @since 0.4
+        */
+       public function register() {
+               $lib = array( 'getEntity' => array( $this, 'getEntity' ) );
+               $this->getEngine()->registerInterface( dirname( __FILE__ ) . 
'/../resources/' . 'mw.wikibase.lua', $lib, array() );
+       }
+       /**
+        * Get entity from prefixed ID (e.g. "Q23") and return it as serialized 
array.
+        *
+        * @since 0.4
+        *
+        * @param string $prefixedEntityId
+        *
+        * @return array $entityArr
+        */
+       public function getEntity( $prefixedEntityId = null ) {
+               $this->checkType( 'getEntity', 1, $prefixedEntityId, 'string' );
+               $prefixedEntityId = trim( $prefixedEntityId );
+               $libRegistry = new \Wikibase\LibRegistry( 
\Wikibase\Settings::singleton() );
+               $parseResult = $libRegistry->getEntityIdParser()->parse( 
$prefixedEntityId );
+
+               if ( !$parseResult->isValid() ) {
+                       throw $this->getEngine()->newException( 
'wikibase-error-invalid-entity-id' );
+               }
+
+               $entityObject = 
Wikibase\ClientStoreFactory::getStore()->getEntityLookup()->getEntity(
+                       Wikibase\EntityId::newFromPrefixedId( $prefixedEntityId 
)
+               );
+               if ( $entityObject == null ) {
+                       return null;
+               }
+               $serializerFactory = new 
\Wikibase\Lib\Serializers\SerializerFactory();
+               $serializer = $serializerFactory->newSerializerForObject( 
$entityObject );
+
+               $opt = new 
\Wikibase\Lib\Serializers\EntitySerializationOptions();
+               $serializer->setOptions( $opt );
+
+               $entityArr = $serializer->getSerialized( $entityObject );
+               return array( $entityArr );
+       }
+}
diff --git a/client/resources/mw.wikibase.lua b/client/resources/mw.wikibase.lua
new file mode 100644
index 0000000..65bfb68
--- /dev/null
+++ b/client/resources/mw.wikibase.lua
@@ -0,0 +1,39 @@
+--[[
+       Registers and defines functions to access Wikibase through the 
Scribunto extension
+       Provides Lua setupInterface
+
+       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 0.4
+
+       @licence GNU GPL v2+
+       @author Jens Ohlig < [email protected] >
+]]
+
+local 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
+  mw_interface = nil
+  wikibase.setupInterface = nil
+end
+
+return wikibase

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9fd05c36f32bffdeb15fb793e7c3332032b3541e
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jens Ohlig <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Jens Ohlig <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to