Extension:ExternalRedirect

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
ExternalRedirect
Release status: stable
Implementation Parser function
Description Allows to make redirects to external websites
Author(s) Dāvis Mošenkovs (DavisNTtalk)
Latest version 1.0.2 (2013-07-14)
MediaWiki MW 1.21+ (most likely works also on older versions)
Database changes No
License GNU General Public License 2.0 or later
Download Download instructions
Hooks used
ParserFirstCallInit
Translate the ExternalRedirect extension if it is available at translatewiki.net
Check usage and version matrix.

The ExternalRedirect extension allows to create redirects to external pages in wiki.

Use this extension only on write-protected wikis/namespaces! Abuse of this extension poses security risk.

Usage[edit]

A new parser function externalredirect with URL as first and only parameter is registered.

Place something like this on wiki page to make it redirect to external site:

{{#externalredirect: http://www.mediawiki.org}}

This allows, for example, to add external links to Categories (by placing pages with externalredirect in them).

Download instructions[edit]

Download both .php files from GitHub (feel free to move this repository to MediaWiki Git) and place them in $IP/extensions/ExternalRedirect/.

Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation[edit]

To load this extension, add the following four lines to LocalSettings.php:
Load the extension from its source directory.

require_once("$IP/extensions/ExternalRedirect/ExternalRedirect.php");

Populate this array with NUMERIC namespace IDs where external redirection should be allowed. Only allow on write-protected namespaces! See Manual:Namespace for more info on namespaces and numeric IDs. This example allows redirects from help pages (12) and pages from custom namespace with numeric ID 500.

$wgExternalRedirectNsIDs = array(12, 500);

Populate this array with page names (see magic word Extension:ExternalRedirect) where external redirection should be allowed. Only allow on write-protected pages! This example allows redirects from the wiki pages about Warren G. Harding and the Teapot Dome Scandal.

 $wgExternalRedirectPages = array('Teapot_Dome_scandal', 'Warren_G._Harding');

Whether to display link to redirection URL (along with error message) in case externalredirect is used where it is not allowed.

$wgExternalRedirectDeniedShowURL = false;

Security[edit]

This extension is meant for usage only on write-protected wikis/namespaces/pages. Here is an example how to add the a name space editable only by the sysops. In LocalSettings.php:

define("NS_MOVED", 500);
$wgExtraNamespaces[NS_MOVED] = "Moved";
$wgNamespaceProtection[NS_MOVED]=array('redirector');
$wgNamespacesWithSubpages[NS_MOVED]=false;
$wgGroupPermissions['sysop']['redirector']=true;
require_once("$IP/extensions/ExternalRedirect/ExternalRedirect.php");
$wgExternalRedirectNsIDs = array(500);


With version 1.0.2 there is introduced basic URL validation (using wfParseUrl()) which prevents seriously malformed URLs, but still allows redirection to arbitrary sites.