if ( mw.Title.newFromText( query ) ) {
return this.getInterwikiPrefixesPromise().then( function ( interwikiPrefixes ) {
- var params,
- interwiki = query.substring( 0, query.indexOf( ':' ) );
+ var interwiki = query.substring( 0, query.indexOf( ':' ) );
if (
interwiki && interwiki !== '' &&
interwikiPrefixes.indexOf( interwiki ) !== -1
} ]
} } ).promise( promiseAbortObject );
} else {
- params = {
- action: 'query',
- prop: [ 'info', 'pageprops' ],
- generator: 'prefixsearch',
- gpssearch: query,
- gpsnamespace: widget.namespace !== null ? widget.namespace : undefined,
- gpslimit: widget.limit,
- ppprop: 'disambiguation'
- };
- if ( widget.showRedirectTargets ) {
- params.redirects = true;
- }
- if ( widget.showImages ) {
- params.prop.push( 'pageimages' );
- params.pithumbsize = 80;
- params.pilimit = widget.limit;
- }
- if ( widget.showDescriptions ) {
- params.prop.push( 'pageterms' );
- params.wbptterms = 'description';
- }
- req = api.get( params );
+ req = api.get( widget.getApiParams( query ) );
promiseAbortObject.abort = req.abort.bind( req ); // TODO ew
return req.then( function ( ret ) {
if ( ret.query === undefined ) {
}
};
+ /**
+ * Get API params for a given query
+ *
+ * @param {string} query User query
+ * @return {Object} API params
+ */
+ mw.widgets.TitleWidget.prototype.getApiParams = function ( query ) {
+ var params = {
+ action: 'query',
+ prop: [ 'info', 'pageprops' ],
+ generator: 'prefixsearch',
+ gpssearch: query,
+ gpsnamespace: this.namespace !== null ? this.namespace : undefined,
+ gpslimit: this.limit,
+ ppprop: 'disambiguation'
+ };
+ if ( this.showRedirectTargets ) {
+ params.redirects = true;
+ }
+ if ( this.showImages ) {
+ params.prop.push( 'pageimages' );
+ params.pithumbsize = 80;
+ params.pilimit = this.limit;
+ }
+ if ( this.showDescriptions ) {
+ params.prop.push( 'pageterms' );
+ params.wbptterms = 'description';
+ }
+ return params;
+ };
+
/**
* Get the API object for title requests
*
imageUrl: OO.getProp( suggestionPage, 'thumbnail', 'source' ),
description: OO.getProp( suggestionPage, 'terms', 'description' ),
// Sort index
- index: suggestionPage.index
+ index: suggestionPage.index,
+ originalData: suggestionPage
};
// Throw away pages from wrong namespaces. This can happen when 'showRedirectTargets' is true
disambiguation: false,
description: mw.msg( 'mw-widgets-titleinput-description-redirect', suggestionPage.title ),
// Sort index, just below its target
- index: suggestionPage.index + 0.5
+ index: suggestionPage.index + 0.5,
+ originalData: suggestionPage
};
titles.push( redirects[ i ] );
}
for ( i = 0, len = titles.length; i < len; i++ ) {
page = pageData[ titles[ i ] ] || {};
- items.push( new mw.widgets.TitleOptionWidget( this.getOptionWidgetData( titles[ i ], page ) ) );
+ items.push( this.createOptionWidget( this.getOptionWidgetData( titles[ i ], page ) ) );
}
return items;
};
+ /**
+ * Create a menu option widget with specified data
+ *
+ * @param {Object} data Data for option widget
+ * @return {OO.ui.MenuOptionWidget} Data for option widget
+ */
+ mw.widgets.TitleWidget.prototype.createOptionWidget = function ( data ) {
+ return new mw.widgets.TitleOptionWidget( data );
+ };
+
/**
* Get menu option widget data from the title and page data
*