* @author SPQRobin * @copyright Copyright (C) 2005-2007 Stephanie Amanda Stevens * @copyright Copyright (C) 2007 SPQRobin * @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' => 'SpecialInterwiki', 'url' => 'http://mediawiki.org/wiki/Extension:SpecialInterwiki', 'description' => 'Adds a [[Special:Interwiki|special page]] to view and edit the interwiki table', 'version' => '14-12-07', 'author' => array( 'Stephanie Amanda Stevens', 'SPQRobin', 'others' ), ); 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'; # 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("delete"); $topmessage = wfMsgHtml('interwiki_delquestion', $prefix); $deletingmessage = wfMsgHtml('interwiki_deleting', $prefix); $reasonmessage = wfMsgHtml('deletecomment'); $defaultreason = wfMsgForContent( 'interwiki_defaultreason' ); $token = htmlspecialchars( $wgUser->editToken() ); $out .= "
$topmessage
$deletingmessage
$reasonmessage  
\n"; } elseif ($do == "delete2" && $safePost) { if (!$admin) { $wgOut->permissionRequired('interwiki'); return; } $prefix = $wgRequest->getVal('prefix'); $reason = $wgRequest->getText('reason'); $dbw =& wfGetDB( DB_MASTER ); $dbw->delete( 'interwiki', array( 'iw_prefix' => $prefix ), $fname ); if ($dbw->affectedRows() == 0) { $wgOut->addWikiText( wfMsg( 'interwiki_delfailed', $prefix ) ); } else { $wgOut->addWikiText( wfMsg( 'interwiki_deleted', $prefix ) . '

' . wfMsg ( 'returnto', '[[Special:Log/interwiki]]' ) ); # I don't know how to add a link to Special:Interwiki $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"); $topmessage = wfMsgHtml( 'interwiki_addtext' ); $intromessage = wfMsg( 'interwiki_addintro' ); $prefixmessage = wfMsgHtml( 'interwiki_prefix' ); $localmessage = wfMsgHtml( 'interwiki_local' ); $transmessage = wfMsgHtml( 'interwiki_trans' ); $reasonmessage = wfMsgHtml( 'interwiki_reasonfield' ); $urlmessage = wfMsgHtml( 'interwiki_url' ); $button = wfMsgHtml( 'interwiki_addbutton' ); $token = htmlspecialchars( $wgUser->editToken() ); $defaulturl = wfMsgHtml( 'interwiki_defaulturl' ); $defaultreason = wfMsgForContent( 'interwiki_defaultreason' ); $out = "
$topmessage $intromessage
$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; $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 ) { $wgOut->addWikiText( wfMsg( 'interwiki_addfailed', $prefix ) ); } else { $wgOut->addWikiText( wfMsg( 'interwiki_added', $prefix ) . '

' . wfMsg ( 'returnto', '[[Special:Log/interwiki]]' ) ); # I don't know how to add a link to Special:Interwiki $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( 'delete'); $addtext = wfMsgHtml( 'interwiki_addtext' ); if ($admin) { $skin = $wgUser->getSkin(); $addlink = $skin->makeLinkObj( $selfTitle, $addtext, 'do=add' ); $wgOut->addWikiText( wfMsg( 'interwiki_intro', '[http://www.mediawiki.org/wiki/Interwiki_table MediaWiki.org]' ) ); $wgOut->addHTML( '' ); } else { $wgOut->addWikiText( wfMsg( 'interwiki_intro', '[http://www.mediawiki.org/wiki/Interwiki_table MediaWiki.org]' ) ); } $out .= "
"; if( $admin ) { $out .= ""; } $out .= "\n"; $numrows = $dbr->numRows( $res ); if ($numrows == 0) { $errormessage = wfMsgHtml('interwiki_error'); $out .= "
$errormessage

"; } while( $s = $dbr->fetchObject( $res ) ) { $prefix = htmlspecialchars( $s->iw_prefix ); $url = htmlspecialchars( $s->iw_url ); $trans = htmlspecialchars( $s->iw_trans ); $local = htmlspecialchars( $s->iw_local ); $out .= ""; if( $admin ) { $skin = $wgUser->getSkin(); $out .= ''; } $out .= "\n"; } $dbr->freeResult( $res ); $out .= "
$prefixmessage $urlmessage $localmessage $transmessage$deletemessage
$prefix $url $local $trans'; $out .= $skin->makeLinkObj( $selfTitle, $deletemessage, 'do=delete&prefix=' . urlencode( $s->iw_prefix ) ); $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; }