MediaWiki master
LanguageEventIngress.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Languages;
4
11use MessageCache;
12
20 extends DomainEventIngress
22{
23
24 private MessageCache $messageCache;
25
27 public const OBJECT_SPEC = [
28 'class' => self::class,
29 'services' => [
30 'MessageCache'
31 ],
32 'events' => [
33 PageRevisionUpdatedEvent::TYPE,
35 ],
36 ];
37
38 public function __construct( MessageCache $messageCache ) {
39 $this->messageCache = $messageCache;
40 }
41
48 if ( $event->getPage()->getNamespace() === NS_MEDIAWIKI &&
49 ( $event->isModifiedSlot( SlotRecord::MAIN )
50 || $event->hasCause( PageRevisionUpdatedEvent::CAUSE_MOVE )
51 || $event->isReconciliationRequest()
52 )
53 ) {
54 $content = $event->getLatestRevisionAfter()->getMainContentRaw();
55 $this->messageCache->updateMessageOverride( $event->getPage(), $content );
56 }
57 }
58
64 public function handlePageDeletedEvent( PageDeletedEvent $event ) {
65 if ( $event->getDeletedPage()->getNamespace() === NS_MEDIAWIKI ) {
66 $this->messageCache->updateMessageOverride( $event->getDeletedPage(), null );
67 }
68 }
69
70}
const NS_MEDIAWIKI
Definition Defines.php:73
Base class for event ingress objects.
isReconciliationRequest()
Determines whether this is a reconciliation event, triggered artificially in order to give listeners ...
The ingress adapter for the language component.
const OBJECT_SPEC
Object spec intended for use with DomainEventSource::registerSubscriber().
handlePageRevisionUpdatedEvent(PageRevisionUpdatedEvent $event)
Listener method for PageRevisionUpdatedEvent, to be registered with a DomainEventSource.
handlePageDeletedEvent(PageDeletedEvent $event)
Listener method for PageDeletedEvent, to be registered with a DomainEventSource.
Domain event representing page deletion.
getDeletedPage()
Returns the page that was deleted, as it was before the deletion.
Domain event representing a page update.
getLatestRevisionAfter()
The revision that became the latest as a result of the update.
isModifiedSlot(string $slotRole)
Whether the given slot was modified by the page update.
hasCause(string $cause)
Checks whether the update had the given cause.
Value object representing a content slot associated with a page revision.
Cache messages that are defined by MediaWiki-namespace pages or by hooks.
Listener interface for PageDeletedEvents.
Listener interface for PageRevisionUpdatedEvents.