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
-