From 5d92dccafc6de6aa139e489bbd14c69aa6fb467f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 6 Sep 2023 01:24:21 +0200 Subject: [PATCH] TopicSubscriptionsPager: Handle invalid titles This approach is borrowed from PageQueryPage in MediaWiki core, and used in a few other places as well. Bug: T345648 Change-Id: I7fbc3c3c1133da78eb9f15de9b2a51a90bcd1980 --- includes/TopicSubscriptionsPager.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/includes/TopicSubscriptionsPager.php b/includes/TopicSubscriptionsPager.php index 66d6d2ed4..3ca767b70 100644 --- a/includes/TopicSubscriptionsPager.php +++ b/includes/TopicSubscriptionsPager.php @@ -5,6 +5,8 @@ namespace MediaWiki\Extension\DiscussionTools; use IContextSource; use InvalidArgumentException; use MediaWiki\Cache\LinkBatchFactory; +use MediaWiki\Html\Html; +use MediaWiki\Linker\Linker; use MediaWiki\Linker\LinkRenderer; use MediaWiki\Title\Title; use OOUI; @@ -79,11 +81,22 @@ class TopicSubscriptionsPager extends TablePager { ''; } else { $titleSection = Title::makeTitleSafe( $row->sub_namespace, $row->sub_title, $row->sub_section ); + if ( !$titleSection ) { + // Handle invalid titles (T345648) + return htmlspecialchars( $row->sub_section ); + } return $linkRenderer->makeLink( $titleSection, $row->sub_section ); } case '_page': $title = Title::makeTitleSafe( $row->sub_namespace, $row->sub_title ); + if ( !$title ) { + // Handle invalid titles (T345648) + return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ], + Linker::getInvalidTitleDescription( + $this->getContext(), $row->sub_namespace, $row->sub_title ) + ); + } return $linkRenderer->makeLink( $title, $title->getPrefixedText() ); case 'sub_created': @@ -96,6 +109,12 @@ class TopicSubscriptionsPager extends TablePager { case '_unsubscribe': $title = Title::makeTitleSafe( $row->sub_namespace, $row->sub_title ); + if ( !$title ) { + // Handle invalid titles (T345648) + // The title isn't checked when unsubscribing, as long as it's a valid title, + // so specify something to make it possible to unsubscribe from the buggy entries. + $title = Title::newMainPage(); + } return (string)new OOUI\ButtonWidget( [ 'label' => $this->msg( 'discussiontools-topicsubscription-pager-unsubscribe-button' )->text(), 'classes' => [ 'ext-discussiontools-special-unsubscribe-button' ],