Λογότυπο Commons File Resolution

Commons File Resolution

Κοινότητα
fuzheado
commons-file-resolution

Resolve Wikimedia Commons file references (File:Example.jpg) to browser-usable HTTP URLs — direct origin URLs, thumbnails, Special:FilePath redirects, cache-busting with timestamps, Action API imageinfo queries, and CORS-aware serving patterns for web applications

Επισκόπηση

Εκδότηςfuzheado
ΑποθετήριοWikipedia-AI-Skills
Όνομα δεξιότηταςcommons-file-resolution
Αστέρια
27
Διακλαδώσεις
10
Συνοδευτικά αρχεία
1
Άδεια χρήσηςMIT
Σύνδεσμοι
  • Οδηγίες σε Markdown

    Ένα αρχείο SKILL.md που το μοντέλο φορτώνει όταν χρειάζεται, ώστε να καταναλώνει token μόνο όταν ένα αίτημα είναι πράγματι σχετικό.

  • Λειτουργεί με οποιοδήποτε LLM

    Οι δεξιότητες AI είναι απλό Markdown, όχι κώδικας για συγκεκριμένο πάροχο, επομένως αυτή η δεξιότητα λειτουργεί με GPT, Claude, Gemini, Grok ή ένα τοπικό μοντέλο.

  • Συνοδευτικά αρχεία: 1

    Αρχεία script, πρότυπα και υλικό αναφοράς που μπορεί να διαβάζει το μοντέλο καθώς εργάζεται. Τα αρχεία είναι μόνο για ανάγνωση και δεν εκτελούνται ποτέ.

  • Ανοιχτού κώδικα

    Δημοσιεύτηκε στο GitHub από τον λογαριασμό fuzheado. Ελέγξτε τα αρχεία της δεξιότητας στο αποθετήριο πριν την εγκαταστήσετε.

Εγκατάσταση

Εγκαταστήστε τη δεξιότητα AI Commons File Resolution στο TypingMind για να τη χρησιμοποιείτε με οποιοδήποτε LLM ή προσθέστε τη σε άλλον πράκτορα AI που διαβάζει αρχεία SKILL.md.

1

Εγκατάσταση στο TypingMind

Το TypingMind εγκαθιστά μια δεξιότητα απευθείας από τον φάκελό της στο GitHub — διαβάζει το SKILL.md, συγκεντρώνει τα συνοδευτικά αρχεία σε πακέτο και αποθηκεύει το αποτέλεσμα τοπικά.

  1. Ανοίξτε την εφαρμογή και μεταβείτε στα Πρόσθετα → Δεξιότητες.
  2. Επιλέξτε «Εγκατάσταση από GitHub».
  3. Επικολλήστε το παρακάτω URL του φακέλου της δεξιότητας και επιβεβαιώστε.
    https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/commons-file-resolution
  4. Ενεργοποιήστε τη δεξιότητα σε κάθε συνομιλία όπου θέλετε να είναι διαθέσιμη.
Πρόσθετα → Δεξιότητες → Προσθήκη δεξιότητας → Από URL του GitHub, έπειτα επικολλήστε το URL του φακέλου και πατήστε «Συνέχεια».
2

Εγκατάσταση σε άλλον πράκτορα AI

Κάθε πράκτορας AI που υποστηρίζει τη μορφή Agent Skills μπορεί να χρησιμοποιήσει αυτή τη δεξιότητα — αντιγράψτε τον φάκελο στον κατάλογο δεξιοτήτων του.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fuzheado/Wikipedia-AI-Skills.git /tmp/Wikipedia-AI-Skills
mkdir -p .claude/skills
cp -r /tmp/Wikipedia-AI-Skills/.claude/skills/commons-file-resolution .claude/skills/commons-file-resolution
Επανεκκινήστε το Claude Code μετά την αντιγραφή, ώστε να εντοπίσει τη νέα δεξιότητα.

Χρησιμοποιήστε τη στο TypingMind

Ενεργοποιήστε τη δεξιότητα Commons File Resolution σε οποιαδήποτε συνομιλία στο TypingMind και το μοντέλο αναλαμβάνει τα υπόλοιπα. Το όνομα και η περιγραφή της περιλαμβάνονται στην προτροπή συστήματος και, μόλις προκύψει ένα σχετικό αίτημα, το μοντέλο φορτώνει μόνο του τις πλήρεις οδηγίες — δεν χρειάζεται ποτέ να την καλείτε χειροκίνητα και δεν καταναλώνει token μέχρι να χρησιμοποιηθεί πραγματικά.

Το μοντέλο φορτώνει αυτόματα τη δεξιότητα Commons File Resolution μόλις λάβει ένα σχετικό αίτημα.

Λειτουργεί με οποιοδήποτε μοντέλο AI

Οι δεξιότητες AI είναι οδηγίες σε απλό κείμενο Markdown και όχι κώδικας για συγκεκριμένο πάροχο, οπότε η δεξιότητα Commons File Resolution δεν περιορίζεται στο μοντέλο για το οποίο γράφτηκε. Εγκαταστήστε τη μία φορά στο TypingMind και χρησιμοποιήστε τη με GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ή ένα τοπικό μοντέλο που εκτελείτε εσείς — πάντα με τα δικά σας κλειδιά API.

  • Φόρτωση μόνο όταν χρειάζεται

    Η προτροπή συστήματος περιλαμβάνει μόνο το όνομα και την περιγραφή. Οι οδηγίες ανακτώνται με το πρώτο σχετικό αίτημα, οπότε μια δεξιότητα που δεν χρησιμοποιείται δεν έχει κόστος.

  • Αλλάξτε μοντέλο κατά τη διάρκεια της συνομιλίας

    Επειδή η δεξιότητα αποτελείται από οδηγίες και όχι από κώδικα, η αλλαγή μοντέλου δεν επηρεάζει τη λειτουργία της — το επόμενο μοντέλο διαβάζει το ίδιο αρχείο SKILL.md.

Οδηγίες δεξιότητας

Αυτό είναι το περιεχόμενο του αρχείου SKILL.md που φορτώνει το μοντέλο. Διαβάστε το πριν από την εγκατάσταση — μια δεξιότητα αποτελείται από οδηγίες που θα ακολουθήσει το μοντέλο σας.

⚠️ Prefer Special:FilePath?width= over computed hash URLs. Direct upload.wikimedia.org/wikipedia/commons/{hash}/{file} URLs can return "File not found" for newer Commons uploads (post-2023 storage backend changes). The Special:FilePath redirect always resolves correctly and supports ?width= for on-the-fly resizing — no MD5 computation, no hash prefix guessing. Only use direct hash URLs if you specifically need the origin URL for archival purposes.

💡 Already know which endpoint you need? See the Quick Reference table below. Otherwise, the SOPs walk through each approach step by step.


The Problem

Browser applications cannot use File:Example.jpg — the wiki page reference — as an image source. They need a real HTTP URL. Wikimedia Commons stores uploaded files at upload.wikimedia.org with a hash-based path, but the exact URL depends on the file's upload timestamp, the hash of its name, and whether you want the original or a thumbnail.

This skill covers every method for resolving a File: reference to a working URL, from simplest (server-side redirect) to most robust (full Action API query with cache busting).


Quick Reference

GoalMethodCode / URLComplexity
Download image to diskSpecial:FilePath/?width=curl -L "https://commons.wikimedia.org/wiki/Special:FilePath/File:Example.jpg?width=800" -o example.jpg⭐
One-off URL, server-sideSpecial:FilePath/ redirecthttps://commons.wikimedia.org/wiki/Special:FilePath/File:Example.jpg⭐
One-off URL, browser <img>Special:FilePath/ redirectSame URL, browser follows 302 redirect⭐
Full metadata + URLAction API prop=imageinfoaction=query&prop=imageinfo&titles=File:Example.jpg&iiprop=url|timestamp|size|mime⭐⭐
Thumbnail URLAdd ?width= to Special:FilePath/Special:FilePath/File:Example.jpg?width=800⭐
Thumbnail via APIiiurlwidth parameterprop=imageinfo&iiurlwidth=800⭐⭐
Cache-busted URL (latest version)timestamp from API + ?v= paramAppend ?v={unix timestamp} to URL⭐⭐
Same-origin for WebGL/CanvasProxy through own serverFetch → cache locally → serve from own domain⭐⭐⭐
Batch resolutionAction API multi-title querytitles=File:A.jpg|File:B.jpg|File:C.jpg⭐⭐
Pasted list of references (names, URLs, wikitext)SOP 6: normalise to titles firstpython3 scripts/parse-file-refs.py refs.txt⭐

Multi-title queries are pipe-separated; a comma is not a separator and Commons file names may contain commas — see SOP 6.


How Commons File URLs Work

The upload.wikimedia.org URL Structure

Every file on Commons has a canonical URL with this structure:

https://upload.wikimedia.org/wikipedia/commons/{hash_prefix}/{filename}

The hash_prefix is derived from the MD5 hash of the filename (including the File: namespace prefix, but as it appears in the wiki database — the first two hex characters):

md5("Example.jpg")[0:2]  →  "4d"

So File:Example.jpg lives at:

https://upload.wikimedia.org/wikipedia/commons/4/4d/Example.jpg

The hash prefix determines which of the 256 possible subdirectories the file sits in. This is the permanent, immutable base URL for a given filename.

Thumbnail URL Structure

Thumbnails follow a consistent pattern branching off the base URL:

https://upload.wikimedia.org/wikipedia/commons/thumb/{hash}/{filename}/{width}px-{filename}.{ext}

Example: File:Example.jpg at 800px width:

https://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Example.jpg/800px-Example.jpg

For SVG, PDF, and video files, the thumbnail URL may include an extra page/frame parameter:

https://upload.wikimedia.org/wikipedia/commons/thumb/{hash}/{filename}/{width}px-{filename}.png
https://upload.wikimedia.org/wikipedia/commons/thumb/{hash}/{filename}/{width}px-{filename}.jpg  # PDF->JPEG

🔗 For full thumbnail URL construction rules (responsive/retina, format conversion, file-type-specific behavior), see wikimedia-commons-thumbnails.


SOP 1: Special:FilePath/ — Simplest Server-Side Resolution

The Special:FilePath/ page redirects to the file's canonical URL. This is the easiest and most reliable method when you just need a browser-usable URL on the server side.

How It Works

https://commons.wikimedia.org/wiki/Special:FilePath/File:Example.jpg returns an HTTP 302 redirect to the canonical upload.wikimedia.org URL — or a 301 when the name needs normalising (spaces vs underscores), so accept both. The /w/ path also works:

https://commons.wikimedia.org/w/index.php?title=Special:FilePath/File:Example.jpg

Server-Side Usage (Node.js)

javascript
async function resolveCommonsFile(filename) {
    const url = `https://commons.wikimedia.org/wiki/Special:FilePath/${encodeURIComponent(filename)}`;
    const resp = await fetch(url, {
        method: 'HEAD',                 // HEAD avoids downloading the file
        redirect: 'manual',             // Don't follow the redirect — we want the URL
        headers: { 'User-Agent': 'YourApp/1.0 (contact)' },
    });
    if (resp.status !== 302 && resp.status !== 301) {
        throw new Error(`File not found: ${filename} (HTTP ${resp.status})`);
    }
    return resp.headers.get('location'); // The direct upload.wikimedia.org URL
}

Why HEAD + redirect:manual over GET:

  • HEAD avoids downloading the file just to find its URL
  • redirect: manual lets you capture the Location header instead of following it

Browser Usage

In an <img> tag, the browser follows the redirect automatically:

html
<img src="https://commons.wikimedia.org/wiki/Special:FilePath/File:Example.jpg?width=800">

The ?width= parameter adjusts thumbnail size (omitting it returns the original).

Limitations

LimitationImpact
No metadataYou only get the URL. No timestamp, size, MIME type, or license info
HEAD may not redirectSome file types return 200 instead of 302 for HEAD (rare, but confirmed for certain SVGs)
No cache-bustingThe URL is fixed — if the file is overwritten, the old URL still points to the old version (see cache busting below)
CORSupload.wikimedia.org doesn't set permissive CORS headers. Special:FilePath/ itself is on commons.wikimedia.org which has permissive CORS — but the redirect destination (upload.wikimedia.org) does NOT

SOP 2: Action API prop=imageinfo — Full Metadata + URL

When you need the URL plus metadata (timestamp, size, MIME type) in a single call, use the Action API. This is the most robust method.

Basic Query

http
GET https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&titles=File:Example.jpg&iiprop=url|timestamp|size|mime&format=json

Response Structure

json
{
  "query": {
    "pages": {
      "12345": {
        "pageid": 12345,
        "ns": 6,
        "title": "File:Example.jpg",
        "imageinfo": [
          {
            "url": "https://upload.wikimedia.org/wikipedia/commons/4/4d/Example.jpg",
            "descriptionurl": "https://commons.wikimedia.org/wiki/File:Example.jpg",
            "thumburl": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Example.jpg/800px-Example.jpg",
            "thumbwidth": 800,
            "thumbheight": 600,
            "timestamp": "2024-06-15T12:34:56Z",
            "size": 1234567,
            "width": 4000,
            "height": 3000,
            "mime": "image/jpeg"
          }
        ]
      }
    }
  }
}

Key Properties

FieldPurpose
urlDirect canonical URL — use this for <img> or as the panorama URL in Pannellum
thumburlPre-generated thumbnail URL (defaults to 800px wide)
timestampLast modification timestamp — essential for cache busting
size, width, heightFile size and dimensions
mimeMIME type — useful for format detection

Custom Thumbnail Size via iiurlwidth

http
GET https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&titles=File:Example.jpg&iiurlwidth=1920&format=json

The response includes thumburl, thumbwidth, and thumbheight for the requested width.

Batch Resolution (Multiple Files)

Query up to 50 files in a single request:

http
GET https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&titles=File:A.jpg|File:B.jpg|File:C.jpg&iiprop=url|timestamp&format=json

Node.js Implementation

javascript
async function resolveCommonsFile(filename) {
    const url = 'https://commons.wikimedia.org/w/api.php?' + new URLSearchParams({
        action: 'query',
        prop: 'imageinfo',
        titles: filename,
        iiprop: 'url|timestamp|size|mime',
        format: 'json',
    });
    const resp = await fetch(url, {
        headers: { 'User-Agent': 'YourApp/1.0 (contact)' },
    });
    const data = await resp.json();
    const pages = data?.query?.pages;
    if (!pages) throw new Error('API returned no pages');
    const page = Object.values(pages)[0];
    if (!page || page.missing === '') throw new Error(`File not found: ${filename}`);
    return page.imageinfo[0];
}

Returns: { url, thumburl, thumbwidth, thumbheight, timestamp, size, width, height, mime }


SOP 3: Cache Busting — Always Get the Latest Version

Files on Commons can be overwritten with new versions (new upload to the same filename). The canonical URL (upload.wikimedia.org/...) is immutable per upload — if the file is overwritten, a NEW hash-based path is created, and the old URL still serves the OLD version.

To always get the latest version, append the file's timestamp as a query parameter:

javascript
const info = await resolveCommonsFile('File:Example.jpg');
const unixTimestamp = new Date(info.timestamp).getTime();  // e.g., 1718469296000
const bustedUrl = info.url + '?v=' + unixTimestamp;
// → https://upload.wikimedia.org/wikipedia/commons/4/4d/Example.jpg?v=1718469296000

The ?v= parameter is respected by Commons' CDN/Varnish layer — it treats URLs with different ?v= as distinct cache entries.

Cache Busting for Thumbnails

Apply the same pattern to thumbnails:

javascript
const bustedThumb = info.thumburl + '?v=' + new Date(info.timestamp).getTime();

Updating Cached URLs

When you've cached a file locally (see SOP 4), re-resolve periodically or on error:

javascript
// If an image fails to load, re-resolve in case it was overwritten
async function getFreshUrl(filename) {
    const info = await resolveCommonsFile(filename);
    return info.url + '?v=' + new Date(info.timestamp).getTime();
}

SOP 4: Same-Origin Serving for WebGL / Canvas Applications

Browsers that use WebGL (e.g., Pannellum 360° viewer) or Canvas 2D faces a CORS problem: upload.wikimedia.org does not set Access-Control-Allow-Origin: *. This means:

  • ❌ <img> tags work fine (CORS doesn't affect display)
  • ❌ fetch() to upload.wikimedia.org fails for cross-origin reads
  • ❌ WebGL textures from upload.wikimedia.org fail with security errors
  • ✅ Proxied images from your own server work everywhere

Solution: Local Image Cache

Download images from Commons through your server, caching them locally, and serve them from your own domain. This gives you:

  • ✅ Same-origin WebGL/CORS compatibility
  • ✅ Faster repeat loads (local cache)
  • ✅ Cache control headers you control
  • ✅ Bandwidth savings (one download from Commons, many serves to clients)

Server-Side Implementation (Node.js, zero dependencies)

javascript
import { createHash } from 'node:crypto';
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { join } from 'node:path';

const CACHE_DIR = './images';
const USER_AGENT = 'YourApp/1.0 (contact)';

async function resolveCommonsFile(filename) {
    const apiUrl = 'https://commons.wikimedia.org/w/api.php?' + new URLSearchParams({
        action: 'query',
        prop: 'imageinfo',
        titles: filename.startsWith('File:') ? filename : 'File:' + filename,
        iiprop: 'url|timestamp',
        format: 'json',
    });
    const resp = await fetch(apiUrl, {
        headers: { 'User-Agent': USER_AGENT },
    });
    const data = await resp.json();
    const page = Object.values(data.query.pages)[0];
    if (!page || page.missing === '') throw new Error(`File not found: ${filename}`);
    const info = page.imageinfo[0];
    return {
        url: info.url + '?v=' + new Date(info.timestamp).getTime(),
        thumb: info.thumburl + '?v=' + new Date(info.timestamp).getTime(),
        original: info.url,
        timestamp: info.timestamp,
    };
}

async function cacheImage(sourceUrl) {
    const hash = createHash('sha256').update(sourceUrl).digest('hex').substring(0, 16);
    const cachePath = join(CACHE_DIR, hash + '.jpg');
    const cacheMeta = join(CACHE_DIR, hash + '.json');

    // Serve from cache if available
    if (existsSync(cachePath)) {
        const meta = JSON.parse(await readFile(cacheMeta, 'utf-8'));
        return { url: '/images/' + hash + '.jpg', thumb: meta.thumb, original: meta.original };
    }

    // Download and cache
    if (!existsSync(CACHE_DIR)) await mkdir(CACHE_DIR, { recursive: true });
    const resp = await fetch(sourceUrl, {
        headers: { 'User-Agent': USER_AGENT },
    });
    if (!resp.ok) throw new Error(`Failed to download: HTTP ${resp.status}`);
    const buffer = Buffer.from(await resp.arrayBuffer());
    await writeFile(cachePath, buffer);

    // Determine extension from MIME type
    const contentType = resp.headers.get('content-type') || 'image/jpeg';
    const ext = { 'image/jpeg': '.jpg', 'image/png': '.png', 'image/webp': '.webp' }[contentType] || '.jpg';
    const finalPath = join(CACHE_DIR, hash + ext);
    if (finalPath !== cachePath) {
        // Remove old .jpg path, write with correct extension
        await writeFile(finalPath, buffer);
    }

    return { url: '/images/' + hash + ext, thumb: null, original: sourceUrl };
}

Serving Cached Images

javascript
import { createServer } from 'node:http';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';

const MIME = {
    '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
    '.png': 'image/png',  '.webp': 'image/webp',
};

createServer(async (req, res) => {
    const url = new URL(req.url, 'http://localhost');

    // Serve cached images with proper headers
    if (url.pathname.startsWith('/images/')) {
        const filePath = join(CACHE_DIR, url.pathname.slice(8));
        try {
            const data = await readFile(filePath);
            const ext = '.' + filePath.split('.').pop();
            res.writeHead(200, {
                'Content-Type': MIME[ext] || 'application/octet-stream',
                'Content-Length': data.length,
                'Cache-Control': 'public, max-age=604800, immutable',  // 1 week
            });
            res.end(data);
        } catch {
            res.writeHead(404); res.end('Not found');
        }
        return;
    }

    // API endpoint to resolve and cache
    if (url.pathname === '/api/resolve') {
        const file = url.searchParams.get('file');
        if (!file) { res.writeHead(400); res.end('Missing file param'); return; }
        try {
            const resolved = await resolveCommonsFile(file);
            const cached = await cacheImage(resolved.url);
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify(cached));
        } catch (e) {
            res.writeHead(404, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify({ error: e.message }));
        }
        return;
    }

    res.writeHead(404); res.end();
}).listen(8765);

Cache Resolution Flow

                   ┌──────────────────────┐
                   │  Browser              │
                   │  (Pannellum Viewer)   │
                   └──────────┬───────────┘
                              │
                        GET /images/abc123.jpg
                              │
                   ┌──────────▼───────────┐
                   │  Your Server          │
                   │  (same origin ✓)      │
                   │                       │
                   │  File on disk?        │
                   │   ├── YES → serve     │
                   │   └── NO  →           │
                   │    1. Fetch from      │
                   │       upload.wikime-  │
                   │       dia.org         │
                   │    2. Save to cache   │
                   │    3. Serve to client │
                   └───────────────────────┘

Caching Caveats

ConcernMitigation
Stale images (file overwritten on Commons)Re-resolve periodically or on 404. Include ?v= timestamp in source URL before caching.
Disk spaceImplement LRU eviction. 500MB is a safe cap for most tools.
Concurrent requests for same missing imageUse a promise cache: if a download is in-flight, queue other requests for the same URL.
Extension guessingUse Content-Type from the download response, not the filename.
Cache directory growthDelete files accessed > N days ago via a periodic cleanup job.

When NOT to Cache Locally

  • You only need to display images in <img> tags (no WebGL/Canvas) → use Special:FilePath/ directly
  • You need thumbnails at varying sizes → use Special:FilePath/?width=N or the thumbnail API
  • Your traffic is very low → the complexity isn't worth it

SOP 5: Beyond Commons — Cross-Wiki File Resolution

Files can also be hosted on other wikis (e.g., File:Example.jpg on English Wikipedia). The action=query API works across all wikis:

javascript
const WIKI_CONFIGS = {
    commons: 'https://commons.wikimedia.org/w/api.php',
    en:      'https://en.wikipedia.org/w/api.php',
    de:      'https://de.wikipedia.org/w/api.php',
    // ... any wiki prefix
};

async function resolveFileAcrossWikis(filename, wikiPrefix = 'commons') {
    const apiUrl = WIKI_CONFIGS[wikiPrefix];
    if (!apiUrl) throw new Error(`Unknown wiki: ${wikiPrefix}`);
    const url = apiUrl + '?' + new URLSearchParams({
        action: 'query',
        prop: 'imageinfo',
        titles: filename,
        iiprop: 'url|timestamp',
        format: 'json',
    });
    const resp = await fetch(url, {
        headers: { 'User-Agent': 'YourApp/1.0 (contact)' },
    });
    const data = await resp.json();
    const page = Object.values(data.query.pages)[0];
    if (!page || page.missing === '') throw new Error(`File not found on ${wikiPrefix}`);
    return page.imageinfo[0];
}

Note: Files on non-Commons wikis may link to Commons via the InstantCommons mechanism — the API returns the Commons URL in that case.


SOP 6: From Pasted References to File: Titles

Users paste whatever their clipboard holds — a bare filename, a wikitext embed, a page URL, a thumbnail URL. Normalise every line to a File: title first, then resolve with SOP 1–5. A pasted string is not a title until you make it one.

1. Recognise the forms

Pasted reference→ titleNote
Foo.jpgFile:Foo.jpgbare name from a list or spreadsheet column
File:Foo.jpg, Image:Foo.jpgunchangedprefix casing is folded by MediaWiki
[[File:Foo.jpg|thumb|Caption, with commas]]File:Foo.jpgcut at the first |
https://commons.wikimedia.org/wiki/File:Example.jpgFile:Example.jpg%-decode, _ → space
…/w/index.php?title=File:Foo.jpgFile:Foo.jpgtake the query parameter, not the path
…/wiki/Special:FilePath/Foo.jpg, …/Special:Redirect/file/Foo.jpgFile:Foo.jpgstrip a leading File: from the tail
https://upload.wikimedia.org/wikipedia/commons/{h}/{h}/Foo.jpgFile:Foo.jpgthe /wikipedia/<project>/ segment names the wiki (SOP 5)
…/thumb/{h}/{h}/Foo.jpg/640px-Foo.jpg (also thumb.wikimedia.org)File:Foo.jpgstrip the NNNpx- prefix
https://en.wikipedia.org/wiki/File:Wiki.pngFile:Wiki.png on en.wikipedia.orgresolve with that wiki's api.php

2. Normalise with stdlib Python

scripts/parse-file-refs.py implements this table (stdlib, argparse; --json adds the wiki, --default-wiki sets what bare names belong to):

console
$ printf '%s\n' "Foo.jpg" "https://en.wikipedia.org/wiki/File:Wiki.png" | python3 scripts/parse-file-refs.py --json
[
  {"raw": "Foo.jpg", "title": "File:Foo.jpg", "wiki": "commons.wikimedia.org"},
  {"raw": "https://en.wikipedia.org/wiki/File:Wiki.png", "title": "File:Wiki.png", "wiki": "en.wikipedia.org"}
]
$ python3 scripts/parse-file-refs.py "File:MKr377445 Susanne Wuest (In die Sonne schauen, Cannes 2025).jpg"
File:MKr377445 Susanne Wuest (In die Sonne schauen, Cannes 2025).jpg

Unparseable lines and characters that cannot appear in a title go to stderr and exit code 1 — never a silent drop.

3. Batch per wiki, joined with |

python
import json
import urllib.parse
import urllib.request

def resolve(entries, thumb_width=640):
    """entries: [{"title": "File:Foo.jpg", "wiki": "commons.wikimedia.org"}, ...]"""
    out = {}
    for wiki in {e["wiki"] for e in entries}:
        titles = [e["title"] for e in entries if e["wiki"] == wiki]
        params = urllib.parse.urlencode({
            "action": "query", "format": "json", "formatversion": "2", "redirects": 1,
            "prop": "imageinfo", "iiprop": "url|size|mime|sha1|extmetadata",
            "iiurlwidth": thumb_width,
            "titles": "|".join(titles),          # "|", never ","
        })
        req = urllib.request.Request(
            f"https://{wiki}/w/api.php?{params}",
            headers={"User-Agent": "YourTool/1.0 (contact) ProjectName/1.0"})
        with urllib.request.urlopen(req, timeout=60) as resp:
            data = json.load(resp)
        # key by (wiki, page["title"]) and map query.normalized / query.redirects back onto
        # the string the user pasted, so the report can show "pasted X -> resolved to Y"
        for page in data.get("query", {}).get("pages", []):
            out[(wiki, page["title"])] = (page.get("imageinfo") or [{}])[0]
    return out

Pitfalls

  • Never split a pasted list on commas or semicolons. Commas are legal in Commons file names, and titles= does not treat a comma as a separator: titles=File:A.jpg,File:B.jpg returns one page titled File:A.jpg,File:B.jpg — HTTP 200, no warning (measured 2026-10-13). Join batches with |. Split a line only when what follows a separator is clearly a new entry (a File:/Image:/http/[[ prefix, or a piece that itself ends in a media extension).
  • # silently truncates. File:Example#1.jpg normalises to File:Example; everything after # is dropped. Truncate deliberately and report it. Same rule for a file-page link pasted with a fragment (…/File:Foo.jpg#/media/File:Bar.jpg).
  • MediaWiki title characters are limited. # < > [ ] | { } cannot appear in a title — upload-time rules live in the pattypan skill. A pasted name containing one cannot exist, so say that instead of reporting a bare "not found".
  • upload.wikimedia.org/wikipedia/<project>/… names the wiki (commons, en, de, meta, species…). A file on en.wikipedia.org is not on Commons — query that wiki's api.php (SOP 5).
  • Namespace aliases are per-wiki. On Commons only File:/Image: resolve; Datei:, Fichier:, Archivo: are de/fr/es aliases and come back unresolved if you send them to Commons.
  • Special:FilePath/ answers 301 or 302 — 301 when the name needs normalising (spaces vs underscores), 302 otherwise. Check both, and strip a duplicated File: prefix: Special:FilePath/File:File:X.jpg redirects to a wrong name.
  • Deduplicate on (wiki, case-folded title) before batching. A typical paste contains the same file as a bare name, a URL, and a thumbnail URL; pageids are only unique per wiki.

Reference: URL Patterns Cheat Sheet

WhatURL Pattern
Direct file URLhttps://upload.wikimedia.org/wikipedia/commons/{hash[0:2]}/{hash}/{filename}
Thumbnailhttps://upload.wikimedia.org/wikipedia/commons/thumb/{hash}/{filename}/{width}px-{filename}.{ext}
Special:FilePathhttps://commons.wikimedia.org/wiki/Special:FilePath/File:{filename}
Special:FilePath with widthhttps://commons.wikimedia.org/wiki/Special:FilePath/File:{filename}?width={width}
API imageinfohttps://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&titles=File:{filename}&iiprop=url|timestamp
Cache-busted{url}?v={unix_timestamp_ms}
Local cached/images/{sha256_prefix}.{ext}

Reference: CORS Behavior by URL Type

URL TypeCORS HeadersWebGL Safe<img> Tagfetch()
commons.wikimedia.org/wiki/...Access-Control-Allow-Origin: *✅✅✅
upload.wikimedia.org/...None❌✅❌
Your server /images/...You control them✅✅✅
Special:FilePath/ redirectNone on destination❌✅❌

See Also

  • wikimedia-commons-thumbnails — Full thumbnail URL construction, responsive sizes, format conversion
  • pattypan — Filename validation rules (# < > [ ] | { } are rejected, : / \ are converted) for names you are about to create or check
  • wikimedia-commons — File search, metadata, upload, categories
  • wikimedia-api-access — User-Agent, rate limiting, error handling
  • CAVEATS.md in the Photosphere Tours project — Real-world gotchas from a browser app that heavily uses file resolution

Συνοδευτικά αρχεία

Το μοντέλο τα διαβάζει όποτε χρειάζεται, όσο η δεξιότητα είναι φορτωμένη. Διατίθενται ως αρχεία για ανάγνωση και δεν εκτελούνται ποτέ.

Συχνές ερωτήσεις

Τι κάνει η δεξιότητα AI Commons File Resolution;

Resolve Wikimedia Commons file references (File:Example.jpg) to browser-usable HTTP URLs — direct origin URLs, thumbnails, Special:FilePath redirects, cache-busting with timestamps, Action API imageinfo queries, and CORS-aware serving patterns for web applications

Γιατί να χρησιμοποιήσετε τη δεξιότητα Commons File Resolution στο TypingMind;

Επειδή την εγκαθιστάτε μία φορά και τη χρησιμοποιείτε με οποιοδήποτε μοντέλο. Η Commons File Resolution είναι απλό Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως η ίδια δεξιότητα λειτουργεί με GPT-5, Claude, Gemini, Grok ή ένα τοπικό μοντέλο — και μπορείτε να αλλάξετε μοντέλο κατά τη διάρκεια της συνομιλίας χωρίς να διακοπεί η λειτουργία της. Το TypingMind λειτουργεί με τα δικά σας κλειδιά API, οπότε πληρώνετε απευθείας τους παρόχους αντί για συνδρομή ανά θέση χρήστη, ενώ οι δεξιότητες και οι συνομιλίες σας παραμένουν στον δικό σας χώρο αποθήκευσης.

Πώς εγκαθιστώ τη δεξιότητα Commons File Resolution στο TypingMind;

Στο TypingMind, ανοίξτε Πρόσθετα → Δεξιότητες → Εγκατάσταση από το GitHub και επικολλήστε τη διεύθυνση https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/commons-file-resolution. Το TypingMind διαβάζει το αρχείο SKILL.md, συγκεντρώνει τα συνοδευτικά αρχεία και εγκαθιστά τη δεξιότητα, την οποία μπορείτε να ενεργοποιείτε ανά συνομιλία.

Ποια μοντέλα AI μπορούν να χρησιμοποιήσουν τη δεξιότητα Commons File Resolution;

Οποιοδήποτε μοντέλο συνδέετε στο TypingMind. Οι δεξιότητες AI είναι απλές οδηγίες Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως τα GPT, Claude, Gemini, Grok και τα τοπικά μοντέλα μπορούν όλα να φορτώσουν αυτή τη δεξιότητα όταν ένα αίτημα αντιστοιχεί σε αυτή.

Με πόσα μοντέλα AI μπορώ να χρησιμοποιήσω τη δεξιότητα Commons File Resolution;

Με όσα θέλετε. Στο TypingMind μπορείτε να χρησιμοποιήσετε τη δεξιότητα Commons File Resolution με οποιοδήποτε μοντέλο υποστηρίζει δεξιότητες, όπως τα GPT, Claude, Gemini, Grok, DeepSeek, Mistral και Llama, χρησιμοποιώντας τα δικά σας κλειδιά API.

Είναι δωρεάν η δεξιότητα AI Commons File Resolution;

Ναι. Δημοσιεύεται στο GitHub από τον λογαριασμό fuzheado με την άδεια χρήσης MIT. Πληρώνετε μόνο τον δικό σας πάροχο AI για τα token που χρησιμοποιείτε.

Τι είναι οι δεξιότητες AI;

Μια δεξιότητα AI είναι ένα επαναχρησιμοποιήσιμο πακέτο οδηγιών που διδάσκει σε ένα μοντέλο AI πώς να εκτελεί μια συγκεκριμένη εργασία. Ακολουθεί την ανοιχτή μορφή Agent Skills: ένα αρχείο SKILL.md με όνομα και περιγραφή, μαζί με τυχόν σενάρια κώδικα, πρότυπα ή αρχεία αναφοράς που μπορεί να χρειαστεί το μοντέλο. Το μοντέλο διαβάζει τις οδηγίες μόνο όταν το αίτημά σας αντιστοιχεί στη δεξιότητα, οπότε μια εγκατεστημένη δεξιότητα δεν κοστίζει τίποτα μέχρι να χρησιμοποιηθεί.

Σε τι διαφέρουν οι δεξιότητες AI από τα πρόσθετα ή τους συνδέσμους MCP;

Ένα πρόσθετο ή ένας σύνδεσμος MCP παρέχει στο μοντέλο νέα εργαλεία που μπορεί να καλέσει — κώδικα που εκτελείται κάπου και επιστρέφει ένα αποτέλεσμα. Μια δεξιότητα AI παρέχει αντί γι’ αυτό γνώσεις και διαδικασίες στο μοντέλο: πώς να προσεγγίσει μια εργασία, ποια βήματα να ακολουθήσει και ποια χαρακτηριστικά έχει ένα καλό αποτέλεσμα. Οι δεξιότητες είναι απλό Markdown, επομένως δεν χρειάζονται διακομιστή, κλειδί API ή περιβάλλον εκτέλεσης και λειτουργούν με οποιοδήποτε μοντέλο.

Προβολή όλων

Δημιουργήστε τώρα τον δικό σας χώρο εργασίας AI

Εγγραφείτε στο ενημερωτικό μας δελτίο για να ενημερώνεστε για νέες λειτουργίες και μελλοντικές κληρώσεις δώρων 👇