3 * Lists all language variants
5 * Copyright © 2014 MediaWiki developers
6 * https://www.mediawiki.org/
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
24 * @ingroup Maintenance
26 require_once dirname( __DIR__
) . '/Maintenance.php';
31 class ListVariants
extends Maintenance
{
33 public function __construct() {
34 parent
::__construct();
35 $this->addDescription( 'Outputs a list of language variants' );
36 $this->addOption( 'flat', 'Output variants in a flat list' );
37 $this->addOption( 'json', 'Output variants as JSON' );
40 public function execute() {
43 foreach ( LanguageConverter
::$languagesWithVariants as $langCode ) {
44 $lang = Language
::factory( $langCode );
45 if ( count( $lang->getVariants() ) > 1 ) {
46 $variants +
= array_flip( $lang->getVariants() );
47 $variantLangs[$langCode] = $lang->getVariants();
50 $variants = array_keys( $variants );
52 $result = $this->hasOption( 'flat' ) ?
$variants : $variantLangs;
54 // Not using $this->output() because muting makes no sense here
55 if ( $this->hasOption( 'json' ) ) {
56 echo FormatJson
::encode( $result, true ) . "\n";
58 foreach ( $result as $key => $value ) {
59 if ( is_array( $value ) ) {
61 foreach ( $value as $variant ) {
72 $maintClass = 'ListVariants';
73 require_once RUN_MAINTENANCE_IF_MAIN
;