MediaWiki  1.34.0
transstat.php
Go to the documentation of this file.
1 <?php
29 $optionsWithArgs = [ 'output' ];
30 $optionsWithoutArgs = [ 'help' ];
31 
32 require_once __DIR__ . '/../commandLine.inc';
33 require_once 'languages.inc';
34 require_once __DIR__ . '/StatOutputs.php';
35 
36 if ( isset( $options['help'] ) ) {
37  showUsage();
38 }
39 
40 # Default output is WikiText
41 if ( !isset( $options['output'] ) ) {
42  $options['output'] = 'wiki';
43 }
44 
46 function showUsage() {
47  print <<<TEXT
48 Usage: php transstat.php [--help] [--output=csv|text|wiki]
49  --help : this helpful message
50  --output : select an output engine one of:
51  * 'csv' : Comma Separated Values.
52  * 'wiki' : MediaWiki syntax (default).
53  * 'text' : Text with tabs.
54 Example: php maintenance/transstat.php --output=text
55 
56 TEXT;
57  exit( 1 );
58 }
59 
60 # Select an output engine
61 switch ( $options['output'] ) {
62  case 'wiki':
63  $output = new WikiStatsOutput();
64  break;
65  case 'text':
66  $output = new TextStatsOutput();
67  break;
68  case 'csv':
69  $output = new CsvStatsOutput();
70  break;
71  default:
72  showUsage();
73 }
74 
75 # Languages
76 $languages = new Languages();
77 
78 # Header
79 $output->heading();
80 $output->blockstart();
81 $output->element( 'Language', true );
82 $output->element( 'Code', true );
83 $output->element( 'Fallback', true );
84 $output->element( 'Translated', true );
85 $output->element( '%', true );
86 $output->element( 'Obsolete', true );
87 $output->element( '%', true );
88 $output->element( 'Problematic', true );
89 $output->element( '%', true );
90 $output->blockend();
91 
92 $wgGeneralMessages = $languages->getGeneralMessages();
94 
95 foreach ( $languages->getLanguages() as $code ) {
96  # Don't check English, RTL English or dummy language codes
97  if ( $code == 'en' || $code == 'enRTL' || ( is_array( $wgDummyLanguageCodes ) &&
98  isset( $wgDummyLanguageCodes[$code] ) )
99  ) {
100  continue;
101  }
102 
103  # Calculate the numbers
104  $language = Language::fetchLanguageName( $code );
105  $fallback = $languages->getFallback( $code );
106  $messages = $languages->getMessages( $code );
107  $messagesNumber = count( $messages['translated'] );
108  $requiredMessagesNumber = count( $messages['required'] );
109  $requiredMessagesPercent = $output->formatPercent(
110  $requiredMessagesNumber,
112  );
113  $obsoleteMessagesNumber = count( $messages['obsolete'] );
114  $obsoleteMessagesPercent = $output->formatPercent(
115  $obsoleteMessagesNumber,
116  $messagesNumber,
117  true
118  );
119  $messagesWithMismatchVariables = $languages->getMessagesWithMismatchVariables( $code );
120  $emptyMessages = $languages->getEmptyMessages( $code );
121  $messagesWithWhitespace = $languages->getMessagesWithWhitespace( $code );
122  $nonXHTMLMessages = $languages->getNonXHTMLMessages( $code );
123  $messagesWithWrongChars = $languages->getMessagesWithWrongChars( $code );
124  $problematicMessagesNumber = count( array_unique( array_merge(
125  $messagesWithMismatchVariables,
126  $emptyMessages,
127  $messagesWithWhitespace,
128  $nonXHTMLMessages,
129  $messagesWithWrongChars
130  ) ) );
131  $problematicMessagesPercent = $output->formatPercent(
132  $problematicMessagesNumber,
133  $messagesNumber,
134  true
135  );
136 
137  # Output them
138  $output->blockstart();
139  $output->element( "$language" );
140  $output->element( "$code" );
141  $output->element( "$fallback" );
142  $output->element( "$requiredMessagesNumber/$wgRequiredMessagesNumber" );
143  $output->element( $requiredMessagesPercent );
144  $output->element( "$obsoleteMessagesNumber/$messagesNumber" );
145  $output->element( $obsoleteMessagesPercent );
146  $output->element( "$problematicMessagesNumber/$messagesNumber" );
147  $output->element( $problematicMessagesPercent );
148  $output->blockend();
149 }
150 
151 # Footer
152 $output->footer();
Language\fetchLanguageName
static fetchLanguageName( $code, $inLanguage=self::AS_AUTONYMS, $include=self::ALL)
Definition: Language.php:832
CsvStatsOutput
csv output.
Definition: StatOutputs.php:138
$languages
switch( $options['output']) $languages
Definition: transstat.php:76
$fallback
$fallback
Definition: MessagesAb.php:11
$optionsWithoutArgs
$optionsWithoutArgs
Definition: transstat.php:30
TextStatsOutput
Output text.
Definition: StatOutputs.php:127
MediaWiki
This class serves as a utility class for this extension.
$output
$output
Definition: SyntaxHighlight.php:335
$wgRequiredMessagesNumber
$wgRequiredMessagesNumber
Definition: transstat.php:93
showUsage
if(isset( $options['help'])) if(!isset( $options['output'])) showUsage()
Print a usage message.
Definition: transstat.php:46
$optionsWithArgs
$optionsWithArgs
Definition: transstat.php:29
WikiStatsOutput
Outputs WikiText.
Definition: StatOutputs.php:54
$wgGeneralMessages
$wgGeneralMessages
Definition: transstat.php:92
$wgDummyLanguageCodes
$wgDummyLanguageCodes
Functionally the same as $wgExtraLanguageCodes, but deprecated.
Definition: DefaultSettings.php:3025