MediaWiki  REL1_22
transstat.php
Go to the documentation of this file.
00001 <?php
00029 $optionsWithArgs = array( 'output' );
00030 
00031 require_once __DIR__ . '/../commandLine.inc';
00032 require_once 'languages.inc';
00033 require_once __DIR__ . '/StatOutputs.php';
00034 
00035 
00036 if ( isset( $options['help'] ) ) {
00037     showUsage();
00038 }
00039 
00040 # Default output is WikiText
00041 if ( !isset( $options['output'] ) ) {
00042     $options['output'] = 'wiki';
00043 }
00044 
00046 function showUsage() {
00047     print <<<TEXT
00048 Usage: php transstat.php [--help] [--output=csv|text|wiki]
00049     --help : this helpful message
00050     --output : select an output engine one of:
00051         * 'csv'      : Comma Separated Values.
00052         * 'wiki'     : MediaWiki syntax (default).
00053         * 'text'     : Text with tabs.
00054 Example: php maintenance/transstat.php --output=text
00055 
00056 TEXT;
00057     exit( 1 );
00058 }
00059 
00060 
00061 
00062 # Select an output engine
00063 switch ( $options['output'] ) {
00064     case 'wiki':
00065         $output = new wikiStatsOutput();
00066         break;
00067     case 'text':
00068         $output = new textStatsOutput();
00069         break;
00070     case 'csv':
00071         $output = new csvStatsOutput();
00072         break;
00073     default:
00074         showUsage();
00075 }
00076 
00077 # Languages
00078 $wgLanguages = new languages();
00079 
00080 # Header
00081 $output->heading();
00082 $output->blockstart();
00083 $output->element( 'Language', true );
00084 $output->element( 'Code', true );
00085 $output->element( 'Fallback', true );
00086 $output->element( 'Translated', true );
00087 $output->element( '%', true );
00088 $output->element( 'Obsolete', true );
00089 $output->element( '%', true );
00090 $output->element( 'Problematic', true );
00091 $output->element( '%', true );
00092 $output->blockend();
00093 
00094 $wgGeneralMessages = $wgLanguages->getGeneralMessages();
00095 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
00096 
00097 foreach ( $wgLanguages->getLanguages() as $code ) {
00098     # Don't check English, RTL English or dummy language codes
00099     if ( $code == 'en' || $code == 'enRTL' || ( is_array( $wgDummyLanguageCodes ) &&
00100         isset( $wgDummyLanguageCodes[$code] ) ) ) {
00101         continue;
00102     }
00103 
00104     # Calculate the numbers
00105     $language = Language::fetchLanguageName( $code );
00106     $fallback = $wgLanguages->getFallback( $code );
00107     $messages = $wgLanguages->getMessages( $code );
00108     $messagesNumber = count( $messages['translated'] );
00109     $requiredMessagesNumber = count( $messages['required'] );
00110     $requiredMessagesPercent = $output->formatPercent( $requiredMessagesNumber, $wgRequiredMessagesNumber );
00111     $obsoleteMessagesNumber = count( $messages['obsolete'] );
00112     $obsoleteMessagesPercent = $output->formatPercent( $obsoleteMessagesNumber, $messagesNumber, true );
00113     $messagesWithMismatchVariables = $wgLanguages->getMessagesWithMismatchVariables( $code );
00114     $emptyMessages = $wgLanguages->getEmptyMessages( $code );
00115     $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
00116     $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
00117     $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
00118     $problematicMessagesNumber = count( array_unique( array_merge( $messagesWithMismatchVariables, $emptyMessages, $messagesWithWhitespace, $nonXHTMLMessages, $messagesWithWrongChars ) ) );
00119     $problematicMessagesPercent = $output->formatPercent( $problematicMessagesNumber, $messagesNumber, true );
00120 
00121     # Output them
00122     $output->blockstart();
00123     $output->element( "$language" );
00124     $output->element( "$code" );
00125     $output->element( "$fallback" );
00126     $output->element( "$requiredMessagesNumber/$wgRequiredMessagesNumber" );
00127     $output->element( $requiredMessagesPercent );
00128     $output->element( "$obsoleteMessagesNumber/$messagesNumber" );
00129     $output->element( $obsoleteMessagesPercent );
00130     $output->element( "$problematicMessagesNumber/$messagesNumber" );
00131     $output->element( $problematicMessagesPercent );
00132     $output->blockend();
00133 }
00134 
00135 # Footer
00136 $output->footer();