KLlinkparam
KLlinkparam MediaWiki Extension
This extension allows linking to articles with parameters.
Usage
{{#linkparam:Article|parameter=value|link text}}
The link [[Contact?subject=Hello]] looks like it should send a parameter to the Contact page, but it doesn’t. MediaWiki interprets the entire link as an article name, like this: Contact?subject=Hello. Use this extension to send parameters like this.
like this: {{#linkparam:Contact
| subject=Just testing the link
& message=Kenny,
I tested the link. It worked. If you’re reading this, I actually sent the message instead of canceling.
| like this}}.
The extra returns in the parameter are urlencoded and become part of the message. Other returns simply make it easier to read the code. Remember: only use ampersands and equal signs to divide the URL parameters—never within a parameter.
Installation
To install:
- Copy the code from the code block at the end of this page to the file
$IP/extensions/KLlinkparam.php - Add this line to LocalSettings.php:
require_once("$IP/extensions/KLlinkparam.php");
Code
<?php
/**
* KLlinkparam.php
* This extension inserts a form mailer into a page
* written by Kennylucius http://kennylucius.com/
* LocalSettings.php file:
* require_once("$IP/extensions/KLlinkparam.php");
*/
if(! defined( 'MEDIAWIKI' ) ) {
die("This is not a valid entry point.\n");
}
$wgExtensionCredits['parserhook'][] = array(
'name' => 'KLlinkparam',
'version' => '0.1',
'author' =>'Kenny Lucius',
'url' => 'http://www.kennylucius.com/KLlinkparam',
'description' => 'Allows linking to articles with parameters via {{#linkparam:Article|parameter=value|link text}}'
);
# KLlinkparam MediaWiki extension
$wgExtensionFunctions[] = "wfKLlinkparam_Extension";
$wgHooks['LanguageGetMagic'][] = 'wfKLlinkparam_Magic';
function wfKLlinkparam_Extension() {
global $wgParser;
$wgParser->setFunctionHook( 'linkparam', "renderKLlinkParam");
}
function wfKLlinkparam_Magic(&$magicWords, $langCode) {
$magicWords['linkparam'] = array( 0, 'linkparam' );
return true;
}
function renderKLlinkParam() {
$arg = func_get_args();
$parser = array_shift($arg);
if(! $arg[0]) return '';
if(! $arg[3]) $arg[3] = $arg[1];
$params = explode('&', $arg[1]);
foreach($params as $idx=>$val) {
$p = explode('=', $val, 2);
if(! $p[1]) {
$params[$idx] = rawurlencode(trim($p[0]));
}
else {
$params[$idx] = trim($p[0]) . '=' . rawurlencode(trim($p[1]));
}
}
$ret = '<span class="plainlinks">[{{fullurl:'.$arg[0].'|'.implode('&', $params).'}} '.$arg[2].']</span>';
return $ret;
}
