Mobrovac has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/314431

Change subject: Send a resource_change event on page_image property change
......................................................................

Send a resource_change event on page_image property change

The modification of images on a page affect the render of a page's
summary, so when the page_image property has been modified send a
resource_change event to EventBus with the 'page_image' tag.

Bug: T145569
Change-Id: Ibe39f13c49e8d420d5c5a3a459f21a8d2c9766aa
---
M EventBus.hooks.php
M extension.json
2 files changed, 45 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventBus 
refs/changes/31/314431/1

diff --git a/EventBus.hooks.php b/EventBus.hooks.php
index e40a791..f1979cc 100644
--- a/EventBus.hooks.php
+++ b/EventBus.hooks.php
@@ -97,7 +97,7 @@
         * Creates a full user page path
         *
         * @param string $userName userName
-        * @returns string
+        * @return string
         */
        private static function getUserPageURL( $userName ) {
                global $wgCanonicalServer, $wgArticlePath, $wgContLang;
@@ -105,6 +105,24 @@
                $encodedUserURL = rawurlencode( strtr( $prefixedUserURL, ' ', 
'_' ) );
                // The $wgArticlePath contains '$1' string where the article 
title should appear.
                return $wgCanonicalServer . str_replace( '$1', $encodedUserURL, 
$wgArticlePath );
+       }
+
+       /**
+        * 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
+        */
+       private static function sendResourceChangedEvent( $title, $tags ) {
+               $event = self::createEvent(
+                       self::getArticleURL( $title ),
+                       'resource_change',
+                       [ 'tags' => $tags ]
+               );
+
+               DeferredUpdates::addCallableUpdate( function() use ( $event ) {
+                       EventBus::getInstance()->send( [ $event ] );
+               } );
        }
 
        /**
@@ -488,13 +506,7 @@
         * @param WikiPage $wikiPage
         */
        public static function onArticlePurge( $wikiPage ) {
-               $event = self::createEvent( self::getArticleURL( 
$wikiPage->getTitle() ), 'resource_change', [
-                       'tags' => [ 'purge' ]
-               ] );
-
-               DeferredUpdates::addCallableUpdate( function() use ( $event ) {
-                       EventBus::getInstance()->send( [ $event ] );
-               } );
+               self::sendResourceChangedEvent( $wikiPage->getTitle(), [ 
'purge' ] );
        }
 
        /**
@@ -522,14 +534,7 @@
        ) {
                // In case of a null edit the status revision value will be null
                if ( is_null( $status->getValue()['revision'] ) ) {
-
-                       $event = self::createEvent( self::getArticleURL( 
$article->getTitle() ), 'resource_change', [
-                               'tags' => [ 'null_edit' ]
-                       ] );
-
-                       DeferredUpdates::addCallableUpdate( function() use ( 
$event ) {
-                               EventBus::getInstance()->send( [ $event ] );
-                       } );
+                       self::sendResourceChangedEvent( $article->getTitle(), [ 
'null_edit' ] );
                }
        }
 
@@ -617,4 +622,24 @@
                        }
                );
        }
+
+       /**
+        * Sends a resource_change event when the page_image property of a page 
is updated
+        *
+        * @param LinksUpdate $linksUpdate the update object
+        */
+       public static function onPageImagesUpdate( $linksUpdate ) {
+               // gather the list of added and removed properties
+               $added = $linksUpdate->getAddedProperties();
+               $removed = $linksUpdate->getRemovedProperties();
+               // TODO: make it so as to use PageImages::PROP_NAME in the 
future
+               $prop = 'page_image';
+               // when a page image has been added, removed or changed either 
or both
+               // of the above arrays will contain the 'page_image' key
+               if ( isset( $added[$prop] ) || isset( $removed[$prop] ) ) {
+                       // send the resource_change event
+                       self::sendResourceChangedEvent( 
$linksUpdate->getTitle(), [ $prop ] );
+               }
+       }
+
 }
diff --git a/extension.json b/extension.json
index 62fecee..5581644 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
 {
        "name": "EventBus",
-       "version": "0.2.10",
+       "version": "0.2.11",
        "author": [
                "Eric Evans",
                "Petr Pchelko",
@@ -48,6 +48,9 @@
                ],
                "BlockIpComplete": [
                        "EventBusHooks::onBlockIpComplete"
+               ],
+               "LinksUpdateComplete": [
+                       "EventBusHooks::onPageImagesUpdate"
                ]
        },
        "manifest_version": 1

-- 
To view, visit https://gerrit.wikimedia.org/r/314431
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe39f13c49e8d420d5c5a3a459f21a8d2c9766aa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventBus
Gerrit-Branch: master
Gerrit-Owner: Mobrovac <[email protected]>

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

Reply via email to