Dbrant has uploaded a new change for review.
https://gerrit.wikimedia.org/r/197945
Change subject: [WIP] Remove parenthetical information from lead sentences.
......................................................................
[WIP] Remove parenthetical information from lead sentences.
Change-Id: I1252ee46410daf0d110c0dea9dc249de87ede848
---
M wikipedia/assets/bundle.js
M wikipedia/assets/preview.js
M wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
M www/js/sections.js
M www/js/transforms.js
5 files changed, 97 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/45/197945/1
diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js
index 8b85e48..0c69f28 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,44 @@
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; i++ ) {
+ ch = string.charAt( i );
+ if ( ch === ')' && level === 0 ) {
+ // abort if we have an imbalance of parentheses
+ break;
+ }
+ if ( ch === '(' ) {
+ level++;
+ continue;
+ } else if ( ch === ')' ) {
+ level--;
+ continue;
+ }
+ if ( level === 0 ) {
+ 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 +692,13 @@
// Move the P!
block_0.insertBefore(p.parentNode.removeChild(p), block_0.firstChild);
+
+ console.log(">>>>>>> " + window.siteLanguage);
+ if ( window.isBeta && window.siteLanguage.indexOf( "en" ) > -1 ) {
+ // As long as we have the P, transform it!
+ p.innerHTML = removeParensFromText(p.innerHTML);
+ }
+
// But only move one P!
break;
}
@@ -1280,4 +1327,4 @@
try { module.exports = parseCSSColor } catch(e) { }
-},{}]},{},[6,15,7,8,11,12,2,1,4,5,3,10,9,13,14])
+},{}]},{},[6,15,7,8,11,12,2,1,4,5,3,10,9,13,14])
\ No newline at end of file
diff --git a/wikipedia/assets/preview.js b/wikipedia/assets/preview.js
index c26d9eb..c466d77 100644
--- a/wikipedia/assets/preview.js
+++ b/wikipedia/assets/preview.js
@@ -594,4 +594,4 @@
try { module.exports = parseCSSColor } catch(e) { }
-},{}]},{},[3,2,4,1,5,6,7,8])
+},{}]},{},[3,2,4,1,5,6,7,8])
\ No newline at end of file
diff --git
a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
index 9361d36..53d56fd 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 01379ba..e6a2896 100644
--- a/www/js/transforms.js
+++ b/www/js/transforms.js
@@ -2,6 +2,44 @@
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; i++ ) {
+ ch = string.charAt( i );
+ if ( ch === ')' && level === 0 ) {
+ // abort if we have an imbalance of parentheses
+ break;
+ }
+ if ( ch === '(' ) {
+ level++;
+ continue;
+ } else if ( ch === ')' ) {
+ level--;
+ continue;
+ }
+ if ( level === 0 ) {
+ 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 +80,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: newchange
Gerrit-Change-Id: I1252ee46410daf0d110c0dea9dc249de87ede848
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits