Dbrant has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/389566 )

Change subject: Update wikimedia-page-library to 4.7.3.
......................................................................

Update wikimedia-page-library to 4.7.3.

This includes a nice optimization when collapsing tables.

Change-Id: Iee5903231bac995a7ebcae8770b4d87ec97cd197
---
M app/src/main/assets/bundle.js
M app/src/main/assets/preview.js
M www/package-lock.json
M www/package.json
4 files changed, 28 insertions(+), 74 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/66/389566/1

diff --git a/app/src/main/assets/bundle.js b/app/src/main/assets/bundle.js
index 9b1c1c7..e051ede 100644
--- a/app/src/main/assets/bundle.js
+++ b/app/src/main/assets/bundle.js
@@ -1273,45 +1273,21 @@
  */
 var getTableHeader = function getTableHeader(element, pageTitle) {
   var thArray = [];
-
-  if (!element.children) {
-    return thArray;
-  }
-
-  for (var i = 0; i < element.children.length; i++) {
-    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');
-      // todo: these conditionals are very confusing. Rewrite by extracting a
-      //       method or simplify.
-      if (aNodes.length < 3) {
-        // todo: remove nonstandard Element.innerText usage
-        // Also ignore it if it's identical to the page title.
-        if ((el.innerText && el.innerText.length || el.textContent.length) > 0 
&& el.innerText !== pageTitle && el.textContent !== pageTitle && el.innerHTML 
!== pageTitle) {
-          thArray.push(el.innerText || el.textContent);
-        }
+  var headers = Polyfill.querySelectorAll(element, 'th');
+  for (var i = 0; i < headers.length; ++i) {
+    var header = headers[i];
+    var anchors = Polyfill.querySelectorAll(header, 'a');
+    if (anchors.length < 3) {
+      // Also ignore it if it's identical to the page title.
+      if ((header.textContent && header.textContent.length) > 0 && 
header.textContent !== pageTitle && header.innerHTML !== pageTitle) {
+        thArray.push(header.textContent);
       }
     }
-
-    // if it's a table within a table, don't worry about it
-    if (el.tagName === 'TABLE') {
-      continue;
-    }
-
-    // todo: why do we need to recurse?
-    // recurse into children of this element
-    var ret = getTableHeader(el, pageTitle);
-
-    // did we get a list of TH from this child?
-    if (ret.length > 0) {
-      thArray = thArray.concat(ret);
+    if (thArray.length === 2) {
+      // 'newCaption' only ever uses the first 2 items.
+      break;
     }
   }
-
   return thArray;
 };
 
@@ -2009,7 +1985,8 @@
   lastEdited: 2,
   pageIssues: 3,
   disambiguation: 4,
-  coordinate: 5
+  coordinate: 5,
+  talkPage: 6
 };
 
 /**
diff --git a/app/src/main/assets/preview.js b/app/src/main/assets/preview.js
index c890a04..73a1a24 100644
--- a/app/src/main/assets/preview.js
+++ b/app/src/main/assets/preview.js
@@ -456,45 +456,21 @@
  */
 var getTableHeader = function getTableHeader(element, pageTitle) {
   var thArray = [];
-
-  if (!element.children) {
-    return thArray;
-  }
-
-  for (var i = 0; i < element.children.length; i++) {
-    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');
-      // todo: these conditionals are very confusing. Rewrite by extracting a
-      //       method or simplify.
-      if (aNodes.length < 3) {
-        // todo: remove nonstandard Element.innerText usage
-        // Also ignore it if it's identical to the page title.
-        if ((el.innerText && el.innerText.length || el.textContent.length) > 0 
&& el.innerText !== pageTitle && el.textContent !== pageTitle && el.innerHTML 
!== pageTitle) {
-          thArray.push(el.innerText || el.textContent);
-        }
+  var headers = Polyfill.querySelectorAll(element, 'th');
+  for (var i = 0; i < headers.length; ++i) {
+    var header = headers[i];
+    var anchors = Polyfill.querySelectorAll(header, 'a');
+    if (anchors.length < 3) {
+      // Also ignore it if it's identical to the page title.
+      if ((header.textContent && header.textContent.length) > 0 && 
header.textContent !== pageTitle && header.innerHTML !== pageTitle) {
+        thArray.push(header.textContent);
       }
     }
-
-    // if it's a table within a table, don't worry about it
-    if (el.tagName === 'TABLE') {
-      continue;
-    }
-
-    // todo: why do we need to recurse?
-    // recurse into children of this element
-    var ret = getTableHeader(el, pageTitle);
-
-    // did we get a list of TH from this child?
-    if (ret.length > 0) {
-      thArray = thArray.concat(ret);
+    if (thArray.length === 2) {
+      // 'newCaption' only ever uses the first 2 items.
+      break;
     }
   }
-
   return thArray;
 };
 
@@ -1192,7 +1168,8 @@
   lastEdited: 2,
   pageIssues: 3,
   disambiguation: 4,
-  coordinate: 5
+  coordinate: 5,
+  talkPage: 6
 };
 
 /**
diff --git a/www/package-lock.json b/www/package-lock.json
index 93aea1b..1d9ef78 100644
--- a/www/package-lock.json
+++ b/www/package-lock.json
@@ -3079,7 +3079,7 @@
       "dev": true
     },
     "wikimedia-page-library": {
-      "version": "4.7.1",
+      "version": "4.7.3",
       "resolved": 
"https://registry.npmjs.org/wikimedia-page-library/-/wikimedia-page-library-4.7.1.tgz";,
       "integrity": "sha1-KdcgUbKg3LRGtqXdW8KeKJyvFQo="
     },
diff --git a/www/package.json b/www/package.json
index 2454a23..18a0a9a 100644
--- a/www/package.json
+++ b/www/package.json
@@ -4,7 +4,7 @@
     "test": "grunt test"
   },
   "dependencies": {
-    "wikimedia-page-library": "^4.7.1"
+    "wikimedia-page-library": "^4.7.3"
   },
   "devDependencies": {
     "browserify": "^14.4.0",

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iee5903231bac995a7ebcae8770b4d87ec97cd197
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

Reply via email to