MediaWiki:Gadget-friendlytalkback.js: Difference between revisions

Repo at d404881: Greatly expand style guidelines, enforce linting rules (#657)
imported>AzaToth
m (v2.0-556-g0beacc0: use .utc() for timestamps and format them the sme way as the wiki does)
imported>Amorymeltzer
(Repo at d404881: Greatly expand style guidelines, enforce linting rules (#657))
 
(6 intermediate revisions by 2 users not shown)
Line 1:
// <nowiki>
 
 
(function($) {
 
 
Line 16:
Twinkle.talkback = function() {
 
if (!mw.config.get('wgRelevantUserName')) {
if ( Morebits.getPageAssociatedUser() === false ) {
return;
}
 
Twinkle.addPortletLink( Twinkle.talkback.callback, "'TB"', "'friendly-talkback"', "'Easy talkback" ');
};
 
Twinkle.talkback.callback = function( ) {
if( Morebits(mw.getPageAssociatedUserconfig.get('wgRelevantUserName') === mw.config.get("'wgUserName"') && !confirm("Is it really so bad that you're talking back to yourself?") ) {
return;
}
 
var Window = new Morebits.simpleWindow( 600, 350 );
Window.setTitle("'Talkback"');
Window.setScriptName("'Twinkle"');
Window.addFooterLink( "'About {{talkback}}"', "'Template:Talkback" ');
Window.addFooterLink( "'Twinkle help"', "'WP:TW/DOC#talkback" ');
 
var form = new Morebits.quickForm( callback_evaluate );
 
form.append({ type: "'radio"', name: "'tbtarget"',
list: [
{
label: "'Talkback: my talk page"',
value: "'mytalk"',
checked: "'true"'
},
{
label: "'Talkback: other user talk page"',
value: "'usertalk"'
},
{
label: "'Talkback: other page"',
value: "'other"'
},
{
label: '"NoticeboardPlease notificationsee"',
value: "notice"'see'
},
{
label: "\"You'veNoticeboard got mail\""notification',
value: "mail"'notice'
},
],{
label: "\"You've got mail\"",
event: callback_change_target
value: 'mail'
});
}
],
event: callback_change_target
});
 
form.append({
type: "'field"',
label: "'Work area"',
name: "'work_area"'
});
 
form.append({ type: "'submit"' });
 
var result = form.render();
Window.setContent( result );
Window.display();
 
// We must init the
var evt = document.createEvent("'Event"');
evt.initEvent( "'change"', true, true );
result.tbtarget[0].dispatchEvent( evt );
 
// Check whether the user has opted out from talkback
var query = {
// TODO: wgCategories is only set on action=view (bug 45033)
action: 'query',
var wgcat = mw.config.get("wgCategories");
prop: 'extlinks',
if (wgcat.length && wgcat.indexOf("Users who do not wish to receive talkbacks") === -1) {
titles: mw.config.get('wgPageName'),
Twinkle.talkback.optout = false;
elquery: 'userjs.invalid/noTalkback',
} else {
ellimit: '1'
var query = {
};
action: 'query',
var wpapi = new Morebits.wiki.api('Fetching talkback opt-out status', query, Twinkle.talkback.callback.optoutStatus);
prop: 'extlinks',
wpapi.post();
titles: mw.config.get('wgPageName'),
elquery: 'userjs.invalid/noTalkback',
ellimit: '1'
};
var wpapi = new Morebits.wiki.api("Fetching talkback opt-out status", query, Twinkle.talkback.callback.optoutStatus);
wpapi.post();
}
};
 
Line 105 ⟶ 103:
 
if ($el.length) {
Twinkle.talkback.optout = Morebitsmw.getPageAssociatedUserconfig.get('wgRelevantUserName') + "' prefers not to receive talkbacks"';
var url = $el.text();
if (url.indexOf("'reason="') > -1) {
Twinkle.talkback.optout += "': "' + decodeURIComponent(url.substring(url.indexOf("'reason="') + 7)) + "'."';
} else {
Twinkle.talkback.optout += "'."';
}
} else {
Line 116 ⟶ 114:
}
 
var $status = $("'#twinkle-talkback-optout-message"');
if ($status.length) {
$status.append(Twinkle.talkback.optout);
Line 122 ⟶ 120:
};
 
var prev_page = ""'';
var prev_section = ""'';
var prev_message = ""'';
 
var callback_change_target = function( e ) {
var value = e.target.values;
var root = e.target.form;
var old_area = Morebits.quickForm.getElements(root, "'work_area"')[0];
 
if (root.section) {
prev_section = root.section.value;
}
if (root.message) {
prev_message = root.message.value;
}
if (root.page) {
prev_page = root.page.value;
}
 
var work_area = new Morebits.quickForm.element({
type: "'field"',
label: "'Talkback information"',
name: "'work_area"'
});
 
switch ( value ) {
case "'mytalk"':
/* falls through */
default:
work_area.append({
type: "'div"',
label: ""'',
style: "'color: red"',
id: "'twinkle-talkback-optout-message"'
});
work_area.append({
type:" 'input"',
name:" 'section"',
label:" 'Linked section (optional)"',
tooltip:" 'The section heading on your talk page where you left a message. Leave empty for no section to be linked."',
value: prev_section
});
break;
case "'usertalk"':
work_area.append({
type: "'div"',
label: ""'',
style: "'color: red"',
id: "'twinkle-talkback-optout-message"'
});
work_area.append({
type:" 'input"',
name:" 'page"',
label:" 'User"',
tooltip:" 'The username of the user on whose talk page you left a message."',
value: prev_page
});
 
work_area.append({
type:" 'input"',
name:" 'section"',
label:" 'Linked section (optional)"',
tooltip:" 'The section heading on the page where you left a message. Leave empty for no section to be linked."',
value: prev_section
});
break;
case "'notice"':
var noticeboard = work_area.append({
type: "'select"',
name: "'noticeboard"',
label: "'Noticeboard:"',
}event: function(e); {
if (e.target.value === 'afchd') {
Morebits.quickForm.overrideElementLabel(e.target.form.section, 'Title of draft (excluding the prefix): ');
Morebits.quickForm.setElementTooltipVisibility(e.target.form.section, false);
} else {
Morebits.quickForm.resetElementLabel(e.target.form.section);
Morebits.quickForm.setElementTooltipVisibility(e.target.form.section, true);
}
}
});
noticeboard.append({
type: "'option"',
label: "WP:AN (Administrators' noticeboard)",
value: "'an"'
});
noticeboard.append({
type: "'option"',
label: "WP:AN3 (Administrators' noticeboard/Edit warring)",
selectedvalue: true,'an3'
});
value: "an3"
});
noticeboard.append({
type: "'option"',
label: "WP:ANI (Administrators' noticeboard/Incidents)",
selected: true,
value: "'ani"'
});
// let's keep AN and its cousins at the top
noticeboard.append({
type: "'option"',
label: "'WP:COINAFCHD (ConflictArticles offor interestcreation/Help noticeboarddesk)"',
value: "coin"'afchd'
});
noticeboard.append({
type: "'option"',
label: "'WP:DRNCOIN (DisputeConflict resolutionof interest noticeboard)"',
value: "drn"'coin'
});
noticeboard.append({
type: "'option"',
label: "'WP:OTRS/NDRN (OTRSDispute resolution noticeboard)"',
value: "otrs"'drn'
});
noticeboard.append({
type: "'option"',
label: "'WP:HD (Help desk)"',
value: "'hd"'
});
noticeboard.append({
type: "'option"',
label: "'WP:THQOTRS/N (TeahouseOTRS question forumnoticeboard)"',
value: "th"'otrs'
});
noticeboard.append({
type: 'option',
label: 'WP:THQ (Teahouse question forum)',
value: 'th'
});
work_area.append({
type:" 'input"',
name:" 'section"',
label:" 'Linked thread"',
tooltip:" 'The heading of the relevant thread on the noticeboard page."',
value: prev_section
});
break;
case "'other"':
work_area.append({
type: "'div"',
label: ""'',
style: "'color: red"',
id: "'twinkle-talkback-optout-message"'
});
work_area.append({
type:" 'input"',
name:" 'page"',
label:" 'Full page name"',
tooltip: "The full page name where you left the message. For example: 'Wikipedia talk:Twinkle'.",
value: prev_page
});
 
work_area.append({
type:" 'input"',
name:" 'section"',
label:" 'Linked section (optional)"',
tooltip:" 'The section heading on the page where you left a message. Leave empty for no section to be linked."',
value: prev_section
});
break;
case "'mail"':
work_area.append({
type:" 'input"',
name:" 'section"',
label:" 'Subject of email (optional)"',
tooltip:" 'The subject line of the email you sent."'
});
break;
case 'see':
work_area.append({
type: 'input',
name: 'page',
label: 'Full page name',
tooltip: "The full page name of where the discussion is being held. For example: 'Wikipedia talk:Twinkle'.",
value: prev_page
});
work_area.append({
type: 'input',
name: 'section',
label: 'Linked section (optional)',
tooltip: "The section heading where the discussion is being held. For example: 'Merge proposal'.",
value: prev_section
});
break;
}
 
if (value !== "'notice"') {
work_area.append({ type:" 'textarea"', label:" 'Additional message (optional):"', name:" 'message"', tooltip:" 'An additional message that you would like to leave below the talkback template. Your signature will be added to the end of the message if you leave one."' });
}
 
work_area = work_area.render();
root.replaceChild( work_area, old_area );
if (root.message) {
root.message.value = prev_message;
Line 288 ⟶ 316:
 
if (Twinkle.talkback.optout) {
$("'#twinkle-talkback-optout-message"').append(Twinkle.talkback.optout);
}
};
 
var callback_evaluate = function( e ) {
 
var tbtarget = e.target.getChecked( "'tbtarget" ')[0];
var page = null;
var section = e.target.section.value;
var fullUserTalkPageName = mw.config.get("'wgFormattedNamespaces"')[ mw.config.get("'wgNamespaceIds"').user_talk ] + "':"' + Morebitsmw.getPageAssociatedUserconfig.get('wgRelevantUserName');
 
if( (tbtarget === "'usertalk"' || tbtarget === "'other"' || tbtarget === 'see') {
page = e.target.page.value;
 
if ( tbtarget === "'usertalk" ') {
if ( !page ) {
alert("'You must specify the username of the user whose talk page you left a message on."');
return;
}
} else {
if ( !page ) {
alert("'You must specify the full page name when your message is not on a user talk page."');
return;
}
}
} else if (tbtarget === "'notice"') {
page = e.target.noticeboard.value;
}
Line 322 ⟶ 350:
}
 
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( e.target );
 
Morebits.wiki.actionCompleted.redirect = fullUserTalkPageName;
Morebits.wiki.actionCompleted.notice = "'Talkback complete; reloading talk page in a few seconds"';
 
var talkpage = new Morebits.wiki.page(fullUserTalkPageName, "'Adding talkback"');
var tbPageName = (tbtarget === "'mytalk")' ? mw.config.get("'wgUserName"') : page;
 
var text;
if ( tbtarget === "'notice" ') {
switch (page) {
case "an"'afchd':
text = "'\n\n== "{{subst:AFCHD/u|' + Twinkle.getFriendlyPref("adminNoticeHeading")section + "'}} ==\n"~~~~';
talkpage.setEditSummary('You have replies at the [[Wikipedia:AFCHD|Articles for Creation Help Desk]]' + Twinkle.getPref('summaryAd'));
text += "{{subst:ANI-notice|thread=" + section + "|noticeboard=Wikipedia:Administrators' noticeboard}} ~~~~";
talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Administrators' noticeboard]]" + Twinkle.getPref("summaryAd") );
break;
case "an3"'an':
text = "'\n\n{{subst:An3-notice|"== ' + sectionTwinkle.getFriendlyPref('adminNoticeHeading') + "}}' ~~~~"==\n';
talkpage.setEditSummary(text "Notice+= of'{{subst:ANI-notice|thread=' discussion+ atsection [[+ "|noticeboard=Wikipedia:Administrators' noticeboard/Edit}} warring]]~~~~" + Twinkle.getPref("summaryAd") );
talkpage.setEditSummary("Notice of discussion at [[Wikipedia:Administrators' noticeboard]]" + Twinkle.getPref('summaryAd'));
break;
case "ani"'an3':
text = "'\n\n== "{{subst:An3-notice|' + Twinkle.getFriendlyPref("adminNoticeHeading")section + "'}} ==\n"~~~~';
text += "{{subst:ANI-notice|thread=talkpage.setEditSummary("Notice +of sectiondiscussion +at "|noticeboard=[[Wikipedia:Administrators' noticeboard/Incidents}}Edit ~~~~warring]]" + Twinkle.getPref('summaryAd'));
talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Administrators' noticeboard/Incidents]]" + Twinkle.getPref("summaryAd") );
break;
case "coin"'ani':
text = "'\n\n{{subst:Coin-notice|thread="= ' + sectionTwinkle.getFriendlyPref('adminNoticeHeading') + "}}' ~~~~"==\n';
text += '{{subst:ANI-notice|thread=' + section + "|noticeboard=Wikipedia:Administrators' noticeboard/Incidents}} ~~~~";
talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Conflict of interest noticeboard]]" + Twinkle.getPref("summaryAd") );
talkpage.setEditSummary("Notice of discussion at [[Wikipedia:Administrators' noticeboard/Incidents]]" + Twinkle.getPref('summaryAd'));
break;
case "drn"'coin':
text = "'\n\n{{subst:DRNCoin-notice|thread="' + section + "'}} ~~~~"';
talkpage.setEditSummary( "'Notice of discussion at [[Wikipedia:DisputeConflict resolutionof interest noticeboard]]"' + Twinkle.getPref("'summaryAd"') );
break;
case "hd"'drn':
text = "'\n\n{{subst:DRN-notice|thread==' Your+ questionsection at+ the'}} Help desk ==\n"~~~~';
talkpage.setEditSummary('Notice of discussion at [[Wikipedia:Dispute resolution noticeboard]]' + Twinkle.getPref('summaryAd'));
text += "{{helpdeskreply|1=" + section + "|ts=~~~~~}}";
talkpage.setEditSummary( "You have replies at the [[Wikipedia:Help desk|Wikipedia help desk]]" + Twinkle.getPref("summaryAd") );
break;
case "otrs"'hd':
text = "'\n\n{{OTRSreply|1="= +Your sectionquestion +at the Help desk "|2=~~~~}}"=\n';
text += '{{helpdeskreply|1=' + section + '|ts=~~~~~}}';
talkpage.setEditSummary( "You have replies at the [[Wikipedia:OTRS noticeboard|OTRS noticeboard]]" + Twinkle.getPref("summaryAd") );
talkpage.setEditSummary('You have replies at the [[Wikipedia:Help desk|Wikipedia help desk]]' + Twinkle.getPref('summaryAd'));
break;
case "th"'otrs':
text = "'\n\n== Teahouse talkback: you've got messages! ==\n{{WP:Teahouse/Teahouse talkbackOTRSreply|WP:Teahouse/Questions|"1=' + section + "'|ts2=~~~~}}"';
talkpage.setEditSummary( "'You have replies at the [[Wikipedia:Teahouse/Questions|TeahouseOTRS questionnoticeboard|OTRS boardnoticeboard]]"' + Twinkle.getPref("'summaryAd"') );
break;
case 'th':
text = "\n\n== Teahouse talkback: you've got messages! ==\n{{WP:Teahouse/Teahouse talkback|WP:Teahouse/Questions|" + section + '|ts=~~~~}}';
talkpage.setEditSummary('You have replies at the [[Wikipedia:Teahouse/Questions|Teahouse question board]]' + Twinkle.getPref('summaryAd'));
break;
default:
throw "'Twinkle.talkback, function callback_evaluate: default case reached"';
}
 
} else if ( tbtarget === "'mail" ') {
text = "'\n\n=="' + Twinkle.getFriendlyPref("'mailHeading"') + "==\n{{you've got mail|subject=";
text += section + "'|ts=~~~~~}}"';
 
if ( message ) {
text += "'\n"' + message.trim() + "' ~~~~"';
} else if ( Twinkle.getFriendlyPref("'insertTalkbackSignature"') ) {
text += "'\n~~~~"';
}
 
talkpage.setEditSummary("Notification: You've got mail" + Twinkle.getPref("'summaryAd"'));
 
} else if (tbtarget === 'see') {
text = '\n\n{{subst:Please see|location=' + tbPageName;
//clean talkback heading: strip section header markers, were erroneously suggested in the documentation
if (section) {
text = "\n\n==" + Twinkle.getFriendlyPref("talkbackHeading").replace( /^\s*=+\s*(.*?)\s*=+$\s*/, "$1" ) + "==\n{{talkback|";
text += '#' + section;
}
text += '|more=' + message.trim() + '}}';
talkpage.setEditSummary('Please check the discussion at [[:' + tbPageName +
(section ? '#' + section : '') + ']]' + Twinkle.getPref('summaryAd'));
 
} else { // tbtarget one of mytalk, usertalk, other
// clean talkback heading: strip section header markers that were erroneously suggested in the documentation
text = '\n\n==' + Twinkle.getFriendlyPref('talkbackHeading').replace(/^\s*=+\s*(.*?)\s*=+$\s*/, '$1') + '==\n{{talkback|';
text += tbPageName;
 
if ( section ) {
text += "'|"' + section;
}
 
text += "'|ts=~~~~~}}"';
 
if ( message ) {
text += "'\n"' + message.trim() + "' ~~~~"';
} else if ( Twinkle.getFriendlyPref("'insertTalkbackSignature"') ) {
text += "'\n~~~~"';
}
 
var editSummary = 'Talkback ([[:';
talkpage.setEditSummary("Talkback ([[" + (tbtarget === "other" ? "" : "User talk:") + tbPageName +
if (tbtarget !== 'other' && !/^\s*user talk:/i.test(tbPageName)) {
(section ? ("#" + section) : "") + "]])" + Twinkle.getPref("summaryAd"));
editSummary += 'User talk:';
}
editSummary += tbPageName + (section ? '#' + section : '') + ']])';
talkpage.setEditSummary(editSummary + Twinkle.getPref('summaryAd'));
}
 
talkpage.setAppendText( text );
talkpage.setCreateOption("'recreate"');
talkpage.setMinorEdit(Twinkle.getFriendlyPref("'markTalkbackAsMinor"'));
talkpage.setFollowRedirect( true );
talkpage.append();
};
Line 416 ⟶ 461:
 
 
// </nowiki>
Anonymous user