jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/389792 )
Change subject: Avoid hardcoding specific GadgetRepo implementations for cache
invalidations
......................................................................
Avoid hardcoding specific GadgetRepo implementations for cache invalidations
Depending on GadgetRepo::singleton() to return a specific implementation
is fragile. Pass each created/updated/deleted page to
GadgetRepo::handlePageCreation/Update/Deletion() and let each specific
implementation deal with it.
Use LinkTarget to be TitleValue compatible for the future.
Change-Id: Ibe2e26d12369a897c53757adf621926f62af7f7b
---
M GadgetHooks.php
M includes/GadgetDefinitionNamespaceRepo.php
M includes/GadgetRepo.php
M includes/MediaWikiGadgetsDefinitionRepo.php
M includes/content/GadgetDefinitionContent.php
M includes/content/GadgetDefinitionDeletionUpdate.php
M includes/content/GadgetDefinitionSecondaryDataUpdate.php
7 files changed, 95 insertions(+), 31 deletions(-)
Approvals:
Krinkle: Looks good to me, approved
jenkins-bot: Verified
diff --git a/GadgetHooks.php b/GadgetHooks.php
index 449e707..4fc24a3 100644
--- a/GadgetHooks.php
+++ b/GadgetHooks.php
@@ -33,13 +33,7 @@
*/
public static function onPageContentSaveComplete( $article, $user,
$content ) {
// update cache if MediaWiki:Gadgets-definition was edited
- $title = $article->getTitle();
- $repo = GadgetRepo::singleton();
- if ( $title->getNamespace() == NS_MEDIAWIKI &&
$title->getText() == 'Gadgets-definition'
- && $repo instanceof MediaWikiGadgetsDefinitionRepo
- ) {
- $repo->purgeDefinitionCache();
- }
+ GadgetRepo::singleton()->handlePageUpdate( $article->getTitle()
);
return true;
}
@@ -277,10 +271,7 @@
*/
public static function onPageContentInsertComplete( WikiPage $page ) {
if ( $page->getTitle()->inNamespace( NS_GADGET_DEFINITION ) ) {
- $repo = GadgetRepo::singleton();
- if ( $repo instanceof GadgetDefinitionNamespaceRepo ) {
- $repo->purgeGadgetIdsList();
- }
+ GadgetRepo::singleton()->handlePageCreation(
$page->getTitle() );
}
}
diff --git a/includes/GadgetDefinitionNamespaceRepo.php
b/includes/GadgetDefinitionNamespaceRepo.php
index 9ed67eb..5746d89 100644
--- a/includes/GadgetDefinitionNamespaceRepo.php
+++ b/includes/GadgetDefinitionNamespaceRepo.php
@@ -1,5 +1,6 @@
<?php
+use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
/**
@@ -54,6 +55,34 @@
}
/**
+ * @inheritDoc
+ */
+ public function handlePageUpdate( LinkTarget $target ) {
+ if ( $target->inNamespace( NS_GADGET_DEFINITION ) ) {
+ $this->purgeGadgetEntry( $target->getText() );
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function handlePageCreation( LinkTarget $target ) {
+ if ( $target->inNamespace( NS_GADGET_DEFINITION ) ) {
+ $this->purgeGadgetIdsList();
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function handlePageDeletion( LinkTarget $target ) {
+ if ( $target->inNamespace( NS_GADGET_DEFINITION ) ) {
+ $this->purgeGadgetIdsList();
+ $this->purgeGadgetEntry( $target->getText() );
+ }
+ }
+
+ /**
* Purge the list of gadget ids when a page is deleted or if a new page
is created
*/
public function purgeGadgetIdsList() {
diff --git a/includes/GadgetRepo.php b/includes/GadgetRepo.php
index 76e9dec..11996f8 100644
--- a/includes/GadgetRepo.php
+++ b/includes/GadgetRepo.php
@@ -1,5 +1,7 @@
<?php
+use MediaWiki\Linker\LinkTarget;
+
abstract class GadgetRepo {
/**
@@ -27,6 +29,39 @@
abstract public function getGadget( $id );
/**
+ * Given that the provided page was updated, invalidate
+ * caches if necessary
+ *
+ * @param LinkTarget $target
+ *
+ * @return void
+ */
+ public function handlePageUpdate( LinkTarget $target ) {
+ }
+
+ /**
+ * Given that the provided page was created, invalidate
+ * caches if necessary
+ *
+ * @param LinkTarget $target
+ *
+ * @return void
+ */
+ public function handlePageCreation( LinkTarget $target ) {
+ }
+
+ /**
+ * Given that the provided page was updated, invalidate
+ * caches if necessary
+ *
+ * @param LinkTarget $target
+ *
+ * @return void
+ */
+ public function handlePageDeletion( LinkTarget $target ) {
+ }
+
+ /**
* Get a list of gadgets sorted by category
*
* @return array [ 'category' => [ 'name' => $gadget ] ]
diff --git a/includes/MediaWikiGadgetsDefinitionRepo.php
b/includes/MediaWikiGadgetsDefinitionRepo.php
index 60fb61d..4715762 100644
--- a/includes/MediaWikiGadgetsDefinitionRepo.php
+++ b/includes/MediaWikiGadgetsDefinitionRepo.php
@@ -1,4 +1,6 @@
<?php
+
+use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\Database;
@@ -28,11 +30,17 @@
}
}
+ public function handlePageUpdate( LinkTarget $target ) {
+ if ( $target->getNamespace() == NS_MEDIAWIKI &&
$target->getText() == 'Gadgets-definition' ) {
+ $this->purgeDefinitionCache();
+ }
+ }
+
/**
* Purge the definitions cache, for example if
MediaWiki:Gadgets-definition
* was edited.
*/
- public function purgeDefinitionCache() {
+ private function purgeDefinitionCache() {
$cache =
MediaWikiServices::getInstance()->getMainWANObjectCache();
$cache->touchCheckKey( $this->getCheckKey() );
}
diff --git a/includes/content/GadgetDefinitionContent.php
b/includes/content/GadgetDefinitionContent.php
index 741b261..b5aa7cf 100644
--- a/includes/content/GadgetDefinitionContent.php
+++ b/includes/content/GadgetDefinitionContent.php
@@ -102,7 +102,7 @@
public function getDeletionUpdates( WikiPage $page, ParserOutput
$parserOutput = null ) {
return array_merge(
parent::getDeletionUpdates( $page, $parserOutput ),
- [ new GadgetDefinitionDeletionUpdate(
$page->getTitle()->getText() ) ]
+ [ new GadgetDefinitionDeletionUpdate( $page->getTitle()
) ]
);
}
@@ -118,7 +118,7 @@
) {
return array_merge(
parent::getSecondaryDataUpdates( $title, $old,
$recursive, $parserOutput ),
- [ new GadgetDefinitionSecondaryDataUpdate(
$title->getText() ) ]
+ [ new GadgetDefinitionSecondaryDataUpdate( $title ) ]
);
}
}
diff --git a/includes/content/GadgetDefinitionDeletionUpdate.php
b/includes/content/GadgetDefinitionDeletionUpdate.php
index 970f8cb..97c8d8e 100644
--- a/includes/content/GadgetDefinitionDeletionUpdate.php
+++ b/includes/content/GadgetDefinitionDeletionUpdate.php
@@ -20,26 +20,24 @@
* @file
*/
+use MediaWiki\Linker\LinkTarget;
+
/**
* DataUpdate to run whenever a page in the Gadget definition
* is deleted.
*/
class GadgetDefinitionDeletionUpdate extends DataUpdate {
/**
- * Gadget id
- * @var string
+ * Page that was deleted
+ * @var LinkTarget
*/
- private $id;
+ private $target;
- public function __construct( $id ) {
- $this->id = $id;
+ public function __construct( LinkTarget $target ) {
+ $this->target = $target;
}
public function doUpdate() {
- $repo = GadgetRepo::singleton();
- if ( $repo instanceof GadgetDefinitionNamespaceRepo ) {
- $repo->purgeGadgetIdsList();
- $repo->purgeGadgetEntry( $this->id );
- }
+ GadgetRepo::singleton()->handlePageDeletion( $this->target );
}
}
diff --git a/includes/content/GadgetDefinitionSecondaryDataUpdate.php
b/includes/content/GadgetDefinitionSecondaryDataUpdate.php
index 10af53e..8a66393 100644
--- a/includes/content/GadgetDefinitionSecondaryDataUpdate.php
+++ b/includes/content/GadgetDefinitionSecondaryDataUpdate.php
@@ -1,4 +1,5 @@
<?php
+
/**
* Copyright 2014
*
@@ -20,18 +21,20 @@
* @file
*/
+use MediaWiki\Linker\LinkTarget;
+
class GadgetDefinitionSecondaryDataUpdate extends DataUpdate {
- private $id;
+ /**
+ * @var LinkTarget
+ */
+ private $target;
- public function __construct( $id ) {
- $this->id = $id;
+ public function __construct( LinkTarget $target ) {
+ $this->target = $target;
}
public function doUpdate() {
- $repo = GadgetRepo::singleton();
- if ( $repo instanceof GadgetDefinitionNamespaceRepo ) {
- $repo->purgeGadgetEntry( $this->id );
- }
+ GadgetRepo::singleton()->handlePageUpdate( $this->target );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/389792
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe2e26d12369a897c53757adf621926f62af7f7b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gadgets
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits