Jens Ohlig has uploaded a new change for review.

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


Change subject: Add mw.wikibase.properties as a Lua function
......................................................................

Add mw.wikibase.properties as a Lua function

Change-Id: I5e1bbe0fd8586ebda123a5aafe73292234b23978
---
M client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
M client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
M client/includes/scribunto/mw.wikibase.lua
M 
client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementationTest.php
4 files changed, 60 insertions(+), 4 deletions(-)


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

diff --git a/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php 
b/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
index 007d5ef..b95df46 100644
--- a/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
+++ b/client/includes/scribunto/Scribunto_LuaWikibaseLibrary.php
@@ -1,6 +1,5 @@
 <?php
 
-use Wikibase\Settings;
 use ValueParsers\ParseException;
 use Wikibase\Client\WikibaseClient;
 
@@ -35,7 +34,7 @@
                        
WikibaseClient::getDefaultInstance()->getEntityIdFormatter(), // 
EntityIdFormatter
                        
WikibaseClient::getDefaultInstance()->getStore()->getSiteLinkTable(), // 
SiteLinkLookup
                        $language, // language
-                       Settings::get( 'siteGlobalID' ) // SiteID
+                       
WikibaseClient::getDefaultInstance()->getSettings()->getSetting( 'siteGlobalID' 
) // siteId
                );
                parent::__construct( $engine );
        }
@@ -46,7 +45,11 @@
         * @since 0.4
         */
        public function register() {
-               $lib = array( 'getEntity' => array( $this, 'getEntity' ), 
'getEntityId' => array( $this, 'getEntityId' ), 'getGlobalSiteId' => array( 
$this, 'getGlobalSiteId' ) );
+               $lib = array(
+                       'getEntity' => array( $this, 'getEntity' ),
+                       'getEntityId' => array( $this, 'getEntityId' ),
+                       'getGlobalSiteId' => array( $this, 'getGlobalSiteId' )
+               );
                $this->getEngine()->registerInterface( dirname( __FILE__ ) . 
'/mw.wikibase.lua', $lib, array() );
        }
 
diff --git 
a/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php 
b/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
index f46bb38..302619e 100644
--- a/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
+++ b/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
@@ -55,7 +55,7 @@
                $this->entityIdFormatter = $entityIdFormatter;
                $this->siteLinkTable = $siteLinkTable;
                $this->language = $language;
-               $this->siteId;
+               $this->siteId = $siteId;
        }
 
 
diff --git a/client/includes/scribunto/mw.wikibase.lua 
b/client/includes/scribunto/mw.wikibase.lua
index 721da00..f42b98f 100644
--- a/client/includes/scribunto/mw.wikibase.lua
+++ b/client/includes/scribunto/mw.wikibase.lua
@@ -28,12 +28,14 @@
 function wikibase.setupInterface()
   local php = mw_interface
   mw_interface = nil
+
   wikibase.getEntity = function ()
     local id = php.getEntityId( tostring( 
mw.title.getCurrentTitle().prefixedText ) )
     if id == nil then return nil end
     local entity = php.getEntity( id )
     return entity
   end
+
   wikibase.label = function ( id )
     local code = mw.language.getContentLanguage():getCode()
     if code == nil then return nil end
@@ -43,6 +45,7 @@
     if label == nil then return nil end
     return label.value
   end
+
   wikibase.sitelink = function ( id )
     local entity = php.getEntity( id )
     if entity == nil or entity.sitelinks == nil then return nil end
@@ -52,6 +55,44 @@
     if sitelink == nil then return nil end
     return sitelink.title
   end
+
+  wikibase.properties = function ()
+    local entity = {}
+    entity = wikibase.getEntity()
+    local properties = {}
+    local n=0
+    if entity.claims == nil then return {} end
+    for k,v in pairs( entity.claims ) do
+      n=n+1
+      properties[n]=k
+    end
+    local filter = function( func, xs )
+         local table= {}
+         for i,v in pairs( xs ) do
+             if func( v ) then
+            table[i]=v
+             end
+         end
+         return table
+     end
+     local is_capital_property = function( x )
+        return ( string.match( x, '^%u%d+' ) ~= nil )
+     end
+     properties = filter( is_capital_property, properties )
+     n = 0
+     local p = {}
+     for k,v in pairs( properties ) do
+           n=n+1
+           p[n]=v
+      end
+      properties = p
+      p = {}
+      for i,v in pairs( properties ) do
+        p[v] = { ["label"] = wikibase.label( v ) }
+      end
+      return p
+  end
+
   mw = mw or {}
   mw.wikibase = wikibase
   package.loaded['mw.wikibase'] = wikibase
diff --git 
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementationTest.php
 
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementationTest.php
index 51b07bc..393645d 100644
--- 
a/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementationTest.php
+++ 
b/client/tests/phpunit/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementationTest.php
@@ -44,4 +44,16 @@
        public function provideEntity() {
                return array( array( 'q42' ), array( 'q23' ) );
        }
+
+       /**
+        * @dataProvider provideTitle
+        */
+       public function testGetEntityId( $title ) {
+               $id = $this->getWikibaseLibraryImplementation()->getEntityId( 
$title );
+               $this->assertInternalType( 'array', $id );
+       }
+
+       public function provideTitle() {
+               return array( array( 'Gold' ), array( 'Silver' ) );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e1bbe0fd8586ebda123a5aafe73292234b23978
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jens Ohlig <jens.oh...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to