Index: trunk/phase3/maintenance/language/checkLanguage.inc |
— | — | @@ -2,92 +2,108 @@ |
3 | 3 | /** |
4 | 4 | * Check a language. |
5 | 5 | * |
6 | | - * @todo Stop with globals. |
7 | 6 | * @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). |
9 | 11 | * @return Number of errors found. |
10 | 12 | */ |
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 ) { |
14 | 14 | # Get messages |
15 | 15 | $messages = $languages->getMessages( $code ); |
16 | 16 | $messagesNumber = count( $messages['translated'] ); |
17 | 17 | |
18 | | - # Skip the checks if specified |
19 | | - if ( $wgDisplayLevel == 0 ) { |
| 18 | + # Skip the checks if told so |
| 19 | + if ( $displayLevel == 0 ) { |
20 | 20 | return; |
21 | 21 | } |
22 | 22 | |
23 | | - // Initialize counts |
24 | | - $untranslatedMessagesNumber = $duplicateMessagesNumber = $obsoleteMessagesNumber |
25 | | - = $messagesWithoutVariablesNumber = $messagesWithoutPluralNumber = $emptyMessagesNumber |
26 | | - = $messagesWithWhitespaceNumber = $nonXHTMLMessagesNumber = $messagesWithWrongCharsNumber |
27 | | - = 0; |
| 23 | + # Initialize counts |
| 24 | + $problems = 0; |
28 | 25 | |
| 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 | + |
29 | 35 | # Untranslated messages |
30 | | - if ( in_array( 'untranslated', $wgChecks ) ) { |
| 36 | + if ( in_array( 'untranslated', $checks ) ) { |
| 37 | + $generalMessages = $languages->getGeneralMessages(); |
| 38 | + $requiredMessagesNumber = count( $generalMessages['required'] ); |
31 | 39 | $untranslatedMessages = $languages->getUntranslatedMessages( $code ); |
32 | 40 | $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; |
34 | 43 | } |
35 | 44 | |
36 | 45 | # Duplicate messages |
37 | | - if ( in_array( 'duplicate', $wgChecks ) ) { |
| 46 | + if ( in_array( 'duplicate', $checks ) ) { |
38 | 47 | $duplicateMessages = $languages->getDuplicateMessages( $code ); |
39 | 48 | $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; |
41 | 51 | } |
42 | 52 | |
43 | 53 | # Obsolete messages |
44 | | - if ( in_array( 'obsolete', $wgChecks ) ) { |
| 54 | + if ( in_array( 'obsolete', $checks ) ) { |
45 | 55 | $obsoleteMessages = $messages['obsolete']; |
46 | 56 | $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; |
48 | 59 | } |
49 | 60 | |
50 | 61 | # Messages without variables |
51 | | - if ( in_array( 'variables', $wgChecks ) ) { |
| 62 | + if ( in_array( 'variables', $checks ) ) { |
52 | 63 | $messagesWithoutVariables = $languages->getMessagesWithoutVariables( $code ); |
53 | 64 | $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; |
55 | 67 | } |
56 | 68 | |
57 | 69 | # Messages without plural |
58 | | - if ( in_array( 'plural', $wgChecks ) ) { |
| 70 | + if ( in_array( 'plural', $checks ) ) { |
59 | 71 | $messagesWithoutPlural = $languages->getMessagesWithoutPlural( $code ); |
60 | 72 | $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; |
62 | 75 | } |
63 | 76 | |
64 | 77 | # Empty messages |
65 | | - if ( in_array( 'empty', $wgChecks ) ) { |
| 78 | + if ( in_array( 'empty', $checks ) ) { |
66 | 79 | $emptyMessages = $languages->getEmptyMessages( $code ); |
67 | 80 | $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; |
69 | 83 | } |
70 | 84 | |
71 | 85 | # Messages with whitespace |
72 | | - if ( in_array( 'whitespace', $wgChecks ) ) { |
| 86 | + if ( in_array( 'whitespace', $checks ) ) { |
73 | 87 | $messagesWithWhitespace = $languages->getMessagesWithWhitespace( $code ); |
74 | 88 | $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; |
76 | 91 | } |
77 | 92 | |
78 | 93 | # Non-XHTML messages |
79 | | - if ( in_array( 'xhtml', $wgChecks ) ) { |
| 94 | + if ( in_array( 'xhtml', $checks ) ) { |
80 | 95 | $nonXHTMLMessages = $languages->getNonXHTMLMessages( $code ); |
81 | 96 | $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; |
83 | 99 | } |
84 | 100 | |
85 | 101 | # Messages with wrong characters |
86 | | - if ( in_array( 'chars', $wgChecks ) ) { |
| 102 | + if ( in_array( 'chars', $checks ) ) { |
87 | 103 | $messagesWithWrongChars = $languages->getMessagesWithWrongChars( $code ); |
88 | 104 | $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; |
90 | 107 | } |
91 | 108 | |
92 | | - return ($untranslatedMessagesNumber + $duplicateMessagesNumber + $obsoleteMessagesNumber + $messagesWithoutVariablesNumber + $messagesWithoutPluralNumber + $emptyMessagesNumber + $messagesWithWhitespaceNumber + $nonXHTMLMessagesNumber + $messagesWithWrongCharsNumber); |
| 109 | + return $problems; |
93 | 110 | } |
94 | | -?> |
Index: trunk/phase3/maintenance/language/checkExtensioni18n.php |
— | — | @@ -36,10 +36,6 @@ |
37 | 37 | // Filename for the extension i18n files database: |
38 | 38 | define( 'EXT_I18N_DB', 'i18n.db' ); |
39 | 39 | |
40 | | -// Global parameters for checkLanguage.inc |
41 | | -$wgDisplayLevel = 2; |
42 | | -$wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' ); |
43 | | - |
44 | 40 | $optionsWithArgs = array( 'extdir', 'lang' ); |
45 | 41 | |
46 | 42 | require_once( dirname(__FILE__).'/../commandLine.inc' ); |
— | — | @@ -143,14 +139,8 @@ |
144 | 140 | * @param $filter Optional, restrict check to a given language code (default; null) |
145 | 141 | */ |
146 | 142 | function checkExtensionLanguage( $filename, $arrayname, $filter = null ) { |
147 | | - global $wgGeneralMessages, $wgRequiredMessagesNumber; |
148 | | - |
149 | 143 | $extLanguages = new extensionLanguages($filename, $arrayname); |
150 | 144 | |
151 | | - // Stuff needed by the checkLanguage routine (globals) |
152 | | - $wgGeneralMessages = $extLanguages->getGeneralMessages(); |
153 | | - $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] ); |
154 | | - |
155 | 145 | $langs = $extLanguages->getLanguages(); |
156 | 146 | if( !$langs ) { |
157 | 147 | print "ERROR> \$$arrayname array does not exist.\n"; |
Index: trunk/phase3/maintenance/language/checkLanguage.php |
— | — | @@ -42,33 +42,20 @@ |
43 | 43 | exit(); |
44 | 44 | } |
45 | 45 | |
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; |
61 | 49 | $wgLinks = isset( $options['links'] ); |
62 | 50 | $wgWikiLanguage = isset( $options['wikilang'] ) ? $options['wikilang'] : 'en'; |
| 51 | +$wgCheckEXIF = !isset( $options['noexif'] ); |
63 | 52 | |
64 | | -# Get the checks to do |
| 53 | +# Get the checks |
65 | 54 | $wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' ); |
66 | 55 | if ( isset( $options['whitelist'] ) ) { |
67 | 56 | $wgChecks = explode( ',', $options['whitelist'] ); |
68 | 57 | } elseif ( isset( $options['blacklist'] ) ) { |
69 | 58 | $wgChecks = array_diff( $wgChecks, explode( ',', $options['blacklist'] ) ); |
70 | 59 | } |
71 | | - |
72 | | -# Add duplicate and plural options if specified |
73 | 60 | if ( isset( $options['duplicate'] ) ) { |
74 | 61 | $wgChecks[] = 'duplicate'; |
75 | 62 | } |
— | — | @@ -76,16 +63,9 @@ |
77 | 64 | $wgChecks[] = 'plural'; |
78 | 65 | } |
79 | 66 | |
80 | | -# Should check for EXIF? |
81 | | -$wgCheckEXIF = !isset( $options['noexif'] ); |
82 | | - |
83 | | -# Get language objects |
| 67 | +# Get language object |
84 | 68 | $wgLanguages = new languages( $wgCheckEXIF ); |
85 | 69 | |
86 | | -# Get the general messages |
87 | | -$wgGeneralMessages = $wgLanguages->getGeneralMessages(); |
88 | | -$wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] ); |
89 | | - |
90 | 70 | # Check the language |
91 | 71 | if ( $wgCode == 'all' ) { |
92 | 72 | foreach ( $wgLanguages->getLanguages() as $language ) { |
— | — | @@ -94,14 +74,12 @@ |
95 | 75 | } |
96 | 76 | } |
97 | 77 | } else { |
98 | | - # Can't check English |
| 78 | + # Can't check English or English RTL |
99 | 79 | if ( $wgCode == 'en' ) { |
100 | 80 | echo "Current selected language is English, which cannot be checked.\n"; |
101 | 81 | } else if ( $wgCode == 'enRTL' ) { |
102 | 82 | echo "Current selected language is RTL English, which cannot be checked.\n"; |
103 | 83 | } else { |
104 | | - checkLanguage( $wgLanguages, $wgCode ); |
| 84 | + checkLanguage( $wgLanguages, $wgCode, $wgDisplayLevel, $wgLinks, $wgWikiLanguage, $wgChecks ); |
105 | 85 | } |
106 | 86 | } |
107 | | - |
108 | | - |