MediaWiki REL1_33
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 ( $lang->hasVariants() ) {
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;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
__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 option 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