User:Suyash.dwivedi/userscripts/AddDerivativeSources

Add Derivative Sources
AddDerivativeSources is a gadget-like script that simplifies the process of citing original source files for derivative works on Wikimedia Commons. It adds a UI button that automates wikitext editing and gallery creation.
Installation
To use this script, add the following line to your common.js page:
// Add Derivative Sources Button
mw.loader.load('https://commons.wikimedia.org/wiki/User:Suyash.dwivedi/userscripts/AddDerivativeSources.js?action=raw&ctype=text/javascript');
How to use
- Navigate to any File: page.
- Look for the Source row in the File Information table.
- Click the blue + Add derivative sources button.
- Enter the names of the source files (e.g.,
File:Example.jpg) in the popup dialog. - Click Update. The script will automatically:
- Fetch the current page content.
- Format the sources into a
<gallery>. - Insert or update the
==Source files==section. - Save the page with a minor edit summary.
Features
- Dynamic Inputs: New input fields appear automatically as you type.
- Smart Replacement: Automatically detects
{{own}}and replaces it with the proper source gallery. - Duplicate Prevention: If a gallery already exists, it merges new files without creating duplicates.
- Mobile Friendly: Designed to work across modern browsers.
Created by Suyash Dwivedi | Updated on: 8 January 2026