mediawiki-extensions-Echo/includes/formatters/EchoModelFormatter.php
Stephane Bisson a73d63d1a4 Echo API returns absolute URLs in notification links
Some notifications return relative urls in their
primary or secondary links. This change makes those
urls absolute so they point to the right wiki
when viewed from another wiki (cross-wiki notifications).

Bug: T125738
Bug: T127697
Change-Id: Ib65337430eb2484f9491668a9998deef70589fb1
2016-02-23 17:54:26 +00:00

27 lines
746 B
PHP

<?php
/**
* A formatter for the notification flyout popup. Just the bare data needed to
* render everything client-side.
*/
class EchoModelFormatter extends EchoEventFormatter {
/**
* @param EchoEventPresentationModel $model
* @return array
*/
protected function formatModel( EchoEventPresentationModel $model ) {
$data = $model->jsonSerialize();
$data['iconUrl'] = EchoNotificationFormatter::getIconUrl( $model->getIconType(), $this->language->getDir() );
if ( isset( $data['links']['primary']['url'] ) ) {
$data['links']['primary']['url'] = wfExpandUrl( $data['links']['primary']['url'] );
}
foreach ( $data['links']['secondary'] as &$link ) {
$link['url'] = wfExpandUrl( $link['url'] );
}
return $data;
}
}