The MediaWiki official documentation for enabling file uploads is very thorough, but if this is a new installation (and it’s probably likely if you are enabling file uploads), it can be somehow stripped down to get the functionality simply up and running quickly. I still recommend reading the whole documentation to make sure you tweak the system in the best possible way, and so you don’t forget the necessary security precautions.
Also, if you are running the Tweeki theme for MediaWiki, there is one step that is not mentioned in the official documentation and that got me stuck for a while. So this article shows you how to enable file uploads in MediaWiki when you are using the Tweeki theme.
Before enabling file uploads in MediaWiki, you need to enable them in PHP first. In the php.ini file, set
fileuploads = On
Configure the correct permissions for the uploads directory (images/ by default):
cd /var/www/html sudo chmod 755 images/ sudo chown www-data:www-data images/
Enable uploads in MediaWiki. In LocalSettings.php, set
$wgEnableUploads = true
Set the allowed file types. By default, only image files are allowed, but if you want to allow users to upload other file types (for example, Word files), you need to add a line to your LocalSettings.php file:
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'doc’);
Enable Show advanced features under Preferences > Appearance tab. Without this setting enabled, the Tools menu that allows you to upload files will never be displayed.
You can now upload the file from the Tools menu:
You can now choose to either embed the file inside a page (if it can be embedded, for example if it’s an image file) or to link to it if it’s a file type that cannot be embedded. There are several ways to do it, so choose the most appropriate one for your use case.
In this post I have shown how to quickly enable file uploads if you are running the popular wiki software MediaWiki. I have also covered one settings that needs to be enabled if you are running the Tweeki theme, without which you just will never see the menu that allows you to upload files, even if the platform has been otherwise configured correctly.
Once again, I recommend going through the official documentation to make sure that your server remains secure even after enabling file uploads, which is something that, if not handled correctly, could easily impact the security of your system, so it’s definitely worth the time necessary to make sure you do this right. This article is only showing you how to get this working quickly, but should not be considered enough in a production environment.