InstantCommons
InstantCommons ist ein Feature von MediaWiki, das die Nutzung von beliebigen Medien aus Wikimedia Commons in jeder beliebigen MediaWiki-Installation weltweit ermöglicht.
Gründe
Im November 2023 enthielt das zentrale Medienarchiv Wikimedia Commons, das von der Wikimedia Foundation gehostet wird, über 100 Millionen Dateien. Alle diese Dateien sind unter einer freien Lizenz verfügbar oder gemeinfrei und es gibt neben den Beschränkungen zur Nutzung offizieller Hoheitszeichen oder Marken keine weiteren Beschränkungen. Lizenzen, die die kommerzielle Nutzung einschränken, werden als unfrei betrachtet.
Mit wachsendem Bewusstsein für die Existenz von Commons wächst auch der Wunsch externer Parteien, die darin enthaltenen Inhalte zu nutzen und neues Material beizutragen. Es ist im Moment technisch möglich, Bilder direkt von Wikimedia-Servern in den Kontext einer beliebigen Webseite zu laden. Dieses "Hotlinking" ist erlaubt, aber aus mehreren Gründen problematisch:
- Es respektiert die Lizenzbedingungen des Bildes nicht und gewährleistet nicht, dass andere Metadaten verlässlich transportiert werden
- Abgesehen davon, dass der Autor der Mediendatei nicht ordnungsgemäß genannt wird, wird Wikimedia auch nicht genannt
- Es nutzt bei jedem Seitenaufruf Bandbreite von Wikimedia (es sei denn, wenn das Bild clientseitig oder von einem Proxy gecacht wurde; diese Funktion ist derzeit standardmäßig deaktiviert)
- Es macht nützliche Bildoperationen, wie das Erstellen von Vorschaubildern oder das Einfügen von Bildunterschriften nicht leichter und ist innerhalb eines Wikis schwierig zu nutzen, insbesondere bei Standard-Layouts
- Es ist an URLs zum Identifizieren einer Ressource gebunden, was Mirroring komplizierter macht
- Es entsteht ein nicht nachvollziehbares Netz von externen Nutzern, bei dem sich jede Änderung auf Seiten von Wikimedia zwangsläufig auf diese externen Nutzer auswirkt
- Es erlaubt keine Offline-Betrachtung, was in Ländern mit eingeschränktem Netzzugang problematisch ist.
InstantCommons versucht, all diese Probleme zu adressieren, indem es eine einfache Methode zum gecachten Laden von Bildern und Metadaten von Wikimedia-Servern zur Verfügung stellt. Although caching functionality is part of the objective, it has been disabled since MediaWiki 1.27.2/1.28.1. InstantCommons was first implemented within MediaWiki, allowing for all MediaWiki image operations (thumbnailing, captioning, galleries, etc.) to be performed transparently. Nichtsdestotrotz können auch andere Wiki-Engines InstantCommons-ähnliche Funktionen implementieren, indem sie die unten beschriebenen API-Operationen nutzen.
Grundlegende Funktionen
Während der Installation kann der Seiten-Administrator auswählen, ob InstantCommons aktiviert werden soll. Idealerweise sollte das Feature allerdings standardmäßig aktiviert sein (gesetzt dem Fall, dass ein beschreibbares Upload-Verzeichnis angegeben ist), um es der größtmöglichen Anzahl Nutzer zu ermöglichen, Inhalte von Wikimedia Commons zu nutzen.
If the feature is enabled, the wiki behaves like a Wikimedia project, that is, if an image or other media file is referred to which exists on Commons, it can be included in a wiki page like a locally uploaded file by specifying its name. Local filenames take precedence over Commons filenames.
Konfiguration
Standardmethode: $wgUseInstantCommons
Um InstantCommons in MediaWiki Version 1.16 oder höher zu aktivieren, reicht es aus, diese Zeile zu LocalSettings.php
hinzuzufügen (siehe $wgUseInstantCommons für Details):
$wgUseInstantCommons = true;
Classic InstantCommons with local thumb caching
Default InstantCommons as enabled through $wgUseInstantCommons uses thumb images hotlinked from Wikimedia.[1]
This may be slow and may also interfere with file caching (broken links).
If you would like to generate and use thumbs on your local server, do not use $wgUseInstantCommons
.
Instead, insert this code into LocalSettings.php as described here: Manual:$wgForeignFileRepos#Usage.
$wgForeignFileRepos[] = [
'class' => ForeignAPIRepo::class,
'name' => 'commonswiki', // Must be a distinct name
'apibase' => 'https://commons.wikimedia.org/w/api.php',
'hashLevels' => 2,
'fetchDescription' => true, // Optional
'descriptionCacheExpiry' => 43200, // 12 Stunden, optional (Werte in Sekunden)
'apiThumbCacheExpiry' => 86400, // 24 hours, optional, but required for local thumb caching
];
Dateien über InstantCommons nutzen
With InstantCommons enabled, you can choose any image from Wikimedia Commons (e.g. this one), click the "Use this file" button (the button with the wiki icon next to) and paste the markup in your wiki.
In unserem Beispiel wird das Einfügen von
[[File:Wikipedia-Marker-commons.svg|thumb|Ein Bild von Wikimedia Commons, das in dieses Wiki eingebettet ist]]
dieses Vorschaubild erzeugen (siehe rechts).
Bitte beachten Sie, dass Sie, wenn Sie Dateien auf diese Weise nutzen, immer noch die Lizenzbestimmungen und alle anderen rechtlichen Anforderungen für die Nutzung der Datei beachten müssen - siehe dazu: Commons:Reusing content outside Wikimedia.
Troubleshooting
Set custom user agent
Since 2025, Wikimedia Commons may categorize your wiki as an unidentified origin and throttle or block its requests. This is due to enforcement of the Wikimedia Foundation User-Agent Policy, to mitigate the increase of automated scraping.
Unfortunately, the User-Agent used by InstantCommons did not set any origin. This will be fixed in MediaWiki 1.45 (including MediaWiki 1.39.14+, 1.43.4+, and 1.44.1+). If you encounter a throttling or block message when using InstantCommons, please add the below code snippet to the end of your LocalSettings.php file. This snippet is compatible with MediaWiki 1.34 and later:
$wgUseInstantCommons = false;
$wgForeignFileRepos[] = [
'class' => ForeignAPIRepoWithFixedUA::class,
'name' => 'wikimediacommons',
'apibase' => 'https://commons.wikimedia.org/w/api.php',
'url' => 'https://upload.wikimedia.org/wikipedia/commons',
'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
'directory' => $wgUploadDirectory,
'hashLevels' => 2,
'transformVia404' => true,
'fetchDescription' => true,
'descriptionCacheExpiry' => 43200,
'apiThumbCacheExpiry' => 0,
];
class ForeignAPIRepoWithFixedUA extends \ForeignAPIRepo {
public static function getUserAgent() {
global $wgCanonicalServer;
$mediaWikiVersion = 'MediaWiki/' . MW_VERSION;
return "$mediaWikiVersion ($wgCanonicalServer) ForeignAPIRepo/T400881";
}
}
HTTPS
Since June 2015, Wikimedia Commons can only be accessed using HTTPS. Some installs may be missing their root certificate store which prevents MediaWiki from contacting Commons over HTTPS. If InstantCommons stopped working, try:
- Installing the php curl extension. (It is generally more reliable, and more likely to have proper certificates already installed.) On Debian/Ubuntu:
sudo apt-get install php-curl
- Verifying you have an up-to-date certificate store. If you have the php curl extension installed, follow the instructions webaware or Talk:InstantCommons#Stop_working.
- Make sure the PHP function
curl_exec()
is not disabled in your web server.
SElinux
If your server OS implements SElinux, please take a look at the dedicated section on the SELinux settings page, and make sure HTTPD scripts and modules can access the network successfully. If SElinux prevents HTTPD scripts and modules from connecting to WikiMedia Commons repository, the InstantCommons feature will simply not work.
Hinter einer Firewall
If the server on which the wiki runs is behind a firewall, the wiki server must be granted outgoing http/https requests to commons.wikimedia.org and upload.wikimedia.org, for Instant Commons to work. The IP address ranges are found at wikitech:IP addresses.
If you need to use a proxy to access the internet from behind the firewall, see $wgHTTPProxy .
Siehe auch
- Handbuch:$wgForeignFileRepos – for the same functionality as InstantCommons but with other wikis
- PhotoCommons – Ein Wordpress-Plugin, das die selbe Funktionalität bereitstellt
- Beispiele von Seiten, die InstantCommons benutzen
- Extension:QuickInstantCommons