Bartosz Dziewoński has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/359074 )

Change subject: Use Parsoid data for template names rather than detect from 
wikitext
......................................................................

Use Parsoid data for template names rather than detect from wikitext

We were incorrectly handling transclusions with trailing
newlines after the template name.

This also improves handling of non-template transclusions,
e.g. parser functions like `{{int:mainpage}}`, which are
no longer mangled as if they were page names.

ve.dm.MWTransclusionNode#isSingleTemplate will now match
a template even if it's name is itself template-generated.

Logic for turning Parsoid's hrefs into page names stolen
from ve.dm.MWImageNode.prototype.getFilename.

Bug: T167613
Change-Id: Ibecf71338eb37bb3da81a7372e4ed41140a9af57
---
M modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js
M modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
2 files changed, 21 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/74/359074/1

diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js 
b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js
index bf2c9b8..5a37a5f 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js
@@ -50,17 +50,22 @@
  * Get a list of descriptions of template parts in a transclusion node
  *
  * @static
- * @param {ve.dm.Node} model Node model
+ * @param {ve.dm.MWTransclusionNode} model Node model
  * @return {string[]} List of template part descriptions
  */
 ve.ce.MWTransclusionNode.static.getTemplatePartDescriptions = function ( model 
) {
-       var i, len, part,
+       var i, len, part, title,
                parts = model.getPartsList(),
                words = [];
 
        for ( i = 0, len = parts.length; i < len; i++ ) {
                part = parts[ i ];
-               if ( part.template ) {
+               // Ignore parts that are just content
+               if ( part.templatePage ) {
+                       title = mw.Title.newFromText( part.templatePage );
+                       words.push( title.getRelativeText( mw.config.get( 
'wgNamespaceIds' ).template ) );
+               } else if ( part.template ) {
+                       // Not actually a template, but e.g. a parser function
                        words.push( part.template );
                }
        }
@@ -73,14 +78,6 @@
  */
 ve.ce.MWTransclusionNode.static.getDescription = function ( model ) {
        return this.getTemplatePartDescriptions( model )
-               .map( function ( template ) {
-                       var title = mw.Title.newFromText( template, 
mw.config.get( 'wgNamespaceIds' ).template );
-                       if ( title ) {
-                               return title.getRelativeText( mw.config.get( 
'wgNamespaceIds' ).template );
-                       } else {
-                               return template;
-                       }
-               } )
                .join( ve.msg( 'comma-separator' ) );
 };
 
diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js 
b/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
index d45c284..7119f8b 100644
--- a/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
+++ b/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
@@ -357,8 +357,8 @@
        }
        for ( i = 0, len = templates.length; i < len; i++ ) {
                if (
-                       partsList[ 0 ].template &&
-                       normalizeTitle( partsList[ 0 ].template ) === 
normalizeTitle( templates[ i ] )
+                       partsList[ 0 ].templatePage &&
+                       partsList[ 0 ].templatePage === normalizeTitle( 
templates[ i ] )
                ) {
                        return true;
                }
@@ -372,18 +372,23 @@
  * @return {Object[]} List of objects with either template or content 
properties
  */
 ve.dm.MWTransclusionNode.prototype.getPartsList = function () {
-       var i, len, part, content;
+       var i, len, href, page, part, content;
 
        if ( !this.partsList ) {
                this.partsList = [];
                content = this.getAttribute( 'mw' );
                for ( i = 0, len = content.parts.length; i < len; i++ ) {
                        part = content.parts[ i ];
-                       this.partsList.push(
-                               part.template ?
-                                       { template: part.template.target.wt } :
-                                       { content: part }
-                       );
+                       if ( part.template ) {
+                               href = part.template.target.href;
+                               page = href ? 
ve.decodeURIComponentIntoArticleTitle( href.replace( /^(\.+\/)*/, '' ) ): null;
+                               this.partsList.push( {
+                                       template: part.template.target.wt,
+                                       templatePage: page
+                               } );
+                       } else {
+                               this.partsList.push( { content: part } );
+                       }
                }
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibecf71338eb37bb3da81a7372e4ed41140a9af57
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

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

Reply via email to