From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Blue Glass Arrow.svg MediaWiki logo.png
This page should be moved to
Please do not move the page by hand. It will be imported by a administrator with the full edit history. In the meantime, you may continue to edit the page as normal.

This will allow users to use an <interwiki>Something</interwiki> tag, which will produce a table with all links from the 'interwiki' mysql table with the attached Something as query string. A contribution to wikilandia networking.

#  Interwiki Mediawiki extension
# display interwiki links  using an <interwiki> tag.
# reads from interwiki mysqltable and adds the
# word in the interwiki tag to all URLs as query string
# by mutante 24.04.2005

$wgExtensionFunctions[] = "wfInterwikiExtension";

function wfInterwikiExtension() {
global $wgParser;
$wgParser->setHook( "interwiki", "renderInterwiki" );

function renderInterwiki( $input ) {

$input = mysql_escape_string($input);

$hd = mysql_connect("localhost", "wikiuser", "password") or die ("Unable to connect");
mysql_select_db ("wikidb", $hd) or die ("Unable to select database");
$res = mysql_query("SELECT * from interwiki", $hd) or die ("Unable to run query");
$output="<table border='1'><tr><th colspan='2'>Interwiki-Links for '$input'</th></tr>";
while ($row = mysql_fetch_assoc($res))
$prefix = $row["iw_prefix"];
$url = $row["iw_url"];
$url = substr($url, 0, -2);
$uurl = $url . $input;
$output.="<tr><td><a href=\"$uurl\">$prefix:$input</a></td></tr>";
$output.="<tr><td>S23-Automatic Interwiki-Link Generator - $count links generated.</td></tr></table>";

return $output;