mediawiki.api.uploadWithFormData: Implement in terms of existing mw.Api functionality
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 18 Aug 2015 22:50:30 +0000 (00:50 +0200)
committerJforrester <jforrester@wikimedia.org>
Mon, 24 Aug 2015 18:26:37 +0000 (18:26 +0000)
commitee7132a55208b1319a28bb85ea8aa752992e7740
treeac1f94a7ba06537a0efff4f09b0184418d52c1d9
parent3de58a4990591bb5e85d8f2454144642c54aac5b
mediawiki.api.uploadWithFormData: Implement in terms of existing mw.Api functionality

* mw.Api#ajax can already handle FormData, if instructed to, since
  d19432a332c21935d42087db706e50c5259063ea (which seems to have been a
  part of mobile uploads experiments).
* MobileFrontend's api.js already had code to provide upload progress
  events while using mw.Api, lifted it from there.

With this change, we should be able to just use mw.ForeignApi (being
added in Ic20b9682d28633baa87d22e6e9fb71ce507da58d) to upload to a
different wiki. (Assuming that the browser supports FormData.)

Additionally:

* Improve detection of whether we can use FormData: if we are given a
  HTMLInputElement, try to get a File from it before we fall back to
  iframe form upload.
* mediawiki.api.edit: In #postWithEditToken, pass through the
  ajaxOptions parameter to #postWithToken.

Change-Id: Ib9abe32ee3320c67ac0a4544c942b844a5550562
resources/src/mediawiki.api/mediawiki.api.edit.js
resources/src/mediawiki.api/mediawiki.api.upload.js