From 8eaaecf9570da777c2e7a2f7362951420462f3f1 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Wed, 27 Apr 2022 15:58:16 -0400 Subject: [PATCH] feat: do not format body content if MobileFrontend is active (#409) MobileFrontend formats body content to enable features such as collasible headers. Citizen should not attempt to format it as it will break features in MF. --- includes/Partials/BodyContent.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/Partials/BodyContent.php b/includes/Partials/BodyContent.php index 19908c0c..4fbb0e1a 100644 --- a/includes/Partials/BodyContent.php +++ b/includes/Partials/BodyContent.php @@ -30,7 +30,9 @@ use DOMElement; use DOMXpath; use Html; use HtmlFormatter\HtmlFormatter; +use MediaWiki\MediaWikiServices; use OutputPage; +use Wikimedia\Services\NoSuchServiceException; final class BodyContent extends Partial { @@ -51,12 +53,20 @@ final class BodyContent extends Partial { private $topHeadingTags = [ "h1", "h2", "h3", "h4", "h5", "h6 " ]; /** - * Helper function to decide if the page should be collapsible + * Helper function to decide if the page should be formatted * * @param Title $title * @return string */ - private function isCollapsiblePage( $title ) { + private function shouldFormatPage( $title ) { + try { + $mfCxt = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' ); + // Check if page is in mobile view and let MF do the formatting + return !$mfCxt->shouldDisplayMobileView(); + } catch ( NoSuchServiceException $ex ) { + // MobileFrontend not installed. Don't do anything + } + return $this->getConfigValue( 'CitizenEnableCollapsibleSections' ) === true && !$title->isMainPage() && $title->isContentPage(); @@ -79,7 +89,7 @@ final class BodyContent extends Partial { } // Make section and sanitize the output - if ( $this->isCollapsiblePage( $title ) ) { + if ( $this->shouldFormatPage( $title ) ) { $formatter = new HtmlFormatter( $htmlBodyContent ); $doc = $formatter->getDoc(); // Make top level sections