2014-06-04 22:31:30 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Lists all language variants
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2014 MediaWiki developers
|
|
|
|
|
* https://www.mediawiki.org/
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2019-08-26 12:24:37 +00:00
|
|
|
|
2024-05-16 12:28:33 +00:00
|
|
|
use MediaWiki\Json\FormatJson;
|
2024-10-21 17:06:13 +00:00
|
|
|
use MediaWiki\Language\LanguageConverter;
|
2024-05-16 12:28:33 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2014-06-04 22:31:30 +00:00
|
|
|
require_once dirname( __DIR__ ) . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2014-06-04 22:31:30 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 1.24
|
|
|
|
|
*/
|
|
|
|
|
class ListVariants extends Maintenance {
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Outputs a list of language variants' );
|
2014-06-04 22:31:30 +00:00
|
|
|
$this->addOption( 'flat', 'Output variants in a flat list' );
|
|
|
|
|
$this->addOption( 'json', 'Output variants as JSON' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2023-08-31 09:21:12 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2023-01-30 20:41:00 +00:00
|
|
|
$languageFactory = $services->getLanguageFactory();
|
|
|
|
|
$languageConverterFactory = $services->getLanguageConverterFactory();
|
2016-02-17 09:09:32 +00:00
|
|
|
$variantLangs = [];
|
|
|
|
|
$variants = [];
|
2014-06-04 22:31:30 +00:00
|
|
|
foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
|
2023-01-30 20:41:00 +00:00
|
|
|
$lang = $languageFactory->getLanguage( $langCode );
|
|
|
|
|
$langConv = $languageConverterFactory->getLanguageConverter( $lang );
|
|
|
|
|
if ( $langConv->hasVariants() ) {
|
|
|
|
|
$variants += array_fill_keys( $langConv->getVariants(), true );
|
|
|
|
|
$variantLangs[$langCode] = $langConv->getVariants();
|
2014-06-04 22:31:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$variants = array_keys( $variants );
|
|
|
|
|
sort( $variants );
|
|
|
|
|
$result = $this->hasOption( 'flat' ) ? $variants : $variantLangs;
|
|
|
|
|
|
|
|
|
|
// Not using $this->output() because muting makes no sense here
|
|
|
|
|
if ( $this->hasOption( 'json' ) ) {
|
|
|
|
|
echo FormatJson::encode( $result, true ) . "\n";
|
|
|
|
|
} else {
|
|
|
|
|
foreach ( $result as $key => $value ) {
|
|
|
|
|
if ( is_array( $value ) ) {
|
|
|
|
|
echo "$key\n";
|
|
|
|
|
foreach ( $value as $variant ) {
|
|
|
|
|
echo " $variant\n";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
echo "$value\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = ListVariants::class;
|
2014-06-04 22:31:30 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|