Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / resources / src / mediawiki / mediawiki.userSuggest.js
blob02a90fc341f47c193ad088c968a88225c8762264
1 /*!
2  * Add autocomplete suggestions for names of registered users.
3  */
4 ( function ( mw, $ ) {
5         var api, config;
7         config = {
8                 fetch: function ( userInput, response, maxRows ) {
9                         var node = this[ 0 ];
11                         api = api || new mw.Api();
13                         $.data( node, 'request', api.get( {
14                                 action: 'query',
15                                 list: 'allusers',
16                                 // Prefix of list=allusers is case sensitive. Normalise first
17                                 // character to uppercase so that "fo" may yield "Foo".
18                                 auprefix: userInput[ 0 ].toUpperCase() + userInput.slice( 1 ),
19                                 aulimit: maxRows
20                         } ).done( function ( data ) {
21                                 var users = $.map( data.query.allusers, function ( userObj ) {
22                                         return userObj.name;
23                                 } );
24                                 response( users );
25                         } ) );
26                 },
27                 cancel: function () {
28                         var node = this[ 0 ],
29                                 request = $.data( node, 'request' );
31                         if ( request ) {
32                                 request.abort();
33                                 $.removeData( node, 'request' );
34                         }
35                 }
36         };
38         $( function () {
39                 $( '.mw-autocomplete-user' ).suggestions( config );
40         } );
41 }( mediaWiki, jQuery ) );