Open main menu

Manual:Hooks/UploadStashFile

< Manual:Hooks
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": "MyExtensionHooks::onUploadStashFile"
	}
}

For MediaWiki ≤1.25:

$wgHooks['UploadStashFile'][] = 'MyExtensionHooks::onUploadStashFile';
Called from:File(s): upload/UploadBase.php
Function(s): runUploadStashFileHook

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.

DetailsEdit

  • $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).