3 var api = new mw.Api(),
4 pageUrl = new mw.Uri(),
5 imagesText = new mw.Message( mw.messages, 'searchprofile-images' ),
6 moreResultsText = new mw.Message( mw.messages, 'search-interwiki-more' );
8 function itemTemplate( results ) {
10 var resultOutput = '', i, result, imageCaption, imageThumbnailSrc;
12 for ( i = 0; i < results.length; i++ ) {
13 result = results[ i ],
14 imageCaption = mw.html.element( 'span', { 'class': 'iw-result__mini-gallery__caption' }, result.title );
15 imageThumbnailSrc = ( result.thumbnail ) ? result.thumbnail.source : '';
16 resultOutput += '<div class="iw-result__mini-gallery">' +
17 /* escaping response content */
18 mw.html.element( 'a', {
19 href: '/wiki/' + result.title,
20 'class': 'iw-result__mini-gallery__image',
21 style: 'background-image: url(' + imageThumbnailSrc + ');'
22 }, new mw.html.Raw( imageCaption ) ) +
29 function itemWrapperTemplate( pageQuery, itemTemplateOutput ) {
31 return '<li class="iw-resultset iw-resultset--image" data-iw-resultsset-pos="0">' +
32 '<div class="iw-result__header">' +
33 '<span class="iw-result__icon iw-result__icon--image"></span>' +
34 '<strong>' + imagesText.escaped() + '</strong>' +
36 '<div class="iw-result__content">' +
37 /* template output has been sanitized by mw.html.element */
40 '<div class="iw-result__footer">' +
41 '<a href="/w/index.php?title=Special:Search&search=' + encodeURIComponent( pageQuery ) + '&fulltext=1&profile=images">' +
42 moreResultsText.escaped() +
52 gsrsearch: pageUrl.query.search,
53 gsrnamespace: mw.config.get( 'wgNamespaceIds' ).file,
61 .done( function ( resp ) {
62 var results = ( resp.query && resp.query.pages ) ? resp.query.pages : false,
63 multimediaWidgetTemplate;
69 results.sort( function( a, b ) {
70 return b.index - a.index;
73 multimediaWidgetTemplate = itemWrapperTemplate( pageUrl.query.search, itemTemplate( results ) );
74 /* we really only need to wait for document ready for DOM manipulation */
76 $( '.iw-results' ).prepend( multimediaWidgetTemplate );
80 }( mediaWiki, jQuery ) );