When the source wiki is the German Wikipedia, and the file description contains a self-link like
[[:de:S-Bahn Mitteldeutschland|S-Bahn Mitteldeutschland]]
… the replacement becomes
[[:w:de:de:S-Bahn Mitteldeutschland|S-Bahn Mitteldeutschland]]
These links work just fine, but clutter the wikitext a bit. Possible solutions and workarounds I can think of at the moment:
- Before adding any prefix to a link, check if a prefix exists (e.g. de:). If it represents the source wiki itself, remove it.
- After adding all prefixes, "implode" duplicates. E.g. de:de: becomes de:. Note this is technically a hack as it assumes all prefixes do have the same meaning on (possibly) different wikis. However:
- This replicates what a user would do.
- To my knowledge it should work 100% of the time on the Wikimedia cluster.