Widget:AddWBRQuestion: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
<div id="addbutton"><img src='http://static.wikidoc.org/5/54/Click_here_to_add_a_question.png' /></div> | |||
<script type="text/javascript"> | <script type="text/javascript"> | ||
$("#addbutton").click(function () { | |||
$("#addbutton"). | |||
if ($.isEmptyObject(wgUserName)) { | if ($.isEmptyObject(wgUserName)) { | ||
alert("Please Log In To Continue."); | alert("Please Log In To Continue."); | ||
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto= | window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=Add_WBR_Question"); | ||
} else { | } else { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
Line 25: | Line 22: | ||
$title = $xml.find("text"); | $title = $xml.find("text"); | ||
var curr = parseInt($title.text()); | var curr = parseInt($title.text()); | ||
window.location.replace("http://www.wikidoc.org/index.php/Special:FormEdit/WBRQuestion/WBR" + curr); | |||
addNewSection("WBRCurrentQuestion", parseInt(curr + 1).toString(), mw.user.tokens.get('editToken')); | addNewSection("WBRCurrentQuestion", parseInt(curr + 1).toString(), mw.user.tokens.get('editToken')); | ||
} | } | ||
}); | }); | ||
} | } | ||
}); | }); | ||
function addNewSection(title, content, editToken) { | |||
$.ajaxSetup({ | |||
async : false | |||
}); | |||
$.ajax({ | |||
url : mw.util.wikiScript('api'), | |||
data : { | |||
format : 'json', | |||
action : 'edit', | |||
title : title, | |||
text : content, | |||
token : editToken, | |||
recreate : 'r', | |||
}, | |||
dataType : 'json', | |||
type : 'POST', | |||
success : function (data) { | |||
if (data && data.edit && data.edit.result == 'Success') { | |||
// reload page if edit was successful | |||
} else if (data && data.error) { | |||
alert('Error: Not Logged In'); | |||
} else { | |||
alert('Error: Not Logged In'); | |||
} | |||
}, | |||
error : function (xhr) { | |||
alert('Error: Not Logged In. Please log in to create a Question.'); | |||
} | |||
}); | |||
} | |||
</script> | </script> | ||
</includeonly> | </includeonly> |