[MediaWiki-commits] [Gerrit] (#46124) Restrict getEntity to connected entity only - change (mediawiki...Wikibase)

2013-03-19 Thread Daniel Kinzler (Code Review)
Daniel Kinzler has submitted this change and it was merged.

Change subject: (#46124) Restrict getEntity to connected entity only
..


(#46124) Restrict getEntity to connected entity only

Change-Id: Ie916bad460f0f42ac220c6e74edfe9105b9b4e8e
---
M client/includes/WikibaseLibrary.php
M client/resources/mw.wikibase.lua
2 files changed, 62 insertions(+), 22 deletions(-)

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



diff --git a/client/includes/WikibaseLibrary.php 
b/client/includes/WikibaseLibrary.php
index 3b276fe..5cb8fe8 100644
--- a/client/includes/WikibaseLibrary.php
+++ b/client/includes/WikibaseLibrary.php
@@ -32,7 +32,10 @@
 * @since 0.4
 */
public function register() {
-   $lib = array( 'getEntity' = array( $this, 'getEntity' ) );
+   $lib = array(
+   'getEntity' = array( $this, 'getEntity' ),
+   'getEntityId' = array( $this, 'getEntityId' )
+   );
$this-getEngine()-registerInterface( dirname( __FILE__ ) . 
'/../resources/' . 'mw.wikibase.lua', $lib, array() );
}
/**
@@ -58,8 +61,9 @@
Wikibase\EntityId::newFromPrefixedId( $prefixedEntityId 
)
);
if ( $entityObject == null ) {
-   return null;
+   return array( null );
}
+
$serializerFactory = new 
\Wikibase\Lib\Serializers\SerializerFactory();
$serializer = $serializerFactory-newSerializerForObject( 
$entityObject );
 
@@ -69,4 +73,34 @@
$entityArr = $serializer-getSerialized( $entityObject );
return array( $entityArr );
}
+
+   /**
+* Get entity id from page title.
+*
+* @since 0.4
+*
+* @param string $pageTitle
+*
+* @return string $id
+*/
+   public function getEntityId( $pageTitle = null ) {
+   $this-checkType( 'getEntityByTitle', 1, $pageTitle, 'string' );
+   $globalSiteId = \Wikibase\Settings::get( 'siteGlobalID' );
+   $table = \Wikibase\ClientStoreFactory::getStore( 'sqlstore' 
)-newSiteLinkTable();
+   if ( $table == null ) {
+   return array( null );
+   }
+
+   $numericId = $table-getItemIdForLink( $globalSiteId, 
$pageTitle );
+   if ( !is_int( $numericId ) ) {
+   return array( null );
+   }
+
+   $id = new Wikibase\EntityId( \Wikibase\Item::ENTITY_TYPE, 
$numericId );
+   if ( $id == null ) {
+   return array( null );
+   }
+
+   return array( $id-getPrefixedId() );
+   }
 }
diff --git a/client/resources/mw.wikibase.lua b/client/resources/mw.wikibase.lua
index 65bfb68..533fb4d 100644
--- a/client/resources/mw.wikibase.lua
+++ b/client/resources/mw.wikibase.lua
@@ -1,38 +1,44 @@
 --[[
-   Registers and defines functions to access Wikibase through the 
Scribunto extension
-   Provides Lua setupInterface
+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 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.
+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
+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
+@since 0.4
 
-  

[MediaWiki-commits] [Gerrit] (#46124) Restrict getEntity to connected entity only - change (mediawiki...Wikibase)

2013-03-18 Thread Jens Ohlig (Code Review)
Jens Ohlig has uploaded a new change for review.

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


Change subject: (#46124) Restrict getEntity to connected entity only
..

(#46124) Restrict getEntity to connected entity only

Change-Id: Ie916bad460f0f42ac220c6e74edfe9105b9b4e8e
---
M client/includes/WikibaseLibrary.php
M client/resources/mw.wikibase.lua
2 files changed, 32 insertions(+), 6 deletions(-)


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

diff --git a/client/includes/WikibaseLibrary.php 
b/client/includes/WikibaseLibrary.php
index 3b276fe..a4ccfbc 100644
--- a/client/includes/WikibaseLibrary.php
+++ b/client/includes/WikibaseLibrary.php
@@ -32,7 +32,10 @@
 * @since 0.4
 */
public function register() {
-   $lib = array( 'getEntity' = array( $this, 'getEntity' ) );
+$lib = array( 
+'getEntity' = array( $this, 'getEntity' ), 
+'getEntityByTitle' = array( $this, 'getEntityByTitle' ) 
+);
$this-getEngine()-registerInterface( dirname( __FILE__ ) . 
'/../resources/' . 'mw.wikibase.lua', $lib, array() );
}
/**
@@ -58,7 +61,7 @@
Wikibase\EntityId::newFromPrefixedId( $prefixedEntityId 
)
);
if ( $entityObject == null ) {
-   return null;
+   return ( null );
}
$serializerFactory = new 
\Wikibase\Lib\Serializers\SerializerFactory();
$serializer = $serializerFactory-newSerializerForObject( 
$entityObject );
@@ -69,4 +72,21 @@
$entityArr = $serializer-getSerialized( $entityObject );
return array( $entityArr );
}
+public function getEntityByTitle( $pageTitle = null ) {
+   $this-checkType( 'getEntityByTitle', 1, $pageTitle, 'string' );
+$globalSiteId = \Wikibase\Settings::get(siteGlobalID);
+$table = \Wikibase\ClientStoreFactory::getStore( 'sqlstore' 
)-newSiteLinkTable();
+if ( $table == null ) {
+return array( null );
+}
+$numericId = $table-getItemIdForLink( $globalSiteId, $pageTitle );
+if ( !is_int( $numericId ) ) {
+return array( null );
+}
+$id = new Wikibase\EntityId( \Wikibase\Item::ENTITY_TYPE, $numericId );
+if ( $id == null ) {
+return array( null );
+}
+return array( $id-getPrefixedId() );
+}
 }
diff --git a/client/resources/mw.wikibase.lua b/client/resources/mw.wikibase.lua
index 65bfb68..b4347de 100644
--- a/client/resources/mw.wikibase.lua
+++ b/client/resources/mw.wikibase.lua
@@ -26,14 +26,20 @@
 local wikibase = {}
 
 function wikibase.setupInterface()
-  for k, v in pairs( mw_interface ) do
-wikibase[k] = v
+  local title  = require('mw.title')
+  local site = require('mw.site')
+  local php = mw_interface
+  mw_interface = nil
+  wikibase.getEntity = function()
+id = php.getEntityByTitle(tostring(title.getCurrentTitle()))
+if (id == nil) then return nil end
+entity = php.getEntity(id)
+return entity
   end
   mw = mw or {}
   mw.wikibase = wikibase
   package.loaded['mw.wikibase'] = wikibase
-  mw_interface = nil
   wikibase.setupInterface = nil
-end
+end 
 
 return wikibase

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie916bad460f0f42ac220c6e74edfe9105b9b4e8e
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