mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Interwiki
synced 2024-11-23 14:06:55 +00:00
Get config with SpecialInterwiki::getConfig
Change-Id: Id12c798a1eca057a9958ad804b1f8532e284c426
This commit is contained in:
parent
9f9e40cf7a
commit
ee7b69b883
|
@ -3,9 +3,7 @@
|
||||||
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
|
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
|
||||||
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" />
|
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" />
|
||||||
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" />
|
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" />
|
||||||
<exclude name="MediaWiki.Usage.ExtendClassUsage.FunctionConfigUsage" />
|
|
||||||
<exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
|
<exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
|
||||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
|
|
||||||
</rule>
|
</rule>
|
||||||
<file>.</file>
|
<file>.</file>
|
||||||
<arg name="extensions" value="php" />
|
<arg name="extensions" value="php" />
|
||||||
|
|
|
@ -76,7 +76,6 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
* @throws PermissionsError|ReadOnlyError
|
* @throws PermissionsError|ReadOnlyError
|
||||||
*/
|
*/
|
||||||
public function canModify( $out = false ) {
|
public function canModify( $out = false ) {
|
||||||
global $wgInterwikiCache;
|
|
||||||
if ( !$this->getUser()->isAllowed( 'interwiki' ) ) {
|
if ( !$this->getUser()->isAllowed( 'interwiki' ) ) {
|
||||||
// Check permissions
|
// Check permissions
|
||||||
if ( $out ) {
|
if ( $out ) {
|
||||||
|
@ -84,7 +83,7 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} elseif ( $wgInterwikiCache ) {
|
} elseif ( $this->getConfig()->get( 'InterwikiCache' ) ) {
|
||||||
// Editing the interwiki cache is not supported
|
// Editing the interwiki cache is not supported
|
||||||
if ( $out ) {
|
if ( $out ) {
|
||||||
$out->addWikiMsg( 'interwiki-cached' );
|
$out->addWikiMsg( 'interwiki-cached' );
|
||||||
|
@ -235,10 +234,9 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSubmit( array $data ) {
|
public function onSubmit( array $data ) {
|
||||||
global $wgInterwikiCentralInterlanguageDB;
|
|
||||||
|
|
||||||
$status = Status::newGood();
|
$status = Status::newGood();
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
$config = $this->getConfig();
|
||||||
$prefix = $this->getRequest()->getVal( 'prefix', '' );
|
$prefix = $this->getRequest()->getVal( 'prefix', '' );
|
||||||
$do = $request->getVal( 'action' );
|
$do = $request->getVal( 'action' );
|
||||||
// Show an error if the prefix is invalid (only when adding one).
|
// Show an error if the prefix is invalid (only when adding one).
|
||||||
|
@ -251,10 +249,11 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
// Disallow adding local interlanguage definitions if using global
|
// Disallow adding local interlanguage definitions if using global
|
||||||
|
$interwikiCentralInterlanguageDB = $config->get( 'InterwikiCentralInterlanguageDB' );
|
||||||
if (
|
if (
|
||||||
$do === 'add' && Language::fetchLanguageName( $prefix )
|
$do === 'add' && Language::fetchLanguageName( $prefix )
|
||||||
&& $wgInterwikiCentralInterlanguageDB !== wfWikiID()
|
&& $interwikiCentralInterlanguageDB !== wfWikiID()
|
||||||
&& $wgInterwikiCentralInterlanguageDB !== null
|
&& $interwikiCentralInterlanguageDB !== null
|
||||||
) {
|
) {
|
||||||
$status->fatal( 'interwiki-cannotaddlocallanguage', htmlspecialchars( $prefix ) );
|
$status->fatal( 'interwiki-cannotaddlocallanguage', htmlspecialchars( $prefix ) );
|
||||||
return $status;
|
return $status;
|
||||||
|
@ -286,6 +285,7 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
case 'add':
|
case 'add':
|
||||||
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
||||||
$prefix = $contLang->lc( $prefix );
|
$prefix = $contLang->lc( $prefix );
|
||||||
|
// Fall through
|
||||||
case 'edit':
|
case 'edit':
|
||||||
$theurl = $data['url'];
|
$theurl = $data['url'];
|
||||||
$api = $data['api'] ?? '';
|
$api = $data['api'] ?? '';
|
||||||
|
@ -341,8 +341,6 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function showList() {
|
protected function showList() {
|
||||||
global $wgInterwikiCentralDB, $wgInterwikiCentralInterlanguageDB, $wgInterwikiViewOnly;
|
|
||||||
|
|
||||||
$canModify = $this->canModify();
|
$canModify = $this->canModify();
|
||||||
|
|
||||||
// Build lists
|
// Build lists
|
||||||
|
@ -350,9 +348,11 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
$iwPrefixes = $lookup->getAllPrefixes( null );
|
$iwPrefixes = $lookup->getAllPrefixes( null );
|
||||||
$iwGlobalPrefixes = [];
|
$iwGlobalPrefixes = [];
|
||||||
$iwGlobalLanguagePrefixes = [];
|
$iwGlobalLanguagePrefixes = [];
|
||||||
if ( $wgInterwikiCentralDB !== null && $wgInterwikiCentralDB !== wfWikiID() ) {
|
$config = $this->getConfig();
|
||||||
|
$interwikiCentralDB = $config->get( 'InterwikiCentralDB' );
|
||||||
|
if ( $interwikiCentralDB !== null && $interwikiCentralDB !== wfWikiID() ) {
|
||||||
// Fetch list from global table
|
// Fetch list from global table
|
||||||
$dbrCentralDB = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralDB );
|
$dbrCentralDB = wfGetDB( DB_REPLICA, [], $interwikiCentralDB );
|
||||||
$res = $dbrCentralDB->select( 'interwiki', '*', [], __METHOD__ );
|
$res = $dbrCentralDB->select( 'interwiki', '*', [], __METHOD__ );
|
||||||
$retval = [];
|
$retval = [];
|
||||||
foreach ( $res as $row ) {
|
foreach ( $res as $row ) {
|
||||||
|
@ -366,13 +366,13 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
|
|
||||||
// Almost the same loop as above, but for global inter*language* links, whereas the above is for
|
// Almost the same loop as above, but for global inter*language* links, whereas the above is for
|
||||||
// global inter*wiki* links
|
// global inter*wiki* links
|
||||||
$usingGlobalInterlangLinks = ( $wgInterwikiCentralInterlanguageDB !== null );
|
$interwikiCentralInterlanguageDB = $config->get( 'InterwikiCentralInterlanguageDB' );
|
||||||
$isGlobalInterlanguageDB = ( $wgInterwikiCentralInterlanguageDB === wfWikiID() );
|
$usingGlobalInterlangLinks = ( $interwikiCentralInterlanguageDB !== null );
|
||||||
|
$isGlobalInterlanguageDB = ( $interwikiCentralInterlanguageDB === wfWikiID() );
|
||||||
$usingGlobalLanguages = $usingGlobalInterlangLinks && !$isGlobalInterlanguageDB;
|
$usingGlobalLanguages = $usingGlobalInterlangLinks && !$isGlobalInterlanguageDB;
|
||||||
if ( $usingGlobalLanguages ) {
|
if ( $usingGlobalLanguages ) {
|
||||||
// Fetch list from global table
|
// Fetch list from global table
|
||||||
// @phan-suppress-next-line PhanTypeMismatchArgument
|
$dbrCentralLangDB = wfGetDB( DB_REPLICA, [], $interwikiCentralInterlanguageDB );
|
||||||
$dbrCentralLangDB = wfGetDB( DB_REPLICA, [], $wgInterwikiCentralInterlanguageDB );
|
|
||||||
$res = $dbrCentralLangDB->select( 'interwiki', '*', [], __METHOD__ );
|
$res = $dbrCentralLangDB->select( 'interwiki', '*', [], __METHOD__ );
|
||||||
$retval2 = [];
|
$retval2 = [];
|
||||||
foreach ( $res as $row ) {
|
foreach ( $res as $row ) {
|
||||||
|
@ -408,7 +408,7 @@ class SpecialInterwiki extends SpecialPage {
|
||||||
$this->getOutput()->addWikiMsg( 'interwiki_intro' );
|
$this->getOutput()->addWikiMsg( 'interwiki_intro' );
|
||||||
|
|
||||||
// Add 'view log' link when possible
|
// Add 'view log' link when possible
|
||||||
if ( $wgInterwikiViewOnly === false ) {
|
if ( !$config->get( 'InterwikiViewOnly' ) ) {
|
||||||
$logLink = $this->getLinkRenderer()->makeLink(
|
$logLink = $this->getLinkRenderer()->makeLink(
|
||||||
SpecialPage::getTitleFor( 'Log', 'interwiki' ),
|
SpecialPage::getTitleFor( 'Log', 'interwiki' ),
|
||||||
$this->msg( 'interwiki-logtext' )->text()
|
$this->msg( 'interwiki-logtext' )->text()
|
||||||
|
|
Loading…
Reference in a new issue