mediawiki-extensions-Echo/includes/formatters/EchoPlainTextEmailFormatter.php
Universal Omega 7b2bed7cce EchoPlainTextEmailFormatter: correctly handle getPrimaryLink() returning false
It is declared to be able to, but is not checked here expecting an array, resulting in `PHP Notice: Trying to access array offset on value of type bool` if false.

Change-Id: I8b3ebdd3b5e6fea9c84816b890198194951ea5c0
2022-07-09 16:34:37 +00:00

56 lines
1.5 KiB
PHP

<?php
class EchoPlainTextEmailFormatter extends EchoEventFormatter {
protected function formatModel( EchoEventPresentationModel $model ) {
$subject = Sanitizer::stripAllTags( $model->getSubjectMessage()->parse() );
$text = Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() );
$text .= "\n\n";
$bodyMsg = $model->getBodyMessage();
if ( $bodyMsg ) {
$text .= Sanitizer::stripAllTags( $bodyMsg->parse() );
}
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
$colon = $this->msg( 'colon-separator' )->text();
if ( $primaryLink ) {
$primaryUrl = wfExpandUrl( $primaryLink['url'], PROTO_CANONICAL );
$text .= "\n\n{$primaryLink['label']}$colon <$primaryUrl>";
}
foreach ( array_filter( $model->getSecondaryLinks() ) as $secondaryLink ) {
$url = wfExpandUrl( $secondaryLink['url'], PROTO_CANONICAL );
$text .= "\n\n{$secondaryLink['label']}$colon <$url>";
}
// Footer
$text .= "\n\n{$this->getFooter()}";
return [
'body' => $text,
'subject' => $subject,
];
}
/**
* @return string
*/
public function getFooter() {
global $wgEchoEmailFooterAddress;
$footerMsg = $this->msg( 'echo-email-plain-footer', $this->user )->text();
$prefsUrl = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )
->getFullURL( '', false, PROTO_CANONICAL );
$text = "--\n\n$footerMsg\n$prefsUrl";
if ( $wgEchoEmailFooterAddress !== '' ) {
$text .= "\n\n$wgEchoEmailFooterAddress";
}
return $text;
}
}