2 * MediaWiki Widgets - MediaSearchProvider class.
4 * @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * @classdesc Media search provider.
13 * @extends mw.widgets.MediaResourceProvider
16 * @description Create an instance of `mw.widgets.MediaSearchProvider`.
17 * @param {string} apiurl The API url
18 * @param {Object} [config] Configuration options
20 mw.widgets.MediaSearchProvider = function MwWidgetsMediaSearchProvider( apiurl, config ) {
21 config = config || {};
23 config.staticParams = Object.assign( {
25 gsrnamespace: mw.config.get( 'wgNamespaceIds' ).file,
26 uselang: mw.config.get( 'wgUserLanguage' )
27 }, config.staticParams );
30 mw.widgets.MediaSearchProvider.super.call( this, apiurl, config );
34 OO.inheritClass( mw.widgets.MediaSearchProvider, mw.widgets.MediaResourceProvider );
41 mw.widgets.MediaSearchProvider.prototype.getContinueData = function ( howMany ) {
43 gsroffset: this.getOffset(),
44 gsrlimit: howMany || this.getDefaultFetchLimit()
51 mw.widgets.MediaSearchProvider.prototype.setContinue = function ( continueData ) {
52 // Update the offset for next time
53 this.setOffset( continueData.gsroffset );
59 mw.widgets.MediaSearchProvider.prototype.sort = function ( results ) {
60 return results.sort( ( a, b ) => a.index - b.index );
66 mw.widgets.MediaSearchProvider.prototype.isValid = function () {
67 return this.getUserParams().gsrsearch && mw.widgets.MediaSearchProvider.super.prototype.isValid.call( this );