Bmansurov has uploaded a new change for review.

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

Change subject: WIP: Show the lead section first paragraph before infoboxes
......................................................................

WIP: Show the lead section first paragraph before infoboxes

Proof of concept using MobileFormatter.

DO NOT MERGE.

Bug: T143803
Change-Id: Ic57b02b1db6f7d0c37a5526fe69c1c2e3f269fc6
---
M extension.json
M includes/MobileFormatter.php
2 files changed, 34 insertions(+), 9 deletions(-)


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

diff --git a/extension.json b/extension.json
index ba9b3ea..6e96863 100644
--- a/extension.json
+++ b/extension.json
@@ -1998,6 +1998,10 @@
                        "beta": [],
                        "base": []
                },
+               "MFShowFirstParagraphBeforeInfobox": {
+                       "base": false,
+                       "beta": true
+               },
                "MFLazyLoadImages": {
                        "base": false,
                        "beta": true
diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php
index 67d0cc9..6313012 100644
--- a/includes/MobileFormatter.php
+++ b/includes/MobileFormatter.php
@@ -128,8 +128,11 @@
                $isSpecialPage = $this->title->isSpecialPage();
                $mfRemovableClasses = $config->get( 'MFRemovableClasses' );
                $removableClasses = $mfRemovableClasses['base'];
+               $mfShowFirstSectionBeforeInfobox = $config->get( 
'MFShowFirstParagraphBeforeInfobox' );
+               $showFirstSectionBeforeInfobox = 
$mfShowFirstSectionBeforeInfobox[ 'base' ];
                if ( $ctx->isBetaGroupMember() ) {
                        $removableClasses = array_merge( $removableClasses, 
$mfRemovableClasses['beta'] );
+                       $showFirstSectionBeforeInfobox = 
$mfShowFirstSectionBeforeInfobox[ 'beta' ];
                }
 
                // Don't remove elements in special pages
@@ -141,7 +144,11 @@
                        $this->doRemoveImages();
                }
 
-               $transformOptions = [ 'images' => $removeImages, 'references' 
=> $removeReferences ];
+               $transformOptions = [
+                       'images' => $removeImages,
+                       'references' => $removeReferences,
+                       'showFirstSectionBeforeInfobox' => 
$showFirstSectionBeforeInfobox 
+               ];
                // Sectionify the content and transform it if necessary per 
section
                if ( !$this->mainPage && $this->expandableSections ) {
                        list( $headings, $subheadings ) = $this->getHeadings( 
$doc );
@@ -174,6 +181,15 @@
                if ( $options['references'] ) {
                        $this->doRewriteReferencesListsForLazyLoading( $el, 
$doc );
                }
+       }
+
+       /*
+        * Move the first paragraph from the section above the first infobox
+        * 
+        * @param DOMElement $sectionBody
+        */
+       private function showFirstSectionBeforeInfobox( $sectionBody ) {
+               
        }
 
        /**
@@ -456,14 +472,19 @@
                                // Insert the previous section body and reset 
it for the new section
                                $body->insertBefore( $sectionBody, $node );
 
-                               if ( $sectionNumber === 0 && 
$this->isTOCEnabled ) {
-                                       // Insert table of content placeholder 
which will be progressively enhanced via JS
-                                       $toc = $doc->createElement( 'div' );
-                                       $toc->setAttribute( 'id', 'toc' );
-                                       $toc->setAttribute( 'class', 
'toc-mobile' );
-                                       $tocHeading = $doc->createElement( 
'h2', wfMessage( 'toc' )->text() );
-                                       $toc->appendChild( $tocHeading );
-                                       $sectionBody->appendChild( $toc );
+                               if ( $sectionNumber === 0 ) {
+                                       if ( $this->isTOCEnabled ) {
+                                               // Insert table of content 
placeholder which will be progressively enhanced via JS
+                                               $toc = 
$doc->createElement('div');
+                                               $toc->setAttribute('id', 'toc');
+                                               $toc->setAttribute('class', 
'toc-mobile');
+                                               $tocHeading = 
$doc->createElement('h2', wfMessage('toc')->text());
+                                               $toc->appendChild($tocHeading);
+                                               $sectionBody->appendChild($toc);
+                                       }
+                                       if ( $transformOptions[ 
'showFirstSectionBeforeInfobox' ] ) {
+                                               
$this->showFirstSectionBeforeInfobox( $sectionBody );
+                                       }
                                }
                                $sectionNumber += 1;
                                $sectionBody = $doc->createElement( 'div' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic57b02b1db6f7d0c37a5526fe69c1c2e3f269fc6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org>

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

Reply via email to