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 |
||
Line 26: | Line 26: | ||
ok: function (data) { | ok: function (data) { | ||
$.each(data.query.pages, function(index, value){ | $.each(data.query.pages, function(index, value){ | ||
token = value.edittoken; | var token = value.edittoken; | ||
addNewSection( 'Testing', "Edit'd!", token ); | |||
})}}); | })}}); | ||
alert( | } | ||
function addNewSection( summary, content, editToken ) { | |||
$.ajax({ | |||
url: mw.util.wikiScript( 'api' ), | |||
data: { | |||
format: 'json', | |||
action: 'edit', | |||
title: 'GroundZero', | |||
section: 'new', | |||
summary: summary, | |||
text: content, | |||
token: editToken | |||
}, | |||
dataType: 'json', | |||
type: 'POST', | |||
success: function( data ) { | |||
if ( data && data.edit && data.edit.result == 'Success' ) { | |||
window.location.reload(); // reload page if edit was successful | |||
} else if ( data && data.error ) { | |||
alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info ); | |||
} else { | |||
alert( 'Error: Unknown result from API.' ); | |||
} | |||
}, | |||
error: function( xhr ) { | |||
alert( 'Error: Request failed.' ); | |||
} | |||
}); | |||
} | } | ||
</script> | </script> |