Type check the APC value in LoadBalancer::doWait()
[mediawiki.git] / maintenance / language / listVariants.php
blobe8d0e768d2bf9732a30456769ad24b55313fe3bd
1 <?php
2 /**
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
23 * @file
24 * @ingroup Maintenance
26 require_once dirname( __DIR__ ) . '/Maintenance.php';
28 /**
29 * @since 1.24
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() {
41 $variantLangs = [];
42 $variants = [];
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 );
51 sort( $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";
57 } else {
58 foreach ( $result as $key => $value ) {
59 if ( is_array( $value ) ) {
60 echo "$key\n";
61 foreach ( $value as $variant ) {
62 echo " $variant\n";
64 } else {
65 echo "$value\n";
72 $maintClass = 'ListVariants';
73 require_once RUN_MAINTENANCE_IF_MAIN;