mediawiki-extensions-Echo/includes/formatters/EchoModelFormatter.php
James D. Forrester 1b2c8eebfc build: Upgrade phan-taint-check-plugin from 1.5.x to 2.0.1
Bonus: unset loop variable after mutable foreach.

Change-Id: I652fe65e4691a92175569a72f081f4553c4459c5
2019-07-11 13:40:37 +00:00

35 lines
955 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
* @suppress SecurityCheck-DoubleEscaped
*/
protected function formatModel( EchoEventPresentationModel $model ) {
$data = $model->jsonSerialize();
$data['iconUrl'] = EchoIcon::getUrl( $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 ) {
// @phan-suppress-next-line PhanTypeMismatchDimAssignment
$link['url'] = wfExpandUrl( $link['url'] );
}
unset( $link );
$bundledIds = $model->getBundledIds();
if ( $bundledIds ) {
$data[ 'bundledIds' ] = $bundledIds;
}
return $data;
}
}