Attachments is a MediaWiki extension to attach files and external links to pages.
❤️ This extension was originally developed and maintained by Gittenburg.
Please review the new configuration options when migrating from the old repository. The default behavior has been changed to accommodate modern skins.
🚀 This repository follows the MediaWiki release branches compatibility policy.
You can find dedicated branches for supported versions here:
- Attachments for MediaWiki 1.44 (legacy stable version)
- Attachments for MediaWiki 1.43 (legacy stable and current LTS version)
- Attachments for MediaWiki 1.39 (legacy LTS version)
Example of the Attachments extension. Left: default configuration. Right: with $wgAttachmentsShowInNamespaces and $wgAttachmentsShowInViews set to true.
- Subpages are automatically attached to their parent page.
- Files can be attached to a page by setting
{{#attach: pagename}}in the file description. - External links can be defined as subpages containing
{{#exturl: URL}}.
For enabled namespaces the attachments of an article are displayed in an automatically generated section at its end. To facilitate adding attachments an attach page action is provided, which is linked in the Vector and Minerva skins.
Some more usage tips:
#attachalso works on regular articles.- You can link files added through
action=attachrelatively with[[File:{{FILEPREFIX}}filename.jpg]](or{{FILEPREFIX:..}}for the parent page). - Enable $wgCountCategorizedImagesAsUsed to exclude attached files from
Special:UnusedImages. - You can exclude subpages starting with a specific prefix from the auto-index with
{{#attachments ignore subpages: prefix}}on the parent page. - Attachments and external URLs are both stored as page props, meaning they can be queried with API:Pageprops and API:Pageswithprop.
- You can access attachments before they are sorted with the
BeforeSortAttachments(&$links)hook, where links is an associative array mapping string keys to HTML links. Return false to take over the sorting. - If new attachments do not show up, it might be because you have many jobs in your job queue.
Clone the extension into your MediaWiki extensions directory:
cd extensions/
git clone https://github.com/vuhuy/AttachmentsThen enable it by adding the following lines to your LocalSettings.php:
wfLoadExtension( 'Attachments' );This extension is enabled for the main namespace by default. You might want to enable the extension for other namespaces, e.g.:
$wgAttachmentsNamespaces[NS_MAIN] = true;Note that you should also enable subpages for these namespaces, e.g.:
$wgNamespacesWithSubpages[NS_MAIN] = 1;File uploads must be enabled and configured in order to attach files to a page.
Optional configuration parameters:
$wgAttachmentsChunkListByLetter(boolean)
Whether or not the attachment list should be chunked by the first letter of list items. Defaults totrue.$wgAttachmentsShowSubpageForm(boolean)
Whether or not the subpage form should be shown. Defaults totrue.$wgAttachmentsShowLinkForm(boolean)
Whether or not the external link form should be shown. Defaults totrue.$wgAttachmentsShowInNamespaces(boolean)
Whether or not a link to the attachments should be shown in the namespaces (page, discussion). Defaults tofalse.$wgAttachmentsShowInViews(boolean)
Whether or not an 'add attachments' link should be shown in the views (read, edit source, view history). Defaults tofalse.$wgAttachmentsShowEmptySection(boolean)
Whether or not to show certain elements when there are no attachments for a page. Defaults tofalse.
This extension is essentially a rewrite of PerPageResources by Mathias Ertl, which consists of Extension:Resources, Extension:AddResource, and Extension:ExternalRedirects. This extension replaces all three. Notable differences are:
- Attachments are stored in page_props instead of pagelinks.
- No open redirects, just links.
- Attachments are shown at the end of pages, as opposed to on a special page.
Originally developed and maintained by Gittenburg.
The icons in resources/ are from Feather and licensed under MIT.