DownloadWithFilename
The DownloadWithFilename extension allows wiki pages to link to a file to download, while specifying a filename for it to be automatically named as upon saving.
This allows for things such as config files which usually have generic names (e.g. config.ini
) to be stored on the wiki with a specific name (e.g. File:FooApplicationConfig.ini
), and allow a user to download it with the generic name without having to manually rename it. It uses the Content-Disposition header to achieve this.
Note
This extension was made while learning how to make an extension for MediaWiki, and so most likely has problems that I'm not aware of. In my personal testing on a MediaWiki setup using 1.37, it worked without any obvious issues.
Doesn't work with foreign file repos like Wikimedia Commons. It might work for foreign repos that use ForeignDBRepo but I haven't tested this.
Only tested for MediaWiki 1.37.
Installation
- Download and place the file(s) in a directory called
DownloadWithFilename
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php:
wfLoadExtension( 'DownloadWithFilename' );
✅ Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Usage
The process happens through the Special:DownloadWithFilename
special page.
Syntax: [[Special:DownloadWithFilename/name of file page/filename to save as]]
The File:
namespace prefix is not required.
Example:
[[Special:DownloadWithFilename/File:My Picture.png/image.png]]
will downloadFile:My Picture.png
and be saved asimage.png
[[Special:DownloadWithFilename/FooApplicationConfig.ini/config.ini]]
will downloadFile:FooApplicationConfig.ini
and be saved asconfig.ini
[[Special:DownloadWithFilename/FooBarModSettings-Version2.0.3.yml/Settings.yml]]
will downloadFile:FooBarModSettings-Version2.0.3.yml
and be saved asSettings.yml
Configuration parameters
$wgDWFMaxSize
The largest file size before the extension refuses to serve the file. Defaults to 1048576 bytes (1 MiB).
$wgDWFMaxSize = 1048576; # default
$wgDWFMaxSize = 16384; # 16 KiB
License
DownloadWithFilename is licensed under the MIT license.