diff --git a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js index b5f0288635..13bdf9d61b 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js @@ -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 ); } }; diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTemplateTitleInputWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTemplateTitleInputWidget.js index b4aa333357..2195eaebdf 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTemplateTitleInputWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTemplateTitleInputWidget.js @@ -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;