mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 08:34:54 +00:00
ada58df361
Change-Id: I3c618c196e504a80ca297a4132a17f1977a24fb7
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWMediaSearchProvider class.
|
|
*
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
|
* @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 );
|
|
};
|