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.
This commit is contained in:
alistair3149 2022-04-27 15:58:16 -04:00
parent 7e068dd4b1
commit 8eaaecf957
No known key found for this signature in database
GPG key ID: 94D081060FD3DD9C

View file

@ -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