isAllowed( 'interwiki' ) ? 'interwiki' : 'interwiki-title-norights' ); } /** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { global $wgRequest, $wgOut, $wgUser; wfLoadExtensionMessages( 'Interwiki' ); $admin = $wgUser->isAllowed( 'interwiki' ); $this->setHeaders(); $this->outputHeader(); $admin = $wgUser->isAllowed( 'interwiki' ); $action = $wgRequest->getVal( 'action', $par ); switch( $action ){ case 'delete': case 'edit': case 'add': // Check permissions if( !$admin ){ $wgOut->permissionRequired( 'interwiki' ); return; } // Is the database in read-only mode? if( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } $this->showForm( $action ); break; case 'submit': // Check permissions if( !$admin ){ $wgOut->permissionRequired( 'interwiki' ); return; } // Is the database in read-only mode? if( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } // Prevent cross-site request forgeries if( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { $wgOut->addWikiMsg( 'sessionfailure' ); return; } $this->doSubmit(); break; default: $this->showList( $admin ); break; } } function showForm( $action ) { global $wgRequest, $wgUser, $wgOut; $actionUrl = $this->getTitle()->getLocalURL( 'action=submit' ); $token = $wgUser->editToken(); switch( $action ){ case 'delete': $prefix = $wgRequest->getVal( 'prefix' ); $button = wfMsg( 'delete' ); $topmessage = wfMsg( 'interwiki_delquestion', $prefix ); $deletingmessage = wfMsgExt( 'interwiki_deleting', array( 'parseinline' ), $prefix ); $reasonmessage = wfMsg( 'deletecomment' ); $wgOut->addHTML( Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, $topmessage ) . Xml::openElement( 'form', array( 'id' => 'mw-interwiki-deleteform', 'method' => 'post', 'action' => $actionUrl ) ) . Xml::openElement( 'table' ) . "$deletingmessage". '' . Xml::label( $reasonmessage, 'mw-interwiki-deletereason' ) . '' . '' . Xml::input( 'wpInterwikiReason', 60, '', array( 'tabindex' => '1', 'id' => 'mw-interwiki-deletereason', 'maxlength' => '200' ) ) . '' . '' . Xml::submitButton( $button, array( 'id' => 'mw-interwiki-submit' ) ) . Xml::hidden( 'wpInterwikiPrefix', $prefix ) . Xml::hidden( 'wpInterwikiAction', $action ) . Xml::hidden( 'wpEditToken', $token ) . '' . Xml::closeElement( 'table' ) . Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ) ); break; case 'edit': case 'add': if( $action == 'edit' ){ $prefix = $wgRequest->getVal( 'prefix' ); $dbr = wfGetDB( DB_SLAVE ); $row = $dbr->selectRow( 'interwiki', '*', array( 'iw_prefix' => $prefix ), __METHOD__ ); if( !$row ){ $this->error( 'interwiki_editerror', $prefix ); return; } $prefix = '' . htmlspecialchars( $row->iw_prefix ) . ''; $defaulturl = $row->iw_url; $trans = $row->iw_trans; $local = $row->iw_local; $old = Xml::hidden( 'wpInterwikiPrefix', $row->iw_prefix ); $topmessage = wfMsgExt( 'interwiki_edittext', array( 'parseinline' ) ); $intromessage = wfMsgExt( 'interwiki_editintro', array( 'parseinline' ) ); $button = wfMsg( 'edit' ); } else { $prefix = $wgRequest->getVal( 'wpInterwikiPrefix' ) ? $wgRequest->getVal( 'wpInterwikiPrefix' ) : $wgRequest->getVal( 'prefix' ); $prefix = Xml::input( 'wpInterwikiPrefix', 20, $prefix, array( 'tabindex' => '1', 'id' => 'mw-interwiki-prefix', 'maxlength' => '20' ) ); $local = $wgRequest->getCheck( 'wpInterwikiLocal' ); $trans = $wgRequest->getCheck( 'wpInterwikiTrans' ); $old = ''; $defaulturl = $wgRequest->getVal( 'wpInterwikiURL' ) ? $wgRequest->getVal( 'wpInterwikiURL' ) : wfMsg( 'interwiki_defaulturl' ); $topmessage = wfMsgExt( 'interwiki_addtext', array( 'parseinline' ) ); $intromessage = wfMsgExt( 'interwiki_addintro', array( 'parseinline' ) ); $button = wfMsg( 'interwiki_addbutton' ); } $prefixmessage = wfMsgHtml( 'interwiki-prefix-label' ); $localmessage = wfMsg( 'interwiki-local-label' ); $transmessage = wfMsg( 'interwiki-trans-label' ); $reasonmessage = wfMsg( 'interwiki_reasonfield' ); $urlmessage = wfMsg( 'interwiki-url-label' ); $wgOut->addHTML( Xml::fieldset( $topmessage ) . $intromessage . Xml::openElement( 'form', array( 'id' => 'mw-interwiki-editform', 'method' => 'post', 'action' => $actionUrl ) ) . Xml::openElement( 'table', array( 'id' => "mw-interwiki-$action" ) ) . "$prefixmessage$prefix" . '' . Xml::label( $localmessage, 'mw-interwiki-local' ) . '' . '' . Xml::check( 'wpInterwikiLocal', $local, array( 'id' => 'mw-interwiki-local' ) ) . '' . '' . Xml::label( $transmessage, 'mw-interwiki-trans' ) . '' . '' . Xml::check( 'wpInterwikiTrans', $trans, array( 'id' => 'mw-interwiki-trans' ) ) . '' . '' . Xml::label( $urlmessage, 'mw-interwiki-url' ) . '' . '' . Xml::input( 'wpInterwikiURL', 60, $defaulturl, array( 'tabindex' => '1', 'maxlength' => '200', 'id' => 'mw-interwiki-url' ) ) . '' . '' . Xml::label( $reasonmessage, 'mw-interwiki-editreason' ) . '' . '' . Xml::input( 'wpInterwikiReason', 60, '', array( 'tabindex' => '1', 'id' => 'mw-interwiki-editreason', 'maxlength' => '200' ) ) . Xml::hidden( 'wpInterwikiAction', $action ) . $old . Xml::hidden( 'wpEditToken', $token ) . '' . '' . Xml::submitButton( $button, array( 'id' => 'mw-interwiki-submit' ) ) . '' . Xml::closeElement( 'table' ) . Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ) ); break; } } function doSubmit() { global $wgRequest, $wgOut; $prefix = $wgRequest->getVal( 'wpInterwikiPrefix' ); $do = $wgRequest->getVal( 'wpInterwikiAction' ); if( preg_match( '/[\s:&=]/', $prefix ) ) { $this->error( 'interwiki-badprefix', htmlspecialchars( $prefix ) ); $this->showForm( $do ); return; } $reason = $wgRequest->getText( 'wpInterwikiReason' ); $selfTitle = $this->getTitle(); $dbw = wfGetDB( DB_MASTER ); switch( $do ){ case 'delete': $dbw->delete( 'interwiki', array( 'iw_prefix' => $prefix ), __METHOD__ ); if ( $dbw->affectedRows() == 0 ) { $this->error( 'interwiki_delfailed', $prefix ); $this->showForm( $do ); } else { $wgOut->addWikiMsg( 'interwiki_deleted', $prefix ); $wgOut->returnToMain( false, $selfTitle ); $log = new LogPage( 'interwiki' ); $log->addEntry( 'iw_delete', $selfTitle, $reason, array( $prefix ) ); } break; case 'edit': case 'add': $theurl = $wgRequest->getVal( 'wpInterwikiURL' ); $local = $wgRequest->getCheck( 'wpInterwikiLocal' ) ? 1 : 0; $trans = $wgRequest->getCheck( 'wpInterwikiTrans' ) ? 1 : 0; $data = array( 'iw_prefix' => $prefix, 'iw_url' => $theurl, 'iw_local' => $local, 'iw_trans' => $trans ); if( $do == 'add' ){ $dbw->insert( 'interwiki', $data, __METHOD__, 'IGNORE' ); } else { $dbw->update( 'interwiki', $data, array( 'iw_prefix' => $prefix ), __METHOD__, 'IGNORE' ); } if( $dbw->affectedRows() == 0 ) { $this->error( "interwiki_{$do}failed", $prefix ); $this->showForm( $do ); } else { $wgOut->addWikiMsg( "interwiki_{$do}ed", $prefix ); $wgOut->returnToMain( false, $selfTitle ); $log = new LogPage( 'interwiki' ); $log->addEntry( 'iw_' . $do, $selfTitle, $reason, array( $prefix, $theurl, $trans, $local ) ); } break; } } function trans_local( $tl, $msg0, $msg1 ) { if( $tl === '0' ) return $msg0; if( $tl === '1' ) return $msg1; return htmlspecialchars( $tl ); } function showList( $admin ) { global $wgUser, $wgOut, $wgScriptPath; $wgOut->addExtensionStyle( "{$wgScriptPath}/extensions/Interwiki/Interwiki.css" ); $prefixmessage = wfMsgHtml( 'interwiki_prefix' ); $urlmessage = wfMsgHtml( 'interwiki_url' ); $localmessage = wfMsgHtml( 'interwiki_local' ); $transmessage = wfMsgHtml( 'interwiki_trans' ); $message_0 = wfMsgHtml( 'interwiki_0' ); $message_1 = wfMsgHtml( 'interwiki_1' ); $out = '
' . $prefixmessage . '' . wfMsgExt( 'interwiki_prefix_intro', 'parseinline' ) . '
' . $urlmessage . '' . wfMsgExt( 'interwiki_url_intro', 'parseinline' ) . '
' . $localmessage . '' . wfMsgExt( 'interwiki_local_intro', 'parseinline' ) . '
' . $message_0 . '' . wfMsgExt( 'interwiki_local_0_intro', 'parseinline' ) . '
' . $message_1 . '' . wfMsgExt( 'interwiki_local_1_intro', 'parseinline' ) . '
' . $transmessage . '' . wfMsgExt( 'interwiki_trans_intro', 'parseinline' ) . '
' . $message_1 . '' . wfMsgExt( 'interwiki_trans_1_intro', 'parseinline' ) . '
' . $message_0 . '' . wfMsgExt( 'interwiki_trans_0_intro', 'parseinline' ) . '
'; $wgOut->addWikiMsg( 'interwiki_intro' ); $wgOut->addHTML( $out ); $wgOut->addWikiMsg( 'interwiki_intro_footer' ); $selfTitle = $this->getTitle(); // Privileged users can add new prefixes if ( $admin ) { $skin = $wgUser->getSkin(); $addtext = wfMsgHtml( 'interwiki_addtext' ); $addlink = $skin->link( $selfTitle, $addtext, array(), array( 'action' => 'add' ) ); $wgOut->addHTML( '

' . $addlink . '

' ); } $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'interwiki', '*', false, __METHOD__ ); $numrows = $res->numRows(); if ( $numrows == 0 ) { // If the interwiki table is empty, display an error message $this->error( 'interwiki_error' ); return; } $out = " "; // Privileged users can modify and delete existing prefixes if( $admin ) { $deletemessage = wfMsgHtml( 'delete' ); $editmessage = wfMsgHtml( 'edit' ); $out .= ''; } $out .= "\n"; while( $s = $res->fetchObject() ) { $prefix = htmlspecialchars( $s->iw_prefix ); $url = htmlspecialchars( $s->iw_url ); $trans = $this->trans_local( $s->iw_trans, $message_0, $message_1 ); $local = $this->trans_local( $s->iw_local, $message_0, $message_1 ); $out .= ""; if( $admin ) { $out .= ''; } $out .= "\n\n"; } $res->free(); $out .= '
$prefixmessage $urlmessage $localmessage $transmessage' . wfMsgHtml( 'interwiki_edit' ) . '
$prefix $url $local $trans'; $out .= $skin->link( $selfTitle, $editmessage, array(), array( 'action' => 'edit', 'prefix' => $s->iw_prefix ) ); $out .= wfMsg( 'comma-separator' ); $out .= $skin->link( $selfTitle, $deletemessage, array(), array( 'action' => 'delete', 'prefix' => $s->iw_prefix ) ); $out .= '

'; $wgOut->addHTML( $out ); } function error() { global $wgOut; $args = func_get_args(); $wgOut->wrapWikiMsg( "

$1

", $args ); } }