Marcoil has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/186015

Change subject: WIP T73161: Support subst: of transclusion blocks
......................................................................

WIP T73161: Support subst: of transclusion blocks

Add new parameter 'subst' to wt2html API. If enabled…

Change-Id: If10cbbd62da5c8df5c5a83188b6fd8fd7ca28fb8
---
M api/routes.js
M lib/ext.core.TemplateHandler.js
M lib/mediawiki.ApiRequest.js
M lib/mediawiki.parser.js
4 files changed, 28 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/15/186015/1

diff --git a/api/routes.js b/api/routes.js
index cd6d61f..789ba1e 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -363,7 +363,11 @@
                        env.page.name = '';
                }
                return new Promise(function( resolve, reject ) {
-                       var parser = 
env.pipelineFactory.getPipeline('text/x-mediawiki/full');
+                       var parser, options = {};
+                       if (res.local('subst')) {
+                               options.substTemplates = true;
+                       }
+                       parser = 
env.pipelineFactory.getPipeline('text/x-mediawiki/full', options);
                        parser.once('document', function( doc ) {
                                // Don't cache requests when wt is set in case 
somebody uses
                                // GET for wikitext parsing
@@ -669,6 +673,8 @@
 routes.post_article = function( req, res ) {
        var body = req.body;
        if ( req.body.wt ) {
+               // Save if client wants only substitution
+               res.local('subst', req.body.subst);
                // Form-based article parsing
                wt2html( req, res, body.wt );
        } else {
diff --git a/lib/ext.core.TemplateHandler.js b/lib/ext.core.TemplateHandler.js
index fa1d8ba..50fd81c 100644
--- a/lib/ext.core.TemplateHandler.js
+++ b/lib/ext.core.TemplateHandler.js
@@ -18,6 +18,7 @@
        TemplateRequest = require('./mediawiki.ApiRequest.js').TemplateRequest,
        api = require('./mediawiki.ApiRequest.js'),
        PreprocessorRequest = api.PreprocessorRequest,
+       PHPParseRequest = api.PHPParseRequest,
        Util = require('./mediawiki.Util.js').Util,
        DU = require('./mediawiki.DOMUtils.js').DOMUtils,
        async = require('async');
@@ -152,7 +153,8 @@
                                        accumReceiveToksFromChild);
                                // Fetch and process the template expansion
                                this.fetchExpandedTpl( env.page.name || '',
-                                               text, PreprocessorRequest,
+                                               text,
+                                               this.options.substTemplates,
                                                accumReceiveToksFromSibling, 
srcHandler);
                        }
                } else {
@@ -1125,9 +1127,8 @@
 
 /**
  * Fetch the preprocessed wikitext for a template-like construct.
- * (The 'Processor' argument is a constructor, hence the capitalization.)
  */
-TemplateHandler.prototype.fetchExpandedTpl = function ( title, text, 
Processor, parentCB, cb ) {
+TemplateHandler.prototype.fetchExpandedTpl = function ( title, text, subst, 
parentCB, cb ) {
        var env = this.manager.env;
        if ( text in env.pageCache ) {
                // XXX: store type too (and cache tokens/x-mediawiki)
@@ -1143,7 +1144,14 @@
                //env.dp( 'requestQueue: ', env.requestQueue );
                if ( env.requestQueue[text] === undefined ) {
                        env.tp( 'Note: Starting new request for ' + text );
-                       env.requestQueue[text] = new Processor( env, title, 
text );
+                       if (subst) {
+                               // If we're in subst mode, use action=parse as 
it allows subst
+                               // processing
+                               env.requestQueue[text] = new 
PHPParseRequest(env, title, text, true);
+                       } else {
+                               // If not, use normal action=expandtemplates
+                               env.requestQueue[text] = new 
PreprocessorRequest(env, title, text);
+                       }
                }
                // append request, process in document order
                env.requestQueue[text].once( 'src', cb );
diff --git a/lib/mediawiki.ApiRequest.js b/lib/mediawiki.ApiRequest.js
index d977513..83e3c16 100644
--- a/lib/mediawiki.ApiRequest.js
+++ b/lib/mediawiki.ApiRequest.js
@@ -461,7 +461,7 @@
  * @param {string} title The title of the page to use as context
  * @param {string} text
  */
-function PHPParseRequest ( env, name, text ) {
+function PHPParseRequest ( env, name, text, onlypst ) {
        ApiRequest.call(this, env, name);
 
        this.text = text;
@@ -476,6 +476,9 @@
                contentmodel: 'wikitext',
                prop: 'text|modules|categories'
        };
+       if (onlypst) {
+               apiargs.onlypst = 'true';
+       }
        var uri = env.conf.wiki.apiURI;
 
        // Pass the page title to the API
diff --git a/lib/mediawiki.parser.js b/lib/mediawiki.parser.js
index cbb449a..7781a78 100644
--- a/lib/mediawiki.parser.js
+++ b/lib/mediawiki.parser.js
@@ -195,6 +195,11 @@
                options.wrapTemplates = true;
        }
 
+       // default: no subst, expand templates fully
+       if (options.substTemplates === undefined) {
+               options.substTemplates = false;
+       }
+
        if (options.cacheKey === undefined) {
                options.cacheKey = null;
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If10cbbd62da5c8df5c5a83188b6fd8fd7ca28fb8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <marc...@wikimedia.org>

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

Reply via email to