Jump to content

Extension:InterwikiDispatcher

From mediawiki.org
MediaWiki extensions manual
InterwikiDispatcher
Release status: stable
Implementation Link markup
Description Adding some simple multi-level interwikis for easier linking to wiki farms.
Author(s)
Latest version 1.4.2
MediaWiki 1.35+
PHP 7.4+
Database changes No
License GNU General Public License 2.0 or later
Download
$wgIWDPrefixes
Public wikis using 6,844 (Ranked 61st)

The InterwikiDispatcher extension adds some simple multi-level interwikis for easier linking to wiki farms.

Hooking into existing interwiki prefixes to provide some limited API support. Subdomain part of the interwiki is validated as a-z\d- to avoid open redirect vulnerabilities. Scary transclusion will work when enabled for the interwiki prefix.

Installation

[edit]

Configuration

[edit]

$wgIWDPrefixes is the sole variable controlling this extension's behaviour. The format is an array (keys do not matter) where values are associative arrays of parameters. These parameters are:

  • 'interwiki' (required): the interwiki prefix to apply this rule to.
    • This prefix must be a valid and defined interwiki prefix.
  • 'subprefix': optional sub-prefix, which will be expected right after the interwiki prefix. For example a prefix of 'p' and sub-prefix of 's' results in links of format [[p:s:wiki:article]] and [[p:s:language.wiki:article]].
  • 'url' (required): external URL format. Placeholder $1 stands for page title, $2 for wiki domain.
    • Example: 'https://$2.fandom.com/wiki/$1'
  • 'urlInt': optional international external URL format. Placeholder $3 stands for the language.
    • Example: 'https://$2.fandom.com/$3/wiki/$1'
  • 'baseTransOnly': if true, falls back to the base, classic interwiki during scary transclusion.
    • Default: false
  • 'dbname': optional wiki ID format, used to check whether a wiki exists locally via $wgLocalDatabases. Placeholder $2 is the wiki domain.
    • Example: '$2_en'
  • 'dbnameInt': optional international wiki ID format, used to check whether a wiki exists locally via $wgLocalDatabases. Placeholder $2 is the wiki domain, $3 is the language.
    • Example: '$2_$3'
  • 'wikiExistsCallback': optional custom function to check if a wiki exists. This completely replaces the DB check of dbname, dbnameInt.
    • function ( $rule, &$wiki, &$language ): bool: Takes this array as $rule, domain as &$wiki, language as &$language (or empty string). Both $wiki and $language are out parameters: the callback may override them as needed.

Examples

[edit]
# [[w:c:minecraft]] => https://minecraft.fandom.com/wiki/
# [[w:c:minecraft:Cookie]] => https://minecraft.fandom.com/wiki/Cookie
# [[w:c:de.minecraft:Keks]] => https://minecraft.fandom.com/de/wiki/Keks
$wgIWDPrefixes[] = [
  'interwiki' => 'w', # Interwiki prefix that exists in the interwiki table
  'subprefix' => 'c', # Optional: Subprefix to keep the base interwiki working mostly as expected
  'url' => 'https://$2.fandom.com/wiki/$1', # URL format for the interwiki `w:c:$2:$1` ($1: page title, $2: domain)
  'urlInt' => 'https://$2.fandom.com/$3/wiki/$1', # Optional: Additional URL format `w:c:$3.$2:$1` ($3: language).
  'baseTransOnly' => true, # Optional: Fall back to the base interwiki for scary transclusion
  'dbname' => '$2_en', # Optional: Wiki ID format to check existence via `$wgLocalDatabases`, subdomain as $2, language unspecified
  'dbnameInt' => '$2_$3', # Optional: As above, but language provided as $3
  'wikiExistsCallback' => null, # Optional: Custom function to check if the wiki exists, replaces the DB check.
                                # Takes this array as `$rule`, domain as `&$wiki`, language as `&$language` (or empty string).
];
# [[gg:terraria]] => https://terraria.wiki.gg/wiki/
# [[gg:terraria:NPCs]] => https://terraria.wiki.gg/wiki/NPCs
# [[gg:de.terraria:NPCs]] => https://terraria.wiki.gg/de/wiki/NPCs
$wgIWDPrefixes[] = [
  'interwiki' => 'gg',
  'url' => 'https://$2.wiki.gg/wiki/$1',
  'urlInt' => 'https://$2.wiki.gg/$3/wiki/$1',
  'dbname' => '$2_en',
  'dbnameInt' => '$2_$3',
];
# [[mh:meta]] => https://meta.miraheze.org/wiki/
# [[mh:meta:Miraheze]] => https://meta.miraheze.org/wiki/Miraheze
$wgIWDPrefixes[] = [
  'interwiki' => 'mh',
  'url' => 'https://$2.miraheze.org/wiki/$1',
];
$wgIWDPrefixes = [
  # [[farm:mh:meta]] => https://meta.miraheze.org/wiki/
  # [[farm:mh:meta:Miraheze]] => https://meta.miraheze.org/wiki/Miraheze
  'miraheze' => [
    'interwiki' => 'farm',
    'subprefix' => 'mh',
    'url' => 'https://$2.miraheze.org/wiki/$1',
  ],
  # [[farm:fd:minecraft]] => https://minecraft.fandom.com/wiki/
  # [[farm:fd:minecraft:Cookie]] => https://minecraft.fandom.com/wiki/Cookie
  # [[farm:fd:de.minecraft:Keks]] => https://minecraft.fandom.com/de/wiki/Keks
  'fandom' => [
    'interwiki' => 'farm',
    'subprefix' => 'fd',
    'url' => 'https://$2.fandom.com/wiki/$1',
    'urlInt' => 'https://$2.fandom.com/$3/wiki/$1',
  ],
  # [[farm:gg:terraria]] => https://terraria.wiki.gg/wiki/
  # [[farm:gg:terraria:NPCs]] => https://terraria.wiki.gg/wiki/NPCs
  # [[farm:gg:de.terraria:NPCs]] => https://terraria.wiki.gg/de/wiki/NPCs
  'wikigg' => [
    'interwiki' => 'farm',
    'subprefix' => 'gg',
    'url' => 'https://$2.wiki.gg/wiki/$1',
    'urlInt' => 'https://$2.wiki.gg/$3/wiki/$1',
  ],
];

Extension:Interwiki integration

[edit]

When Extension:Interwiki is enabled, an additional table for "Multi-level interwiki prefixes" will be added to Special:Interwiki listing the interwikis managed by this extension.