Convert MediaWiki filenames into hashed upload URLs
npm install mediawiki-file-url$wgHashedUploadDirectory enabled.
npm i mediawiki-file-url
`
Usage
`js
import {
mwFileUrl,
mwWikiFileUrl,
mwSetBaseUrl,
mwWithBaseUrl,
} from "mediawiki-file-url";
// From a plain filename (default base URL is set to Wikimedia Commons uploads root)
const url1 = mwFileUrl("Tesla_circa_1890.jpeg");
// Set a module-wide default base URL once (used when you omit baseUrl)
mwSetBaseUrl("https://wiki.archlinux.org/images");
const url2 = mwFileUrl("Tango-edit-clear.svg");
const url3 = mwWikiFileUrl("File:Tango-edit-clear.svg");
// Or create bound converters for one base URL (recommended if you need multiple wikis)
const lol = mwWithBaseUrl("https://wiki.leagueoflegends.com/en-us/images");
const url4 = lol.mwFileUrl("Champions_Mesh_concept_03.jpg");
const url5 = lol.mwWikiFileUrl(" Image: Champions_Mesh_concept_02.jpg ");
`
API
$3
- filename (string) - e.g. "My Image.png"
- baseUrl (string, optional) — if omitted, uses the configured default base URL (which is the Tower Defense Simulator Wiki)
Returns the hashed upload URL.
$3
- wikiSyntax (string) - must start with File: or Image: (whitespace is trimmed)
- baseUrl (string, optional) — if omitted, uses the configured default base URL
Extracts the filename and calls mwFileUrl.
$3
Sets the module-wide default base URL used by mwFileUrl / mwWikiFileUrl when baseUrl is omitted.
$3
Returns { mwFileUrl, mwWikiFileUrl } functions bound to a specific baseUrl`, so you don’t have to pass it each call.