Extension:Interwiki

This is an extension to add a Special:Interwiki page to MediaWiki, to view and manipulate the interwiki table, and a log of any actions made with it. It was made by Stephanie Amanda Stevens a.k.a Phroziac, because she was annoyed at forgetting the interwiki prefixes. It's made for MediaWiki 1.6 onwards, and has been reported to also work on 1.5.

Warning: this extension originally had security bugs, which are fixed in the version below:

SpecialInterwiki.php
 * @copyright Copyright (C) 2005 Stephanie Amanda Stevens * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * Formatting improvements Stephen Kennedy, 2006. */

if (!defined('MEDIAWIKI')) die; $wgExtensionFunctions[] = "Interwiki";

$wgExtensionCredits['specialpage'][] = array(       'name' => 'Special:Interwiki',        'url' => 'http://mediawiki.org/wiki/Extension:Special_page_to_work_with_the_interwiki_table',        'description' => 'adds a special page to view and manipulate the interwiki table',        'version' => '040107',        'author' => 'Stephanie Amanda Stevens and others' );

function Interwiki { global $IP, $wgMessageCache, $wgHooks; require_once( "$IP/includes/SpecialPage.php" );

$wgMessageCache->addMessage('interwiki', 'View and manipulate interwiki data'); $wgMessageCache->addMessage('interwiki_delquestion', 'Deleting "$1"'); $wgMessageCache->addMessage('interwiki_deleted', '$1 was successfully removed from the interwiki table.'); $wgMessageCache->addMessage('interwiki_prefix', 'Prefix'); $wgMessageCache->addMessage('interwiki_prefix2', 'Prefix:'); $wgMessageCache->addMessage('interwiki_url', 'URL'); $wgMessageCache->addMessage('interwiki_local', 'Local'); $wgMessageCache->addMessage('interwiki_trans', 'Trans'); $wgMessageCache->addMessage('interwiki_delete', 'Delete'); $wgMessageCache->addMessage('interwiki_yes', 'Yes'); $wgMessageCache->addMessage('interwiki_delfailed', '$1 could not be removed from the interwiki table.'); $wgMessageCache->addMessage('interwiki_added', '$1 was successfully added to the interwiki table.'); $wgMessageCache->addMessage('interwiki_addfailed', '$1 could not be added to the interwiki table.'); $wgMessageCache->addMessage('interwiki_log_added', 'Added "$1" ($2) (local: $3) (trans: $4) to the interwiki table: $5'); $wgMessageCache->addMessage('interwiki_alreadyexists', '$1 already exists in the interwiki table!'); $wgMessageCache->addMessage('interwiki_log_deleted', 'Removed prefix "$1" from the interwiki table: $2'); $wgMessageCache->addMessage('interwiki_add', '*Add an interwiki prefix'); $wgMessageCache->addMessage('interwiki_show', '*View all interwiki prefixes'); $wgMessageCache->addMessage('interwiki_logpagename', 'Interwiki table log'); $wgMessageCache->addMessage('interwiki_logpagetext', 'This is a log of changes to the interwiki table.'); $wgMessageCache->addMessage('interwiki_logentry', ''); $wgMessageCache->addMessage('interwiki_reasonfield', 'Reason'); $wgMessageCache->addMessage('interwiki_addtext', 'Add an interwiki prefix'); $wgMessageCache->addMessage('interwiki_delbutton', 'Delete'); $wgMessageCache->addMessage('interwiki_addbutton', 'Add');

# Add a new log type $wgHooks['LogPageValidTypes'][] = 'wfInterwikiAddLogType'; $wgHooks['LogPageLogName'][] = 'wfInterwikiAddLogName'; $wgHooks['LogPageLogHeader'][] = 'wfInterwikiAddLogHeader'; $wgHooks['LogPageActionText'][] = 'wfInterwikiAddActionText'; class Interwiki extends SpecialPage { function Interwiki { SpecialPage::SpecialPage( 'Interwiki' ); $this->includable( true ); }		function execute( $par = null ) { $fname = 'Interwiki::execute'; global $wgOut, $wgRequest, $wgUser; $this->setHeaders; $wgOut->setPagetitle( wfMsg( 'interwiki' ) ); $do = $wgRequest->getVal( 'do' ); // Some common checks $admin = $wgUser->isAllowed( 'interwiki' ); $selfTitle = Title::makeTitle( NS_SPECIAL, 'Interwiki' ); // Protect administrative actions against malicious requests $safePost = $wgRequest->wasPosted && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ); if ($do == "delete") { if (!$admin) { $wgOut->permissionRequired('interwiki'); return; } $prefix = $wgRequest->getVal( 'prefix' ); $encPrefix = htmlspecialchars( $prefix ); $action = $selfTitle->escapeLocalURL( "do=delete2" ); $button = wfMsgHtml("interwiki_delbutton"); $question = htmlspecialchars( wfMsg('interwiki_delquestion', $prefix) ); $reasonmessage = wfMsgHtml('interwiki_reasonfield'); $token = htmlspecialchars( $wgUser->editToken ); $out = $question; $out .= "										$reasonmessage 															 \n"; } elseif ($do == "delete2" && $safePost) { if (!$admin) { $wgOut->permissionRequired('interwiki'); return; } $prefix = $wgRequest->getVal('prefix'); $reason = $wgRequest->getText('reason'); $deletedmessage = htmlspecialchars( wfMsg('interwiki_deleted', $prefix) ); $delfailedmessage = htmlspecialchars( wfMsg('interwiki_delfailed', $prefix) ); $dbw =& wfGetDB( DB_MASTER ); $dbw->delete( 'interwiki', array( 'iw_prefix' => $prefix ), $fname ); if ($dbw->affectedRows == 0) { $out = $delfailedmessage; } else { $out = $deletedmessage; $log = new LogPage( 'interwiki' ); $log->addEntry( 'interwiki', $selfTitle, wfMsgForContent( 'interwiki_log_deleted', $prefix, $reason ) ); }			} elseif ($do == "add") { if (!$admin) { $wgOut->permissionRequired('interwiki'); return; }; $action = $selfTitle->escapeLocalURL( "do=add2"); $prefixmessage = wfMsgHtml('interwiki_prefix'); $transmessage = wfMsgHtml('interwiki_trans'); $localmessage = wfMsgHtml('interwiki_local'); $reasonmessage = wfMsgHtml('interwiki_reasonfield'); $urlmessage = wfMsgHtml('interwiki_url'); $button = wfMsgHtml('interwiki_addbutton'); $token = htmlspecialchars( $wgUser->editToken ); $out = "					$prefixmessage 

$localmessage 

$transmessage 

$urlmessage 

$reasonmessage 

  \n";			} elseif ($do == "add2" && $safePost) {				if (!$admin) { $wgOut->permissionRequired('interwiki'); return; }				$prefix = $wgRequest->getVal('prefix');				$reason = $wgRequest->getText('reason');				$theurl = $wgRequest->getVal('theurl');				$local = $wgRequest->getCheck('local') ? 1 : 0;				$trans = $wgRequest->getCheck('trans') ? 1 : 0;				$addedmessage = htmlspecialchars( wfMsg('interwiki_added', $prefix) );				$addfailedmessage = htmlspecialchars( wfMsg('interwiki_addfailed', $prefix) );				$alreadyexists = htmlspecialchars( wfMsg('interwiki_alreadyexists', $prefix) );				$dbw =& wfGetDB( DB_MASTER );				$dbw->insert( 'interwiki',					array(						'iw_prefix' => $prefix,						'iw_url'   => $theurl,						'iw_local'  => $local,						'iw_trans'  => $trans ),					$fname,					'IGNORE' );				if( $dbw->affectedRows == 0 ) {					$out = $alreadyexists;				} else {					$out = $addedmessage; $log = new LogPage( 'interwiki' ); $log->addEntry( 'interwiki', $selfTitle, wfMsgForContent( 'interwiki_log_added', $prefix, $theurl, $trans, $local, $reason ) ); }			} else { $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->select( 'interwiki', '*' ); $prefixmessage = wfMsgHtml('interwiki_prefix'); $urlmessage = wfMsgHtml('interwiki_url'); $localmessage = wfMsgHtml('interwiki_local'); $transmessage = wfMsgHtml('interwiki_trans'); $deletemessage = wfMsgHtml('interwiki_delete'); $addtext = wfMsgHtml('interwiki_addtext'); if ($admin) { $skin = $wgUser->getSkin; $out = $skin->makeLinkObj( $selfTitle, $addtext, 'do=add' ); } else { $out = ''; }				$out .= "

";			}			$wgOut->addHTML($out);		}	}	SpecialPage::addPage( new Interwiki ); }

function wfInterwikiAddLogType( &$types ) { if ( !in_array( 'interwiki', $types ) ) $types[] = 'interwiki'; return true; }

function wfInterwikiAddLogName( &$names ) { $names['interwiki'] = 'interwiki_logpagename'; return true; }

function wfInterwikiAddLogHeader( &$headers ) { $headers['interwiki'] = 'interwiki_logpagetext'; return true; }

function wfInterwikiAddActionText( &$actions ) { $actions['interwiki/interwiki'] = 'interwiki_logentry'; return true; } ?>

LocalSettings.php
You'll need something similar to this in your LocalSettings.php.

require_once('extensions/SpecialInterwiki.php');

$wgGroupPermissions['*']['interwiki'] = false; $wgGroupPermissions['interwiki']['interwiki'] = true;

With this configuration, the "interwiki" flag is required to modify the interwiki table, this flag can be set in Special:Userrights by a bureaucrat.

Patch for french Translation
A new patch is created for translation in french.

*** SpecialInterwiki.php.old	2006-12-24 20:35:23.000000000 +0100 --- SpecialInterwiki.php.new	2006-12-24 20:38:31.000000000 +0100 ); function Interwiki { !         global $IP, $wgMessageCache, $wgHooks;          require_once( "$IP/includes/SpecialPage.php" ); ! !         $wgMessageCache->addMessage('interwiki', 'View and manipulate interwiki data'); !         $wgMessageCache->addMessage('interwiki_delquestion', 'Deleting "$1"'); !         $wgMessageCache->addMessage('interwiki_deleted', '$1 was successfully removed from the interwiki table.'); !         $wgMessageCache->addMessage('interwiki_prefix', 'Prefix'); !         $wgMessageCache->addMessage('interwiki_prefix2', 'Prefix:'); !         $wgMessageCache->addMessage('interwiki_url', 'URL'); !         $wgMessageCache->addMessage('interwiki_local', 'Local'); !         $wgMessageCache->addMessage('interwiki_trans', 'Trans'); !         $wgMessageCache->addMessage('interwiki_delete', 'Delete'); !         $wgMessageCache->addMessage('interwiki_yes', 'Yes'); !         $wgMessageCache->addMessage('interwiki_delfailed', '$1 could not be removed from the interwiki table.'); !        $wgMessageCache->addMessage('interwiki_added', '$1 was successfully added to the interwiki table.'); !        $wgMessageCache->addMessage('interwiki_addfailed', '$1 could not be added to the interwiki table.'); !        $wgMessageCache->addMessage('interwiki_log_added', 'Added "$1" ($2) (local: $3) (trans: $4) to the interwiki table: $5'); !        $wgMessageCache->addMessage('interwiki_alreadyexists', '$1 already exists in the interwiki table!'); !        $wgMessageCache->addMessage('interwiki_log_deleted', 'Removed prefix "$1" from the interwiki table: $2'); !        $wgMessageCache->addMessage('interwiki_add', '*Add an interwiki prefix'); !        $wgMessageCache->addMessage('interwiki_show', '*View all interwiki prefixes'); !        $wgMessageCache->addMessage('interwiki_logpagename', 'Interwiki table log'); !        $wgMessageCache->addMessage('interwiki_logpagetext', 'This is a log of changes to the interwiki table.'); !        $wgMessageCache->addMessage('interwiki_logentry', ''); !        $wgMessageCache->addMessage('interwiki_reasonfield', 'Reason'); !        $wgMessageCache->addMessage('interwiki_addtext', 'Add an interwiki prefix'); !        $wgMessageCache->addMessage('interwiki_delbutton', 'Delete'); !        $wgMessageCache->addMessage('interwiki_addbutton', 'Add'); # Add a new log type $wgHooks['LogPageValidTypes'][] = 'wfInterwikiAddLogType'; --- 20,30  );  function Interwiki { !         global $IP, $wgMessageCache, $wgHooks, $wgSpecialInterwikiMessages ;          require_once( "$IP/includes/SpecialPage.php" ); ! 	require_once( 'SpecialInterwiki.i18n.php'); ! 	foreach( $wgSpecialInterwikiMessages as $key => $value ) { ! 	$wgMessageCache->addMessages( $wgSpecialInterwikiMessages[$key], $key );}          # Add a new log type          $wgHooks['LogPageValidTypes'][] = 'wfInterwikiAddLogType';
 * 20,53 ****
 * 20,53 ****

A new file was created :


 * SpecialInterwiki.i18n.php

 * @copyright Copyright (C) 2005 Stephanie Amanda Stevens * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * French Translation by Bertrand GRONDIN, Même licence. */

$wgSpecialInterwikiMessages = array;

$wgSpecialInterwikiMessages['en'] = array(	'interwiki' => 'View and manipulate interwiki data',	'interwiki_delquestion' => 'Deleting "$1"',	'interwiki_deleted' => '$1 was successfully removed from the interwiki table.',	'interwiki_prefix' => 'Prefix',	'interwiki_prefix2' => 'Prefix:',	'interwiki_url' => 'URL',	'interwiki_local' => 'Local',	'interwiki_trans' => 'Trans',	'interwiki_delete' => 'Delete',	'interwiki_yes' => 'Yes',	'interwiki_delfailed' => '$1 could not be removed from the interwiki table.',	'interwiki_added' => '$1 was successfully added to the interwiki table.',	'interwiki_addfailed' => '$1 could not be added to the interwiki table.',	'interwiki_log_added' => 'Added "$1" ($2) (local: $3) (trans: $4) to the interwiki table: $5',	'interwiki_alreadyexists' => '$1 already exists in the interwiki table!',	'interwiki_log_deleted' => 'Removed prefix "$1" from the interwiki table: $2', 'interwiki_add' => '*Add an interwiki prefix', 'interwiki_show' => '*View all interwiki prefixes', 'interwiki_logpagename' => 'Interwiki table log', 'interwiki_logpagetext' => 'This is a log of changes to the interwiki table.', 'interwiki_logentry' => '', 'interwiki_reasonfield' => 'Reason', 'interwiki_addtext' => 'Add an interwiki prefix', 'interwiki_delbutton' => 'Delete', 'interwiki_addbutton' => 'Add', ); $wgSpecialInterwikiMessages['fr'] = array( 'interwiki' => 'Voir et manipuler les données interwiki', 'interwiki_delquestion' => 'Suppression "$1"', 'interwiki_deleted' => '$1 a été enlevée avec succès de la table interwiki.', 'interwiki_prefix' => 'Préfixe', 'interwiki_prefix2' => 'Préfixe:', 'interwiki_url' => 'URL', 'interwiki_local' => 'Local', 'interwiki_trans' => 'Trans', 'interwiki_delete' => 'Supprimer', 'interwiki_yes' => 'Oui', 'interwiki_delfailed' => '$1 n\'a pas pu être enlevé de la table interwiki.', 'interwiki_added' => '$1 a été ajouté avec succès dans la table interwiki.', 'interwiki_addfailed' => '$1 n\'a pas pu être ajouté à la table interwiki.', 'interwiki_log_added' => 'Ajouté "$1" ($2) (local: $3) (trans: $4) dans la table interwiki: $5', 'interwiki_alreadyexists' => '$1 existe déjà dans la table interwiki !', 'interwiki_log_deleted' => 'Préfixe "$1" supprimé de la table interwiki: $2', 'interwiki_add' => '*Ajoute un préfixe interwiki', 'interwiki_show' => '*Voir tous les préfixes interwiki', 'interwiki_logpagename' => 'Journal de la table interwiki', 'interwiki_logpagetext' => 'Ceci est le journal des changements dans la table interwiki.', 'interwiki_logentry' => '', 'interwiki_reasonfield' => 'Motif', 'interwiki_addtext' => 'Ajoute un préfixe interwiki', 'interwiki_delbutton' => 'Supprimer', 'interwiki_addbutton' => 'Ajouter', ); ?>