MediaWiki  master
date-formats.php
Go to the documentation of this file.
1 <?php
25 
26 require_once __DIR__ . '/../Maintenance.php';
27 
33 class DateFormats extends Maintenance {
34 
35  private $ts = '20010115123456';
36 
37  public function __construct() {
38  parent::__construct();
39  $this->addDescription( 'Test various language time and date functions' );
40  }
41 
42  public function execute() {
43  global $IP;
44  foreach ( glob( "$IP/languages/messages/Messages*.php" ) as $filename ) {
45  $base = basename( $filename );
46  $m = [];
47  if ( !preg_match( '/Messages(.*)\.php$/', $base, $m ) ) {
48  continue;
49  }
50  $code = str_replace( '_', '-', strtolower( $m[1] ) );
51  $this->output( "$code " );
52  $lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $code );
53  $prefs = $lang->getDatePreferences();
54  if ( !$prefs ) {
55  $prefs = [ 'default' ];
56  }
57  $this->output( "date: " );
58  foreach ( $prefs as $index => $pref ) {
59  if ( $index > 0 ) {
60  $this->output( ' | ' );
61  }
62  $this->output( $lang->date( $this->ts, false, $pref ) );
63  }
64  $this->output( "\n$code time: " );
65  foreach ( $prefs as $index => $pref ) {
66  if ( $index > 0 ) {
67  $this->output( ' | ' );
68  }
69  $this->output( $lang->time( $this->ts, false, $pref ) );
70  }
71  $this->output( "\n$code both: " );
72  foreach ( $prefs as $index => $pref ) {
73  if ( $index > 0 ) {
74  $this->output( ' | ' );
75  }
76  $this->output( $lang->timeanddate( $this->ts, false, $pref ) );
77  }
78  $this->output( "\n\n" );
79  }
80  }
81 }
82 
83 $maintClass = DateFormats::class;
84 require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
$IP
Definition: WebStart.php:41
if(!isset( $args[0])) $lang
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:86
$maintClass
addDescription( $text)
Set the description text.
output( $out, $channel=null)
Throw some output to the user.
Maintenance script that tests various language time and date functions.