Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/93959
Change subject: Make entity change hooks usable by Wikibase Query ...................................................................... Make entity change hooks usable by Wikibase Query Change-Id: I2308ac71fa9de82cccb5d270484e0e4834487eda --- M repo/RELEASE-NOTES M repo/includes/content/ItemContent.php M repo/includes/content/PropertyContent.php M repo/includes/updates/EntityDeletionUpdate.php M repo/includes/updates/EntityModificationUpdate.php M repo/includes/updates/ItemDeletionUpdate.php M repo/includes/updates/ItemModificationUpdate.php 7 files changed, 81 insertions(+), 112 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/59/93959/1 diff --git a/repo/RELEASE-NOTES b/repo/RELEASE-NOTES index 40e73f1..ff1bc02 100644 --- a/repo/RELEASE-NOTES +++ b/repo/RELEASE-NOTES @@ -4,9 +4,16 @@ Latest version of the release notes: https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/Wikibase.git;a=blob;f=repo/RELEASE-NOTES +=== Version 0.5 === +(dev) + +* WikibaseEntityModificationUpdate hook now only gets fired on modification and not on insertion and +takes different arguments then it did before. +* WikibaseEntityInsertionUpdate hook was added +* WikibaseEntityDeletionUpdate hook now gets an EntityContent rather than an EntityDeletionUpdate. === Version 0.4 === -(dev) +(not released) ; Interface @@ -19,7 +26,7 @@ * Referenced entities are now added to the pagelinks table and thus show up on places such as Special:WhatLinksHere === Version 0.3 === -(???) +(not released) ; Interface @@ -45,7 +52,7 @@ * Internal serialization logic for Snak, Claim, Statement and Reference has been implemented in toArray and newFromArray. === Version 0.2 === -(???) +(not released) * Added Special:SetLabel * Added Special:EntitiesWithoutLabel diff --git a/repo/includes/content/ItemContent.php b/repo/includes/content/ItemContent.php index 7259d74..d1c934d 100644 --- a/repo/includes/content/ItemContent.php +++ b/repo/includes/content/ItemContent.php @@ -270,7 +270,7 @@ return array_merge( parent::getSecondaryDataUpdates( $title, $old, $recursive, $parserOutput ), - array( new ItemModificationUpdate( $this ) ) + array( new ItemModificationUpdate( $this, $old ) ) ); } diff --git a/repo/includes/content/PropertyContent.php b/repo/includes/content/PropertyContent.php index 37ba15b..00b5c89 100644 --- a/repo/includes/content/PropertyContent.php +++ b/repo/includes/content/PropertyContent.php @@ -186,7 +186,7 @@ return array_merge( parent::getSecondaryDataUpdates( $title, $old, $recursive, $parserOutput ), array( - new EntityModificationUpdate( $this ), + new EntityModificationUpdate( $this, $old ), new PropertyInfoUpdate( $this->getProperty(), $infoStore ), ) ); diff --git a/repo/includes/updates/EntityDeletionUpdate.php b/repo/includes/updates/EntityDeletionUpdate.php index 3a3d3b2..c455888 100644 --- a/repo/includes/updates/EntityDeletionUpdate.php +++ b/repo/includes/updates/EntityDeletionUpdate.php @@ -5,25 +5,7 @@ /** * Deletion update to handle deletion of Wikibase entities. * - * 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.1 - * - * @file - * @ingroup WikibaseRepo * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -49,17 +31,6 @@ } /** - * Returns the EntityContent that's being deleted. - * - * @since 0.1 - * - * @return EntityContent - */ - public function getEntityContent() { - return $this->content; - } - - /** * @see DeferrableUpdate::doUpdate * * @since 0.1 @@ -79,11 +50,11 @@ * Gets called after the deletion of an item has been committed, * allowing for extensions to do additional cleanup. * - * @since 0.1 + * @since 0.5 * - * @param EntityDeletionUpdate $this + * @param EntityContent $entityContent */ - wfRunHooks( 'WikibaseEntityDeletionUpdate', array( $this ) ); + wfRunHooks( 'WikibaseEntityDeletionUpdate', array( $this->content ) ); wfProfileOut( __METHOD__ ); } diff --git a/repo/includes/updates/EntityModificationUpdate.php b/repo/includes/updates/EntityModificationUpdate.php index 6e37c62..3155f85 100644 --- a/repo/includes/updates/EntityModificationUpdate.php +++ b/repo/includes/updates/EntityModificationUpdate.php @@ -6,25 +6,7 @@ * Represents an update to the structured storage for a single Entity. * TODO: we could keep track of actual changes in a lot of cases, and so be able to do less (expensive) queries to update. * - * 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.1 - * - * @file - * @ingroup WikibaseRepo * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -32,34 +14,30 @@ class EntityModificationUpdate extends \DataUpdate { /** - * The entity to update. - * * @since 0.1 * * @var EntityContent */ - protected $content; + protected $newContent; + + /** + * @since 0.5 + * + * @var null|EntityContent + */ + protected $oldContent; /** * Constructor. * * @since 0.1 * - * @param EntityContent $content + * @param EntityContent $newContent + * @param EntityContent|null $oldContent */ - public function __construct( EntityContent $content ) { - $this->content = $content; - } - - /** - * Returns the EntityContent that's being saved. - * - * @since 0.1 - * - * @return EntityContent - */ - public function getEntityContent() { - return $this->content; + public function __construct( EntityContent $newContent, EntityContent $oldContent = null ) { + $this->newContent = $newContent; + $this->oldContent = $oldContent; } /** @@ -70,23 +48,18 @@ public function doUpdate() { wfProfileIn( __METHOD__ ); + $this->updateRepoStore(); + $this->fireHooks(); + + wfProfileOut( __METHOD__ ); + } + + protected function updateRepoStore() { $store = StoreFactory::getStore(); - $entity = $this->content->getEntity(); + $entity = $this->newContent->getEntity(); $store->getTermIndex()->saveTermsOfEntity( $entity ); $this->doTypeSpecificStuff( $store, $entity ); - - /** - * Gets called after the structured save of an item has been comitted, - * allowing for extensions to do additional storage/indexing. - * - * @since 0.1 - * - * @param EntityModificationUpdate $this - */ - wfRunHooks( 'WikibaseEntityModificationUpdate', array( $this ) ); - - wfProfileOut( __METHOD__ ); } /** @@ -101,4 +74,42 @@ // Override to add behavior. } + protected function fireHooks() { + if ( $this->isInsertionUpdate() ) { + $this->firstInsertionHook(); + } + else { + $this->fireModificationHook(); + } + } + + protected function isInsertionUpdate() { + return $this->oldContent === null; + } + + protected function firstInsertionHook() { + /** + * Gets called after the structured save of an item has been committed, + * allowing for extensions to do additional storage/indexing. + * + * @since 0.5 + * + * @param EntityContent $entityContent + */ + wfRunHooks( 'WikibaseEntityInsertionUpdate', array( $this->newContent ) ); + } + + protected function fireModificationHook() { + /** + * Gets called after the structured save of an item has been committed, + * allowing for extensions to do additional storage/indexing. + * + * @since 0.5 + * + * @param EntityContent $newEntityContent + * @param EntityContent $oldEntityContent + */ + wfRunHooks( 'WikibaseEntityModificationUpdate', array( $this->newContent, $this->oldContent ) ); + } + } diff --git a/repo/includes/updates/ItemDeletionUpdate.php b/repo/includes/updates/ItemDeletionUpdate.php index 5c75e5c..83e08db 100644 --- a/repo/includes/updates/ItemDeletionUpdate.php +++ b/repo/includes/updates/ItemDeletionUpdate.php @@ -7,9 +7,6 @@ * * @since 0.1 * - * @file - * @ingroup WikibaseRepo - * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > */ @@ -20,10 +17,10 @@ * * @since 0.1 * - * @param ItemContent $content + * @param ItemContent $newContent */ - public function __construct( ItemContent $content ) { - $this->content = $content; + public function __construct( ItemContent $newContent ) { + $this->content = $newContent; } /** diff --git a/repo/includes/updates/ItemModificationUpdate.php b/repo/includes/updates/ItemModificationUpdate.php index 0d7576d..633eb82 100644 --- a/repo/includes/updates/ItemModificationUpdate.php +++ b/repo/includes/updates/ItemModificationUpdate.php @@ -6,25 +6,7 @@ * Represents an update to the structured storage for a single Item. * TODO: we could keep track of actual changes in a lot of cases, and so be able to do less (expensive) queries to update. * - * 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.1 - * - * @file - * @ingroup WikibaseRepo * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -36,10 +18,11 @@ * * @since 0.1 * - * @param ItemContent $content + * @param ItemContent $newContent + * @param null|ItemContent $oldContent */ - public function __construct( ItemContent $content ) { - $this->content = $content; + public function __construct( ItemContent $newContent, ItemContent $oldContent = null ) { + parent::__construct( $newContent, $oldContent ); } /** -- To view, visit https://gerrit.wikimedia.org/r/93959 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2308ac71fa9de82cccb5d270484e0e4834487eda Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
