Ppchelko has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/343767 )
Change subject: Emit mediawiki.page-restrictions-change event.
......................................................................
Emit mediawiki.page-restrictions-change event.
Bug: T160942
Change-Id: I907a702378bbe34171b079c41cffcacf7c7aa8cf
Depends-On: I8798a78b6dacd7544763ee926980b3473d6cce3f
---
M EventBus.hooks.php
M extension.json
2 files changed, 53 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventBus
refs/changes/67/343767/1
diff --git a/EventBus.hooks.php b/EventBus.hooks.php
index 1da90e3..44eaf84 100644
--- a/EventBus.hooks.php
+++ b/EventBus.hooks.php
@@ -27,7 +27,7 @@
* Creates and sends a single resource_change event to EventBus
*
* @param Title $title article title object
- * @param Array $tags the array of tags to use in the event
+ * @param array $tags the array of tags to use in the event
*/
private static function sendResourceChangedEvent( $title, $tags ) {
$event = EventBus::createEvent(
@@ -610,4 +610,52 @@
}
);
}
+
+ /**
+ * Sends a page-restrictions-change event
+ *
+ * @param WikiPage $article the article which restrictions were changed
+ * @param User $user the user who have changed the article
+ * @param array $protect the new protection details
+ * @param string $reason the reason for page protection
+ */
+ public static function onArticleProtectComplete( $article, $user,
$protect, $reason ) {
+ global $wgDBname;
+ $events = [];
+
+ // Create a mediawiki page restrictions change event.
+ $attrs = [
+ // Common Mediawiki entity fields
+ 'database' => $wgDBname,
+ 'performer' => EventBus::createPerformerAttrs(
$user ),
+
+ // page entity fields
+ 'page_id' => $article->getId(),
+ 'page_title' =>
$article->getTitle()->getPrefixedDBkey(),
+ 'page_namespace' =>
$article->getTitle()->getNamespace(),
+ 'page_is_redirect' => $article->isRedirect(),
+
+ // page restrictions change specific fields:
+ 'reason' => $reason,
+ 'page_restrictions' => array_map( function ( $value ) {
+ return strlen( $value ) ? $value : 'none';
+ }, $protect )
+ ];
+
+ if ( $article->getRevision() ) {
+ $attrs['rev_id'] = $article->getRevision()->getId();
+ }
+
+ $events[] = EventBus::createEvent(
+ EventBus::getArticleURL( $article->getTitle() ),
+ 'mediawiki.page-restrictions-change',
+ $attrs
+ );
+
+ DeferredUpdates::addCallableUpdate(
+ function() use ( $events ) {
+ EventBus::getInstance()->send( $events );
+ }
+ );
+ }
}
diff --git a/extension.json b/extension.json
index 4ece993..b865a38 100644
--- a/extension.json
+++ b/extension.json
@@ -1,7 +1,7 @@
{
"name": "EventBus",
- "version": "0.2.12",
+ "version": "0.2.13",
"author": [
"Eric Evans",
"Petr Pchelko",
@@ -54,6 +54,9 @@
],
"LinksUpdateComplete": [
"EventBusHooks::onLinksUpdateComplete"
+ ],
+ "ArticleProtectComplete": [
+ "EventBusHooks::onArticleProtectComplete"
]
},
"manifest_version": 1
--
To view, visit https://gerrit.wikimedia.org/r/343767
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I907a702378bbe34171b079c41cffcacf7c7aa8cf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventBus
Gerrit-Branch: master
Gerrit-Owner: Ppchelko <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits