Extension:MagicalLinkers

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
MagicalLinkers
Release status: stable
Implementation Parser extension
Description Provides dynamic linking of inline keywords, such as magic links.
Author(s) Nuno Tavares, wsd? (Nuno Tavarestalk)
Latest version 1.0
MediaWiki 1.25+ ?
Database changes No
License GNU General Public License 2.0 or later
Download github.com/ntavares/mediawiki-extensions-magicallinkers
Parameters
  • $wgMagicalInit
  • $wgMagicalClassic
  • $wgMagicalLinkers
  • $wgMagicalPattern
Translate the MagicalLinkers extension if it is available at translatewiki.net
Check usage and version matrix.

The MagicalLinkers extension provides dynamic linking of inline keywords, such as magic links. Following the discussion around the the future of magic links (more specifically, its removal from mediawiki core), 'wsd' (untraced) submitted a patch[1] to demonstrate how magiclinks could be turned into an extension. In the meantime, $wgEnableMagicLinks was introduced to aid in phasing these out, but the possibility of extending the list was not there.

This extension is nothing but the extension.json wrapping of the simple submitted patch.

Installation[edit]

  • Download and place the file(s) in a directory called MagicalLinkers in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'MagicalLinkers' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.27 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension() If you need to install this extension on these earlier versions (MediaWiki 1.27 and earlier), instead of wfLoadExtension( 'MagicalLinkers' );, you need to use:

require_once "$IP/extensions/MagicalLinkers/MagicalLinkers.php";

Usage[edit]

Besides normal extension insertion, you'll probably want to extend it with your own keywords. Example:

wfLoadExtension( 'MagicalLinkers' );
class MagicalLinkersExt {
	public static function linkBug( $text ) {
        $urlNumber = ltrim( substr( $text, 4 ), '0');
		$url = 'https://mybugplatform.mysite.pt/issues/?id=' . $urlNumber;
		$safeUrl = $url;
		return '<a href=\'' . $safeUrl . '\' class=\'mw-magiclink-bug\'>bug ' . $urlNumber . '</a>';
	}
}
$wgMagicalLinkers = array(
	array( 
		'linker' => 'MagicalLinkersExt::linkBug',
		'pattern' => 'bug:\\s*[0-9]+'
	)
);

Tested on[edit]

  • Mediawiki 1.31

References[edit]

Other languages: English