Florianschmidtwelzow has uploaded a new change for review. https://gerrit.wikimedia.org/r/234314
Change subject: Be more restrictive when selecting the tag for the first heading ...................................................................... Be more restrictive when selecting the tag for the first heading The selection of the so called "first heading" is a very important, considering, that it controls, which (or which not) section heading is the top of all headings and the text "under it" will be collapsible. Therefore, make the selection of the first heading more restrictive and allow only h-tags, that doesn't have a class, style or id attribute. Headings generated from mediawiki-core generally doesn't have any of these attributes and can safely be considered as a possible "first" heading. This removes an experimental configuration variable without any replacement. This was mentioned in the explanation of the config var. Bug: T110436 Change-Id: I31efaad6378c45b84a40800750cb74c6c278db9d --- M includes/MobileFormatter.php M includes/config/Experimental.php 2 files changed, 5 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/14/234314/1 diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php index b9d94c1..c224bc2 100644 --- a/includes/MobileFormatter.php +++ b/includes/MobileFormatter.php @@ -19,9 +19,6 @@ /** @var string $headingTransformEnd String prefixes to be applied before and after section content. */ protected $headingTransformEnd = '<div>'; - /** @var array $topHeadingTags Array of strings with possible tags, - can be recognized as top headings. */ - public $topHeadingTags = array(); /** * Saves a Title Object @@ -72,7 +69,6 @@ $html = self::wrapHTML( $html ); $formatter = new MobileFormatter( $html, $title ); $formatter->enableExpandableSections( !$isMainPage && !$isSpecialPage ); - $formatter->topHeadingTags = $config->get( 'MFTopHeadingPossibleTags' ); $formatter->setIsMainPage( $isMainPage ); if ( $context->getContentTransformations() && !$isFilePage ) { @@ -292,17 +288,11 @@ * @return string the tag name for the top level headings */ protected function findTopHeading( $html ) { - $tags = $this->topHeadingTags; - if ( !is_array( $tags ) ) { - throw new UnexpectedValueException( 'Possible top headings needs to be an array of strings, ' . - gettype( $tags ) . ' given.' ); - } - foreach ( $tags as $tag ) { - if ( strpos( $html, '<' . $tag ) !== false ) { - return $tag; - } - } - return 'h6'; + // FIXME: first heading should never be in $html? + $headingRegEx = '/<(h[1-6])(?! (class|style|id="(?!firstHeading).*"))/si'; + preg_match( $headingRegEx, $html, $matches ); + + return isset( $matches[1] ) ? $matches[1] : 'h6'; } /** diff --git a/includes/config/Experimental.php b/includes/config/Experimental.php index d172c4f..1f0358a 100644 --- a/includes/config/Experimental.php +++ b/includes/config/Experimental.php @@ -40,10 +40,3 @@ * FIXME: This config is highly experimental and temporary only. Use it on your own risk! */ $wgMFNoLoginOverride = false; - -/** - * This is a list of html tags, that could be recognized as the first heading of a page. - * This is an interim solution to fix Bug T110436 and shouldn't be used, if you don't know, - * what you do. Moreover, this configuration variable will be removed in the near future (hopefully). - */ -$wgMFTopHeadingPossibleTags = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ); \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/234314 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I31efaad6378c45b84a40800750cb74c6c278db9d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits