Merge "ApiQueryInfo: fix query limits for testactions"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / MediaSearch / mw.widgets.MediaSearchProvider.js
1 /*!
2 * MediaWiki Widgets - MediaSearchProvider class.
3 *
4 * @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7 ( function ( $, mw ) {
8
9 /**
10 * MediaWiki media search provider.
11 *
12 * @class
13 * @extends mw.widgets.MediaResourceProvider
14 *
15 * @constructor
16 * @param {string} apiurl The API url
17 * @param {Object} [config] Configuration options
18 */
19 mw.widgets.MediaSearchProvider = function MwWidgetsMediaSearchProvider( apiurl, config ) {
20 config = config || {};
21
22 config.staticParams = $.extend( {
23 generator: 'search',
24 gsrnamespace: mw.config.get( 'wgNamespaceIds' ).file
25 }, config.staticParams );
26
27 // Parent constructor
28 mw.widgets.MediaSearchProvider.super.call( this, apiurl, config );
29 };
30
31 /* Inheritance */
32 OO.inheritClass( mw.widgets.MediaSearchProvider, mw.widgets.MediaResourceProvider );
33
34 /* Methods */
35
36 /**
37 * @inheritdoc
38 */
39 mw.widgets.MediaSearchProvider.prototype.getContinueData = function ( howMany ) {
40 return {
41 gsroffset: this.getOffset(),
42 gsrlimit: howMany || this.getDefaultFetchLimit()
43 };
44 };
45
46 /**
47 * @inheritdoc
48 */
49 mw.widgets.MediaSearchProvider.prototype.setContinue = function ( continueData ) {
50 // Update the offset for next time
51 this.setOffset( continueData.gsroffset );
52 };
53
54 /**
55 * @inheritdoc
56 */
57 mw.widgets.MediaSearchProvider.prototype.sort = function ( results ) {
58 return results.sort( function ( a, b ) {
59 return a.index - b.index;
60 } );
61 };
62
63 /**
64 * @inheritdoc
65 */
66 mw.widgets.MediaSearchProvider.prototype.isValid = function () {
67 return this.getUserParams().gsrsearch && mw.widgets.MediaSearchProvider.super.prototype.isValid.call( this );
68 };
69 }( jQuery, mediaWiki ) );