[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Lists all language variants 4 * 5 * Copyright © 2014 MediaWiki developers 6 * https://www.mediawiki.org/ 7 * 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. 12 * 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. 17 * 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 22 * 23 * @file 24 * @ingroup Maintenance 25 */ 26 require_once dirname( __DIR__ ) . '/Maintenance.php'; 27 28 /** 29 * @since 1.24 30 */ 31 class ListVariants extends Maintenance { 32 33 public function __construct() { 34 parent::__construct(); 35 $this->mDescription = 'Outputs a list of language variants'; 36 $this->addOption( 'flat', 'Output variants in a flat list' ); 37 $this->addOption( 'json', 'Output variants as JSON' ); 38 } 39 40 public function execute() { 41 $variantLangs = array(); 42 $variants = array(); 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(); 48 } 49 } 50 $variants = array_keys( $variants ); 51 sort( $variants ); 52 $result = $this->hasOption( 'flat' ) ? $variants : $variantLangs; 53 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"; 63 } 64 } else { 65 echo "$value\n"; 66 } 67 } 68 } 69 } 70 } 71 72 $maintClass = 'ListVariants'; 73 require_once RUN_MAINTENANCE_IF_MAIN;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |