[Mediawiki-l] using images as icons

Joshua Oreman oremanj at gmail.com
Tue Aug 30 19:04:04 UTC 2005


On 8/30/05, Sy <sy1234 at gmail.com> wrote:
> On 8/30/05, jdd <jdd at dodin.org> wrote:
> > is there a way to use images as icons, that is clicking on
> > the image drives to an other page, not the image page.
> 
> Did some more thinking.. the only solution I can see is some kind of
> extension designed to do this.

Yep.
Untested, but should work.

extensions/ImageLink.php:
--snip--
require_once('../includes/Image.php');

$wgExtensionFunctions[] = "wfImageLink";

function wfImageLink() 
{
    global $wgParser;
    $wgParser->setHook ('imglink', 'renderImageLink');
}

function renderImageLink ($text, $attr)
{
    global $wgParser, $wgUser, $wgTitle;
    $parserOptions = ParserOptions::newFromUser( $wgUser );
    $parser =& new Parser();
    $output =& $parser->parse("[[".$input."|IMAGE]]", $wgTitle, $parserOptions);
    $ret = $output->getText();
    $itag = "<img border='0' ";
    foreach ($attr as $k => $v) {
        if ($k == "src") {
            $itag .= "src='" . Image::imageUrl($attr['src']) . "' ";
        } else {
            $itag .= "$k='$v' ";
    }
     $itag .= "/>";
    return str_replace ($ret, "IMAGE", $itag);
}
--snip--
and add
  require_once('extensions/ImageLink.php');
to LocalSettings.php.

To use, do
<imglink src='MyImage'>Destination page</imglink>
instead of the doesn't-work
[[Destination page|[[Image:MyImage]]]]
You can also use height and width attributes on the <imglink> tag.

Hope this helps.
-- Josh

> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l at Wikimedia.org
> http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
>



More information about the MediaWiki-l mailing list