How to get Mediawiki interwiki links to open in a new tab?
Mediawiki is a popular software used for creating and managing wikis. It allows users to easily create interwiki links, which are links to other wikis or websites. By default, when a user clicks on an interwiki link, it opens in the same tab or window. However, if you want these links to open in a new tab, you can make a simple configuration change in the Mediawiki settings.
Step 1: Accessing the Mediawiki configuration file
To get started, you need to access the Mediawiki configuration file. This file contains various settings and options for your wiki. You can usually find the configuration file named "LocalSettings.php" in the root directory of your Mediawiki installation.
Step 2: Editing the configuration file
Open the "LocalSettings.php" file using a text editor and locate the section where the interwiki links are defined. It typically looks something like this:
$wgInterwikiCache = false;
$wgInterwikiMagic = array();
$wgInterwikiMagic = array_merge($wgInterwikiMagic, [
'wikipedia' => 'https://en.wikipedia.org/wiki/$1',
'mediawiki' => 'https://www.mediawiki.org/wiki/$1',
'example' => 'https://www.example.com/$1',
]);
In this example, we have three interwiki links defined: "wikipedia", "mediawiki", and "example". To make these links open in a new tab, we need to add a target attribute to each link. Modify the code as follows:
$wgInterwikiCache = false;
$wgInterwikiMagic = array();
$wgInterwikiMagic = array_merge($wgInterwikiMagic, [
'wikipedia' => 'https://en.wikipedia.org/wiki/$1',
'mediawiki' => 'https://www.mediawiki.org/wiki/$1',
'example' => 'https://www.example.com/$1',
]);
foreach ($wgInterwikiMagic as $key => $value) {
$wgInterwikiMagic[$key] = $value . '" target="_blank';
}
Save the changes to the configuration file and close it.
Step 3: Clearing the cache
After making changes to the configuration file, you need to clear the cache for the changes to take effect. To do this, navigate to your Mediawiki installation directory using a file manager or command line, and delete the contents of the "cache" folder.
Step 4: Testing the interwiki links
Now, when you create or click on an interwiki link, it should open in a new tab or window, depending on the user's browser settings. Test the interwiki links on your wiki to ensure they are opening in a new tab.
That's it! You have successfully configured Mediawiki to open interwiki links in a new tab. Users can now navigate to other wikis or websites without losing their place in your wiki.
References
| Number | Source |
|---|---|
| 1 | Mediawiki Documentation |
| 2 | Stack Overflow |
| 3 | Mediawiki Support Forum |