MediaWiki REL1_31
listVariants.php
Go to the documentation of this file.
1<?php
26require_once dirname( __DIR__ ) . '/Maintenance.php';
27
32
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' );
38 }
39
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();
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::class;
73require_once RUN_MAINTENANCE_IF_MAIN;
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
$maintClass
require_once RUN_MAINTENANCE_IF_MAIN
if(!isset( $args[0])) $lang