Search code examples
mediawikiwikihotlinking

Displaying a distant image on a (MediaWiki) wiki?


I run a Wiki hosted in a Wikifarm, using MediaWiki.

I'd like to know if hotlinking an image (not being in Wikipedia Commons) is possible:

Showing this image without downloading it.

Would I need special extensions to do that, or is it simply impossible to do?


Solution

  • I'm not sure what you mean with "showing an image without downloading it". It you mean a similar functionality as InstantCommons (showing an image from Wikimedia Commons on your "local" wiki), then this still needs to be downloaded somewhere.

    If you mean such a functionality, you can, of course, use images of another wiki. There're multiple ways of doing it, all of them can be configured using the $wgForeignFileRepos config variable. This allows you to define one or more file repositories, which are not your own wiki (in fact, instant commons is using the same configuration to actually do it's magic).

    You could, e.g., use the API of your other wiki to use the images from there:

    $wgForeignFileRepos[] = [
        'class' => 'ForeignAPIRepo',
        'name' => 'choose_your_name', // Must be a distinct name
        'apibase' => 'https://other.wiki.domain/w/api.php',
        'hashLevels' => 2,
        'fetchDescription' => true,
        'descriptionCacheExpiry' => 43200,
        'apiThumbCacheExpiry' => 86400,
    ];
    

    There're also other examples on the documentation where you can probably find ways of having a more performance optimized way to access images, e.g. through the database.