Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/292911
Change subject: Templates: Use wikidata to find find template in target wiki ...................................................................... Templates: Use wikidata to find find template in target wiki The existing check was simple title search in target wiki. This was problematic and not helpful. Replace it with langlinks api which will resolve the titles using wikidata connection information. Testplan: Translate Giovan Battista Perasso from it to en. Inspect the reference "Gattera 2007, pagg..". The translation should be using 'Harward citation no brackets' Bug: T126957 Bug: T125579 Bug: T112739 Change-Id: I346d5653b7f6a4756f59e99881242d1cf2d17fb6 --- M modules/tools/ext.cx.tools.template.js 1 file changed, 33 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/11/292911/1 diff --git a/modules/tools/ext.cx.tools.template.js b/modules/tools/ext.cx.tools.template.js index 7df92c9..34238dd 100644 --- a/modules/tools/ext.cx.tools.template.js +++ b/modules/tools/ext.cx.tools.template.js @@ -200,14 +200,12 @@ this.templateTitle = this.templateData.parts[ 0 ].template.target.wt; this.getTargetTemplate() - .done( function ( targetTitleData ) { - var pageId = Object.keys( targetTitleData.pages )[ 0 ]; - + .done( function ( targetTitle ) { templateTool.markReadOnly(); if ( templateTool.templateMapping ) { templateTool.adapt(); } else { - templateTool.adaptTitle( targetTitleData.pages[ pageId ].title ); + templateTool.adaptTitle( targetTitle ); } deferred.resolve(); } ) @@ -235,12 +233,14 @@ } // TODO: Avoid direct access to globals - api = mw.cx.siteMapper.getApi( mw.cx.targetLanguage ); + api = mw.cx.siteMapper.getApi( mw.cx.sourceLanguage ); // Note that we use canonical namespace 'Template' for title. request = api.get( { action: 'query', titles: 'Template:' + this.templateTitle, + prop: 'langlinks', + lllang: mw.cx.siteMapper.getWikiDomainCode( mw.cx.targetLanguage ), redirects: true, format: 'json' }, { @@ -248,12 +248,38 @@ // This prevents warnings about the unrecognized parameter "_" cache: true } ).then( function ( response ) { - var pageId = Object.keys( response.query.pages )[ 0 ]; + var redirects, targetTitle, + pageId = Object.keys( response.query.pages )[ 0 ]; if ( pageId === '-1' ) { return $.Deferred().reject().promise(); } - return response.query; + redirects = jQuery.extend( {}, response.query.redirects ); + + $.each( response.query.pages, function ( pageId, page ) { + var i, key, title; + + for ( i in redirects ) { + // Locate the title in redirects, if any. + if ( redirects[ i ].to === page.title ) { + key = redirects[ i ].from; + break; + } + } + + if ( !key ) { + key = page.title; + } + + title = mw.Title.newFromText( key ); + + if ( title ) { + targetTitle = page.langlinks && page.langlinks[ 0 ][ '*' ]; + return; + } + } ); + + return targetTitle; } ); cachedTemplates[ cacheKey ] = request; -- To view, visit https://gerrit.wikimedia.org/r/292911 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I346d5653b7f6a4756f59e99881242d1cf2d17fb6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits