[MediaWiki-commits] [Gerrit] (Bug 47288) Abstraction layer for usage tracking. - change (mediawiki...Wikibase)
Aude has submitted this change and it was merged. Change subject: (Bug 47288) Abstraction layer for usage tracking. .. (Bug 47288) Abstraction layer for usage tracking. This introduces the EntityUsageIndex for tracking which client pages used which entity. Change-Id: I50dbac5760ec5cb331d3372545f1eac4e53a19bd --- M lib/WikibaseLib.classes.php M lib/WikibaseLib.hooks.php A lib/includes/store/EntityUsageIndex.php A lib/tests/phpunit/store/EntityUsageIndexTest.php 4 files changed, 648 insertions(+), 0 deletions(-) Approvals: Aude: Checked; Looks good to me, approved jenkins-bot: Verified diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php index 9bd68de..6dd483d 100644 --- a/lib/WikibaseLib.classes.php +++ b/lib/WikibaseLib.classes.php @@ -116,6 +116,7 @@ 'Wikibase\ChunkAccess' = 'includes/store/ChunkAccess.php', 'Wikibase\EntityLookup' = 'includes/store/EntityLookup.php', 'Wikibase\PropertyLabelResolver' = 'includes/store/PropertyLabelResolver.php', + 'Wikibase\EntityUsageIndex' = 'includes/store/EntityUsageIndex.php', 'Wikibase\SiteLinkCache' = 'includes/store/SiteLinkCache.php', 'Wikibase\SiteLinkLookup' = 'includes/store/SiteLinkLookup.php', 'Wikibase\TermIndex' = 'includes/store/TermIndex.php', diff --git a/lib/WikibaseLib.hooks.php b/lib/WikibaseLib.hooks.php index 2bb2884..6df4241 100644 --- a/lib/WikibaseLib.hooks.php +++ b/lib/WikibaseLib.hooks.php @@ -63,6 +63,7 @@ 'store/SiteLinkTable', 'store/WikiPageEntityLookup', 'store/CachingEntityLoader', + 'store/EntityUsageIndex', 'store/TermPropertyLabelResolver', diff --git a/lib/includes/store/EntityUsageIndex.php b/lib/includes/store/EntityUsageIndex.php new file mode 100644 index 000..85ba5f4 --- /dev/null +++ b/lib/includes/store/EntityUsageIndex.php @@ -0,0 +1,183 @@ +?php + +namespace Wikibase; + +use Site; + +/** + * Index for tracking the usage of entities on a specific client wiki. + * + * 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 + * + * @file + * @ingroup WikibaseLib + * + * @licence GNU GPL v2+ + * + * + * @author Daniel Kinzler + */ +class EntityUsageIndex { + + /** +* @param Site $clientSite +* @param SiteLinkLookup $siteLinks +*/ + public function __construct( Site $clientSite, SiteLinkLookup $siteLinks ) { + $this-clientSite = $clientSite; + $this-siteLinks = $siteLinks; + } + + /** +* Returns the Site of the client wiki this usage index is tracking. +* +* @since0.4 +* +* @return Site +*/ + public function getClientSite() { + return $this-clientSite; + } + + /** +* Determines which pages use any of the given entities. +* +* @since0.4 +* +* @param EntityId[] $entities +* +* @return String[] list of pages using any of the given entities +*/ + public function getEntityUsage( array $entities ) { + if ( empty( $entities ) ) { + return array(); + } + + $ids = array_map( + function ( EntityId $id ) { + return $id-getNumericId(); + }, + $entities + ); + + $rows = $this-siteLinks-getLinks( $ids, array( $this-clientSite-getGlobalId() ) ) ; + + $pages = array_map( + function ( array $row ) { + return $row[1]; // page name + }, + $rows + ); + + $pages = array_unique( $pages ); + return $pages; + } + + /** +* Checks which of the given entities is used on the target wiki, +* and removed all others. +* +* @since0.4 +* +* @param EntityID[] $entities The
[MediaWiki-commits] [Gerrit] (Bug 47288) Abstraction layer for usage tracking. - change (mediawiki...Wikibase)
Daniel Kinzler has uploaded a new change for review. https://gerrit.wikimedia.org/r/59412 Change subject: (Bug 47288) Abstraction layer for usage tracking. .. (Bug 47288) Abstraction layer for usage tracking. This introduces the EntityUsageIndex for tracking which client pages used wwhich entity. Change-Id: I50dbac5760ec5cb331d3372545f1eac4e53a19bd --- M lib/WikibaseLib.hooks.php M lib/WikibaseLib.php A lib/includes/store/EntityUsageIndex.php A lib/tests/phpunit/store/EntityUsageIndexTest.php 4 files changed, 648 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/12/59412/1 diff --git a/lib/WikibaseLib.hooks.php b/lib/WikibaseLib.hooks.php index 069a109..7df5cde 100644 --- a/lib/WikibaseLib.hooks.php +++ b/lib/WikibaseLib.hooks.php @@ -65,6 +65,7 @@ 'store/SiteLinkTable', 'store/WikiPageEntityLookup', 'store/CachingEntityLoader', + 'store/EntityUsageIndex', 'store/sql/PropertySQLLookup', diff --git a/lib/WikibaseLib.php b/lib/WikibaseLib.php index 2395625..942ed8d 100644 --- a/lib/WikibaseLib.php +++ b/lib/WikibaseLib.php @@ -194,6 +194,7 @@ $wgAutoloadClasses['Wikibase\TermCombinationMatchFinder'] = $dir . 'includes/store/TermCombinationMatchFinder.php'; $wgAutoloadClasses['Wikibase\TermMatchScoreCalculator'] = $dir . 'includes/store/TermMatchScoreCalculator.php'; $wgAutoloadClasses['Wikibase\TermSqlIndex']= $dir . 'includes/store/sql/TermSqlIndex.php'; +$wgAutoloadClasses['Wikibase\EntityUsageIndex']= $dir . 'includes/store/EntityUsageIndex.php'; // includes/store/sql $wgAutoloadClasses['Wikibase\CachingEntityLoader'] = $dir . 'includes/store/sql/CachingEntityLoader.php'; diff --git a/lib/includes/store/EntityUsageIndex.php b/lib/includes/store/EntityUsageIndex.php new file mode 100644 index 000..86febd5 --- /dev/null +++ b/lib/includes/store/EntityUsageIndex.php @@ -0,0 +1,183 @@ +?php + +namespace Wikibase; + +use Site; + +/** + * Index for tracking the usage of entities on a specific client wiki. + * + * 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 + * + * @file + * @ingroup WikibaseLib + * + * @licence GNU GPL v2+ + * + * + * @author Daniel Kinzler + */ +class EntityUsageIndex { + + /** +* @param Site $clientSite +* @param SiteLinkLookup $siteLinks +*/ + public function __construct( Site $clientSite, SiteLinkLookup $siteLinks ) { + $this-clientSite = $clientSite; + $this-siteLinks = $siteLinks; + } + + /** +* Returns the global site ID of the client wiki this usage index is tracking. +* +* @since0.4 +* +* @return Site +*/ + public function getClientSite() { + return $this-clientSite; + } + + /** +* Determines which pages use any of the given entities. +* +* @since0.4 +* +* @param EntityId[] $entities +* +* @return String[] list of pages using any of the given entities +*/ + public function getEntityUsage( array $entities ) { + if ( empty( $entities ) ) { + return array(); + } + + $ids = array_map( + function ( EntityId $id ) { + return $id-getNumericId(); + }, + $entities + ); + + $rows = $this-siteLinks-getLinks( $ids, array( $this-clientSite-getGlobalId() ) ) ; + + $pages = array_map( + function ( array $row ) { + return $row[1]; // page name + }, + $rows + ); + + $pages = array_unique( $pages ); + return $pages; + } + + /** +* Checks which of the given entities is used on the target wiki, +* and removed all others. +* +* @since