Mholloway has uploaded a new change for review.

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

Change subject: Fix bug in lead paragraph shifting leading to incorrect section 
output
......................................................................

Fix bug in lead paragraph shifting leading to incorrect section output

In the content service, unlike when loading from the MediaWiki action API,
we apply JavaScript transformations to the page content as a whole before
splitting into sections, rather than section-by-section.

This led to a condition in some cases in which a section entry was missing
from the sections list, with the result that an incorrect section would
load when the user attempted to edit a section.  Content could also
be generally mangled in these cases (an infobox in an unexpected place,
for example).

Performing lead paragraph shifting separately on just the lead section, as
we do with MWAPI loading, fixes this problem.

Bug: T65874
Change-Id: I105ff58e0ad2640982225ab54c2c7a9bfd5dfcd7
---
M lib/parsoid-access.js
M lib/transformations/relocateFirstParagraph.js
M lib/transforms.js
M test/features/mobile-sections-lead/pagecontent.js
4 files changed, 15 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/02/275702/1

diff --git a/lib/parsoid-access.js b/lib/parsoid-access.js
index 0b6a8e1..83c8564 100644
--- a/lib/parsoid-access.js
+++ b/lib/parsoid-access.js
@@ -13,6 +13,7 @@
 var parseProperty = require('./parseProperty');
 var parseDefinition = require('./parseDefinition');
 var transforms = require('./transforms');
+var relocateFirstParagraph = 
require('./transformations/relocateFirstParagraph');
 var HTTPError = sUtil.HTTPError;
 var BBPromise = require('bluebird');
 
@@ -126,12 +127,16 @@
         section,
         output,
         i = 0,
-        node = doc.body.firstChild;
+        node = doc.body.firstChild,
+        firstParaDom;
 
     output = parseSection(node);
+    firstParaDom = domino.createDocument(output.text);
+    relocateFirstParagraph(firstParaDom);
+
     sections.push({
         "id": 0,
-        "text": output.text
+        "text": firstParaDom.outerHTML
     });
 
     while (output.nextNode) {
diff --git a/lib/transformations/relocateFirstParagraph.js 
b/lib/transformations/relocateFirstParagraph.js
index e2a2eb8..cf4b4fa 100644
--- a/lib/transformations/relocateFirstParagraph.js
+++ b/lib/transformations/relocateFirstParagraph.js
@@ -96,6 +96,4 @@
     block_0.insertBefore( leadSpan, block_0.firstChild );
 }
 
-module.exports = {
-    moveFirstGoodParagraphUp: moveFirstGoodParagraphUp
-};
+module.exports = moveFirstGoodParagraphUp;
diff --git a/lib/transforms.js b/lib/transforms.js
index 3db581d..6b9e286 100644
--- a/lib/transforms.js
+++ b/lib/transforms.js
@@ -228,7 +228,6 @@
     // any page except main pages. It's ok to do unconditionally since we 
throw away
     // the page content if this turns out to be a main page.
     // TODO: should we also exclude file and other special pages?
-    relocateFirstParagraph.moveFirstGoodParagraphUp(doc);
 }
 
 /**
diff --git a/test/features/mobile-sections-lead/pagecontent.js 
b/test/features/mobile-sections-lead/pagecontent.js
index b2a8d27..e114712 100644
--- a/test/features/mobile-sections-lead/pagecontent.js
+++ b/test/features/mobile-sections-lead/pagecontent.js
@@ -110,4 +110,11 @@
                 assert.deepEqual(lead.pronunciation.url, 
'//upload.wikimedia.org/wikipedia/commons/c/c2/Pronunciation_of_the_Odia_language_word_%22Odisha%22.ogg');
             });
     });
+    it('Lead paragraph shifting behaves as intended and does not occlude any 
content sections', function() {
+        return preq.get({ uri: server.config.uri + 
'en.wikipedia.org/v1/page/mobile-sections-lead/Barry_Marshall' })
+            .then(function (res) {
+                assert.deepEqual(res.status, 200);
+                assert.deepEqual(res.body.sections.length, 6);
+            })
+    })
 });

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I105ff58e0ad2640982225ab54c2c7a9bfd5dfcd7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to