MWTransclusionModel: Update for change in TemplateData

Depends-On: I7905502d0c419a04e4487095214634f1513b461c
Change-Id: I97a1bfc9f9ead082a673a91b9d2053630a90309c
This commit is contained in:
James D. Forrester 2017-04-20 18:51:11 -07:00 committed by Jforrester
parent 1862f74f11
commit 8fd621ad74
2 changed files with 38 additions and 20 deletions

View file

@ -311,6 +311,9 @@
action: 'templatedata',
titles: titles,
lang: mw.config.get( 'wgUserLanguage' ),
format: 'json',
formatversion: '2',
doNotIgnoreMissingTitles: '1',
redirects: '1'
} ).done( this.fetchRequestDone.bind( this, titles, specs ) );
xhr.always( this.fetchRequestAlways.bind( this, queue, xhr ) );
@ -318,12 +321,25 @@
};
ve.dm.MWTransclusionModel.prototype.fetchRequestDone = function ( titles, specs, data ) {
var i, len, id, title, aliasMap = [];
var i, len, id, title, missingTitle, aliasMap = [];
if ( data && data.pages ) {
// Keep spec data on hand for future use
for ( id in data.pages ) {
specs[ data.pages[ id ].title ] = data.pages[ id ];
title = data.pages[ id ].title;
if ( data.pages[ id ].missing ) {
// Remmeber templates that don't exist in the link cache
// { title: { missing: true|false }
missingTitle = {};
missingTitle[ title ] = { missing: true };
ve.init.platform.linkCache.setMissing( missingTitle );
} else if ( data.pages[ id ].notemplatedata ) {
// Prevent asking again for templates that have no specs
specs[ title ] = null;
} else {
specs[ title ] = data.pages[ id ];
}
}
// Follow redirects
if ( data.redirects ) {
@ -342,14 +358,6 @@
}
}
// Prevent asking again for templates that have no specs
for ( i = 0, len = titles.length; i < len; i++ ) {
title = titles[ i ];
if ( !specs[ title ] ) {
specs[ title ] = null;
}
}
ve.extendObject( specCache, specs );
}
};

View file

@ -37,6 +37,7 @@ ve.ui.MWTemplateTitleInputWidget = function VeUiMWTemplateTitleInputWidget( conf
/* Inheritance */
// FIXME: This should extend mw.widgets.TitleSearchWidget instead
OO.inheritClass( ve.ui.MWTemplateTitleInputWidget, mw.widgets.TitleInputWidget );
/* Methods */
@ -52,7 +53,7 @@ ve.ui.MWTemplateTitleInputWidget.prototype.getLookupRequest = function () {
if ( this.showTemplateDescriptions ) {
return promise
.then( function ( response ) {
var xhr, pageId, index, params, redirIndex,
var xhr, pageId, index, redirIndex,
redirects = ( response.query && response.query.redirects ) || {},
origPages = ( response.query && response.query.pages ) || {},
newPages = [],
@ -84,27 +85,36 @@ ve.ui.MWTemplateTitleInputWidget.prototype.getLookupRequest = function () {
originalResponse = response; // lie!
// Also get descriptions
// FIXME: This should go through MWTransclusionModel rather than duplicate.
if ( titles.length > 0 ) {
params = {
xhr = widget.getApi().get( {
action: 'templatedata',
format: 'json',
formatversion: '2',
titles: titles,
redirects: !!widget.showRedirects,
doNotIgnoreMissingTitles: '1',
lang: mw.config.get( 'wgUserLanguage' )
};
if ( widget.showRedirects ) {
params.redirects = '1';
}
xhr = widget.getApi().get( params );
} );
return xhr.promise( { abort: xhr.abort } );
}
} )
.then( function ( templateDataResponse ) {
var index, page,
var index, page, missingTitle,
pages = ( templateDataResponse && templateDataResponse.pages ) || {};
// Look for descriptions and cache them
for ( index in pages ) {
page = pages[ index ];
// Cache descriptions
widget.descriptions[ page.title ] = page.description;
if ( page.missing ) {
// Remmeber templates that don't exist in the link cache
// { title: { missing: true|false }
missingTitle = {};
missingTitle[ page.title ] = { missing: true };
ve.init.platform.linkCache.setMissing( missingTitle );
} else if ( !page.notemplatedata ) {
// Cache descriptions
widget.descriptions[ page.title ] = page.description;
}
}
// Return the original response
return originalResponse;