mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 10:59:56 +00:00
52cb066dc7
All link input/title input functionality has been moved to core, so we can replace the link widget, redirect widget and template search widget with it. Depends on Ib463e60cad96 in MediaWiki core. Change-Id: I452f3b86ead403307072cf904f0553c9771f4300
107 lines
3 KiB
JavaScript
107 lines
3 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface MWTemplateTitleInputWidget class.
|
|
*
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.MWTemplateTitleInputWidget object.
|
|
*
|
|
* @class
|
|
* @extends mw.widgets.TitleInputWidget
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {number} [namespace] Namespace to prepend to queries. Defaults to template namespace.
|
|
*/
|
|
ve.ui.MWTemplateTitleInputWidget = function VeUiMWTemplateTitleInputWidget( config ) {
|
|
config = ve.extendObject( {}, {
|
|
namespace: mw.config.get( 'wgNamespaceIds' ).template
|
|
}, config );
|
|
|
|
// Parent constructor
|
|
ve.ui.MWTemplateTitleInputWidget.super.call( this, config );
|
|
|
|
this.showTemplateDescriptions = this.showDescriptions;
|
|
// Clear the showDescriptions flag for subsequent requests as we implement
|
|
// description fetch ourselves
|
|
this.showDescriptions = false;
|
|
|
|
// Properties
|
|
this.descriptions = {};
|
|
|
|
// Initialization
|
|
this.$element.addClass( 've-ui-mwTemplateTitleInputWidget' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWTemplateTitleInputWidget, mw.widgets.TitleInputWidget );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* See the parent documentation at <https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.widgets.TitleInputWidget>
|
|
*/
|
|
ve.ui.MWTemplateTitleInputWidget.prototype.getLookupRequest = function () {
|
|
var widget = this,
|
|
originalResponse,
|
|
promise = ve.ui.MWTemplateTitleInputWidget.super.prototype.getLookupRequest.call( this );
|
|
|
|
if ( this.showTemplateDescriptions ) {
|
|
return promise
|
|
// Also get descriptions
|
|
.then( function ( response ) {
|
|
var xhr, index, params,
|
|
pages = ( response.query && response.query.pages ) || {},
|
|
titles = [];
|
|
|
|
for ( index in pages ) {
|
|
titles.push( pages[index].title );
|
|
}
|
|
|
|
originalResponse = response;
|
|
|
|
if ( titles.length > 0 ) {
|
|
params = {
|
|
action: 'templatedata',
|
|
titles: titles.join( '|' ),
|
|
lang: mw.config.get( 'wgUserLanguage' )
|
|
};
|
|
if ( widget.showRedirects ) {
|
|
params.redirects = '1';
|
|
}
|
|
xhr = new mw.Api().get( params );
|
|
return xhr.promise( { abort: xhr.abort } );
|
|
}
|
|
} )
|
|
.then( function ( templateDataResponse ) {
|
|
var index, page,
|
|
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;
|
|
}
|
|
// Return the original response
|
|
return originalResponse;
|
|
} )
|
|
.promise( { abort: function () {} } );
|
|
|
|
}
|
|
|
|
return promise;
|
|
};
|
|
|
|
/**
|
|
* See the parent documentation at <https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.widgets.TitleInputWidget>
|
|
*/
|
|
ve.ui.MWTemplateTitleInputWidget.prototype.getOptionWidgetData = function ( title ) {
|
|
return ve.extendObject(
|
|
ve.ui.MWTemplateTitleInputWidget.super.prototype.getOptionWidgetData.apply( this, arguments ),
|
|
{ description: this.descriptions[title] }
|
|
);
|
|
};
|