Steps to replicate the issue (include links if applicable):
- Set $wgEnableUploads = true;
- Set $wgMaxUploadSize = 5242880; (5MiB)
- Set $wgUploadSizeWarning = 1048576; (1MiB)
- If you have WikiEditor installed:
- Open the editor on any page
- Select the "Images and media" button
- In the dialog, select "Upload"
- In the upload dialog, select a file which is over 1MiB but under 5MiB
- If you don't have WikiEditor installed:
- Visit Special:Upload
- Select a (for example, JPEG) file which is over 1MiB and under 5MiB in the Choose File option
- Run the following JavaScript:
new mw.Api().upload(document.getElementById('wpUploadFile'), { filename: 'Your file.jpg' }) .then(d => console.log('It works!')) .catch((_, info) => console.error('Nope', info.error));
What happens?: The API throws the following error (anonymized):
{ "error": { "code": "internal_api_error_InvalidArgumentException", "info": "[134c82cb4b267260be809e60] Exception caught: UploadBase::makeWarningsSerializable: Unexpected object of class Wikimedia\\Message\\ScalarParam", "errorclass": "InvalidArgumentException", "*": "InvalidArgumentException at $IP/includes/upload/UploadBase.php(772)\nfrom $IP/includes/upload/UploadBase.php(772)\n#0 [internal function]: UploadBase::{closure}()\n#1 $IP/includes/upload/UploadBase.php(765): array_walk_recursive()\n#2 $IP/includes/api/ApiUpload.php(937): UploadBase::makeWarningsSerializable()\n#3 $IP/includes/api/ApiUpload.php(249): MediaWiki\\Api\\ApiUpload->getApiWarnings()\n#4 $IP/includes/api/ApiUpload.php(172): MediaWiki\\Api\\ApiUpload->getContextResult()\n#5 $IP/includes/api/ApiMain.php(1974): MediaWiki\\Api\\ApiUpload->execute()\n#6 $IP/includes/api/ApiMain.php(942): MediaWiki\\Api\\ApiMain->executeAction()\n#7 $IP/includes/api/ApiMain.php(913): MediaWiki\\Api\\ApiMain->executeActionWithErrorHandling()\n#8 $IP/includes/api/ApiEntryPoint.php(153): MediaWiki\\Api\\ApiMain->execute()\n#9 $IP/includes/MediaWikiEntryPoint.php(200): MediaWiki\\Api\\ApiEntryPoint->execute()\n#10 $IP/api.php(44): MediaWiki\\MediaWikiEntryPoint->run()\n#11 {main}" } }
This happens because UploadBase::checkFileSize sets an array in the large-file key with a Message::sizeParam, and ApiUpload::getApiWarnings then runs that through UploadBase::makeWarningsSerializable, which throws an error if it encounters an unserializable object (which is Wikimedia\Message\ScalarParam in this case).
What should have happened instead?: It should have properly told me what's the warning.
Software version 1.43.0 (5976d8f)
Other information (browser name/version, screenshots, etc.):
This is how the error looks like inside of the upload dialog:
It is likely that this affects more than just size warnings. For example, UploadBase::checkUnwantedFileExtensions returns a Wikimedia\Message\ListParam, though I couldn't figure out the purpose of said function.
