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
 
(5 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">
mw.loader.load('mediaWiki.user');
$("#addbutton").click(function () {
$(document).ready(function(){
mw.loader.load('mediaWiki.user');
});
$("#addbutton").ready(function () {
mw.loader.getState;
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=User%3AMatt+Pijoan");
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());
$("#addbutton").html("<a id='add' href='http://wikidoc.org/index.php/Special:FormEdit/WBRQuestion/WBR" + curr + "'><img src='http://static.wikidoc.org/5/54/Click_here_to_add_a_question.png' /></a>");
window.location.replace("http://www.wikidoc.org/index.php/Special:FormEdit/WBRQuestion/WBR" + curr);
$('#add').click(function () {
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>
<div id="addbutton"></div>
</includeonly>
</includeonly>

Latest revision as of 15:53, 5 September 2013