2008-04-03 21:00:22 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-08-27 13:02:57 +00:00
|
|
|
* Implements Special:Interwiki
|
2008-12-31 18:44:54 +00:00
|
|
|
* @ingroup SpecialPage
|
2008-04-03 21:00:22 +00:00
|
|
|
*/
|
|
|
|
class SpecialInterwiki extends SpecialPage {
|
2009-08-27 13:02:57 +00:00
|
|
|
/**
|
|
|
|
* Constructor - sets up the new special page
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
2008-04-03 21:00:22 +00:00
|
|
|
parent::__construct( 'Interwiki' );
|
|
|
|
}
|
|
|
|
|
2011-03-11 14:20:39 +00:00
|
|
|
/**
|
|
|
|
* Different description will be shown on Special:SpecialPage depending on
|
2011-07-19 12:45:38 +00:00
|
|
|
* whether the user can modify the data.
|
2012-05-22 17:59:00 +00:00
|
|
|
* @return String
|
2011-03-11 14:20:39 +00:00
|
|
|
*/
|
2010-01-22 21:19:01 +00:00
|
|
|
function getDescription() {
|
2012-04-25 10:08:42 +00:00
|
|
|
return $this->msg( $this->canModify() ?
|
2011-07-21 05:43:08 +00:00
|
|
|
'interwiki' : 'interwiki-title-norights' )->plain();
|
2010-01-22 21:19:01 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 13:02:57 +00:00
|
|
|
/**
|
|
|
|
* Show the special page
|
|
|
|
*
|
|
|
|
* @param $par Mixed: parameter passed to the page or null
|
|
|
|
*/
|
|
|
|
public function execute( $par ) {
|
2008-04-03 21:00:22 +00:00
|
|
|
$this->setHeaders();
|
2008-12-31 18:44:54 +00:00
|
|
|
$this->outputHeader();
|
|
|
|
|
2011-09-26 16:40:05 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
2012-05-21 13:29:32 +00:00
|
|
|
$out->addModules( 'ext.interwiki.specialpage' );
|
2011-07-19 12:45:38 +00:00
|
|
|
|
2011-09-26 16:40:05 +00:00
|
|
|
$action = $par ? $par : $request->getVal( 'action', $par );
|
2013-12-27 07:01:43 +00:00
|
|
|
$return = $this->getPageTitle();
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2011-03-11 14:20:39 +00:00
|
|
|
switch( $action ) {
|
2009-08-27 13:02:57 +00:00
|
|
|
case 'delete':
|
|
|
|
case 'edit':
|
|
|
|
case 'add':
|
2012-04-25 08:53:49 +00:00
|
|
|
if ( $this->canModify( $out ) ) {
|
2012-05-25 23:51:14 +00:00
|
|
|
$this->showForm( $action );
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
2011-09-26 16:40:05 +00:00
|
|
|
$out->returnToMain( false, $return );
|
2008-12-31 18:44:54 +00:00
|
|
|
break;
|
2009-08-27 13:02:57 +00:00
|
|
|
case 'submit':
|
2012-04-25 08:53:49 +00:00
|
|
|
if ( !$this->canModify( $out ) ) {
|
2014-07-18 21:29:23 +00:00
|
|
|
// Error msg added by canModify()
|
2013-08-02 14:33:29 +00:00
|
|
|
} elseif ( !$request->wasPosted() ||
|
|
|
|
!$this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) )
|
|
|
|
) {
|
2011-06-11 22:14:03 +00:00
|
|
|
// Prevent cross-site request forgeries
|
2011-09-26 16:40:05 +00:00
|
|
|
$out->addWikiMsg( 'sessionfailure' );
|
2011-06-11 22:14:03 +00:00
|
|
|
} else {
|
|
|
|
$this->doSubmit();
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2011-09-26 16:40:05 +00:00
|
|
|
$out->returnToMain( false, $return );
|
2008-12-31 18:44:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-07-19 12:45:38 +00:00
|
|
|
$this->showList();
|
2008-12-31 18:44:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-19 12:45:38 +00:00
|
|
|
/**
|
|
|
|
* Returns boolean whether the user can modify the data.
|
2012-05-22 17:59:00 +00:00
|
|
|
* @param $out OutputPage|bool If $wgOut object given, it adds the respective error message.
|
|
|
|
* @throws PermissionsError
|
|
|
|
* @return bool
|
2011-07-19 12:45:38 +00:00
|
|
|
*/
|
|
|
|
public function canModify( $out = false ) {
|
2011-09-26 16:40:05 +00:00
|
|
|
global $wgInterwikiCache;
|
2012-04-25 08:53:49 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'interwiki' ) ) {
|
2014-07-18 21:29:23 +00:00
|
|
|
// Check permissions
|
2012-04-25 10:02:50 +00:00
|
|
|
if ( $out ) {
|
|
|
|
throw new PermissionsError( 'interwiki' );
|
|
|
|
}
|
|
|
|
|
2011-07-19 12:45:38 +00:00
|
|
|
return false;
|
2012-04-25 08:53:49 +00:00
|
|
|
} elseif ( $wgInterwikiCache ) {
|
2014-07-18 21:29:23 +00:00
|
|
|
// Editing the interwiki cache is not supported
|
2012-04-25 10:02:50 +00:00
|
|
|
if ( $out ) {
|
|
|
|
$out->addWikiMsg( 'interwiki-cached' );
|
|
|
|
}
|
|
|
|
|
2011-07-19 12:45:38 +00:00
|
|
|
return false;
|
2012-04-25 08:53:49 +00:00
|
|
|
} elseif ( wfReadOnly() ) {
|
2014-07-18 21:29:23 +00:00
|
|
|
// Is the database in read-only mode?
|
2012-04-25 10:02:50 +00:00
|
|
|
if ( $out ) {
|
|
|
|
$out->readOnlyPage();
|
|
|
|
}
|
2011-07-19 12:45:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-21 10:49:52 +00:00
|
|
|
|
2012-05-22 17:59:00 +00:00
|
|
|
/**
|
|
|
|
* @param $action string
|
|
|
|
*/
|
2011-07-19 12:45:38 +00:00
|
|
|
function showForm( $action ) {
|
2011-09-26 16:40:05 +00:00
|
|
|
$request = $this->getRequest();
|
2011-07-20 15:29:34 +00:00
|
|
|
|
2011-09-26 16:40:05 +00:00
|
|
|
$prefix = $request->getVal( 'prefix' );
|
2011-07-20 15:29:34 +00:00
|
|
|
$wpPrefix = '';
|
|
|
|
$label = array( 'class' => 'mw-label' );
|
|
|
|
$input = array( 'class' => 'mw-input' );
|
|
|
|
|
2012-05-18 10:07:43 +00:00
|
|
|
if ( $action === 'delete' ) {
|
2012-04-25 10:08:42 +00:00
|
|
|
$topmessage = $this->msg( 'interwiki_delquestion', $prefix )->text();
|
2012-05-20 21:44:27 +00:00
|
|
|
$intromessage = $this->msg( 'interwiki_deleting', $prefix )->escaped();
|
2011-07-20 15:29:34 +00:00
|
|
|
$wpPrefix = Html::hidden( 'wpInterwikiPrefix', $prefix );
|
|
|
|
$button = 'delete';
|
|
|
|
$formContent = '';
|
2012-05-18 10:07:43 +00:00
|
|
|
} elseif ( $action === 'edit' ) {
|
2011-07-20 15:29:34 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$row = $dbr->selectRow( 'interwiki', '*', array( 'iw_prefix' => $prefix ), __METHOD__ );
|
2012-04-25 10:02:50 +00:00
|
|
|
|
2012-04-25 08:53:49 +00:00
|
|
|
if ( !$row ) {
|
2011-07-20 15:29:34 +00:00
|
|
|
$this->error( 'interwiki_editerror', $prefix );
|
2012-05-25 23:51:14 +00:00
|
|
|
return;
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
2012-04-25 10:02:50 +00:00
|
|
|
|
2012-09-14 13:01:51 +00:00
|
|
|
$prefix = $prefixElement = $row->iw_prefix;
|
2011-07-20 15:29:34 +00:00
|
|
|
$defaulturl = $row->iw_url;
|
|
|
|
$trans = $row->iw_trans;
|
|
|
|
$local = $row->iw_local;
|
|
|
|
$wpPrefix = Html::hidden( 'wpInterwikiPrefix', $row->iw_prefix );
|
2012-04-25 10:08:42 +00:00
|
|
|
$topmessage = $this->msg( 'interwiki_edittext' )->text();
|
2012-05-20 21:44:27 +00:00
|
|
|
$intromessage = $this->msg( 'interwiki_editintro' )->escaped();
|
2011-07-20 15:29:34 +00:00
|
|
|
$button = 'edit';
|
2012-05-18 10:07:43 +00:00
|
|
|
} elseif ( $action === 'add' ) {
|
2011-09-26 16:40:05 +00:00
|
|
|
$prefix = $request->getVal( 'wpInterwikiPrefix', $request->getVal( 'prefix' ) );
|
2012-08-01 08:03:51 +00:00
|
|
|
$prefixElement = Xml::input( 'wpInterwikiPrefix', 20, $prefix,
|
2011-07-20 15:29:34 +00:00
|
|
|
array( 'tabindex' => 1, 'id' => 'mw-interwiki-prefix', 'maxlength' => 20 ) );
|
2011-09-26 16:40:05 +00:00
|
|
|
$local = $request->getCheck( 'wpInterwikiLocal' );
|
|
|
|
$trans = $request->getCheck( 'wpInterwikiTrans' );
|
2012-04-25 10:08:42 +00:00
|
|
|
$defaulturl = $request->getVal( 'wpInterwikiURL', $this->msg( 'interwiki-defaulturl' )->text() );
|
|
|
|
$topmessage = $this->msg( 'interwiki_addtext' )->text();
|
2012-05-20 21:44:27 +00:00
|
|
|
$intromessage = $this->msg( 'interwiki_addintro' )->escaped();
|
2011-07-20 15:29:34 +00:00
|
|
|
$button = 'interwiki_addbutton';
|
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2012-05-18 10:07:43 +00:00
|
|
|
if ( $action === 'add' || $action === 'edit' ) {
|
2011-07-20 15:29:34 +00:00
|
|
|
$formContent = Html::rawElement( 'tr', null,
|
2012-04-25 10:08:42 +00:00
|
|
|
Html::element( 'td', $label, $this->msg( 'interwiki-prefix-label' )->text() ) .
|
2012-08-01 08:03:51 +00:00
|
|
|
Html::rawElement( 'td', null, '<tt>' . $prefixElement . '</tt>' )
|
2013-08-02 14:33:29 +00:00
|
|
|
) . Html::rawElement(
|
|
|
|
'tr',
|
|
|
|
null,
|
|
|
|
Html::rawElement(
|
|
|
|
'td',
|
|
|
|
$label,
|
|
|
|
Xml::label( $this->msg( 'interwiki-local-label' )->text(), 'mw-interwiki-local' )
|
|
|
|
) .
|
|
|
|
Html::rawElement(
|
|
|
|
'td',
|
|
|
|
$input,
|
|
|
|
Xml::check( 'wpInterwikiLocal', $local, array( 'id' => 'mw-interwiki-local' ) )
|
|
|
|
)
|
2011-07-20 15:29:34 +00:00
|
|
|
) . Html::rawElement( 'tr', null,
|
2013-08-02 14:33:29 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'td',
|
|
|
|
$label,
|
|
|
|
Xml::label( $this->msg( 'interwiki-trans-label' )->text(), 'mw-interwiki-trans' )
|
|
|
|
) .
|
|
|
|
Html::rawElement(
|
|
|
|
'td',
|
|
|
|
$input, Xml::check( 'wpInterwikiTrans', $trans, array( 'id' => 'mw-interwiki-trans' ) ) )
|
2011-07-20 15:29:34 +00:00
|
|
|
) . Html::rawElement( 'tr', null,
|
2013-08-02 14:33:29 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'td',
|
|
|
|
$label,
|
|
|
|
Xml::label( $this->msg( 'interwiki-url-label' )->text(), 'mw-interwiki-url' )
|
|
|
|
) .
|
2011-07-20 15:29:34 +00:00
|
|
|
Html::rawElement( 'td', $input, Xml::input( 'wpInterwikiURL', 60, $defaulturl,
|
|
|
|
array( 'tabindex' => 1, 'maxlength' => 200, 'id' => 'mw-interwiki-url' ) ) )
|
2008-04-03 21:00:22 +00:00
|
|
|
);
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2011-07-20 15:29:34 +00:00
|
|
|
|
2013-08-02 14:33:29 +00:00
|
|
|
$form = Xml::fieldset( $topmessage, Html::rawElement(
|
|
|
|
'form',
|
|
|
|
array(
|
|
|
|
'id' => "mw-interwiki-{$action}form",
|
|
|
|
'method' => 'post',
|
2013-12-27 07:01:43 +00:00
|
|
|
'action' => $this->getPageTitle()->getLocalUrl( array(
|
2013-08-02 14:33:29 +00:00
|
|
|
'action' => 'submit',
|
|
|
|
'prefix' => $prefix
|
|
|
|
) )
|
|
|
|
),
|
2011-07-20 16:25:53 +00:00
|
|
|
Html::rawElement( 'p', null, $intromessage ) .
|
2011-07-20 15:29:34 +00:00
|
|
|
Html::rawElement( 'table', array( 'id' => "mw-interwiki-{$action}" ),
|
|
|
|
$formContent . Html::rawElement( 'tr', null,
|
2012-04-25 10:08:42 +00:00
|
|
|
Html::rawElement( 'td', $label, Xml::label( $this->msg( 'interwiki_reasonfield' )->text(),
|
2011-07-20 15:29:34 +00:00
|
|
|
"mw-interwiki-{$action}reason" ) ) .
|
|
|
|
Html::rawElement( 'td', $input, Xml::input( 'wpInterwikiReason', 60, '',
|
|
|
|
array( 'tabindex' => 1, 'id' => "mw-interwiki-{$action}reason", 'maxlength' => 200 ) ) )
|
|
|
|
) . Html::rawElement( 'tr', null,
|
|
|
|
Html::rawElement( 'td', null, '' ) .
|
|
|
|
Html::rawElement( 'td', array( 'class' => 'mw-submit' ),
|
2012-04-25 10:08:42 +00:00
|
|
|
Xml::submitButton( $this->msg( $button )->text(), array( 'id' => 'mw-interwiki-submit' ) ) )
|
2011-07-20 15:29:34 +00:00
|
|
|
) . $wpPrefix .
|
2012-08-30 12:57:43 +00:00
|
|
|
Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() ) .
|
2011-07-20 15:29:34 +00:00
|
|
|
Html::hidden( 'wpInterwikiAction', $action )
|
|
|
|
)
|
|
|
|
) );
|
2012-05-25 23:51:14 +00:00
|
|
|
$this->getOutput()->addHTML( $form );
|
|
|
|
return;
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2008-12-31 18:44:54 +00:00
|
|
|
function doSubmit() {
|
2014-07-19 17:40:44 +00:00
|
|
|
global $wgMemc, $wgContLang;
|
2011-12-01 20:23:04 +00:00
|
|
|
|
2011-09-26 16:40:05 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$prefix = $request->getVal( 'wpInterwikiPrefix' );
|
|
|
|
$do = $request->getVal( 'wpInterwikiAction' );
|
2012-05-20 21:44:27 +00:00
|
|
|
// Show an error if the prefix is invalid (only when adding one).
|
2012-08-01 18:47:16 +00:00
|
|
|
// Invalid characters for a title should also be invalid for a prefix.
|
|
|
|
// Whitespace, ':', '&' and '=' are invalid, too.
|
|
|
|
// (Bug 30599).
|
|
|
|
global $wgLegalTitleChars;
|
|
|
|
$validPrefixChars = preg_replace( '/[ :&=]/', '', $wgLegalTitleChars );
|
|
|
|
if ( preg_match( "/\s|[^$validPrefixChars]/", $prefix ) && $do === 'add' ) {
|
2008-12-31 18:44:54 +00:00
|
|
|
$this->error( 'interwiki-badprefix', htmlspecialchars( $prefix ) );
|
|
|
|
$this->showForm( $do );
|
|
|
|
return;
|
|
|
|
}
|
2011-09-26 16:40:05 +00:00
|
|
|
$reason = $request->getText( 'wpInterwikiReason' );
|
2013-12-27 07:01:43 +00:00
|
|
|
$selfTitle = $this->getPageTitle();
|
2008-12-31 18:44:54 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2012-04-25 08:53:49 +00:00
|
|
|
switch( $do ) {
|
2009-08-27 13:02:57 +00:00
|
|
|
case 'delete':
|
2008-12-31 18:44:54 +00:00
|
|
|
$dbw->delete( 'interwiki', array( 'iw_prefix' => $prefix ), __METHOD__ );
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2012-05-18 10:07:43 +00:00
|
|
|
if ( $dbw->affectedRows() === 0 ) {
|
2008-12-31 18:44:54 +00:00
|
|
|
$this->error( 'interwiki_delfailed', $prefix );
|
|
|
|
$this->showForm( $do );
|
|
|
|
} else {
|
2011-09-26 16:40:05 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'interwiki_deleted', $prefix );
|
2008-12-31 18:44:54 +00:00
|
|
|
$log = new LogPage( 'interwiki' );
|
|
|
|
$log->addEntry( 'iw_delete', $selfTitle, $reason, array( $prefix ) );
|
2012-04-15 20:00:42 +00:00
|
|
|
$wgMemc->delete( wfMemcKey( 'interwiki', $prefix ) );
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-08-27 13:02:57 +00:00
|
|
|
case 'add':
|
2011-12-01 20:23:04 +00:00
|
|
|
$prefix = $wgContLang->lc( $prefix );
|
2012-05-20 21:44:27 +00:00
|
|
|
// N.B.: no break!
|
2011-12-01 20:23:04 +00:00
|
|
|
case 'edit':
|
2011-09-26 16:40:05 +00:00
|
|
|
$theurl = $request->getVal( 'wpInterwikiURL' );
|
|
|
|
$local = $request->getCheck( 'wpInterwikiLocal' ) ? 1 : 0;
|
|
|
|
$trans = $request->getCheck( 'wpInterwikiTrans' ) ? 1 : 0;
|
2011-03-11 14:20:39 +00:00
|
|
|
$data = array(
|
|
|
|
'iw_prefix' => $prefix,
|
|
|
|
'iw_url' => $theurl,
|
|
|
|
'iw_local' => $local,
|
|
|
|
'iw_trans' => $trans
|
|
|
|
);
|
2012-04-25 08:53:49 +00:00
|
|
|
|
2012-05-18 10:07:43 +00:00
|
|
|
if ( $prefix === '' || $theurl === '' ) {
|
2011-06-11 22:14:03 +00:00
|
|
|
$this->error( 'interwiki-submit-empty' );
|
|
|
|
$this->showForm( $do );
|
|
|
|
return;
|
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2012-08-01 08:03:51 +00:00
|
|
|
// Simple URL validation: check that the protocol is one of
|
|
|
|
// the supported protocols for this wiki.
|
|
|
|
// (bug 30600)
|
|
|
|
if ( !wfParseUrl( $theurl ) ) {
|
|
|
|
$this->error( 'interwiki-submit-invalidurl' );
|
|
|
|
$this->showForm( $do );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-18 10:07:43 +00:00
|
|
|
if ( $do === 'add' ) {
|
2008-12-31 18:44:54 +00:00
|
|
|
$dbw->insert( 'interwiki', $data, __METHOD__, 'IGNORE' );
|
2012-05-20 21:44:27 +00:00
|
|
|
} else { // $do === 'edit'
|
2008-12-31 18:44:54 +00:00
|
|
|
$dbw->update( 'interwiki', $data, array( 'iw_prefix' => $prefix ), __METHOD__, 'IGNORE' );
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
|
|
|
|
2012-05-20 21:44:27 +00:00
|
|
|
// used here: interwiki_addfailed, interwiki_added, interwiki_edited
|
2012-05-18 10:07:43 +00:00
|
|
|
if ( $dbw->affectedRows() === 0 ) {
|
2008-12-31 18:44:54 +00:00
|
|
|
$this->error( "interwiki_{$do}failed", $prefix );
|
|
|
|
$this->showForm( $do );
|
|
|
|
} else {
|
2011-09-26 16:40:05 +00:00
|
|
|
$this->getOutput()->addWikiMsg( "interwiki_{$do}ed", $prefix );
|
2008-12-31 18:44:54 +00:00
|
|
|
$log = new LogPage( 'interwiki' );
|
2009-08-27 13:02:57 +00:00
|
|
|
$log->addEntry( 'iw_' . $do, $selfTitle, $reason, array( $prefix, $theurl, $trans, $local ) );
|
2012-04-15 20:00:42 +00:00
|
|
|
$wgMemc->delete( wfMemcKey( 'interwiki', $prefix ) );
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
2008-12-31 18:44:54 +00:00
|
|
|
break;
|
2012-04-25 08:53:49 +00:00
|
|
|
}
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2011-07-19 12:45:38 +00:00
|
|
|
function showList() {
|
2014-07-19 17:40:44 +00:00
|
|
|
global $wgInterwikiCentralDB;
|
2011-07-19 12:45:38 +00:00
|
|
|
$canModify = $this->canModify();
|
2009-02-07 03:30:23 +00:00
|
|
|
|
2014-07-19 17:40:44 +00:00
|
|
|
// Build lists
|
|
|
|
if ( !method_exists( 'Interwiki', 'getAllPrefixes' ) ) {
|
|
|
|
// version 2.0 is not backwards compatible (but will still display a nice error)
|
|
|
|
$this->error( 'interwiki_error' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$iwPrefixes = Interwiki::getAllPrefixes( null );
|
|
|
|
$iwGlobalPrefixes = array();
|
|
|
|
if ( $wgInterwikiCentralDB !== null && $wgInterwikiCentralDB !== wfWikiId() ) {
|
|
|
|
// Fetch list from global table
|
|
|
|
$dbrCentralDB = wfGetDB( DB_SLAVE, array(), $wgInterwikiCentralDB );
|
|
|
|
$res = $dbrCentralDB->select( 'interwiki', '*', false, __METHOD__ );
|
|
|
|
$retval = array();
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$row = (array)$row;
|
|
|
|
if ( !Language::fetchLanguageName( $row['iw_prefix'] ) ) {
|
|
|
|
$retval[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$iwGlobalPrefixes = $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split out language links
|
|
|
|
$iwLocalPrefixes = array();
|
|
|
|
$iwLanguagePrefixes = array();
|
|
|
|
foreach ( $iwPrefixes as $iwPrefix ) {
|
|
|
|
if ( Language::fetchLanguageName( $iwPrefix['iw_prefix'] ) ) {
|
|
|
|
$iwLanguagePrefixes[] = $iwPrefix;
|
|
|
|
} else {
|
|
|
|
$iwLocalPrefixes[] = $iwPrefix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-12 22:33:39 +00:00
|
|
|
// Page intro content
|
|
|
|
$this->getOutput()->addWikiMsg( 'interwiki_intro' );
|
|
|
|
$logLink = Linker::link(
|
|
|
|
SpecialPage::getTitleFor( 'log', 'interwiki' ),
|
|
|
|
$this->msg( 'interwiki-logtext' )->escaped()
|
|
|
|
);
|
|
|
|
$this->getOutput()->addHTML( '<p class="mw-interwiki-log">' . $logLink . '</p>' );
|
|
|
|
|
|
|
|
// Add 'add' link
|
2011-07-19 12:45:38 +00:00
|
|
|
if ( $canModify ) {
|
2014-07-19 17:40:44 +00:00
|
|
|
if ( count( $iwGlobalPrefixes ) !== 0 ) {
|
|
|
|
$addtext = $this->msg( 'interwiki-addtext-local' )->escaped();
|
|
|
|
} else {
|
|
|
|
$addtext = $this->msg( 'interwiki_addtext' )->escaped();
|
|
|
|
}
|
2013-12-27 07:01:43 +00:00
|
|
|
$addlink = Linker::linkKnown( $this->getPageTitle( 'add' ), $addtext );
|
2011-09-26 16:40:05 +00:00
|
|
|
$this->getOutput()->addHTML( '<p class="mw-interwiki-addlink">' . $addlink . '</p>' );
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2014-09-12 22:33:39 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'interwiki-legend' );
|
|
|
|
|
2014-07-19 17:40:44 +00:00
|
|
|
if ( !is_array( $iwPrefixes ) || count( $iwPrefixes ) === 0 ) {
|
|
|
|
if ( !is_array( $iwGlobalPrefixes ) || count( $iwGlobalPrefixes ) === 0 ) {
|
|
|
|
// If the interwiki table(s) are empty, display an error message
|
|
|
|
$this->error( 'interwiki_error' );
|
|
|
|
return;
|
|
|
|
}
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2011-07-19 12:45:38 +00:00
|
|
|
|
2014-07-19 17:40:44 +00:00
|
|
|
// Add the global table
|
|
|
|
if ( count( $iwGlobalPrefixes ) !== 0 ) {
|
|
|
|
$this->getOutput()->addHTML(
|
|
|
|
'<h2 id="interwikitable-global">' .
|
|
|
|
$this->msg( 'interwiki-global-links' )->parse() .
|
|
|
|
'</h2>'
|
|
|
|
);
|
|
|
|
$this->getOutput()->addWikiMsg( 'interwiki-global-description' );
|
|
|
|
|
|
|
|
// $canModify is false here because this is just a display of remote data
|
|
|
|
$this->makeTable( false, $iwGlobalPrefixes );
|
2011-07-19 12:45:38 +00:00
|
|
|
}
|
|
|
|
|
2014-07-19 17:40:44 +00:00
|
|
|
// Add the local table
|
|
|
|
if ( count( $iwLocalPrefixes ) !== 0 ) {
|
|
|
|
if ( count( $iwGlobalPrefixes ) !== 0 ) {
|
|
|
|
$this->getOutput()->addHTML(
|
|
|
|
'<h2 id="interwikitable-local">' .
|
|
|
|
$this->msg( 'interwiki-local-links' )->parse() .
|
|
|
|
'</h2>'
|
|
|
|
);
|
|
|
|
$this->getOutput()->addWikiMsg( 'interwiki-local-description' );
|
|
|
|
} else {
|
|
|
|
$this->getOutput()->addHTML(
|
|
|
|
'<h2 id="interwikitable-local">' .
|
|
|
|
$this->msg( 'interwiki-links' )->parse() .
|
|
|
|
'</h2>'
|
|
|
|
);
|
|
|
|
$this->getOutput()->addWikiMsg( 'interwiki-description' );
|
|
|
|
}
|
|
|
|
$this->makeTable( $canModify, $iwLocalPrefixes );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the language table
|
|
|
|
if ( count( $iwLanguagePrefixes ) !== 0 ) {
|
|
|
|
$this->getOutput()->addHTML(
|
|
|
|
'<h2 id="interwikitable-language">' .
|
|
|
|
$this->msg( 'interwiki-language-links' )->parse() .
|
|
|
|
'</h2>'
|
|
|
|
);
|
|
|
|
$this->getOutput()->addWikiMsg( 'interwiki-language-description' );
|
|
|
|
|
|
|
|
$this->makeTable( $canModify, $iwLanguagePrefixes );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeTable( $canModify, $iwPrefixes ) {
|
2014-07-18 21:29:23 +00:00
|
|
|
// Output the existing Interwiki prefixes table header
|
2013-08-02 14:33:29 +00:00
|
|
|
$out = '';
|
|
|
|
$out .= Html::openElement(
|
|
|
|
'table',
|
|
|
|
array( 'class' => 'mw-interwikitable wikitable sortable body' )
|
|
|
|
) . "\n";
|
2014-07-19 17:40:44 +00:00
|
|
|
$out .= Html::openElement( 'tr', array( 'class' => 'interwikitable-header' ) ) .
|
2012-05-20 21:44:27 +00:00
|
|
|
Html::element( 'th', null, $this->msg( 'interwiki_prefix' )->text() ) .
|
|
|
|
Html::element( 'th', null, $this->msg( 'interwiki_url' )->text() ) .
|
|
|
|
Html::element( 'th', null, $this->msg( 'interwiki_local' )->text() ) .
|
|
|
|
Html::element( 'th', null, $this->msg( 'interwiki_trans' )->text() ) .
|
2013-08-02 14:33:29 +00:00
|
|
|
( $canModify ?
|
|
|
|
Html::element(
|
|
|
|
'th',
|
|
|
|
array( 'class' => 'unsortable' ),
|
|
|
|
$this->msg( 'interwiki_edit' )->text()
|
|
|
|
) :
|
|
|
|
''
|
|
|
|
);
|
2011-07-19 12:45:38 +00:00
|
|
|
$out .= Html::closeElement( 'tr' ) . "\n";
|
2009-08-27 13:02:57 +00:00
|
|
|
|
2013-12-27 07:01:43 +00:00
|
|
|
$selfTitle = $this->getPageTitle();
|
2011-06-11 22:14:03 +00:00
|
|
|
|
2014-07-18 21:29:23 +00:00
|
|
|
// Output the existing Interwiki prefixes table rows
|
2012-05-22 17:59:00 +00:00
|
|
|
foreach ( $iwPrefixes as $iwPrefix ) {
|
2011-07-19 12:45:38 +00:00
|
|
|
$out .= Html::openElement( 'tr', array( 'class' => 'mw-interwikitable-row' ) );
|
2012-05-16 09:43:25 +00:00
|
|
|
$out .= Html::element( 'td', array( 'class' => 'mw-interwikitable-prefix' ),
|
2012-05-20 21:44:27 +00:00
|
|
|
$iwPrefix['iw_prefix'] );
|
2013-08-02 14:33:29 +00:00
|
|
|
$out .= Html::element(
|
|
|
|
'td',
|
|
|
|
array( 'class' => 'mw-interwikitable-url' ),
|
|
|
|
$iwPrefix['iw_url']
|
|
|
|
);
|
2012-05-21 11:19:59 +00:00
|
|
|
$attribs = array( 'class' => 'mw-interwikitable-local' );
|
|
|
|
// Green background for cells with "yes".
|
|
|
|
if( $iwPrefix['iw_local'] ) {
|
2014-07-18 21:29:23 +00:00
|
|
|
$attribs['class'] .= ' mw-interwikitable-local-yes';
|
2012-05-21 11:19:59 +00:00
|
|
|
}
|
2012-05-20 21:44:27 +00:00
|
|
|
// The messages interwiki_0 and interwiki_1 are used here.
|
2013-08-02 14:33:29 +00:00
|
|
|
$contents = isset( $iwPrefix['iw_local'] ) ?
|
|
|
|
$this->msg( 'interwiki_' . $iwPrefix['iw_local'] )->text() :
|
|
|
|
'-';
|
|
|
|
$out .= Html::element( 'td', $attribs, $contents );
|
2012-05-21 11:19:59 +00:00
|
|
|
$attribs = array( 'class' => 'mw-interwikitable-trans' );
|
|
|
|
// Green background for cells with "yes".
|
|
|
|
if( $iwPrefix['iw_trans'] ) {
|
2014-07-18 21:29:23 +00:00
|
|
|
$attribs['class'] .= ' mw-interwikitable-trans-yes';
|
2012-05-21 11:19:59 +00:00
|
|
|
}
|
|
|
|
// The messages interwiki_0 and interwiki_1 are used here.
|
2013-08-02 14:33:29 +00:00
|
|
|
$contents = isset( $iwPrefix['iw_trans'] ) ?
|
|
|
|
$this->msg( 'interwiki_' . $iwPrefix['iw_trans'] )->text() :
|
|
|
|
'-';
|
|
|
|
$out .= Html::element( 'td', $attribs, $contents );
|
2012-05-21 11:19:59 +00:00
|
|
|
|
|
|
|
// Additional column when the interwiki table can be modified.
|
2012-04-25 08:53:49 +00:00
|
|
|
if ( $canModify ) {
|
2011-07-19 12:45:38 +00:00
|
|
|
$out .= Html::rawElement( 'td', array( 'class' => 'mw-interwikitable-modify' ),
|
2012-04-25 10:08:42 +00:00
|
|
|
Linker::linkKnown( $selfTitle, $this->msg( 'edit' )->escaped(), array(),
|
2011-07-19 12:45:38 +00:00
|
|
|
array( 'action' => 'edit', 'prefix' => $iwPrefix['iw_prefix'] ) ) .
|
2012-04-25 10:08:42 +00:00
|
|
|
$this->msg( 'comma-separator' ) .
|
|
|
|
Linker::linkKnown( $selfTitle, $this->msg( 'delete' )->escaped(), array(),
|
2011-07-19 12:45:38 +00:00
|
|
|
array( 'action' => 'delete', 'prefix' => $iwPrefix['iw_prefix'] ) )
|
|
|
|
);
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
2011-07-19 12:45:38 +00:00
|
|
|
$out .= Html::closeElement( 'tr' ) . "\n";
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
2011-07-19 12:45:38 +00:00
|
|
|
$out .= Html::closeElement( 'table' );
|
|
|
|
|
2011-09-26 16:40:05 +00:00
|
|
|
$this->getOutput()->addHTML( $out );
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2009-08-27 13:02:57 +00:00
|
|
|
|
2008-12-31 18:44:54 +00:00
|
|
|
function error() {
|
|
|
|
$args = func_get_args();
|
2011-09-26 16:40:05 +00:00
|
|
|
$this->getOutput()->wrapWikiMsg( "<p class='error'>$1</p>", $args );
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
2010-12-09 11:57:55 +00:00
|
|
|
}
|
2011-09-26 16:40:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Needed to pass the URL as a raw parameter, because it contains $1
|
2012-05-20 21:44:27 +00:00
|
|
|
*/
|
2011-09-26 16:40:05 +00:00
|
|
|
class InterwikiLogFormatter extends LogFormatter {
|
2012-05-22 17:59:00 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2011-09-26 16:40:05 +00:00
|
|
|
protected function getMessageParameters() {
|
|
|
|
$params = parent::getMessageParameters();
|
2012-04-25 08:53:49 +00:00
|
|
|
if ( isset( $params[4] ) ) {
|
2012-04-27 23:24:48 +00:00
|
|
|
$params[4] = Message::rawParam( htmlspecialchars( $params[4] ) );
|
2011-09-26 16:40:05 +00:00
|
|
|
}
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
}
|