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

Change subject: Improve collapsed infobox formatting.
......................................................................


Improve collapsed infobox formatting.

- Pull headers from the original table, but don't show them if they
  contain more than *two* links.
- Don't show table header if it's identical to the page title.

Change-Id: I3f8e863e3e11e4537a4cefa05ce7ab8d3eb36e75
---
M wikipedia/assets/bundle.js
M www/js/sections.js
M www/js/transforms.js
3 files changed, 30 insertions(+), 12 deletions(-)

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



diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js
index 9d92a55..35af7d2 100644
--- a/wikipedia/assets/bundle.js
+++ b/wikipedia/assets/bundle.js
@@ -473,6 +473,7 @@
     window.string_table_infobox = payload.string_table_infobox;
     window.string_table_other = payload.string_table_other;
     window.string_table_close = payload.string_table_close;
+    window.pageTitle = payload.title;
 
     content = transformer.transform( "leadSection", content );
     content = transformer.transform( "section", content );
@@ -706,17 +707,25 @@
         return thArray;
     }
     for (var i = 0; i < element.children.length; i++) {
-        if (element.children[i].tagName === "TH") {
-            if (element.children[i].innerText.length > 0) {
-                thArray.push(element.children[i].innerText);
+        var el = element.children[i];
+        if (el.tagName === "TH") {
+            // ok, we have a TH element!
+            // However, if it contains more than two links, then ignore it, 
because
+            // it will probably appear weird when rendered as plain text.
+            var aNodes = el.querySelectorAll( "a" );
+            if (aNodes.length < 3) {
+                // Also ignore it if it's identical to the page title.
+                if (el.innerText.length > 0 && el.innerText !== 
window.pageTitle && el.innerHTML !== window.pageTitle) {
+                    thArray.push(el.innerText);
+                }
             }
         }
         //if it's a table within a table, don't worry about it
-        if (element.children[i].tagName === "TABLE") {
+        if (el.tagName === "TABLE") {
             continue;
         }
         //recurse into children of this element
-        var ret = getTableHeader(element.children[i]);
+        var ret = getTableHeader(el);
         //did we get a list of TH from this child?
         if (ret.length > 0) {
             thArray = thArray.concat(ret);
@@ -773,7 +782,7 @@
         if (headerText.length > 1) {
             caption += ", " + headerText[1];
         }
-        if (headerText.length > 2) {
+        if (headerText.length > 0) {
             caption += ", ...";
         }
         caption += "</span>";
diff --git a/www/js/sections.js b/www/js/sections.js
index f9b2d2d..5092e60 100644
--- a/www/js/sections.js
+++ b/www/js/sections.js
@@ -44,6 +44,7 @@
     window.string_table_infobox = payload.string_table_infobox;
     window.string_table_other = payload.string_table_other;
     window.string_table_close = payload.string_table_close;
+    window.pageTitle = payload.title;
 
     content = transformer.transform( "leadSection", content );
     content = transformer.transform( "section", content );
diff --git a/www/js/transforms.js b/www/js/transforms.js
index 31e8d5f..5acce6c 100644
--- a/www/js/transforms.js
+++ b/www/js/transforms.js
@@ -64,17 +64,25 @@
         return thArray;
     }
     for (var i = 0; i < element.children.length; i++) {
-        if (element.children[i].tagName === "TH") {
-            if (element.children[i].innerText.length > 0) {
-                thArray.push(element.children[i].innerText);
+        var el = element.children[i];
+        if (el.tagName === "TH") {
+            // ok, we have a TH element!
+            // However, if it contains more than two links, then ignore it, 
because
+            // it will probably appear weird when rendered as plain text.
+            var aNodes = el.querySelectorAll( "a" );
+            if (aNodes.length < 3) {
+                // Also ignore it if it's identical to the page title.
+                if (el.innerText.length > 0 && el.innerText !== 
window.pageTitle && el.innerHTML !== window.pageTitle) {
+                    thArray.push(el.innerText);
+                }
             }
         }
         //if it's a table within a table, don't worry about it
-        if (element.children[i].tagName === "TABLE") {
+        if (el.tagName === "TABLE") {
             continue;
         }
         //recurse into children of this element
-        var ret = getTableHeader(element.children[i]);
+        var ret = getTableHeader(el);
         //did we get a list of TH from this child?
         if (ret.length > 0) {
             thArray = thArray.concat(ret);
@@ -131,7 +139,7 @@
         if (headerText.length > 1) {
             caption += ", " + headerText[1];
         }
-        if (headerText.length > 2) {
+        if (headerText.length > 0) {
             caption += ", ...";
         }
         caption += "</span>";

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3f8e863e3e11e4537a4cefa05ce7ab8d3eb36e75
Gerrit-PatchSet: 4
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to