jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/349369 )

Change subject: MWTransclusionModel: Update for change in TemplateData
......................................................................


MWTransclusionModel: Update for change in TemplateData

Depends-On: I7905502d0c419a04e4487095214634f1513b461c
Change-Id: I97a1bfc9f9ead082a673a91b9d2053630a90309c
---
M modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
M modules/ve-mw/ui/widgets/ve.ui.MWTemplateTitleInputWidget.js
2 files changed, 38 insertions(+), 20 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js 
b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
index b5f0288..13bdf9d 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 ) {
@@ -339,14 +355,6 @@
                                // 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 ];
-                               if ( !specs[ title ] ) {
-                                       specs[ title ] = null;
                                }
                        }
 
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTemplateTitleInputWidget.js 
b/modules/ve-mw/ui/widgets/ve.ui.MWTemplateTitleInputWidget.js
index b4aa333..2195eae 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 @@
 
 /* Inheritance */
 
+// FIXME: This should extend mw.widgets.TitleSearchWidget instead
 OO.inheritClass( ve.ui.MWTemplateTitleInputWidget, mw.widgets.TitleInputWidget 
);
 
 /* Methods */
@@ -52,7 +53,7 @@
        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 @@
                                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;

-- 
To view, visit https://gerrit.wikimedia.org/r/349369
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I97a1bfc9f9ead082a673a91b9d2053630a90309c
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jforrester <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to