maintenance: Remove odd use of $wgLang
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 1 Mar 2016 21:36:08 +0000 (21:36 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 3 Mar 2016 01:37:45 +0000 (01:37 +0000)
* testCompression.php: Called $wgLang, but didn't set it.
  It just assumed it was English. Use a local variable instead.

* update.php: Set $wgLang to English. Set main RequestContext as well.

* transstat.php: Rename $wgLanguages to $languages for less confusion.
  It's just a local instance of language.inc's Languages class.

Change-Id: I67865f4d8710946001f7586ab0a17e125366b184

maintenance/language/transstat.php
maintenance/storage/testCompression.php
maintenance/update.php

index ac53554..ca94473 100644 (file)
@@ -72,7 +72,7 @@ switch ( $options['output'] ) {
 }
 
 # Languages
-$wgLanguages = new Languages();
+$languages = new Languages();
 
 # Header
 $output->heading();
@@ -88,10 +88,10 @@ $output->element( 'Problematic', true );
 $output->element( '%', true );
 $output->blockend();
 
-$wgGeneralMessages = $wgLanguages->getGeneralMessages();
+$wgGeneralMessages = $languages->getGeneralMessages();
 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
 
-foreach ( $wgLanguages->getLanguages() as $code ) {
+foreach ( $languages->getLanguages() as $code ) {
        # Don't check English, RTL English or dummy language codes
        if ( $code == 'en' || $code == 'enRTL' || ( is_array( $wgDummyLanguageCodes ) &&
                        isset( $wgDummyLanguageCodes[$code] ) )
@@ -101,8 +101,8 @@ foreach ( $wgLanguages->getLanguages() as $code ) {
 
        # Calculate the numbers
        $language = Language::fetchLanguageName( $code );
-       $fallback = $wgLanguages->getFallback( $code );
-       $messages = $wgLanguages->getMessages( $code );
+       $fallback = $languages->getFallback( $code );
+       $messages = $languages->getMessages( $code );
        $messagesNumber = count( $messages['translated'] );
        $requiredMessagesNumber = count( $messages['required'] );
        $requiredMessagesPercent = $output->formatPercent(
@@ -115,11 +115,11 @@ foreach ( $wgLanguages->getLanguages() as $code ) {
                $messagesNumber,
                true
        );
-       $messagesWithMismatchVariables = $wgLanguages->getMessagesWithMismatchVariables( $code );
-       $emptyMessages = $wgLanguages->getEmptyMessages( $code );
-       $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
-       $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
-       $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
+       $messagesWithMismatchVariables = $languages->getMessagesWithMismatchVariables( $code );
+       $emptyMessages = $languages->getEmptyMessages( $code );
+       $messagesWithWhitespace = $languages->getMessagesWithWhitespace( $code );
+       $nonXHTMLMessages = $languages->getNonXHTMLMessages( $code );
+       $messagesWithWrongChars = $languages->getMessagesWithWrongChars( $code );
        $problematicMessagesNumber = count( array_unique( array_merge(
                $messagesWithMismatchVariables,
                $emptyMessages,
index 58644c2..2692a07 100644 (file)
@@ -30,10 +30,11 @@ if ( !isset( $args[0] ) ) {
        exit( 1 );
 }
 
+$lang = Language::factory( 'en' );
 $title = Title::newFromText( $args[0] );
 if ( isset( $options['start'] ) ) {
        $start = wfTimestamp( TS_MW, strtotime( $options['start'] ) );
-       echo "Starting from " . $wgLang->timeanddate( $start ) . "\n";
+       echo "Starting from " . $lang->timeanddate( $start ) . "\n";
 } else {
        $start = '19700101000000';
 }
@@ -83,7 +84,7 @@ printf( "%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
        $type,
        count( $hashes ),
        $uncompressedSize / strlen( $serialized ),
-       $wgLang->formatSize( $uncompressedSize ),
+       $lang->formatSize( $uncompressedSize ),
        strlen( $serialized )
 );
 printf( "Compression time: %5.2f ms\n", $t * 1000 );
index 7fe9770..ed8dfa9 100755 (executable)
@@ -112,7 +112,10 @@ class UpdateMediaWiki extends Maintenance {
                        }
                }
 
-               $wgLang = Language::factory( 'en' );
+               $lang = Language::factory( 'en' );
+               // Set global language to ensure localised errors are in English (bug 20633)
+               RequestContext::getMain()->setLanguage( $lang );
+               $wgLang = $lang; // BackCompat
 
                define( 'MW_UPDATER', true );
 
@@ -191,7 +194,7 @@ class UpdateMediaWiki extends Maintenance {
 
                $time2 = microtime( true );
 
-               $timeDiff = $wgLang->formatTimePeriod( $time2 - $time1 );
+               $timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
                $this->output( "\nDone in $timeDiff.\n" );
        }