2008-04-03 21:00:22 +00:00
|
|
|
<?php
|
2018-06-07 18:39:17 +00:00
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2008-04-03 21:00:22 +00:00
|
|
|
/**
|
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' );
|
|
|
|
}
|
|
|
|
|
2016-01-15 21:53:45 +00:00
|
|
|
public function doesWrites() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2018-10-31 22:38:46 +00:00
|
|
|
public 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
|
|
|
}
|
|
|
|
|
2015-12-28 21:58:31 +00:00
|
|
|
public function getSubpagesForPrefixSearch() {
|
|
|
|
// delete, edit both require the prefix parameter.
|
2016-03-07 14:41:22 +00:00
|
|
|
return [ 'add' ];
|
2015-12-28 21:58:31 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 13:02:57 +00:00
|
|
|
/**
|
|
|
|
* Show the special page
|
|
|
|
*
|
2017-10-06 22:51:04 +00:00
|
|
|
* @param string|null $par parameter passed to the page or null
|
2009-08-27 13:02:57 +00:00
|
|
|
*/
|
|
|
|
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();
|
|
|
|
|
2017-08-28 05:12:20 +00:00
|
|
|
$out->addModuleStyles( 'ext.interwiki.specialpage' );
|
2011-07-19 12:45:38 +00:00
|
|
|
|
2016-03-07 14:26:57 +00:00
|
|
|
$action = $par ?: $request->getVal( 'action', $par );
|
2013-12-27 07:01:43 +00:00
|
|
|
$return = $this->getPageTitle();
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2014-12-16 01:46:38 +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.
|
2017-10-06 22:51:04 +00:00
|
|
|
* @param OutputPage|bool $out If $wgOut object given, it adds the respective error message.
|
2016-03-07 14:29:11 +00:00
|
|
|
* @throws PermissionsError|ReadOnlyError
|
2012-05-22 17:59:00 +00:00
|
|
|
* @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() ) {
|
2016-03-07 14:29:11 +00:00
|
|
|
throw new ReadOnlyError;
|
2011-07-19 12:45:38 +00:00
|
|
|
}
|
2016-03-07 14:29:11 +00:00
|
|
|
|
2011-07-19 12:45:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-06-21 10:49:52 +00:00
|
|
|
|
2012-05-22 17:59:00 +00:00
|
|
|
/**
|
2017-10-06 22:51:04 +00:00
|
|
|
* @param string $action The action of the form
|
2012-05-22 17:59:00 +00:00
|
|
|
*/
|
2016-03-07 14:34:01 +00:00
|
|
|
protected 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 = '';
|
2016-03-07 14:41:22 +00:00
|
|
|
$label = [ 'class' => 'mw-label' ];
|
|
|
|
$input = [ 'class' => 'mw-input' ];
|
2011-07-20 15:29:34 +00:00
|
|
|
|
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' ) {
|
2017-09-24 05:27:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-03-07 14:41:22 +00:00
|
|
|
$row = $dbr->selectRow( 'interwiki', '*', [ '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,
|
2016-03-07 14:41:22 +00:00
|
|
|
[ '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() ) .
|
2016-03-07 14:30:46 +00:00
|
|
|
Html::rawElement( 'td', null, '<code>' . $prefixElement . '</code>' )
|
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,
|
2016-03-07 14:41:22 +00:00
|
|
|
Xml::check( 'wpInterwikiLocal', $local, [ 'id' => 'mw-interwiki-local' ] )
|
2013-08-02 14:33:29 +00:00
|
|
|
)
|
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',
|
2018-12-30 10:39:25 +00:00
|
|
|
$input, Xml::check( 'wpInterwikiTrans', $trans, [ '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,
|
2016-03-07 14:41:22 +00:00
|
|
|
[ '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',
|
2016-03-07 14:41:22 +00:00
|
|
|
[
|
2013-08-02 14:33:29 +00:00
|
|
|
'id' => "mw-interwiki-{$action}form",
|
|
|
|
'method' => 'post',
|
2016-03-07 14:41:22 +00:00
|
|
|
'action' => $this->getPageTitle()->getLocalURL( [
|
2013-08-02 14:33:29 +00:00
|
|
|
'action' => 'submit',
|
|
|
|
'prefix' => $prefix
|
2016-03-07 14:41:22 +00:00
|
|
|
] )
|
|
|
|
],
|
2011-07-20 16:25:53 +00:00
|
|
|
Html::rawElement( 'p', null, $intromessage ) .
|
2016-03-07 14:41:22 +00:00
|
|
|
Html::rawElement( 'table', [ 'id' => "mw-interwiki-{$action}" ],
|
2011-07-20 15:29:34 +00:00
|
|
|
$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, '',
|
2016-03-07 14:41:22 +00:00
|
|
|
[ 'tabindex' => 1, 'id' => "mw-interwiki-{$action}reason", 'maxlength' => 200 ] ) )
|
2017-06-20 07:09:12 +00:00
|
|
|
) . Html::rawElement( 'tr', null,
|
2011-07-20 15:29:34 +00:00
|
|
|
Html::rawElement( 'td', null, '' ) .
|
2016-03-07 14:41:22 +00:00
|
|
|
Html::rawElement( 'td', [ 'class' => 'mw-submit' ],
|
|
|
|
Xml::submitButton( $this->msg( $button )->text(), [ '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 );
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2016-03-07 14:34:01 +00:00
|
|
|
protected function doSubmit() {
|
2015-04-29 22:04:43 +00:00
|
|
|
global $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 );
|
2016-03-07 14:21:34 +00:00
|
|
|
if ( $do === 'add' && preg_match( "/\s|[^$validPrefixChars]/", $prefix ) ) {
|
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();
|
2018-06-07 18:39:17 +00:00
|
|
|
$lookup = MediaWikiServices::getInstance()->getInterwikiLookup();
|
2008-12-31 18:44:54 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2014-12-16 01:46:38 +00:00
|
|
|
switch ( $do ) {
|
2009-08-27 13:02:57 +00:00
|
|
|
case 'delete':
|
2016-03-07 14:41:22 +00:00
|
|
|
$dbw->delete( 'interwiki', [ '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' );
|
2016-03-07 14:41:22 +00:00
|
|
|
$log->addEntry( 'iw_delete', $selfTitle, $reason, [ $prefix ] );
|
2018-06-07 18:39:17 +00:00
|
|
|
$lookup->invalidateCache( $prefix );
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-07 14:19:26 +00:00
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */
|
2009-08-27 13:02:57 +00:00
|
|
|
case 'add':
|
2011-12-01 20:23:04 +00:00
|
|
|
$prefix = $wgContLang->lc( $prefix );
|
|
|
|
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;
|
2016-03-07 14:41:22 +00:00
|
|
|
$data = [
|
2011-03-11 14:20:39 +00:00
|
|
|
'iw_prefix' => $prefix,
|
|
|
|
'iw_url' => $theurl,
|
|
|
|
'iw_local' => $local,
|
|
|
|
'iw_trans' => $trans
|
2016-03-07 14:41:22 +00:00
|
|
|
];
|
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'
|
2016-03-07 14:41:22 +00:00
|
|
|
$dbw->update( 'interwiki', $data, [ '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' );
|
2016-03-07 14:41:22 +00:00
|
|
|
$log->addEntry( 'iw_' . $do, $selfTitle, $reason, [ $prefix, $theurl, $trans, $local ] );
|
2018-06-07 18:39:17 +00:00
|
|
|
$lookup->invalidateCache( $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
|
|
|
|
2016-03-07 14:34:01 +00:00
|
|
|
protected function showList() {
|
2015-07-02 21:12:21 +00:00
|
|
|
global $wgInterwikiCentralDB, $wgInterwikiViewOnly;
|
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
|
2018-06-07 18:39:17 +00:00
|
|
|
$lookup = MediaWikiServices::getInstance()->getInterwikiLookup();
|
|
|
|
$iwPrefixes = $lookup->getAllPrefixes( null );
|
2016-03-07 14:41:22 +00:00
|
|
|
$iwGlobalPrefixes = [];
|
2016-03-07 14:35:32 +00:00
|
|
|
if ( $wgInterwikiCentralDB !== null && $wgInterwikiCentralDB !== wfWikiID() ) {
|
2014-07-19 17:40:44 +00:00
|
|
|
// Fetch list from global table
|
2017-09-24 05:27:39 +00:00
|
|
|
$dbrCentralDB = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralDB );
|
2014-07-19 17:40:44 +00:00
|
|
|
$res = $dbrCentralDB->select( 'interwiki', '*', false, __METHOD__ );
|
2016-03-07 14:41:22 +00:00
|
|
|
$retval = [];
|
2014-07-19 17:40:44 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$row = (array)$row;
|
|
|
|
if ( !Language::fetchLanguageName( $row['iw_prefix'] ) ) {
|
|
|
|
$retval[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$iwGlobalPrefixes = $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split out language links
|
2016-03-07 14:41:22 +00:00
|
|
|
$iwLocalPrefixes = [];
|
|
|
|
$iwLanguagePrefixes = [];
|
2014-07-19 17:40:44 +00:00
|
|
|
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' );
|
2015-06-23 02:27:58 +00:00
|
|
|
|
|
|
|
// Add 'view log' link when possible
|
|
|
|
if ( $wgInterwikiViewOnly === false ) {
|
2018-04-02 19:41:28 +00:00
|
|
|
$logLink = $this->getLinkRenderer()->makeLink(
|
2015-06-23 02:27:58 +00:00
|
|
|
SpecialPage::getTitleFor( 'Log', 'interwiki' ),
|
2018-04-02 19:41:28 +00:00
|
|
|
$this->msg( 'interwiki-logtext' )->text()
|
2015-06-23 02:27:58 +00:00
|
|
|
);
|
|
|
|
$this->getOutput()->addHTML( '<p class="mw-interwiki-log">' . $logLink . '</p>' );
|
|
|
|
}
|
2014-09-12 22:33:39 +00:00
|
|
|
|
|
|
|
// 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 ) {
|
2018-04-02 19:41:28 +00:00
|
|
|
$addtext = $this->msg( 'interwiki-addtext-local' )->text();
|
2014-07-19 17:40:44 +00:00
|
|
|
} else {
|
2018-04-02 19:41:28 +00:00
|
|
|
$addtext = $this->msg( 'interwiki_addtext' )->text();
|
2014-07-19 17:40:44 +00:00
|
|
|
}
|
2018-04-02 19:41:28 +00:00
|
|
|
$addlink = $this->getLinkRenderer()->makeKnownLink(
|
|
|
|
$this->getPageTitle( 'add' ), $addtext );
|
|
|
|
$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' );
|
|
|
|
|
2016-03-07 14:25:36 +00:00
|
|
|
if ( ( !is_array( $iwPrefixes ) || count( $iwPrefixes ) === 0 ) &&
|
2017-06-20 07:09:12 +00:00
|
|
|
( !is_array( $iwGlobalPrefixes ) || count( $iwGlobalPrefixes ) === 0 )
|
|
|
|
) {
|
2016-03-07 14:25:36 +00:00
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 14:34:01 +00:00
|
|
|
protected 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 = '';
|
2018-12-30 10:39:25 +00:00
|
|
|
$out .= Html::openElement(
|
2013-08-02 14:33:29 +00:00
|
|
|
'table',
|
2016-03-07 14:41:22 +00:00
|
|
|
[ 'class' => 'mw-interwikitable wikitable sortable body' ]
|
2013-08-02 14:33:29 +00:00
|
|
|
) . "\n";
|
2018-12-30 10:39:25 +00:00
|
|
|
$out .= Html::openElement( 'thead' ) .
|
|
|
|
Html::openElement( 'tr', [ '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',
|
2016-03-07 14:41:22 +00:00
|
|
|
[ 'class' => 'unsortable' ],
|
2013-08-02 14:33:29 +00:00
|
|
|
$this->msg( 'interwiki_edit' )->text()
|
|
|
|
) :
|
|
|
|
''
|
|
|
|
);
|
2018-12-30 10:39:25 +00:00
|
|
|
$out .= Html::closeElement( 'tr' ) .
|
|
|
|
Html::closeElement( 'thead' ) . "\n" .
|
|
|
|
Html::openElement( 'tbody' );
|
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 ) {
|
2016-03-07 14:41:22 +00:00
|
|
|
$out .= Html::openElement( 'tr', [ 'class' => 'mw-interwikitable-row' ] );
|
|
|
|
$out .= Html::element( 'td', [ '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',
|
2016-03-07 14:41:22 +00:00
|
|
|
[ 'class' => 'mw-interwikitable-url' ],
|
2013-08-02 14:33:29 +00:00
|
|
|
$iwPrefix['iw_url']
|
|
|
|
);
|
2016-03-07 14:41:22 +00:00
|
|
|
$attribs = [ 'class' => 'mw-interwikitable-local' ];
|
2012-05-21 11:19:59 +00:00
|
|
|
// Green background for cells with "yes".
|
2014-12-16 01:46:38 +00:00
|
|
|
if ( isset( $iwPrefix['iw_local'] ) && $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 );
|
2016-03-07 14:41:22 +00:00
|
|
|
$attribs = [ 'class' => 'mw-interwikitable-trans' ];
|
2012-05-21 11:19:59 +00:00
|
|
|
// Green background for cells with "yes".
|
2014-12-16 01:46:38 +00:00
|
|
|
if ( isset( $iwPrefix['iw_trans'] ) && $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 ) {
|
2016-03-07 14:41:22 +00:00
|
|
|
$out .= Html::rawElement( 'td', [ 'class' => 'mw-interwikitable-modify' ],
|
2018-04-02 19:41:28 +00:00
|
|
|
$this->getLinkRenderer()->makeKnownLink(
|
|
|
|
$selfTitle,
|
|
|
|
$this->msg( 'edit' )->text(),
|
|
|
|
[],
|
|
|
|
[ 'action' => 'edit', 'prefix' => $iwPrefix['iw_prefix'] ]
|
|
|
|
) .
|
2012-04-25 10:08:42 +00:00
|
|
|
$this->msg( 'comma-separator' ) .
|
2018-04-02 19:41:28 +00:00
|
|
|
$this->getLinkRenderer()->makeKnownLink(
|
|
|
|
$selfTitle,
|
|
|
|
$this->msg( 'delete' )->text(),
|
|
|
|
[],
|
|
|
|
[ 'action' => 'delete', 'prefix' => $iwPrefix['iw_prefix'] ]
|
|
|
|
)
|
2011-07-19 12:45:38 +00:00
|
|
|
);
|
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
|
|
|
}
|
2018-12-30 10:39:25 +00:00
|
|
|
$out .= Html::closeElement( 'tbody' ) .
|
|
|
|
Html::closeElement( 'table' );
|
2011-07-19 12:45:38 +00:00
|
|
|
|
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
|
|
|
|
2016-03-07 14:34:01 +00:00
|
|
|
protected function error() {
|
2008-12-31 18:44:54 +00:00
|
|
|
$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
|
|
|
}
|
2015-05-15 20:21:23 +00:00
|
|
|
|
|
|
|
protected function getGroupName() {
|
|
|
|
return 'wiki';
|
|
|
|
}
|
2010-12-09 11:57:55 +00:00
|
|
|
}
|