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

Change subject: Templates: Fixes for inline template adaptation
......................................................................


Templates: Fixes for inline template adaptation

* When the template is missing template data and is a redirect
  like Template:Citation needed in gu.wikipedia, the template
  mapping will not have 'title' key causing the entire template
  not mapped. This commit fixes it
* When the target template does not accept any params, while source
  template has params, consider the template adaptation successful
  This also happens in the case of gu.wikipedia citation needed template.
  In English, this template accepts date parameter, while gu.wikipedia
  does not accept any params.
* The <link> tags were unconditionally removed before publishing. But
  this was done when we used to load the whole HTML tree of source article.
  Now we work with the body section of source and translation. Removing
  <link> tags caused template data missing. See Bug T95391 for example

Testplan:
Test and article with citation needed template from en to gu or eo and
see if the template get adapted properly and publishing creates the
template as expected.

Bug:  T95391
Change-Id: Ia2047991a89e4c75262e46c62d6926ee45f1fd87
---
M modules/publish/ext.cx.publish.js
M modules/tools/ext.cx.tools.template.js
2 files changed, 15 insertions(+), 7 deletions(-)

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



diff --git a/modules/publish/ext.cx.publish.js 
b/modules/publish/ext.cx.publish.js
index 174d1a9..201290d 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -331,8 +331,8 @@
         * @return {string} processed html
         */
        CXPublish.prototype.prepareTranslationForPublish = function ( $content 
) {
-               // Remove unnecessary elements
-               $content.find( 'link, title, .placeholder' ).remove();
+               // Remove all placeholders
+               $content.find( '.placeholder' ).remove();
 
                $content.find( mw.cx.getSectionSelector() ).each( function () {
                        var attributesToRemove, classesToRemove, $section = $( 
this );
diff --git a/modules/tools/ext.cx.tools.template.js 
b/modules/tools/ext.cx.tools.template.js
index dc27153..784cc63 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -134,16 +134,18 @@
                        // This prevents warnings about the unrecognized 
parameter "_"
                        cache: true
                } ).then( function ( resp ) {
-                       var pageContent = '';
+                       var title, pageContent = '';
 
                        if (
                                resp.query.pages[ resp.query.pageids[ 0 ] 
].revisions &&
                                resp.query.pages[ resp.query.pageids[ 0 ] 
].revisions[ 0 ]
                        ) {
                                pageContent = resp.query.pages[ 
resp.query.pageids[ 0 ] ].revisions[ 0 ][ '*' ];
+                               title = resp.query.pages[ resp.query.pageids[ 0 
] ].title;
                        }
 
                        return {
+                               title: title,
                                params: self.extractParametersFromTemplateCode( 
pageContent )
                        };
                } );
@@ -238,16 +240,22 @@
                // Update the name of the template
                return this.getTemplateNamespaceTranslation( 
this.targetLanguage )
                        .then( function ( translatedNamespace ) {
-                               var templateName, targetParams, targetName;
+                               var templateName, sourceParams, targetParams, 
targetName;
 
                                targetName = 
self.templateMapping.cxMapping.targetname || self.templateMapping.title;
                                if ( !targetName ) {
                                        return false;
                                }
+                               sourceParams = self.getSourceParams();
+                               targetParams = self.getAdaptedTargetParams( 
sourceParams );
 
-                               targetParams = self.getAdaptedTargetParams( 
self.getSourceParams() );
-                               if ( $.isEmptyObject( targetParams ) ) {
-                                       return false;
+                               if ( !$.isEmptyObject( sourceParams ) && 
$.isEmptyObject( targetParams ) ) {
+                                       if ( self.templateMapping.params && 
Object( self.templateMapping.params ).length > 0 ) {
+                                               // Checking whether there is 
any params defined for target template.
+                                               // It is possible that source 
template definition has params and target
+                                               // does not have any. Mapping 
failed only when target has some params.
+                                               return false;
+                                       }
                                }
 
                                // So we were able to map at least one 
parameter to the target template.

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia2047991a89e4c75262e46c62d6926ee45f1fd87
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to