jenkins-bot has submitted this change and it was merged.

Change subject: Remove parenthetical information from lead sentences.
......................................................................


Remove parenthetical information from lead sentences.

Currently restricted to non-production builds, and to enwiki only.

Bug: T91792
Change-Id: I1252ee46410daf0d110c0dea9dc249de87ede848
---
M wikipedia/assets/bundle.js
M wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
M www/js/sections.js
M www/js/transforms.js
4 files changed, 104 insertions(+), 1 deletion(-)

Approvals:
  BearND: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js
index 518d05a..3f1add0 100644
--- a/wikipedia/assets/bundle.js
+++ b/wikipedia/assets/bundle.js
@@ -432,6 +432,8 @@
     window.string_expand_refs = payload.string_expand_refs;
     window.pageTitle = payload.title;
     window.isMainPage = payload.isMainPage;
+    window.isBeta = payload.isBeta;
+    window.siteLanguage = payload.siteLanguage;
 
     // append the content to the DOM now, so that we can obtain
     // dimension measurements for items.
@@ -612,6 +614,48 @@
 var night = require("./night");
 var bridge = require( "./bridge" );
 
+// Takes a block of text, and removes any text within parentheses, but only
+// until the end of the first sentence.
+// Based on Extensions:Popups - ext.popups.renderer.article.js
+function removeParensFromText( string ) {
+    var ch;
+    var newString = '';
+    var level = 0;
+    var i = 0;
+    for( ; i < string.length - 1; i++ ) {
+        ch = string.charAt( i );
+        if ( ch === ')' && level === 0  ) {
+            // abort if we have an imbalance of parentheses
+            return string;
+        }
+        if ( ch === '(' ) {
+            level++;
+            continue;
+        } else if ( ch === ')' ) {
+            level--;
+            continue;
+        }
+        if ( level === 0 ) {
+            // Remove leading spaces before parentheses
+            if ( ch === ' ' && string.charAt( i + 1 ) === '(' ) {
+                continue;
+            }
+            newString += ch;
+            if ( ch === '.' ) {
+                // stop at the end of the first sentence
+                break;
+            }
+        }
+    }
+    // fill in the rest of the string
+    if ( i + 1 < string.length ) {
+        newString += string.substring( i + 1, string.length );
+    }
+    // if we had an imbalance of parentheses, then return the original string,
+    // instead of the transformed one.
+    return ( level === 0 ) ? newString : string;
+}
+
 // Move the first non-empty paragraph of text to the top of the section.
 // This will have the effect of shifting the infobox and/or any images at the 
top of the page
 // below the first paragraph, allowing the user to start reading the page 
right away.
@@ -652,6 +696,13 @@
 
         // Move the P!
         block_0.insertBefore(p.parentNode.removeChild(p), block_0.firstChild);
+
+        // Transform the first sentence of the first paragraph.
+        // (but only for non-production, and only on enwiki)
+        if ( window.isBeta && window.siteLanguage.indexOf( "en" ) > -1 ) {
+            p.innerHTML = removeParensFromText(p.innerHTML);
+        }
+
         // But only move one P!
         break;
     }
@@ -1280,4 +1331,4 @@
 
 try { module.exports = parseCSSColor } catch(e) { }
 
-},{}]},{},[6,15,7,8,11,12,2,1,4,5,3,10,9,13,14])
\ No newline at end of file
+},{}]},{},[6,15,7,8,11,12,2,1,4,5,3,10,9,13,14])
diff --git 
a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java 
b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
index fa80a63..98f4372 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
@@ -209,6 +209,7 @@
             leadSectionPayload.put("string_table_close", 
getString(R.string.table_close));
             leadSectionPayload.put("string_expand_refs", 
getString(R.string.expand_refs));
             leadSectionPayload.put("isBeta", app.getReleaseType() != 
WikipediaApp.RELEASE_PROD);
+            leadSectionPayload.put("siteLanguage", 
title.getSite().getLanguage());
             leadSectionPayload.put("isMainPage", 
page.getPageProperties().isMainPage());
             leadSectionPayload.put("apiLevel", Build.VERSION.SDK_INT);
             bridge.sendMessage("displayLeadSection", leadSectionPayload);
diff --git a/www/js/sections.js b/www/js/sections.js
index abb9f92..520caf4 100644
--- a/www/js/sections.js
+++ b/www/js/sections.js
@@ -52,6 +52,8 @@
     window.string_expand_refs = payload.string_expand_refs;
     window.pageTitle = payload.title;
     window.isMainPage = payload.isMainPage;
+    window.isBeta = payload.isBeta;
+    window.siteLanguage = payload.siteLanguage;
 
     // append the content to the DOM now, so that we can obtain
     // dimension measurements for items.
diff --git a/www/js/transforms.js b/www/js/transforms.js
index 50b069f..3d71126 100644
--- a/www/js/transforms.js
+++ b/www/js/transforms.js
@@ -2,6 +2,48 @@
 var night = require("./night");
 var bridge = require( "./bridge" );
 
+// Takes a block of text, and removes any text within parentheses, but only
+// until the end of the first sentence.
+// Based on Extensions:Popups - ext.popups.renderer.article.js
+function removeParensFromText( string ) {
+    var ch;
+    var newString = '';
+    var level = 0;
+    var i = 0;
+    for( ; i < string.length - 1; i++ ) {
+        ch = string.charAt( i );
+        if ( ch === ')' && level === 0  ) {
+            // abort if we have an imbalance of parentheses
+            return string;
+        }
+        if ( ch === '(' ) {
+            level++;
+            continue;
+        } else if ( ch === ')' ) {
+            level--;
+            continue;
+        }
+        if ( level === 0 ) {
+            // Remove leading spaces before parentheses
+            if ( ch === ' ' && string.charAt( i + 1 ) === '(' ) {
+                continue;
+            }
+            newString += ch;
+            if ( ch === '.' ) {
+                // stop at the end of the first sentence
+                break;
+            }
+        }
+    }
+    // fill in the rest of the string
+    if ( i + 1 < string.length ) {
+        newString += string.substring( i + 1, string.length );
+    }
+    // if we had an imbalance of parentheses, then return the original string,
+    // instead of the transformed one.
+    return ( level === 0 ) ? newString : string;
+}
+
 // Move the first non-empty paragraph of text to the top of the section.
 // This will have the effect of shifting the infobox and/or any images at the 
top of the page
 // below the first paragraph, allowing the user to start reading the page 
right away.
@@ -42,6 +84,13 @@
 
         // Move the P!
         block_0.insertBefore(p.parentNode.removeChild(p), block_0.firstChild);
+
+        // Transform the first sentence of the first paragraph.
+        // (but only for non-production, and only on enwiki)
+        if ( window.isBeta && window.siteLanguage.indexOf( "en" ) > -1 ) {
+            p.innerHTML = removeParensFromText(p.innerHTML);
+        }
+
         // But only move one P!
         break;
     }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1252ee46410daf0d110c0dea9dc249de87ede848
Gerrit-PatchSet: 5
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Deskana <dga...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to