From 86615fcedcd1f32670a7abc9c24e56a7628399db Mon Sep 17 00:00:00 2001 From: petarpetkovic Date: Wed, 13 Jun 2018 21:15:37 +0200 Subject: [PATCH] Check for normalized and converted titles in ve.init.mw.ApiResponseCache Besides redirects, API can return from-to title pairs for normalized and converted titles, as well. Currently, doing an API query on eswiki for page info (prop='info' in params) with titles='User:Title' returns normalized title 'Usuario:Title'. processResult() method in ve.init.mw.ApiResponseCache.prototype.processQueue sets page.title ('Usuario:Title') in cached results, and the promise for actual queried title ('User:Title') gets rejected in rejectSubqueue() method. Change-Id: I33fd4640b6eac8018e35c6fe21234f4c469dd97d --- .../ve-mw/init/ve.init.mw.ApiResponseCache.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js b/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js index 2fd31dcae2..352fd4236d 100644 --- a/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js +++ b/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js @@ -160,11 +160,14 @@ ve.init.mw.ApiResponseCache.prototype.processQueue = function () { } function processResult( data ) { - var i, pageid, page, processedPage, redirects, + var i, pageid, page, processedPage, from, mappedTitles = [], pages = ( data.query && data.query.pages ) || data.pages, processed = {}; - redirects = ( data.query && data.query.redirects ) || []; + [ 'redirects', 'normalized', 'converted' ].forEach( function ( map ) { + mappedTitles = mappedTitles.concat( ( data.query && data.query[ map ] ) || [] ); + } ); + if ( pages ) { for ( pageid in pages ) { page = pages[ pageid ]; @@ -173,10 +176,13 @@ ve.init.mw.ApiResponseCache.prototype.processQueue = function () { processed[ page.title ] = processedPage; } } - for ( i = 0; i < redirects.length; i++ ) { - // Locate the title in redirects, if any. - if ( redirects[ i ].to === page.title ) { - processed[ redirects[ i ].from ] = processedPage; + for ( i = 0; i < mappedTitles.length; i++ ) { + // Locate the title in mapped titles, if any. + if ( mappedTitles[ i ].to === page.title ) { + from = mappedTitles[ i ].fromencoded === '' ? + decodeURIComponent( mappedTitles[ i ].from ) : + mappedTitles[ i ].from; + processed[ from ] = processedPage; break; } }