User:Suyash.dwivedi/userscripts/WikidataLocationButton

Wikidata Location Button
WikidataLocationButton is a user script that allows you to quickly insert the
| Camera location | | View all coordinates using: OpenStreetMap |
|---|
template into a file page by fetching coordinates directly from the file's corresponding Wikidata entity (Structured Data).
Installation
To install this script, add the following code to your common.js page:
// Wikidata Location Button mw.loader.load('https://commons.wikimedia.org/wiki/User:Suyash.dwivedi/userscripts/WikidataLocationButton.js?action=raw&ctype=text/javascript');
How to use
Navigate to a File: page on Wikimedia Commons.
Locate the button labeled Add
| Camera location | | View all coordinates using: OpenStreetMap |
|---|
from Wikidata near the top of the page (below the title).
Click the button.
The script will:
Check the Structured Data (Wikidata) of the file for the Coordinates of the point of view (P1259) property.
Fetch the current page wikitext.
Append or update the
Camera location 
View all coordinates using: OpenStreetMap 
template at the end of the content.
Refresh the page once the edit is successful.
Features
Precision Handling: Latitude and longitude are rounded to 7 decimal places for accuracy.
Smart Update: If a
Camera location 
View all coordinates using: OpenStreetMap 
template already exists, the script replaces it to ensure the coordinates remain synchronized with Wikidata.
Validation: Prevents the insertion of invalid or "zero" coordinates (0.0, 0.0).
Automated Summary: Adds a clear edit summary indicating that the location was added via Wikidata.