* @cfg {boolean} [showImages] Show page images
* @cfg {boolean} [showDescriptions] Show page descriptions
* @cfg {boolean} [showMissing=true] Show missing pages
+ * @cfg {boolean} [showInterwikis=false] Show pages with a valid interwiki prefix
* @cfg {boolean} [addQueryInput=true] Add exact user's input query to results
* @cfg {boolean} [excludeCurrentPage] Exclude the current page from suggestions
* @cfg {boolean} [excludeDynamicNamespaces] Exclude pages whose namespace is negative
this.showImages = !!config.showImages;
this.showDescriptions = !!config.showDescriptions;
this.showMissing = config.showMissing !== false;
+ this.showInterwikis = !!config.showInterwikis;
this.addQueryInput = config.addQueryInput !== false;
this.excludeCurrentPage = !!config.excludeCurrentPage;
this.excludeDynamicNamespaces = !!config.excludeDynamicNamespaces;
};
mw.widgets.TitleWidget.prototype.getInterwikiPrefixesPromise = function () {
- var api = this.getApi(),
- cache = this.constructor.static.interwikiPrefixesPromiseCache,
- key = api.defaults.ajax.url;
+ var api, cache, key;
+
+ if ( !this.showInterwikis ) {
+ return $.Deferred().resolve( [] ).promise();
+ }
+
+ api = this.getApi();
+ cache = this.constructor.static.interwikiPrefixesPromiseCache;
+ key = api.defaults.ajax.url;
+
if ( !Object.prototype.hasOwnProperty.call( cache, key ) ) {
cache[ key ] = api.get( {
action: 'query',
}
return this.getInterwikiPrefixesPromise().then( function ( interwikiPrefixes ) {
- var interwiki = query.substring( 0, query.indexOf( ':' ) );
- if (
- interwiki && interwiki !== '' &&
- interwikiPrefixes.indexOf( interwiki ) !== -1
- ) {
- return $.Deferred().resolve( { query: {
- pages: [ {
- title: query
- } ]
- } } ).promise( promiseAbortObject );
- } else {
- req = api.get( widget.getApiParams( query ) );
- promiseAbortObject.abort = req.abort.bind( req ); // TODO ew
- return req.then( function ( ret ) {
- if ( widget.showMissing && ret.query === undefined ) {
- ret = api.get( { action: 'query', titles: query } );
- promiseAbortObject.abort = ret.abort.bind( ret );
- }
- return ret;
- } );
+ var interwiki;
+ // Optimization: check we have any prefixes.
+ if ( interwikiPrefixes.length ) {
+ interwiki = query.substring( 0, query.indexOf( ':' ) );
+ if (
+ interwiki && interwiki !== '' &&
+ interwikiPrefixes.indexOf( interwiki ) !== -1
+ ) {
+ // Interwiki prefix is valid: return the original query as a valid title
+ // NB: This doesn't check if the title actually exists on the other wiki
+ return $.Deferred().resolve( { query: {
+ pages: [ {
+ title: query
+ } ]
+ } } ).promise( promiseAbortObject );
+ }
}
+ // Not a interwiki: do an API lookup of the query
+ req = api.get( widget.getApiParams( query ) );
+ promiseAbortObject.abort = req.abort.bind( req ); // TODO ew
+ return req.then( function ( ret ) {
+ if ( widget.showMissing && ret.query === undefined ) {
+ ret = api.get( { action: 'query', titles: query } );
+ promiseAbortObject.abort = ret.abort.bind( ret );
+ }
+ return ret;
+ } );
} ).promise( promiseAbortObject );
};