Widget:EditSandbox: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
(31 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
function execute(){ | function execute(){ | ||
addToQueue("Edit'd"); | |||
} | } | ||
function | |||
function addToQueue(question){ | |||
var api = new mw.Api(); | var api = new mw.Api(); | ||
var result; | |||
var pageString = "User:" + mw.user.name() + "/WBRQueue"; | |||
api.get( { | api.get( { | ||
action: 'query', | action: 'query', | ||
format: 'json', | format: 'json', | ||
titles: | titles: pageString, | ||
export: 'export', | export: 'export', | ||
} , { | } , { | ||
ok:function (data) { | ok:function (data) { | ||
var xml = data.query.export["*"]; | |||
xmlDoc = $.parseXML( xml ), | |||
$xml = $( xmlDoc ), | |||
$title = $xml.find( "text" ); | |||
var pageContent = $title.text().split(','); | |||
)}}); | pageContent.push(question); | ||
alert(pageContent.toString()); | |||
var token = getToken(pageContent.toString()); | |||
}}); | |||
return result; | |||
} | } | ||
function getToken(){ | function getToken(question){ | ||
var token; | var token; | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
Line 31: | Line 38: | ||
format: 'json', | format: 'json', | ||
intoken: 'edit', | intoken: 'edit', | ||
titles: | titles: "User:" + mw.user.name() + "/WBRQueue", | ||
async: false | async: false | ||
}, { | }, { | ||
Line 37: | Line 44: | ||
$.each(data.query.pages, function(index, value){ | $.each(data.query.pages, function(index, value){ | ||
var token = value.edittoken; | var token = value.edittoken; | ||
addNewSection( " | addNewSection( "User:" + mw.user.name() + "/WBRQueue",question, token ); | ||
})}}); | })}}); | ||
} | } | ||
function addNewSection( content, editToken ) { | function addNewSection( title, content, editToken ) { | ||
$.ajax({ | $.ajax({ | ||
url: mw.util.wikiScript( 'api' ), | url: mw.util.wikiScript( 'api' ), | ||
Line 47: | Line 54: | ||
format: 'json', | format: 'json', | ||
action: 'edit', | action: 'edit', | ||
title: | title: title, | ||
text: content, | |||
token: editToken | token: editToken | ||
}, | }, | ||
Line 68: | Line 74: | ||
}); | }); | ||
} | } | ||
</script> | </script> | ||
<form> | <form> |