Make LBFactorySingle call initLoadBalancer() as the others do
[mediawiki.git] / maintenance / language / transstat.php
blob720295234cadea4dfda2aaa04636f95c8ce4c233
1 <?php
2 /**
3 * Statistics about the localisation.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup MaintenanceLanguage
23 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
24 * @author Antoine Musso <hashar at free dot fr>
26 * Output is posted from time to time on:
27 * https://www.mediawiki.org/wiki/Localisation_statistics
29 $optionsWithArgs = [ 'output' ];
30 $optionsWithoutArgs = [ 'help' ];
32 require_once __DIR__ . '/../commandLine.inc';
33 require_once 'languages.inc';
34 require_once __DIR__ . '/StatOutputs.php';
36 if ( isset( $options['help'] ) ) {
37 showUsage();
40 # Default output is WikiText
41 if ( !isset( $options['output'] ) ) {
42 $options['output'] = 'wiki';
45 /** Print a usage message*/
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
56 TEXT;
57 exit( 1 );
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();
75 # Languages
76 $languages = new Languages();
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();
92 $wgGeneralMessages = $languages->getGeneralMessages();
93 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
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;
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,
111 $wgRequiredMessagesNumber
113 $obsoleteMessagesNumber = count( $messages['obsolete'] );
114 $obsoleteMessagesPercent = $output->formatPercent(
115 $obsoleteMessagesNumber,
116 $messagesNumber,
117 true
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
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();
151 # Footer
152 $output->footer();