User:Chicocvenancio/HelpDeskTBLinks.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Chicocvenancio/HelpDeskTBLinks. |
if ((mw.config.get('wgPageName') === "Wikipedia:Help_desk") || (mw.config.get('wgPageName') === "Wikipedia:Media_copyright_questions") || (mw.config.get('wgPageName') === "Wikipedia:New_contributors'_help_page/questions") || (mw.config.get('wgPageName') === "Wikipedia:Editor_assistance/Requests") && mw.config.get('wgAction') === 'view') {
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'jquery.tipsy', 'jquery.ui'], function () {
$(mw.TBLinks()); });
};
( function ( mw, $ ) {
var TBLinks;
TBLinks = function () {
"use strict";
if ($("#mw-content-text").length > 0) {
var $nodeList = $('a[title^="User talk:"]'), pdne = ' (page does not exist)', i, $link, $newLink;
if ($nodeList !== null) {
for (i = 0; i < $nodeList.length; i += 1) {
$link = $($nodeList[i]);
$newLink = $('<a href="#' + $link[0].title.replace(pdne, "") + '" style="font-size:x-small; display:inline-block;" title="Send a talkback!" noPopup=1 id="TBsubmit' + i + '">TB</a>');
$($link).after($newLink);
}
}
$('a[title="Send a talkback!"]').tipsy({html: true}).before("|").after("|").click(function (e) {
TBLinks.submit($(this).attr('href').substr(1), this.id);
});
};
};
TBLinks.submit = function (page, id) {
'use strict';
TBLinks.edit = function (section) {
var sectionTitle = "{{Talkback|" + mw.config.get('wgPageName').replace(/_/g, ' ') + "|", data;
if (section === "") {
sectionTitle += "ts=~~" + "~~}}";
} else {
sectionTitle += section + "|ts=~~" + "~~}}";
}
data = {
format : 'json',
action : 'edit',
minor : false,
title : page,
text : sectionTitle,
section : 'new',
summary : "Talkback: you've got messages!",
token : mw.user.tokens.get('csrfToken')
};
$.ajax({
url : mw.util.wikiScript('api'),
type : 'POST',
dataType : 'json',
data : data,
success : function (data) {
if (data && data.edit && data.edit.result && data.edit.result === 'Success') {
TBLinks.useDialog('Success', 'Success in sending your talkback (<a href="' +
mw.util.getUrl( page ) + '">Open</a>) (<a href="' +
mw.util.getUrl( page ) + '?diff=0">diff</a>)', 'nprompt-dialog');
} else {
TBLinks.useDialog('Error!!', 'There was an error requesting the edit. Code: ' + data.error.code + '": ' + data.error.info, 'nprompt-dialog');
}
},
error : function () {
TBLinks.useDialog('Error!!', 'There was an error in using AJAX to edit the page.', 'nprompt-dialog');
}
});
}
TBLinks.nicePrompt("Please enter the title of the question you're replying to (or just leave it blank):", "Section:", TBLinks.edit);
};
TBLinks.nicePrompt = function (title, label, callback) {
'use strict';
$('<div id="nprompt-dialog" class="ui-widget">' + (label ? '<label for="nprompt-input">' + label + '</label>' : '') + '<input type="text" id="nprompt-input"> </input></div>').dialog({
title: title,
open: function () {
$(".ui-dialog-titlebar-close").hide();
$('#nprompt-input').autocomplete({source: $('.toctext').map(function() { return $(this).text(); }).get()})
},
close: function () {
$('#nprompt-dialog').dialog('destroy')
$('#nprompt-dialog').remove()
},
buttons: {
"OK": function () {
callback($('#nprompt-input').val());
},
Cancel: function() {
TBLinks.useDialog('Oh!', 'You have canceled!', 'nprompt-dialog');
}
}
});
};
TBLinks.useDialog = function (title, message, id) {
'use strict';
$('#' + id).empty();
$('#' + id).dialog("option", "title", title);
$('#' + id).append($('<div>' + message + '</div>'));
$('#' + id).dialog("option", "buttons", { "Close": function() {
$(this).dialog("close");
} } );
};
mw.TBLinks = TBLinks;
}( mediaWiki, jQuery ) );