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.
|
2019-07-26 11:11:21 +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 );
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
if ( !in_array( $action, [ 'add', 'edit', 'delete' ] ) || !$this->canModify( $out ) ) {
|
2011-07-19 12:45:38 +00:00
|
|
|
$this->showList();
|
2016-05-15 12:23:14 +00:00
|
|
|
} else {
|
|
|
|
$this->showForm( $action );
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2012-05-22 17:59:00 +00:00
|
|
|
* @return bool
|
2020-03-26 15:52:09 +00:00
|
|
|
* @throws PermissionsError|ReadOnlyError
|
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 ) {
|
2016-05-15 12:23:14 +00:00
|
|
|
$formDescriptor = [];
|
|
|
|
$hiddenFields = [
|
|
|
|
'action' => $action,
|
|
|
|
];
|
|
|
|
|
|
|
|
$status = Status::newGood();
|
2011-09-26 16:40:05 +00:00
|
|
|
$request = $this->getRequest();
|
2016-05-15 12:23:14 +00:00
|
|
|
$prefix = $request->getVal( 'prefix', $request->getVal( 'hiddenPrefix' ) );
|
|
|
|
|
|
|
|
switch ( $action ) {
|
|
|
|
case 'add':
|
|
|
|
case 'edit':
|
|
|
|
$formDescriptor = [
|
|
|
|
'prefix' => [
|
|
|
|
'type' => 'text',
|
|
|
|
'label-message' => 'interwiki-prefix-label',
|
|
|
|
'name' => 'prefix',
|
|
|
|
],
|
|
|
|
|
|
|
|
'local' => [
|
|
|
|
'type' => 'check',
|
|
|
|
'id' => 'mw-interwiki-local',
|
|
|
|
'label-message' => 'interwiki-local-label',
|
|
|
|
'name' => 'local',
|
|
|
|
],
|
2011-07-20 15:29:34 +00:00
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
'trans' => [
|
|
|
|
'type' => 'check',
|
|
|
|
'id' => 'mw-interwiki-trans',
|
|
|
|
'label-message' => 'interwiki-trans-label',
|
|
|
|
'name' => 'trans',
|
|
|
|
],
|
|
|
|
|
|
|
|
'url' => [
|
|
|
|
'type' => 'url',
|
|
|
|
'id' => 'mw-interwiki-url',
|
|
|
|
'label-message' => 'interwiki-url-label',
|
|
|
|
'maxlength' => 200,
|
|
|
|
'name' => 'wpInterwikiURL',
|
|
|
|
'size' => 60,
|
|
|
|
'tabindex' => 1,
|
|
|
|
],
|
|
|
|
|
|
|
|
'reason' => [
|
|
|
|
'type' => 'text',
|
|
|
|
'id' => "mw-interwiki-{$action}reason",
|
|
|
|
'label-message' => 'interwiki_reasonfield',
|
|
|
|
'maxlength' => 200,
|
|
|
|
'name' => 'wpInterwikiReason',
|
|
|
|
'size' => 60,
|
|
|
|
'tabindex' => 1,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
$formDescriptor = [
|
|
|
|
'prefix' => [
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'prefix',
|
|
|
|
'default' => $prefix,
|
|
|
|
],
|
|
|
|
|
|
|
|
'reason' => [
|
|
|
|
'type' => 'text',
|
|
|
|
'name' => 'reason',
|
|
|
|
'label-message' => 'interwiki_reasonfield',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$formDescriptor['hiddenPrefix'] = [
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'hiddenPrefix',
|
|
|
|
'default' => $prefix,
|
|
|
|
];
|
2011-07-20 15:29:34 +00:00
|
|
|
|
2019-07-26 11:13:43 +00:00
|
|
|
if ( $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
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
$formDescriptor['prefix']['disabled'] = true;
|
|
|
|
$formDescriptor['prefix']['default'] = $prefix;
|
|
|
|
$hiddenFields['prefix'] = $prefix;
|
|
|
|
|
2012-04-25 08:53:49 +00:00
|
|
|
if ( !$row ) {
|
2016-05-15 12:23:14 +00:00
|
|
|
$status->fatal( 'interwiki_editerror', $prefix );
|
|
|
|
} else {
|
|
|
|
$formDescriptor['url']['default'] = $row->iw_url;
|
|
|
|
$formDescriptor['url']['trans'] = $row->iw_trans;
|
|
|
|
$formDescriptor['url']['local'] = $row->iw_local;
|
2008-04-03 21:00:22 +00:00
|
|
|
}
|
2016-05-15 12:23:14 +00:00
|
|
|
}
|
2012-04-25 10:02:50 +00:00
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
$formDescriptor = [];
|
2011-07-20 15:29:34 +00:00
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
|
|
|
|
$htmlForm
|
|
|
|
->addHiddenFields( $hiddenFields )
|
|
|
|
->setSubmitCallback( [ $this, 'onSubmit' ] );
|
|
|
|
|
|
|
|
if ( $status->isOK() ) {
|
|
|
|
if ( $action === 'delete' ) {
|
|
|
|
$htmlForm->setSubmitDestructive();
|
|
|
|
}
|
|
|
|
|
|
|
|
$htmlForm->setSubmitTextMsg( $action !== 'add' ? $action : 'interwiki_addbutton' )
|
|
|
|
->setIntro( $this->msg( $action !== 'delete' ? "interwiki_{$action}intro" :
|
|
|
|
'interwiki_deleting', $prefix ) )
|
|
|
|
->show();
|
|
|
|
} else {
|
|
|
|
$htmlForm->suppressDefaultSubmit()
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( $status );
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2011-07-20 15:29:34 +00:00
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
$this->getOutput()->addBacklinkSubtitle( $this->getPageTitle() );
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2008-04-03 21:00:22 +00:00
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
public function onSubmit( array $data ) {
|
2019-09-02 08:52:12 +00:00
|
|
|
global $wgInterwikiCentralInterlanguageDB;
|
2011-12-01 20:23:04 +00:00
|
|
|
|
2016-05-15 12:23:14 +00:00
|
|
|
$status = Status::newGood();
|
2011-09-26 16:40:05 +00:00
|
|
|
$request = $this->getRequest();
|
2016-05-15 12:23:14 +00:00
|
|
|
$prefix = $this->getRequest()->getVal( 'prefix', '' );
|
|
|
|
$do = $request->getVal( 'action' );
|
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 ) ) {
|
2016-05-15 12:23:14 +00:00
|
|
|
$status->fatal( 'interwiki-badprefix', htmlspecialchars( $prefix ) );
|
|
|
|
return $status;
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2019-04-05 23:47:04 +00:00
|
|
|
// Disallow adding local interlanguage definitions if using global
|
|
|
|
if (
|
|
|
|
$do === 'add' && Language::fetchLanguageName( $prefix )
|
|
|
|
&& $wgInterwikiCentralInterlanguageDB !== wfWikiID()
|
|
|
|
&& $wgInterwikiCentralInterlanguageDB !== null
|
|
|
|
) {
|
|
|
|
$status->fatal( 'interwiki-cannotaddlocallanguage', htmlspecialchars( $prefix ) );
|
|
|
|
return $status;
|
|
|
|
}
|
2016-05-15 12:23:14 +00:00
|
|
|
$reason = $data['reason'];
|
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 ) {
|
2016-05-15 12:23:14 +00:00
|
|
|
$status->fatal( 'interwiki_delfailed', $prefix );
|
2008-12-31 18:44:54 +00:00
|
|
|
} 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' );
|
2020-01-25 02:29:06 +00:00
|
|
|
$log->addEntry(
|
|
|
|
'iw_delete',
|
|
|
|
$selfTitle,
|
|
|
|
$reason,
|
|
|
|
[ $prefix ],
|
|
|
|
$this->getUser()
|
|
|
|
);
|
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':
|
2019-09-02 08:52:12 +00:00
|
|
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
|
|
|
$prefix = $contLang->lc( $prefix );
|
2011-12-01 20:23:04 +00:00
|
|
|
case 'edit':
|
2016-05-15 12:23:14 +00:00
|
|
|
$theurl = $data['url'];
|
|
|
|
$local = $data['local'] ? 1 : 0;
|
|
|
|
$trans = $data['trans'] ? 1 : 0;
|
|
|
|
$rows = [
|
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 === '' ) {
|
2016-05-15 12:23:14 +00:00
|
|
|
$status->fatal( 'interwiki-submit-empty' );
|
|
|
|
break;
|
2011-06-11 22:14:03 +00:00
|
|
|
}
|
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 ) ) {
|
2016-05-15 12:23:14 +00:00
|
|
|
$status->fatal( 'interwiki-submit-invalidurl' );
|
|
|
|
break;
|
2012-08-01 08:03:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 10:07:43 +00:00
|
|
|
if ( $do === 'add' ) {
|
2019-03-17 23:32:13 +00:00
|
|
|
$dbw->insert( 'interwiki', $rows, __METHOD__, [ 'IGNORE' ] );
|
2012-05-20 21:44:27 +00:00
|
|
|
} else { // $do === 'edit'
|
2019-03-17 23:32:13 +00:00
|
|
|
$dbw->update( 'interwiki', $rows, [ '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 ) {
|
2016-05-15 12:23:14 +00:00
|
|
|
$status->fatal( "interwiki_{$do}failed", $prefix );
|
2008-12-31 18:44:54 +00:00
|
|
|
} 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' );
|
2020-01-25 02:29:06 +00:00
|
|
|
$log->addEntry(
|
|
|
|
'iw_' . $do,
|
|
|
|
$selfTitle,
|
|
|
|
$reason,
|
|
|
|
[ $prefix, $theurl, $trans, $local ],
|
|
|
|
$this->getUser()
|
|
|
|
);
|
2019-12-21 12:28:57 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
|
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
|
|
|
}
|
2016-05-15 12:23:14 +00:00
|
|
|
|
|
|
|
return $status;
|
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() {
|
2019-04-05 23:47:04 +00:00
|
|
|
global $wgInterwikiCentralDB, $wgInterwikiCentralInterlanguageDB, $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 = [];
|
2019-04-05 23:47:04 +00:00
|
|
|
$iwGlobalLanguagePrefixes = [];
|
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 );
|
2019-12-09 18:49:51 +00:00
|
|
|
$res = $dbrCentralDB->select( 'interwiki', '*', [], __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;
|
|
|
|
}
|
|
|
|
|
2019-04-05 23:47:04 +00:00
|
|
|
// Almost the same loop as above, but for global inter*language* links, whereas the above is for
|
|
|
|
// global inter*wiki* links
|
|
|
|
$usingGlobalInterlangLinks = ( $wgInterwikiCentralInterlanguageDB !== null );
|
|
|
|
$isGlobalInterlanguageDB = ( $wgInterwikiCentralInterlanguageDB === wfWikiID() );
|
|
|
|
$usingGlobalLanguages = $usingGlobalInterlangLinks && !$isGlobalInterlanguageDB;
|
|
|
|
if ( $usingGlobalLanguages ) {
|
|
|
|
// Fetch list from global table
|
|
|
|
$dbrCentralLangDB = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralInterlanguageDB );
|
2019-12-09 18:49:51 +00:00
|
|
|
$res = $dbrCentralLangDB->select( 'interwiki', '*', [], __METHOD__ );
|
2019-04-05 23:47:04 +00:00
|
|
|
$retval2 = [];
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$row = (array)$row;
|
|
|
|
// Note that the above DB query explicitly *excludes* interlang ones
|
|
|
|
// (which makes sense), whereas here we _only_ care about interlang ones!
|
|
|
|
if ( Language::fetchLanguageName( $row['iw_prefix'] ) ) {
|
|
|
|
$retval2[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$iwGlobalLanguagePrefixes = $retval2;
|
|
|
|
}
|
|
|
|
|
2014-07-19 17:40:44 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 23:47:04 +00:00
|
|
|
// If using global interlanguage links, just ditch the data coming from the
|
|
|
|
// local table and overwrite it with the global data
|
|
|
|
if ( $usingGlobalInterlangLinks ) {
|
|
|
|
unset( $iwLanguagePrefixes );
|
|
|
|
$iwLanguagePrefixes = $iwGlobalLanguagePrefixes;
|
|
|
|
}
|
|
|
|
|
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 ) {
|
2019-04-05 23:47:04 +00:00
|
|
|
if ( $usingGlobalLanguages ) {
|
|
|
|
$addtext = 'interwiki-addtext-local-nolang';
|
|
|
|
} else {
|
|
|
|
$addtext = 'interwiki-addtext-local';
|
|
|
|
}
|
2014-07-19 17:40:44 +00:00
|
|
|
} else {
|
2019-04-05 23:47:04 +00:00
|
|
|
if ( $usingGlobalLanguages ) {
|
|
|
|
$addtext = 'interwiki-addtext-nolang';
|
|
|
|
} else {
|
|
|
|
$addtext = 'interwiki_addtext';
|
|
|
|
}
|
2014-07-19 17:40:44 +00:00
|
|
|
}
|
2019-04-05 23:47:04 +00:00
|
|
|
$addtext = $this->msg( $addtext )->text();
|
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' );
|
|
|
|
|
2019-11-03 18:20:19 +00:00
|
|
|
if ( $iwPrefixes === [] && $iwGlobalPrefixes === [] ) {
|
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 ) {
|
2019-04-05 23:47:04 +00:00
|
|
|
if ( $usingGlobalLanguages ) {
|
|
|
|
$header = 'interwiki-global-language-links';
|
|
|
|
$description = 'interwiki-global-language-description';
|
|
|
|
} else {
|
|
|
|
$header = 'interwiki-language-links';
|
|
|
|
$description = 'interwiki-language-description';
|
|
|
|
}
|
|
|
|
|
2014-07-19 17:40:44 +00:00
|
|
|
$this->getOutput()->addHTML(
|
|
|
|
'<h2 id="interwikitable-language">' .
|
2019-04-05 23:47:04 +00:00
|
|
|
$this->msg( $header )->parse() .
|
2014-07-19 17:40:44 +00:00
|
|
|
'</h2>'
|
|
|
|
);
|
2019-04-05 23:47:04 +00:00
|
|
|
$this->getOutput()->addWikiMsg( $description );
|
2014-07-19 17:40:44 +00:00
|
|
|
|
2019-04-05 23:47:04 +00:00
|
|
|
// When using global interlanguage links, don't allow them to be modified
|
|
|
|
// except on the source wiki
|
|
|
|
$canModify = ( $usingGlobalLanguages ? false : $canModify );
|
2014-07-19 17:40:44 +00:00
|
|
|
$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' ] ) .
|
2019-12-21 12:28:57 +00:00
|
|
|
Html::element( 'th', [], $this->msg( 'interwiki_prefix' )->text() ) .
|
|
|
|
Html::element( 'th', [], $this->msg( 'interwiki_url' )->text() ) .
|
|
|
|
Html::element( 'th', [], $this->msg( 'interwiki_local' )->text() ) .
|
|
|
|
Html::element( 'th', [], $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'] ]
|
|
|
|
) .
|
2019-05-23 12:46:11 +00:00
|
|
|
$this->msg( 'comma-separator' )->escaped() .
|
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 );
|
2019-01-20 18:23:38 +00:00
|
|
|
$this->getOutput()->addModuleStyles( 'jquery.tablesorter.styles' );
|
|
|
|
$this->getOutput()->addModules( 'jquery.tablesorter' );
|
2008-12-31 18:44:54 +00:00
|
|
|
}
|
2009-08-27 13:02:57 +00:00
|
|
|
|
2019-03-08 21:04:53 +00:00
|
|
|
/**
|
|
|
|
* @param string ...$args
|
|
|
|
*/
|
|
|
|
protected function error( ...$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
|
|
|
}
|