<?php

require_once __DIR__ . '/Maintenance.php';

class BrokenLangs extends Maintenance {
	public function execute() {
		$languageFactory = $this->getServiceContainer()->getLanguageFactory();
		$opts = ArrayUtils::cartesianProduct(
			[ 'time', 'date', 'monthonly', 'both', 'pretty' ],
			[ 'mdy', 'dmy', 'ymd', 'ISO 8601', 'default' ]
		);

		$count = 0;

		foreach ( array_keys( MediaWiki\Languages\Data\Names::NAMES ) as $code ) {
			$lang = $languageFactory->getLanguage( $code );

			foreach ( $opts as [ $type, $pref ] ) {
				$str = $lang->getDateFormatString( $type, $pref );
				if ( $str === null ) {
					$this->output( "$code: $type $pref is broken\n" );
					$count++;
				}
			}
		}

		$this->output( "Total broken: $count\n" );
	}
}

$maintClass = BrokenLangs::class;
require RUN_MAINTENANCE_IF_MAIN;
