Skip to content

Publish file uploads via the MediaWiki upload stash #155

Description

@LukasGold

WikiFileController.put uploads before storing the entity (#153). Since a file and its description page share one title, action=upload creates the page as a side effect, with empty wikitext and no jsondata slot.

Consequences:

Proposal

Use MediaWiki's upload stash, which separates accepting the bytes from publishing them to a title:

  1. action=upload&stash=1 returns a filekey and creates no page
  2. store_entity creates the page normally, with page.exists false and no policy override
  3. action=upload&filekey=...&filename=... publishes onto the page that now exists, so text is ignored and nothing is rewritten

One content revision, the caller's overwrite untouched, no validator noise. Failure behaviour improves in both directions: a file the wiki refuses never reaches step 2, and if step 2 fails nothing is published and the stash expires on its own, needing no delete rights.

Effort

mwclient exposes no stash parameter. Site.post forwards to api(), which takes no files, so step 1 needs raw_call('api', data, files={'file': ...}) with manual result handling, roughly 15 lines mirroring Site.upload. Step 3 can use Site.upload(filekey=...) as is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions