MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 32: | Line 32: | ||
var currentUser = ( window.mw && mw.config.get( 'wgUserName' ) ) || ''; | var currentUser = ( window.mw && mw.config.get( 'wgUserName' ) ) || ''; | ||
var userInitial = currentUser ? currentUser.charAt( 0 ).toUpperCase() : '?'; | var userInitial = currentUser ? currentUser.charAt( 0 ).toUpperCase() : '?'; | ||
var currentUserEmail = ''; // fetched from MW API for logged-in users | |||
// Fetch the logged-in user's email address from MW API | |||
if ( currentUser && window.mw ) { | |||
new mw.Api().get({ | |||
action: 'query', | |||
meta: 'userinfo', | |||
uiprop: 'email', | |||
formatversion: 2, | |||
}).then( function ( data ) { | |||
var info = data && data.query && data.query.userinfo; | |||
if ( info && info.email ) currentUserEmail = info.email; | |||
} ).catch( function () {} ); | |||
} | |||
if ( window.mw ) { | if ( window.mw ) { | ||
| Line 336: | Line 350: | ||
// Center on screen — not anchored to selection | // Center on screen — not anchored to selection | ||
$fbComposer.css({ top: '', left: '', transform: '' }); | $fbComposer.css({ top: '', left: '', transform: '' }); | ||
// Pre-fill email for logged-in users | |||
if ( currentUserEmail ) { | |||
$fbEmail.val( currentUserEmail ); | |||
} | |||
$fbComposer.addClass('gra-composer-visible'); | $fbComposer.addClass('gra-composer-visible'); | ||
$backdrop.addClass('gra-backdrop-visible'); | $backdrop.addClass('gra-backdrop-visible'); | ||
| Line 372: | Line 390: | ||
payload.append( 'selected_text', quote ); | payload.append( 'selected_text', quote ); | ||
payload.append( 'details', details || '' ); | payload.append( 'details', details || '' ); | ||
payload.append( 'user_email', email || '' ); | payload.append( 'user_email', email || currentUserEmail || '' ); | ||
payload.append( 'wiki_user', currentUser || 'anonymous' ); | payload.append( 'wiki_user', currentUser || 'anonymous' ); | ||