mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Merge "Follow redirects when looking up template data"
This commit is contained in:
commit
b34249a563
|
@ -231,26 +231,34 @@ ve.dm.MWTransclusionModel.prototype.fetch = function () {
|
|||
request = ve.init.mw.Target.static.apiRequest( {
|
||||
'action': 'templatedata',
|
||||
'titles': titles.join( '|' ),
|
||||
'lang': mw.config.get( 'wgUserLanguage' )
|
||||
'lang': mw.config.get( 'wgUserLanguage' ),
|
||||
'redirects': '1'
|
||||
} )
|
||||
.done( function ( data ) {
|
||||
var i, len, id;
|
||||
var i, len, id, 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];
|
||||
}
|
||||
// Cross-reference under normalized titles
|
||||
// Follow redirects
|
||||
if ( data.redirects ) {
|
||||
aliasMap = data.redirects;
|
||||
}
|
||||
// Follow MW's normalisation
|
||||
if ( data.normalized ) {
|
||||
for ( i = 0, len = data.normalized.length; i < len; i++ ) {
|
||||
// Only define the alias if the target exists, otherwise
|
||||
// we create a new property with an invalid "undefined" value.
|
||||
if ( hasOwn.call( specs, data.normalized[i].to ) ) {
|
||||
specs[data.normalized[i].from] = specs[data.normalized[i].to];
|
||||
}
|
||||
aliasMap.push.apply( aliasMap, data.normalized );
|
||||
}
|
||||
// Cross-reference aliased titles.
|
||||
for ( i = 0, len = aliasMap.length; i < len; i++ ) {
|
||||
// Only define the alias if the target exists, otherwise
|
||||
// we create a new property with an invalid "undefined" value.
|
||||
if ( hasOwn.call( specs, aliasMap[i].to ) ) {
|
||||
specs[aliasMap[i].from] = specs[aliasMap[i].to];
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent asking again for templates that have no specs
|
||||
for ( i = 0, len = titles.length; i < len; i++ ) {
|
||||
title = titles[i];
|
||||
|
|
Loading…
Reference in a new issue