User:Writ Keeper/Scripts/teahouseTalkbackLink.js: Difference between revisions

Content deleted Content added
test
use mw.api
Line 12:
var $link = $($nodeList[i]);
var newLinkString = "<span class='reply-link-wrapper'>|";
var newLinkHrefredlink = $link[0].title.replace(pdne, "") false;
var newLinkHref = $link[0].title
if(newLinkHref.includes(pdne))
{
redlink = true;
newLinkHref = newLinkHref.replace(pdne, "");
}
var newLinkId = "TBsubmit" + i;
newLinkString += '<a href=' + (($link[0].href).replace("User_talk:", "Special:Contributions/")) + ' style="font-size:x-small; display:inline-block;">C</a>|'
Line 19 ⟶ 25:
$("#" + newLinkId).click(function (e)
{
talkbackSubmit($(this).attr('href').substr(1), this.idredlink)
});
}
Line 25 ⟶ 31:
}
}
function talkbackSubmit(page, idredlink)
{
var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):", ""),
sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse|";
{
if (questionTitle === null)
{
Line 41 ⟶ 48:
sectionTitle += questionTitle + "|ts=~~" + "~~}}";
}
if(redlink)
var data =
{
summary:sectionTitle = "== Teahouse talkback: you've got messages! ==\n", + sectionTitle;
format: 'json',
var requestData =
action: 'edit',
minor: false,
title: page,
text: sectionTitle,
section: 'new',
summary: "Teahouse talkback: you've got messages!",
token: mw.user.tokens.get('editToken')
};
$.ajax(
{
url: mw.util.wikiScript('api'),
type: 'POST',
dataType: 'json',
data: data,
success: function (data)
{
summary: "Teahouse talkback: you've got messages!"
if (data && data.edit && data.edit.result && data.edit.result === 'Success')
{
//window.___location = mw.util.getUrl(page);
alert("Talkback posted!");
}
else
{
alert('There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info);
}
},
error: function ()
{
alert('There was an error using AJAX to edit the page.');
}
new mw.Api().create(page, requestData, sectionTitle).done(function(data)
{
if (data && data.edit && data.edit.result && data.edit.result === 'Success')
{
alert("Talkback posted!");
}
else
{
alert('There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info);
}
success: }).fail(function (data) {
alert('There was an error using AJAX to edit the page.');
});
}
else
{
var requestData =
{
minor: false,
text: sectionTitle,
section: 'new',
summary: "Teahouse talkback: you've got messages!"
},;
new mw.Api().edit(page, function() {
return requestData;
error: }).done(function (data) {
if (data && data.result && data.result === 'Success')
{
alert("Talkback posted!");
}
else
{
alert('There was an error requesting the page edit. Code: ' + data);
}
}).fail(function(data) {
alert('There was an error using AJAX to edit the page.');
});
}
);
}
if (mw.config.get('wgPageName') === "Wikipedia:Teahouse")
{
mw.loader.using("mediawiki.api", function()
teahouseTalkbackLink();
{
teahouseTalkbackLink();
});
}