jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/360396 )

Change subject: Move addRedlinks to DOMUtils so it can used in bin/parse.js
......................................................................


Move addRedlinks to DOMUtils so it can used in bin/parse.js

Change-Id: Ib04e9fedb92ea1dd71c6bac2fbe5c13d556a1469
---
M bin/parse.js
M lib/api/apiUtils.js
M lib/api/routes.js
M lib/utils/DOMUtils.js
4 files changed, 73 insertions(+), 68 deletions(-)

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



diff --git a/bin/parse.js b/bin/parse.js
index 0863b56..ba32008 100755
--- a/bin/parse.js
+++ b/bin/parse.js
@@ -208,6 +208,11 @@
        env.setPageSrcInfo(input);
        var handler = env.getContentHandler(argv.contentmodel);
        return handler.toHTML(env)
+       .tap(function(doc) {
+               if (env.conf.parsoid.useBatchAPI) {
+                       return DU.addRedLinks(env, doc);
+               }
+       })
        .then(function(doc) {
                if (argv.lint) {
                        env.log("end/parse");
diff --git a/lib/api/apiUtils.js b/lib/api/apiUtils.js
index 7f3b282..08cf704 100644
--- a/lib/api/apiUtils.js
+++ b/lib/api/apiUtils.js
@@ -14,7 +14,6 @@
 var PegTokenizer = require('../wt2html/tokenizer.js').PegTokenizer;
 var Promise = require('../utils/promise.js');
 var PHPParseRequest = require('../mw/ApiRequest.js').PHPParseRequest;
-var Batcher = require('../mw/Batcher.js').Batcher;
 
 
 /**
@@ -559,7 +558,7 @@
        var doc = DU.parseHTML(revision.html.body);
        var pb = apiUtils.extractPageBundle(revision);
        apiUtils.validatePageBundle(pb, env.originalVersion);
-       return apiUtils.addRedLinks(env, doc)
+       return DU.addRedLinks(env, doc)
        .then(function() {
                // No need to `DU.extractDpAndSerialize`, it wasn't applied.
                var html = DU.toXML(res.locals.bodyOnly ? doc.body : doc, {
@@ -620,68 +619,3 @@
                return def;
        }
 };
-
-var processPage = function(page) {
-       return {
-               missing: page.missing !== undefined,
-               known: page.known !== undefined,
-               redirect: page.redirect !== undefined,
-               disambiguation: page.pageprops &&
-                       page.pageprops.disambiguation !== undefined,
-       };
-};
-
-/**
- * Add red links to a document.
- *
- * @method
- * @param {MWParserEnvironment} env
- * @param {Document} doc
- */
-apiUtils.addRedLinks = Promise.method(function(env, doc) {
-       var wikiLinks = doc.body.querySelectorAll('a[rel~="mw:WikiLink"]');
-
-       var titleSet = wikiLinks.reduce(function(s, a) {
-               var title = a.getAttribute('title');
-               // Magic links, at least, don't have titles
-               if (title !== null) { s.add(title); }
-               return s;
-       }, new Set());
-
-       var titles = Array.from(titleSet.values());
-       if (titles.length === 0) { return; }
-
-       return Batcher.getPageProps(env, titles)
-       .then(function(result) {
-               var titleMap = new Map();
-               result.forEach(function(r) {
-                       Object.keys(r.batchResponse).forEach(function(t) {
-                               var o = r.batchResponse[t];
-                               titleMap.set(o.title, processPage(o));
-                       });
-               });
-               wikiLinks.forEach(function(a) {
-                       var k = a.getAttribute('title');
-                       if (k === null) { return; }
-                       var data = titleMap.get(k);
-                       if (data === undefined) {
-                               env.log('warn', 'We should have data for the 
title: ' + k);
-                               return;
-                       }
-                       a.removeAttribute('class');  // Clear all
-                       if (data.missing && !data.known) {
-                               a.classList.add('new');
-                       }
-                       if (data.redirect) {
-                               a.classList.add('mw-redirect');
-                       }
-                       // Jforrester suggests that, "ideally this'd be a 
registry so that
-                       // extensions could, er, extend this functionality – 
this is an
-                       // API response/CSS class that is provided by the 
Disambigutation
-                       // extension."
-                       if (data.disambiguation) {
-                               a.classList.add('mw-disambig');
-                       }
-               });
-       });
-});
diff --git a/lib/api/routes.js b/lib/api/routes.js
index ce1d255..11b5fd2 100644
--- a/lib/api/routes.js
+++ b/lib/api/routes.js
@@ -520,7 +520,7 @@
                        return p2
                        .tap(function(doc) {
                                if (env.conf.parsoid.useBatchAPI) {
-                                       return apiUtils.addRedLinks(env, doc);
+                                       return DU.addRedLinks(env, doc);
                                }
                        })
                        // .timeout(REQ_TIMEOUT)
diff --git a/lib/utils/DOMUtils.js b/lib/utils/DOMUtils.js
index 47bfa5d..da83ae5 100644
--- a/lib/utils/DOMUtils.js
+++ b/lib/utils/DOMUtils.js
@@ -15,6 +15,7 @@
 var JSUtils = require('./jsutils.js').JSUtils;
 var Consts = require('../config/WikitextConstants.js').WikitextConstants;
 var ApiRequest = require('../mw/ApiRequest.js');
+var Batcher = require('../mw/Batcher.js').Batcher;
 var pd = require('../wt2html/parser.defines.js');
 var XMLSerializer = require('../wt2html/XMLSerializer.js');
 
@@ -2758,6 +2759,71 @@
        }).nodify(cb);
 };
 
+var processPage = function(page) {
+       return {
+               missing: page.missing !== undefined,
+               known: page.known !== undefined,
+               redirect: page.redirect !== undefined,
+               disambiguation: page.pageprops &&
+                       page.pageprops.disambiguation !== undefined,
+       };
+};
+
+/**
+ * Add red links to a document.
+ *
+ * @method
+ * @param {MWParserEnvironment} env
+ * @param {Document} doc
+ */
+DOMUtils.addRedLinks = Promise.method(function(env, doc) {
+       var wikiLinks = doc.body.querySelectorAll('a[rel~="mw:WikiLink"]');
+
+       var titleSet = wikiLinks.reduce(function(s, a) {
+               var title = a.getAttribute('title');
+               // Magic links, at least, don't have titles
+               if (title !== null) { s.add(title); }
+               return s;
+       }, new Set());
+
+       var titles = Array.from(titleSet.values());
+       if (titles.length === 0) { return; }
+
+       return Batcher.getPageProps(env, titles)
+       .then(function(result) {
+               var titleMap = new Map();
+               result.forEach(function(r) {
+                       Object.keys(r.batchResponse).forEach(function(t) {
+                               var o = r.batchResponse[t];
+                               titleMap.set(o.title, processPage(o));
+                       });
+               });
+               wikiLinks.forEach(function(a) {
+                       var k = a.getAttribute('title');
+                       if (k === null) { return; }
+                       var data = titleMap.get(k);
+                       if (data === undefined) {
+                               env.log('warn', 'We should have data for the 
title: ' + k);
+                               return;
+                       }
+                       a.removeAttribute('class');  // Clear all
+                       if (data.missing && !data.known) {
+                               a.classList.add('new');
+                       }
+                       if (data.redirect) {
+                               a.classList.add('mw-redirect');
+                       }
+                       // Jforrester suggests that, "ideally this'd be a 
registry so that
+                       // extensions could, er, extend this functionality – 
this is an
+                       // API response/CSS class that is provided by the 
Disambigutation
+                       // extension."
+                       if (data.disambiguation) {
+                               a.classList.add('mw-disambig');
+                       }
+               });
+       });
+});
+
 if (typeof module === "object") {
        module.exports.DOMUtils = DOMUtils;
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib04e9fedb92ea1dd71c6bac2fbe5c13d556a1469
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to