jenkins-bot has submitted this change and it was merged. ( 
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, 51 insertions(+), 2 deletions(-)

Approvals:
  Mobrovac: Looks good to me, approved
  Ottomata: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/EventBus.hooks.php b/EventBus.hooks.php
index 1da90e3..83086fe 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,50 @@
                        }
                );
        }
+
+       /**
+        * 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 set of new restrictions 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'  => $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: merged
Gerrit-Change-Id: I907a702378bbe34171b079c41cffcacf7c7aa8cf
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/EventBus
Gerrit-Branch: master
Gerrit-Owner: Ppchelko <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Ottomata <[email protected]>
Gerrit-Reviewer: Ppchelko <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to