2015-12-18 16:00:32 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWMediaSearchProvider class.
|
|
|
|
*
|
2016-01-03 22:56:59 +00:00
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
2015-12-18 16:00:32 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki media search provider.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.MWMediaResourceProvider
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {string} apiurl The API url
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.dm.MWMediaSearchProvider = function VeDmMWMediaSearchProvider( apiurl, config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
config.staticParams = $.extend( {
|
|
|
|
generator: 'search',
|
|
|
|
gsrnamespace: mw.config.get( 'wgNamespaceIds' ).file
|
|
|
|
}, config.staticParams );
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.dm.MWMediaSearchProvider.super.call( this, apiurl, config );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.dm.MWMediaSearchProvider, ve.dm.MWMediaResourceProvider );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWMediaSearchProvider.prototype.getContinueData = function ( howMany ) {
|
|
|
|
return {
|
|
|
|
gsroffset: this.getOffset(),
|
|
|
|
gsrlimit: howMany || this.getDefaultFetchLimit()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWMediaSearchProvider.prototype.setContinue = function ( continueData ) {
|
|
|
|
// Update the offset for next time
|
|
|
|
this.setOffset( continueData.gsroffset );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWMediaSearchProvider.prototype.sort = function ( results ) {
|
|
|
|
return results.sort( function ( a, b ) {
|
|
|
|
return a.index - b.index;
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWMediaSearchProvider.prototype.isValid = function () {
|
|
|
|
return this.getUserParams().gsrsearch && ve.dm.MWMediaSearchProvider.super.prototype.isValid.call( this );
|
|
|
|
};
|