Merge "mw.widgets.MediaSearchWidget: Show user uploads when query empty"

This commit is contained in:
jenkins-bot 2020-07-12 15:32:00 +00:00 committed by Gerrit Code Review
commit 8ad4ae0365
8 changed files with 208 additions and 10 deletions

View file

@ -4139,6 +4139,7 @@
"mw-widgets-dateinput-placeholder-day": "YYYY-MM-DD",
"mw-widgets-dateinput-placeholder-month": "YYYY-MM",
"mw-widgets-mediasearch-input-placeholder": "Search for media",
"mw-widgets-mediasearch-recent-uploads": "{{GENDER:$1|Your}} recent uploads",
"mw-widgets-mediasearch-noresults": "No results found.",
"mw-widgets-table-row-delete": "Delete row",
"mw-widgets-titleinput-description-new-page": "page does not exist yet",

View file

@ -4355,6 +4355,7 @@
"mw-widgets-dateinput-placeholder-day": "[[File:DateInputWidget active, empty.png|frame|Screenshot]]\nPlaceholder displayed in a date input field when it's empty, representing a date format with 4 digits for year, 2 digits for month, and 2 digits for day, separated with hyphens. This should be uppercase, if possible, and must not include any additional explanations. If there is no good way to translate it, make this message blank.",
"mw-widgets-dateinput-placeholder-month": "Placeholder displayed in a date input field when it's empty, representing a date format with 4 digits for year and 2 digits for month, separated with hyphens (without a day). This should be uppercase, if possible, and must not include any additional explanations. If there is no good way to translate it, make this message blank.",
"mw-widgets-mediasearch-input-placeholder": "Place holder text for media search input",
"mw-widgets-mediasearch-recent-uploads": "Heading for section showing a user's recent uploads",
"mw-widgets-mediasearch-noresults": "Label notifying the user no results were found for the media search.",
"mw-widgets-table-row-delete": "Tooltip for the delete row button in table widgets",
"mw-widgets-titleinput-description-new-page": "Description label for a new page in the title input widget.",

View file

@ -2557,8 +2557,10 @@ return [
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.APIResultsQueue.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResourceProvider.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaSearchProvider.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaUserUploadsProvider.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResourceQueue.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaSearchQueue.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaUserUploadsQueue.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaSearchWidget.js',
'resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResultWidget.js',
],
@ -2575,6 +2577,7 @@ return [
'messages' => [
'mw-widgets-mediasearch-noresults',
'mw-widgets-mediasearch-input-placeholder',
'mw-widgets-mediasearch-recent-uploads',
],
'targets' => [ 'desktop', 'mobile' ],
],

View file

@ -22,8 +22,6 @@
// Parent constructor
mw.widgets.MediaSearchQueue.super.call( this, config );
this.searchQuery = '';
};
/* Inheritance */

View file

@ -8,3 +8,17 @@
.mw-widget-mediaSearchWidget .oo-ui-searchWidget-query .oo-ui-inputWidget {
max-width: none;
}
.mw-widget-mediaSearchWidget > .oo-ui-searchWidget-results {
display: block;
line-height: 1em;
}
.mw-widget-mediaSearchWidget-noResults {
font-style: italic;
}
.mw-widget-mediaSearchWidget-recentUploads {
margin: 0.5em 0 1em 0;
font-weight: bold;
}

View file

@ -17,6 +17,8 @@
* @param {number} [size] Vertical size of thumbnails
*/
mw.widgets.MediaSearchWidget = function MwWidgetsMediaSearchWidget( config ) {
var queueConfig;
// Configuration initialization
config = $.extend( {
placeholder: mw.msg( 'mw-widgets-mediasearch-input-placeholder' )
@ -28,10 +30,14 @@
// Properties
this.providers = {};
this.lastQueryValue = '';
this.searchQueue = new mw.widgets.MediaSearchQueue( {
queueConfig = {
limit: this.constructor.static.limit,
threshold: this.constructor.static.threshold
} );
};
this.searchQueue = new mw.widgets.MediaSearchQueue( queueConfig );
this.userUploadsQueue = new mw.widgets.MediaUserUploadsQueue( queueConfig );
this.currentQueue = null;
this.queryTimeout = null;
this.itemCache = {};
@ -54,15 +60,19 @@
this.selected = null;
this.recentUploadsMessage = new OO.ui.LabelWidget( {
label: mw.msg( 'mw-widgets-mediasearch-recent-uploads', mw.user ),
classes: [ 'mw-widget-mediaSearchWidget-recentUploads' ]
} );
this.recentUploadsMessage.toggle( false );
this.noItemsMessage = new OO.ui.LabelWidget( {
label: mw.msg( 'mw-widgets-mediasearch-noresults' ),
classes: [ 'mw-widget-mediaSearchWidget-noresults' ]
classes: [ 'mw-widget-mediaSearchWidget-noResults' ]
} );
this.noItemsMessage.toggle( false );
// Events
this.$results.on( 'scroll', this.onResultsScroll.bind( this ) );
this.$query.append( this.noItemsMessage.$element );
this.results.connect( this, {
change: 'onResultsChange',
remove: 'onResultsRemove'
@ -72,6 +82,7 @@
// Initialization
this.setLang( config.lang || 'en' );
this.$results.prepend( this.recentUploadsMessage.$element, this.noItemsMessage.$element );
this.$element.addClass( 'mw-widget-mediaSearchWidget' );
};
@ -140,14 +151,26 @@
value = this.getQueryValue();
if ( value === '' ) {
return;
if ( mw.user.isAnon() ) {
return;
} else {
if ( this.currentQueue !== this.userUploadsQueue ) {
this.userUploadsQueue.reset();
}
this.currentQueue = this.userUploadsQueue;
// TODO: use cached results?
}
} else {
this.currentQueue = this.searchQueue;
this.currentQueue.setSearchQuery( value );
}
this.recentUploadsMessage.toggle( this.currentQueue === this.userUploadsQueue );
this.query.pushPending();
search.noItemsMessage.toggle( false );
this.searchQueue.setSearchQuery( value );
this.searchQueue.get( this.constructor.static.limit )
this.currentQueue.get( this.constructor.static.limit )
.then( function ( items ) {
if ( items.length > 0 ) {
search.processQueueResults( items );
@ -175,7 +198,10 @@
inputSearchQuery = this.getQueryValue(),
queueSearchQuery = this.searchQueue.getSearchQuery();
if ( inputSearchQuery === '' || queueSearchQuery !== inputSearchQuery ) {
if (
this.currentQueue === this.searchQueue &&
( inputSearchQuery === '' || queueSearchQuery !== inputSearchQuery )
) {
return;
}
@ -233,6 +259,7 @@
this.itemCache = {};
this.currentItemCache = [];
this.resetRows();
this.recentUploadsMessage.toggle( false );
// Empty the results queue
this.layoutQueue = [];

View file

@ -0,0 +1,70 @@
/*!
* MediaWiki Widgets - MediaUserUploadsProvider class.
*
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
( function () {
/**
* MediaWiki media search provider.
*
* @class
* @extends mw.widgets.MediaResourceProvider
*
* @constructor
* @param {string} apiurl The API url
* @param {Object} [config] Configuration options
*/
mw.widgets.MediaUserUploadsProvider = function MwWidgetsMediaUserUploadsProvider( apiurl, config ) {
config = config || {};
config.staticParams = $.extend( {
generator: 'allimages',
gaisort: 'timestamp',
gaidir: 'descending'
}, config.staticParams );
// Parent constructor
mw.widgets.MediaUserUploadsProvider.super.call( this, apiurl, config );
};
/* Inheritance */
OO.inheritClass( mw.widgets.MediaUserUploadsProvider, mw.widgets.MediaResourceProvider );
/* Methods */
/**
* @inheritdoc
*/
mw.widgets.MediaUserUploadsProvider.prototype.getContinueData = function ( howMany ) {
return {
gaicontinue: this.getOffset() || undefined,
gailimit: howMany || this.getDefaultFetchLimit()
};
};
/**
* @inheritdoc
*/
mw.widgets.MediaUserUploadsProvider.prototype.setContinue = function ( continueData ) {
// Update the offset for next time
this.setOffset( continueData.gsroffset );
};
/**
* @inheritdoc
*/
mw.widgets.MediaUserUploadsProvider.prototype.sort = function ( results ) {
return results.sort( function ( a, b ) {
return a.timestamp - b.timestamp;
} );
};
/**
* @inheritdoc
*/
mw.widgets.MediaUserUploadsProvider.prototype.isValid = function () {
return this.getUserParams().gaiuser && mw.widgets.MediaUserUploadsProvider.super.prototype.isValid.call( this );
};
}() );

View file

@ -0,0 +1,84 @@
/*!
* MediaWiki Widgets - MediaUserUploadsQueue class.
*
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
( function () {
/**
* MediaWiki media resource queue.
*
* @class
* @extends mw.widgets.MediaResourceQueue
*
* @constructor
* @param {Object} [config] Configuration options
* @cfg {number} maxHeight The maximum height of the media, used in the
* search call to the API.
*/
mw.widgets.MediaUserUploadsQueue = function MwWidgetsMediaUserUploadsQueue( config ) {
config = config || {};
// Parent constructor
mw.widgets.MediaUserUploadsQueue.super.call( this, config );
if ( !mw.user.isAnon() ) {
this.setUser( mw.user.getName() );
}
};
/* Inheritance */
OO.inheritClass( mw.widgets.MediaUserUploadsQueue, mw.widgets.MediaResourceQueue );
/**
* Override parent method to set up the providers according to
* the file repos
*
* @return {jQuery.Promise} Promise that resolves when the resources are set up
*/
mw.widgets.MediaUserUploadsQueue.prototype.setup = function () {
var i, len,
queue = this;
return this.getFileRepos().then( function ( sources ) {
if ( queue.providers.length === 0 ) {
// Set up the providers
for ( i = 0, len = sources.length; i < len; i++ ) {
queue.addProvider( new mw.widgets.MediaUserUploadsProvider(
sources[ i ].apiurl,
{
name: sources[ i ].name,
local: sources[ i ].local,
scriptDirUrl: sources[ i ].scriptDirUrl,
userParams: {
gaiuser: queue.getUser()
},
staticParams: {
iiurlheight: queue.getMaxHeight()
}
} )
);
}
}
} );
};
/**
* Set the user nae
*
* @param {string} user User name
*/
mw.widgets.MediaUserUploadsQueue.prototype.setUser = function ( user ) {
this.setParams( { gaiuser: user } );
};
/**
* Get the user name
*
* @return {string} API search query
*/
mw.widgets.MediaUserUploadsQueue.prototype.getUser = function () {
return this.getParams().gaiuser;
};
}() );