[[ https://phabricator.wikimedia.org/T229244 | This ticket ]] identified a bug that made it impossible to edit captions for many files on Beta Commons. The problem was fixed for files with existing structured data as of [[ https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/526195 | this patch ]] and for those without any existing data with [[ https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/WikibaseMediaInfo/+/526399/ | this patch ]].
Unfortunately, newly-created files are still not properly initializing the CaptionsPanel class, and edit functionality is still broken.Ideally, This is because the WikibaseMediaInfo extension iscould relying on the `wikibase.entityPage.entityLoaded` hook to for initialization: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/WikibaseMediaInfo/+/refs/heads/master/resources/filepage/init.js#43
This hook is only run if there structured caption info. However, this hook is currently only run if structured data already exists for a given file. Newly-created files generally lack this data, and therefore the captions panel UI iwas broken on these pages prior to the recent workaround.
It seems like there are two possible solutions here: either 1) ensure that the `wikibase.entityPage.entityLoaded` always fires (a Wikibase change), or 2) changing the way that CaptionsPanel gets initialized (a MediaInfo change).
If we go down the latter route, some refactoring may be necessary in the CaptionsPanel class to allow for a widget to be created with no data and then (optionally) have that data provided at a later time based on whether or not the relevant hook gets called. This class is one of the most complex bits of JS in the extension so it may be a non-trivial change.
Let's use this ticket to discuss how to move forward.
**Steps to Reproduce: **
1. Upload a new file (example: https://commons.wikimedia.beta.wmflabs.org/wiki/File:Permansive_paucidentate.jpg)
2. Navigate to the file page for that file
**Actual Results:**
No "Edit" button appears in the captions panel for the file.
**Expected Results:**
A working "Edit" button should appear regardless of whether or not any captions data exists for the file yet.