diff options
Diffstat (limited to 'www/wiki/extensions/Translate/resources/js/ext.translate.storage.js')
-rw-r--r-- | www/wiki/extensions/Translate/resources/js/ext.translate.storage.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/www/wiki/extensions/Translate/resources/js/ext.translate.storage.js b/www/wiki/extensions/Translate/resources/js/ext.translate.storage.js new file mode 100644 index 00000000..85e9cb9e --- /dev/null +++ b/www/wiki/extensions/Translate/resources/js/ext.translate.storage.js @@ -0,0 +1,42 @@ +( function () { + 'use strict'; + + /** + * This class can save a translation into MediaWiki pages using the + * MediaWiki edit WebApi. + * + * @since 2013.10 + */ + var TranslationApiStorage = function () { + // No-op for now. Could take api module as param for example. + }; + + TranslationApiStorage.prototype = { + /** + * Save the translation. + * + * @param {string} title The title of the page including language code + * to store the translation. + * @param {string} translation The translation of the message + * @param {string} editSummary The edit summary + * @return {jQuery.Promise} + */ + save: function ( title, translation, editSummary ) { + var api = new mw.Api(); + + return api.postWithToken( 'csrf', { + action: 'edit', + title: title, + text: translation, + summary: editSummary, + // If the session expires, fail the saving instead of saving it + // as an anonymous user (if anonymous can save). + // When undefined, the parameter is not included in the request + assert: mw.user.isAnon() ? undefined : 'user' + } ); + } + }; + + mw.translate = mw.translate || {}; + mw.translate.TranslationApiStorage = TranslationApiStorage; +}() ); |