Clean up subscribe links/buttons

* Don't generate `<!--__DTSUBSCRIBELINK__...-->` placeholder comments
  (follow-up to Idb23b0f5e438d35ed74569ff50302c7fad5ba688)
* Remove unused method parameter
* Remove unnecessary pass-by-reference (only $tocInfo needs it)

Change-Id: Ie3348671c486de5bbd9f286772a8d145e3609bd5
This commit is contained in:
Bartosz Dziewoński 2024-03-08 20:44:54 +01:00
parent f22dabfb80
commit dacef1a97a

View file

@ -151,7 +151,7 @@ class CommentFormatter {
);
self::addSubscribeLink(
$headingItem, $doc, $headingElement, $wrapperNode, $latestReplyItem, $bar
$headingItem, $doc, $wrapperNode, $latestReplyItem, $bar
);
if ( $latestReplyItem ) {
@ -171,11 +171,11 @@ class CommentFormatter {
* of comments, and number of editors in the discussion.
*/
protected static function addTopicContainer(
Element &$wrapperNode,
Element $wrapperNode,
?ContentCommentItem $latestReplyItem,
Document &$doc,
ContentHeadingItem &$headingItem,
?Element &$bar,
Document $doc,
ContentHeadingItem $headingItem,
?Element $bar,
array &$tocInfo
) {
if ( !DOMCompat::getClassList( $wrapperNode )->contains( 'mw-heading' ) ) {
@ -223,10 +223,9 @@ class CommentFormatter {
protected static function addSubscribeLink(
ContentHeadingItem $headingItem,
Document $doc,
Element $headingElement,
Element &$wrapperNode,
Element $wrapperNode,
?ContentCommentItem $latestReplyItem,
?Element &$bar
?Element $bar
) {
$headingJSONEscaped = htmlspecialchars(
json_encode( static::getJsonForHeadingMarker( $headingItem ) )
@ -234,9 +233,6 @@ class CommentFormatter {
// Replaced in ::postprocessTopicSubscription() as the text depends on user state
if ( $headingItem->isSubscribable() ) {
$subscribeLink = $doc->createComment( '__DTSUBSCRIBELINK__' . $headingJSONEscaped );
$headingElement->insertBefore( $subscribeLink, $headingElement->firstChild );
$subscribeButton = $doc->createComment( '__DTSUBSCRIBEBUTTONDESKTOP__' . $headingJSONEscaped );
$wrapperNode->insertBefore( $subscribeButton, $wrapperNode->firstChild );
}
@ -459,6 +455,7 @@ class CommentFormatter {
] );
$text = preg_replace( '/<!--__DTELLIPSISBUTTON__(.*?)-->/', '', $text );
// No longer used, this can be removed once parser cache expires:
$text = preg_replace( '/<!--__DTSUBSCRIBELINK__(.*?)-->/', '', $text );
$text = preg_replace( '/<!--__DTSUBSCRIBEBUTTON(DESKTOP|MOBILE)__(.*?)-->/', '', $text );
@ -474,6 +471,7 @@ class CommentFormatter {
): string {
$doc = DOMCompat::newDocument( true );
// No longer used, this can be removed once parser cache expires:
$text = preg_replace( '/<!--__DTSUBSCRIBELINK__(.*?)-->/', '', $text );
$matches = [];