Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/234331

Change subject: Make the list of possible top headings configurable
......................................................................

Make the list of possible top headings configurable

This is a very temporary implementation of a configurable list of
possible html tags, that could be recognized as a so called top
heading.

Bug: T110436
Change-Id: Ifdeb51f47cc4e41692a95d38e4b0a64c1da6a472
---
M includes/MobileFormatter.php
M includes/config/Experimental.php
2 files changed, 18 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/31/234331/1

diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php
index dff8d0e..3a9f0d8 100644
--- a/includes/MobileFormatter.php
+++ b/includes/MobileFormatter.php
@@ -19,6 +19,9 @@
        /** @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
@@ -47,6 +50,8 @@
                parent::__construct( $html );
 
                $this->title = $title;
+               $this->topHeadingTags = MobileContext::singleton()
+                       ->getMFConfig()->get( 'MFMobileFormatterHeadings' );
        }
 
        /**
@@ -287,7 +292,11 @@
         * @return string the tag name for the top level headings
         */
        protected function findTopHeading( $html ) {
-               $tags = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' );
+               $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;
diff --git a/includes/config/Experimental.php b/includes/config/Experimental.php
index 1f0358a..a340132 100644
--- a/includes/config/Experimental.php
+++ b/includes/config/Experimental.php
@@ -40,3 +40,11 @@
  * 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).
+ */
+$wgMFMobileFormatterHeadings = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' );

-- 
To view, visit https://gerrit.wikimedia.org/r/234331
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifdeb51f47cc4e41692a95d38e4b0a64c1da6a472
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: wmf/1.26wmf20
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to