r25221 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25220‎ | r25221 | r25222 >
Date:02:37, 28 August 2007
Author:rotem
Status:old
Tags:
Comment:
Using (optional) parameters instead of globals in checkLanguage.inc.
Modified paths:
  • /trunk/phase3/maintenance/language/checkExtensioni18n.php (modified) (history)
  • /trunk/phase3/maintenance/language/checkLanguage.inc (modified) (history)
  • /trunk/phase3/maintenance/language/checkLanguage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/checkLanguage.inc
@@ -2,92 +2,108 @@
33 /**
44 * Check a language.
55 *
6 - * @todo Stop with globals.
76 * @param $languages The languages object.
8 - * @param $code The language code.
 7+ * @param $code The language code (default content language of the wiki running the script on).
 8+ * @param: $links Show wiki links to messages (default false)?
 9+ * @param: $wikiLanguage Language of the wiki to show the output in, if showing links (default en).
 10+ * @param: $checks Checks to do (default all except for duplicates and plural).
911 * @return Number of errors found.
1012 */
11 -function checkLanguage( $languages, $code ) {
12 - global $wgRequiredMessagesNumber, $wgDisplayLevel, $wgLinks, $wgWikiLanguage, $wgChecks;
13 -
 13+function checkLanguage( $languages, $code = null, $displayLevel = 2, $links = false, $wikiLanguage = 'en', $checks = null ) {
1414 # Get messages
1515 $messages = $languages->getMessages( $code );
1616 $messagesNumber = count( $messages['translated'] );
1717
18 - # Skip the checks if specified
19 - if ( $wgDisplayLevel == 0 ) {
 18+ # Skip the checks if told so
 19+ if ( $displayLevel == 0 ) {
2020 return;
2121 }
2222
23 - // Initialize counts
24 - $untranslatedMessagesNumber = $duplicateMessagesNumber = $obsoleteMessagesNumber
25 - = $messagesWithoutVariablesNumber = $messagesWithoutPluralNumber = $emptyMessagesNumber
26 - = $messagesWithWhitespaceNumber = $nonXHTMLMessagesNumber = $messagesWithWrongCharsNumber
27 - = 0;
 23+ # Initialize counts
 24+ $problems = 0;
2825
 26+ # Set default language code and checks
 27+ if ( !$code ) {
 28+ global $wgContLang;
 29+ $code = $wgContLang->getCode();
 30+ }
 31+ if ( !$checks ) {
 32+ $checks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
 33+ }
 34+
2935 # Untranslated messages
30 - if ( in_array( 'untranslated', $wgChecks ) ) {
 36+ if ( in_array( 'untranslated', $checks ) ) {
 37+ $generalMessages = $languages->getGeneralMessages();
 38+ $requiredMessagesNumber = count( $generalMessages['required'] );
3139 $untranslatedMessages = $languages->getUntranslatedMessages( $code );
3240 $untranslatedMessagesNumber = count( $untranslatedMessages );
33 - $languages->outputMessagesList( $untranslatedMessages, $code, "\n$untranslatedMessagesNumber messages of $wgRequiredMessagesNumber are not translated to $code, but exist in en:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 41+ $languages->outputMessagesList( $untranslatedMessages, $code, "\n$untranslatedMessagesNumber messages of $requiredMessagesNumber are not translated to $code, but exist in en:", $displayLevel, $links, $wikiLanguage );
 42+ $problems += $untranslatedMessagesNumber;
3443 }
3544
3645 # Duplicate messages
37 - if ( in_array( 'duplicate', $wgChecks ) ) {
 46+ if ( in_array( 'duplicate', $checks ) ) {
3847 $duplicateMessages = $languages->getDuplicateMessages( $code );
3948 $duplicateMessagesNumber = count( $duplicateMessages );
40 - $languages->outputMessagesList( $duplicateMessages, $code, "\n$duplicateMessagesNumber messages of $messagesNumber are translated the same in en and $code:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 49+ $languages->outputMessagesList( $duplicateMessages, $code, "\n$duplicateMessagesNumber messages of $messagesNumber are translated the same in en and $code:", $displayLevel, $links, $wikiLanguage );
 50+ $problems += $duplicateMessagesNumber;
4151 }
4252
4353 # Obsolete messages
44 - if ( in_array( 'obsolete', $wgChecks ) ) {
 54+ if ( in_array( 'obsolete', $checks ) ) {
4555 $obsoleteMessages = $messages['obsolete'];
4656 $obsoleteMessagesNumber = count( $obsoleteMessages );
47 - $languages->outputMessagesList( $obsoleteMessages, $code, "\n$obsoleteMessagesNumber messages of $messagesNumber do not exist in en (or are in the ignored list), but still exist in $code:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 57+ $languages->outputMessagesList( $obsoleteMessages, $code, "\n$obsoleteMessagesNumber messages of $messagesNumber do not exist in en (or are in the ignored list), but still exist in $code:", $displayLevel, $links, $wikiLanguage );
 58+ $problems += $obsoleteMessagesNumber;
4859 }
4960
5061 # Messages without variables
51 - if ( in_array( 'variables', $wgChecks ) ) {
 62+ if ( in_array( 'variables', $checks ) ) {
5263 $messagesWithoutVariables = $languages->getMessagesWithoutVariables( $code );
5364 $messagesWithoutVariablesNumber = count( $messagesWithoutVariables );
54 - $languages->outputMessagesList( $messagesWithoutVariables, $code, "\n$messagesWithoutVariablesNumber messages of $messagesNumber in $code don't use some variables while en uses them:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 65+ $languages->outputMessagesList( $messagesWithoutVariables, $code, "\n$messagesWithoutVariablesNumber messages of $messagesNumber in $code don't use some variables while en uses them:", $displayLevel, $links, $wikiLanguage );
 66+ $problems += $messagesWithoutVariablesNumber;
5567 }
5668
5769 # Messages without plural
58 - if ( in_array( 'plural', $wgChecks ) ) {
 70+ if ( in_array( 'plural', $checks ) ) {
5971 $messagesWithoutPlural = $languages->getMessagesWithoutPlural( $code );
6072 $messagesWithoutPluralNumber = count( $messagesWithoutPlural );
61 - $languages->outputMessagesList( $messagesWithoutPlural, $code, "\n$messagesWithoutPluralNumber messages of $messagesNumber in $code don't use {{plural}} while en uses it:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 73+ $languages->outputMessagesList( $messagesWithoutPlural, $code, "\n$messagesWithoutPluralNumber messages of $messagesNumber in $code don't use {{plural}} while en uses it:", $displayLevel, $links, $wikiLanguage );
 74+ $problems += $messagesWithoutPluralNumber;
6275 }
6376
6477 # Empty messages
65 - if ( in_array( 'empty', $wgChecks ) ) {
 78+ if ( in_array( 'empty', $checks ) ) {
6679 $emptyMessages = $languages->getEmptyMessages( $code );
6780 $emptyMessagesNumber = count( $emptyMessages );
68 - $languages->outputMessagesList( $emptyMessages, $code, "\n$emptyMessagesNumber messages of $messagesNumber in $code are empty or -:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 81+ $languages->outputMessagesList( $emptyMessages, $code, "\n$emptyMessagesNumber messages of $messagesNumber in $code are empty or -:", $displayLevel, $links, $wikiLanguage );
 82+ $problems += $emptyMessagesNumber;
6983 }
7084
7185 # Messages with whitespace
72 - if ( in_array( 'whitespace', $wgChecks ) ) {
 86+ if ( in_array( 'whitespace', $checks ) ) {
7387 $messagesWithWhitespace = $languages->getMessagesWithWhitespace( $code );
7488 $messagesWithWhitespaceNumber = count( $messagesWithWhitespace );
75 - $languages->outputMessagesList( $messagesWithWhitespace, $code, "\n$messagesWithWhitespaceNumber messages of $messagesNumber in $code have a trailing whitespace:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 89+ $languages->outputMessagesList( $messagesWithWhitespace, $code, "\n$messagesWithWhitespaceNumber messages of $messagesNumber in $code have a trailing whitespace:", $displayLevel, $links, $wikiLanguage );
 90+ $problems += $messagesWithWhitespaceNumber;
7691 }
7792
7893 # Non-XHTML messages
79 - if ( in_array( 'xhtml', $wgChecks ) ) {
 94+ if ( in_array( 'xhtml', $checks ) ) {
8095 $nonXHTMLMessages = $languages->getNonXHTMLMessages( $code );
8196 $nonXHTMLMessagesNumber = count( $nonXHTMLMessages );
82 - $languages->outputMessagesList( $nonXHTMLMessages, $code, "\n$nonXHTMLMessagesNumber messages of $messagesNumber in $code are not well-formed XHTML:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 97+ $languages->outputMessagesList( $nonXHTMLMessages, $code, "\n$nonXHTMLMessagesNumber messages of $messagesNumber in $code are not well-formed XHTML:", $displayLevel, $links, $wikiLanguage );
 98+ $problems += $nonXHTMLMessagesNumber;
8399 }
84100
85101 # Messages with wrong characters
86 - if ( in_array( 'chars', $wgChecks ) ) {
 102+ if ( in_array( 'chars', $checks ) ) {
87103 $messagesWithWrongChars = $languages->getMessagesWithWrongChars( $code );
88104 $messagesWithWrongCharsNumber = count( $messagesWithWrongChars );
89 - $languages->outputMessagesList( $messagesWithWrongChars, $code, "\n$messagesWithWrongCharsNumber messages of $messagesNumber in $code include hidden chars which should not be used in the messages:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
 105+ $languages->outputMessagesList( $messagesWithWrongChars, $code, "\n$messagesWithWrongCharsNumber messages of $messagesNumber in $code include hidden chars which should not be used in the messages:", $displayLevel, $links, $wikiLanguage );
 106+ $problems += $messagesWithWrongCharsNumber;
90107 }
91108
92 - return ($untranslatedMessagesNumber + $duplicateMessagesNumber + $obsoleteMessagesNumber + $messagesWithoutVariablesNumber + $messagesWithoutPluralNumber + $emptyMessagesNumber + $messagesWithWhitespaceNumber + $nonXHTMLMessagesNumber + $messagesWithWrongCharsNumber);
 109+ return $problems;
93110 }
94 -?>
Index: trunk/phase3/maintenance/language/checkExtensioni18n.php
@@ -36,10 +36,6 @@
3737 // Filename for the extension i18n files database:
3838 define( 'EXT_I18N_DB', 'i18n.db' );
3939
40 -// Global parameters for checkLanguage.inc
41 -$wgDisplayLevel = 2;
42 -$wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
43 -
4440 $optionsWithArgs = array( 'extdir', 'lang' );
4541
4642 require_once( dirname(__FILE__).'/../commandLine.inc' );
@@ -143,14 +139,8 @@
144140 * @param $filter Optional, restrict check to a given language code (default; null)
145141 */
146142 function checkExtensionLanguage( $filename, $arrayname, $filter = null ) {
147 - global $wgGeneralMessages, $wgRequiredMessagesNumber;
148 -
149143 $extLanguages = new extensionLanguages($filename, $arrayname);
150144
151 - // Stuff needed by the checkLanguage routine (globals)
152 - $wgGeneralMessages = $extLanguages->getGeneralMessages();
153 - $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
154 -
155145 $langs = $extLanguages->getLanguages();
156146 if( !$langs ) {
157147 print "ERROR> \$$arrayname array does not exist.\n";
Index: trunk/phase3/maintenance/language/checkLanguage.php
@@ -42,33 +42,20 @@
4343 exit();
4444 }
4545
46 -# Get the language code
47 -if ( isset( $options['lang'] ) ) {
48 - $wgCode = $options['lang'];
49 -} else {
50 - $wgCode = $wgContLang->getCode();
51 -}
52 -
53 -# Get the display level
54 -if ( isset( $options['level'] ) ) {
55 - $wgDisplayLevel = $options['level'];
56 -} else {
57 - $wgDisplayLevel = 2;
58 -}
59 -
60 -# Get the links options
 46+# Get the parameters
 47+$wgCode = isset( $options['lang'] ) ? $options['lang'] : null;
 48+$wgDisplayLevel = isset( $options['level'] ) ? $options['level'] : 2;
6149 $wgLinks = isset( $options['links'] );
6250 $wgWikiLanguage = isset( $options['wikilang'] ) ? $options['wikilang'] : 'en';
 51+$wgCheckEXIF = !isset( $options['noexif'] );
6352
64 -# Get the checks to do
 53+# Get the checks
6554 $wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
6655 if ( isset( $options['whitelist'] ) ) {
6756 $wgChecks = explode( ',', $options['whitelist'] );
6857 } elseif ( isset( $options['blacklist'] ) ) {
6958 $wgChecks = array_diff( $wgChecks, explode( ',', $options['blacklist'] ) );
7059 }
71 -
72 -# Add duplicate and plural options if specified
7360 if ( isset( $options['duplicate'] ) ) {
7461 $wgChecks[] = 'duplicate';
7562 }
@@ -76,16 +63,9 @@
7764 $wgChecks[] = 'plural';
7865 }
7966
80 -# Should check for EXIF?
81 -$wgCheckEXIF = !isset( $options['noexif'] );
82 -
83 -# Get language objects
 67+# Get language object
8468 $wgLanguages = new languages( $wgCheckEXIF );
8569
86 -# Get the general messages
87 -$wgGeneralMessages = $wgLanguages->getGeneralMessages();
88 -$wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
89 -
9070 # Check the language
9171 if ( $wgCode == 'all' ) {
9272 foreach ( $wgLanguages->getLanguages() as $language ) {
@@ -94,14 +74,12 @@
9575 }
9676 }
9777 } else {
98 - # Can't check English
 78+ # Can't check English or English RTL
9979 if ( $wgCode == 'en' ) {
10080 echo "Current selected language is English, which cannot be checked.\n";
10181 } else if ( $wgCode == 'enRTL' ) {
10282 echo "Current selected language is RTL English, which cannot be checked.\n";
10383 } else {
104 - checkLanguage( $wgLanguages, $wgCode );
 84+ checkLanguage( $wgLanguages, $wgCode, $wgDisplayLevel, $wgLinks, $wgWikiLanguage, $wgChecks );
10585 }
10686 }
107 -
108 -

Follow-up revisions

RevisionCommit summaryAuthorDate
r25303Merged revisions 25215-25302 via svnmerge from...david07:10, 30 August 2007

Status & tagging log