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