Don't try to parse section titles as wikitext in subscription notifs

Bug: T299572
Depends-On: Idb3a87fd18330f90a8cdc1276994d54288e17b28
Change-Id: I3b58f337bb2ea1f5255fc0a41dbd7a5ad8c433db
This commit is contained in:
Bartosz Dziewoński 2022-01-21 00:08:01 +01:00
parent d2405cc11c
commit 5919e4e371
2 changed files with 53 additions and 3 deletions

View file

@ -0,0 +1,51 @@
<?php
/**
* Our override of the built-in Echo helper for displaying section titles.
*
* @file
* @ingroup Extensions
* @license MIT
*/
namespace MediaWiki\Extension\DiscussionTools\Notifications;
use EchoDiscussionParser;
use EchoPresentationModelSection;
use MWException;
/**
* Built-in Echo events store section titles as wikitext, and when displaying or linking to them,
* they parse it and then strip the formatting to get the plaintext versions.
*
* Our subscription notifications store section titles as plaintext already, so this processing is
* unnecessary and incorrect (text that looks like markup can disappear).
*/
class PlaintextEchoPresentationModelSection extends EchoPresentationModelSection {
/**
* @inheritDoc
*/
protected function getParsedSectionTitle() {
$plaintext = $this->getRawSectionTitle();
if ( !$plaintext ) {
return false;
}
$plaintext = trim( $plaintext );
return $this->language->truncateForVisual( $plaintext, EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH );
}
/**
* @inheritDoc
*/
public function getTitleWithSection() {
$title = $this->event->getTitle();
if ( $title === null ) {
throw new MWException( 'Event #' . $this->event->getId() . ' with no title' );
}
$section = $this->getParsedSectionTitle();
if ( $section ) {
$title = $title->createFragmentTarget( $section );
}
return $title;
}
}

View file

@ -11,7 +11,6 @@ namespace MediaWiki\Extension\DiscussionTools\Notifications;
use EchoEvent;
use EchoEventPresentationModel;
use EchoPresentationModelSection;
use Language;
use MediaWiki\MediaWikiServices;
use Message;
@ -23,7 +22,7 @@ class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel {
use DiscussionToolsEventTrait;
/**
* @var EchoPresentationModelSection
* @var PlaintextEchoPresentationModelSection
*/
protected $section;
@ -32,7 +31,7 @@ class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel {
*/
protected function __construct( EchoEvent $event, Language $language, User $user, $distributionType ) {
parent::__construct( $event, $language, $user, $distributionType );
$this->section = new EchoPresentationModelSection( $event, $user, $language );
$this->section = new PlaintextEchoPresentationModelSection( $event, $user, $language );
}
/**