mediawiki-extensions-Echo/includes/Formatters/EchoForeignPresentationModel.php
thiemowmde 7e3d73c11b More specific type hints and type declarations
Most notably:
* Use the much more narrow UserIdentity interface where possible.
* Make array type hints in PHPDocs as specific as possible.

Change-Id: Id189da4028b7874909277881dcf6539169dd13b6
2024-05-16 10:32:19 +02:00

59 lines
1.5 KiB
PHP

<?php
namespace MediaWiki\Extension\Notifications\Formatters;
use MediaWiki\Extension\Notifications\ForeignNotifications;
class EchoForeignPresentationModel extends EchoEventPresentationModel {
public function getIconType() {
return 'global';
}
public function getPrimaryLink() {
return false;
}
protected function getHeaderMessageKey() {
$data = $this->event->getExtra();
$section = $data['section'] == 'message' ? 'notice' : $data['section'];
// notification-header-foreign-alert
// notification-header-foreign-notice
// notification-header-foreign-all
return "notification-header-foreign-{$section}";
}
public function getHeaderMessage() {
$msg = parent::getHeaderMessage();
$data = $this->event->getExtra();
$firstWiki = reset( $data['wikis'] );
$names = $this->getWikiNames( [ $firstWiki ] );
$msg->params( $names[0] );
$msg->numParams( count( $data['wikis'] ) - 1 );
$msg->numParams( count( $data['wikis'] ) );
return $msg;
}
public function getBodyMessage() {
$data = $this->event->getExtra();
$msg = $this->msg( 'notification-body-foreign' );
$msg->params( $this->language->listToText( $this->getWikiNames( $data['wikis'] ) ) );
return $msg;
}
/**
* @param string[] $wikis
* @return string[]
*/
protected function getWikiNames( array $wikis ): array {
$data = ForeignNotifications::getApiEndpoints( $wikis );
$names = [];
foreach ( $wikis as $wiki ) {
$names[] = $data[$wiki]['title'];
}
return $names;
}
}