MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 349: | Line 349: | ||
var author = currentUser | var author = currentUser | ||
|| ( $cmpName.length ? $cmpName.val().trim() : '' ) | || ( $cmpName.length ? $cmpName.val().trim() : '' ) | ||
|| ' | || 'Guest'; | ||
var id = uid(); | var id = uid(); | ||
| Line 361: | Line 361: | ||
_comments.push( entry ); | _comments.push( entry ); | ||
persistCommentHighlight( id, quote ); | persistCommentHighlight( id, quote ); | ||
saveCommentToWiki( id, author, quote, text, ts ); | saveCommentToWiki( id, author, quote, text, ts, id ); | ||
notifyByEmail( id, author, quote, text, ts ); | notifyByEmail( id, author, quote, text, ts ); | ||
| Line 369: | Line 369: | ||
} | } | ||
function saveCommentToWiki( id, author, quote, text, ts ) { | function saveCommentToWiki( id, author, quote, text, ts, anchorId ) { | ||
if ( !window.mw ) return; | if ( !window.mw ) return; | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
| Line 394: | Line 394: | ||
summary:'Comment — ' + author, | summary:'Comment — ' + author, | ||
bot:0, | bot:0, | ||
}).then(function(){ | |||
// Silently notify admin by appending a compact notice to their Talk page. | |||
// MediaWiki Echo picks this up and sends an email to whoever watches that page. | |||
// This is completely invisible to the commenter — no browser hijack. | |||
var adminTalk = 'User_talk:Chandrashekars'; | |||
var artPath = (mw.config.get('wgArticlePath')||'/wiki/$1'); | |||
var link = window.location.origin | |||
+ artPath.replace('$1', pageTitle) | |||
+ (anchorId ? '#' + anchorId : ''); | |||
var notice = '\n<!-- grantha-comment-notify -->\n' | |||
+ '; [[' + pageTitle.replace(/_/g,' ') + ']] — ' + author + '\n' | |||
+ ': ' + quote.slice(0,80) + '\n' | |||
+ ': ' + link + '\n'; | |||
new mw.Api().postWithEditToken({ | |||
action:'edit', title:adminTalk, section:'new', | |||
sectiontitle:'New comment on ' + pageTitle.replace(/_/g,' '), | |||
text:notice, | |||
summary:'Comment notification', | |||
bot:1, /* bot=1 suppresses Echo "someone edited your talk page" popup | |||
but still triggers email watchlist notifications */ | |||
}).catch(function(){}); /* silent — never block the comment flow */ | |||
}).catch(function(){}); | }).catch(function(){}); | ||
}).catch(function(){}); | }).catch(function(){}); | ||
| Line 399: | Line 420: | ||
function notifyByEmail( anchorId, author, quote, text, ts ) { | function notifyByEmail( anchorId, author, quote, text, ts ) { | ||
/* Notification is handled server-side by MediaWiki's Echo extension | |||
* when saveCommentToWiki() edits the Talk page — no client-side | |||
* mailto needed. A mailto would abruptly open the user's mail app | |||
* mid-session which breaks the commenting flow entirely. */ | |||
} | } | ||
| Line 799: | Line 797: | ||
restoreBookmarkHighlights(); | restoreBookmarkHighlights(); | ||
restoreCommentHighlights(); | restoreCommentHighlights(); | ||
loadComments(function(){ | loadComments(function(){}); // pre-load comments in background | ||
}); | }); | ||
}() ); | }() ); | ||