Manual:Hooks/UploadStashFile

UploadStashFile
Available from version 1.28.0
Occurs before a file is stashed (uploaded to stash).
Define function:
public static function onUploadStashFile( UploadBase $uploadBase, User $user, ?array $props, &$error ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"UploadStashFile": "MediaWiki\\Extension\\MyExtension\\Hooks::onUploadStashFile"
	}
}
Called from: File(s): upload/UploadBase.php
Function(s): runUploadStashFileHook
Interface: UploadStashFileHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:UploadStashFile extensions.


Note that code which has not been updated for MediaWiki 1.28 may not call this hook. If your extension absolutely, positively must prevent some files from being uploaded, use UploadVerifyFile or UploadVerifyUpload .

Details

edit
  • $upload: (object) An instance of UploadBase, with all info about the upload
  • $user: (object) An instance of User, the user uploading this file
  • $props: (array|null) File properties, as returned by MWFileProps::getPropsFromPath(). Note this is not always guaranteed to be set, e.g. in test scenarios. Call MWFileProps::getPropsFromPath() yourself in case you need the information.
  • &$error: output: If the file stashing should be prevented, set this to the reason in the form of [ messagename, param1, param2, ... ] or a MessageSpecifier instance (you might want to use ApiMessage to provide machine-readable details for the API).