Remove ?>'s from files. They're pointless, and just asking for people to mess with...
[lhc/web/wiklou.git] / maintenance / language / checkLanguage.php
1 <?php
2 /**
3 * Check a language file.
4 *
5 * @addtogroup Maintenance
6 */
7
8 require_once( dirname(__FILE__).'/../commandLine.inc' );
9 require_once( 'languages.inc' );
10 require_once( 'checkLanguage.inc' );
11
12 # Show help
13 if ( isset( $options['help'] ) ) {
14 echo <<<ENDS
15 Run this script to check a specific language file, or all of them.
16 Parameters:
17 * lang: Language code (default: the installation default language). You can also specify "all" to check all the languages.
18 * help: Show this help.
19 * level: Show the following level (default: 2).
20 * links: Link the message values (default off).
21 * wikilang: For the links, what is the content language of the wiki to display the output in (default en).
22 * whitelist: Make only the following checks (form: code,code).
23 * blacklist: Don't make the following checks (form: code,code).
24 * duplicate: Additionally check for messages which are translated the same to English (default off).
25 * plural: Additionally check for messages that don't use plural while English does (default off).
26 * noexif: Don't check for EXIF messages (a bit hard and boring to translate), if you know that they are currently not translated and want to focus on other problems (default off).
27 Check codes (ideally, all of them should result 0; all the checks are executed by default):
28 * untranslated: Messages which are required to translate, but are not translated.
29 * obsolete: Messages which are untranslatable, but translated.
30 * variables: Messages without variables which should be used.
31 * empty: Empty messages.
32 * whitespace: Messages which have trailing whitespace.
33 * xhtml: Messages which are not well-formed XHTML.
34 * chars: Messages with hidden characters.
35 Display levels (default: 2):
36 * 0: Skip the checks (useful for checking syntax).
37 * 1: Show only the stub headers and number of wrong messages, without list of messages.
38 * 2: Show only the headers and the message keys, without the message values.
39 * 3: Show both the headers and the complete messages, with both keys and values.
40
41 ENDS;
42 exit();
43 }
44
45 # Get the language code
46 if ( isset( $options['lang'] ) ) {
47 $wgCode = $options['lang'];
48 } else {
49 $wgCode = $wgContLang->getCode();
50 }
51
52 # Get the display level
53 if ( isset( $options['level'] ) ) {
54 $wgDisplayLevel = $options['level'];
55 } else {
56 $wgDisplayLevel = 2;
57 }
58
59 # Get the links options
60 $wgLinks = isset( $options['links'] );
61 $wgWikiLanguage = isset( $options['wikilang'] ) ? $options['wikilang'] : 'en';
62
63 # Get the checks to do
64 $wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
65 if ( isset( $options['whitelist'] ) ) {
66 $wgChecks = explode( ',', $options['whitelist'] );
67 } elseif ( isset( $options['blacklist'] ) ) {
68 $wgChecks = array_diff( $wgChecks, explode( ',', $options['blacklist'] ) );
69 }
70
71 # Add duplicate and plural options if specified
72 if ( isset( $options['duplicate'] ) ) {
73 $wgChecks[] = 'duplicate';
74 }
75 if ( isset( $options['plural'] ) ) {
76 $wgChecks[] = 'plural';
77 }
78
79 # Should check for EXIF?
80 $wgCheckEXIF = !isset( $options['noexif'] );
81
82 # Get language objects
83 $wgLanguages = new languages( $wgCheckEXIF );
84
85 # Get the general messages
86 $wgGeneralMessages = $wgLanguages->getGeneralMessages();
87 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
88
89 # Check the language
90 if ( $wgCode == 'all' ) {
91 foreach ( $wgLanguages->getLanguages() as $language ) {
92 if ( $language != 'en' && $language != 'enRTL' ) {
93 checkLanguage( $wgLanguages, $language );
94 }
95 }
96 } else {
97 # Can't check English
98 if ( $wgCode == 'en' ) {
99 echo "Current selected language is English, which cannot be checked.\n";
100 } else if ( $wgCode == 'enRTL' ) {
101 echo "Current selected language is RTL English, which cannot be checked.\n";
102 } else {
103 checkLanguage( $wgLanguages, $wgCode );
104 }
105 }
106
107