X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Flanguage%2FcheckLanguage.inc;h=ac70ead221267d22ebdd4d3a1f2247afe5bf20f8;hb=f8acd5fa6f9c9aee11728767803102e8154583ab;hp=4b49ada3d2582560c3b074f9901b8e17caba40ba;hpb=5c3fecdb372bbd96301a1c21d8fae3219c55a356;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/language/checkLanguage.inc b/maintenance/language/checkLanguage.inc index 4b49ada3d2..ac70ead221 100644 --- a/maintenance/language/checkLanguage.inc +++ b/maintenance/language/checkLanguage.inc @@ -89,7 +89,7 @@ class CheckLanguageCLI { $this->output = $options['output']; } - $this->L = new languages( $this->includeExif ); + $this->L = new Languages( $this->includeExif ); } /** @@ -182,21 +182,25 @@ class CheckLanguageCLI { return array( 'untranslated' => '$1 message(s) of $2 are not translated to $3, but exist in en:', 'duplicate' => '$1 message(s) of $2 are translated the same in en and $3:', - 'obsolete' => '$1 message(s) of $2 do not exist in en or are in the ignore list, but exist in $3:', + 'obsolete' => + '$1 message(s) of $2 do not exist in en or are in the ignore list, but exist in $3:', 'variables' => '$1 message(s) of $2 in $3 don\'t match the variables used in en:', 'plural' => '$1 message(s) of $2 in $3 don\'t use {{plural}} while en uses:', 'empty' => '$1 message(s) of $2 in $3 are empty or -:', 'whitespace' => '$1 message(s) of $2 in $3 have trailing whitespace:', 'xhtml' => '$1 message(s) of $2 in $3 contain illegal XHTML:', - 'chars' => '$1 message(s) of $2 in $3 include hidden chars which should not be used in the messages:', + 'chars' => + '$1 message(s) of $2 in $3 include hidden chars which should not be used in the messages:', 'links' => '$1 message(s) of $2 in $3 have problematic link(s):', 'unbalanced' => '$1 message(s) of $2 in $3 have unbalanced {[]}:', 'namespace' => '$1 namespace name(s) of $2 are not translated to $3, but exist in en:', - 'projecttalk' => '$1 namespace name(s) and alias(es) in $3 are project talk namespaces without the parameter:', + 'projecttalk' => + '$1 namespace name(s) and alias(es) in $3 are project talk namespaces without the parameter:', 'magic' => '$1 magic word(s) of $2 are not translated to $3, but exist in en:', 'magic-old' => '$1 magic word(s) of $2 do not exist in en, but exist in $3:', 'magic-over' => '$1 magic word(s) of $2 in $3 do not contain the original en word(s):', - 'magic-case' => '$1 magic word(s) of $2 in $3 change the case-sensitivity of the original en word:', + 'magic-case' => + '$1 magic word(s) of $2 in $3 change the case-sensitivity of the original en word:', 'special' => '$1 special page alias(es) of $2 are not translated to $3, but exist in en:', 'special-old' => '$1 special page alias(es) of $2 do not exist in en, but exist in $3:', ); @@ -216,35 +220,49 @@ Parameters: --all: Check all customized languages. --level: Show the following display level (default: 2): * 0: Skip the checks (useful for checking syntax). - * 1: Show only the stub headers and number of wrong messages, without list of messages. - * 2: Show only the headers and the message keys, without the message values. - * 3: Show both the headers and the complete messages, with both keys and values. + * 1: Show only the stub headers and number of wrong messages, without + list of messages. + * 2: Show only the headers and the message keys, without the message + values. + * 3: Show both the headers and the complete messages, with both keys and + values. --links: Link the message values (default off). --prefix: prefix to add to links. - --wikilang: For the links, what is the content language of the wiki to display the output in (default en). - --noexif: Do not 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). + --wikilang: For the links, what is the content language of the wiki to + display the output in (default en). + --noexif: Do not check for Exif messages (a bit hard and boring to + translate), if you know what they are currently not translated and want + to focus on other problems (default off). --whitelist: Do only the following checks (form: code,code). --blacklist: Do not do the following checks (form: code,code). - --easy: Do only the easy checks, which can be treated by non-speakers of the language. - -Check codes (ideally, all of them should result 0; all the checks are executed by default (except language-specific check blacklists in checkLanguage.inc): - * untranslated: Messages which are required to translate, but are not translated. - * duplicate: Messages which translation equal to fallback - * obsolete: Messages which are untranslatable or do not exist, but are translated. - * variables: Messages without variables which should be used, or with variables which should not be used. + --easy: Do only the easy checks, which can be treated by non-speakers of + the language. + +Check codes (ideally, all of them should result 0; all the checks are executed +by default (except language-specific check blacklists in checkLanguage.inc): + * untranslated: Messages which are required to translate, but are not + translated. + * duplicate: Messages which translation equal to fallback. + * obsolete: Messages which are untranslatable or do not exist, but are + translated. + * variables: Messages without variables which should be used, or with + variables which should not be used. * empty: Empty messages and messages that contain only -. * whitespace: Messages which have trailing whitespace. - * xhtml: Messages which are not well-formed XHTML (checks only few common errors). + * xhtml: Messages which are not well-formed XHTML (checks only few common + errors). * chars: Messages with hidden characters. * links: Messages which contains broken links to pages (does not find all). - * unbalanced: Messages which contains unequal numbers of opening {[ and closing ]}. + * unbalanced: Messages which contains unequal numbers of opening {[ and + closing ]}. * namespace: Namespace names that were not translated. - * projecttalk: Namespace names and aliases where the project talk does not contain $1. + * projecttalk: Namespace names and aliases where the project talk does not + contain $1. * magic: Magic words that were not translated. * magic-old: Magic words which do not exist. * magic-over: Magic words that override the original English word. - * magic-case: Magic words whose translation changes the case-sensitivity of the original English word. + * magic-case: Magic words whose translation changes the case-sensitivity of + the original English word. * special: Special page names that were not translated. * special-old: Special page names which do not exist. @@ -291,6 +309,17 @@ ENDS; $this->results[$this->code] = $this->checkLanguage( $this->code ); } } + + $results = $this->results; + foreach ( $results as $code => $checks ) { + foreach ( $checks as $check => $messages ) { + foreach ( $messages as $key => $details ) { + if ( $this->isCheckBlacklisted( $check, $code, $key ) ) { + unset( $this->results[$code][$check][$key] ); + } + } + } + } } /** @@ -298,9 +327,53 @@ ENDS; * @return array The list of checks which should not be executed. */ protected function getCheckBlacklist() { + static $blacklist = null; + + if ( $blacklist !== null ) { + return $blacklist; + } + + // @codingStandardsIgnoreStart Ignore that globals should have a "wg" prefix. global $checkBlacklist; + // @codingStandardsIgnoreEnd + + $blacklist = $checkBlacklist; + + wfRunHooks( 'LocalisationChecksBlacklist', array( &$blacklist ) ); + + return $blacklist; + } + + /** + * Verify whether a check is blacklisted. + * + * @param string $check Check name + * @param string $code Language code + * @param string|bool $message Message name, or False for a whole language + * @return bool Whether the check is blacklisted + */ + protected function isCheckBlacklisted( $check, $code, $message ) { + $blacklist = $this->getCheckBlacklist(); + + foreach ( $blacklist as $item ) { + if ( isset( $item['check'] ) && $check !== $item['check'] ) { + continue; + } - return $checkBlacklist; + if ( isset( $item['code'] ) && !in_array( $code, $item['code'] ) ) { + continue; + } + + if ( isset( $item['message'] ) && + ( $message === false || !in_array( $message, $item['message'] ) ) + ) { + continue; + } + + return true; + } + + return false; } /** @@ -319,11 +392,8 @@ ENDS; } $checkFunctions = $this->getChecks(); - $checkBlacklist = $this->getCheckBlacklist(); foreach ( $this->checks as $check ) { - if ( isset( $checkBlacklist[$code] ) && - in_array( $check, $checkBlacklist[$code] ) - ) { + if ( $this->isCheckBlacklisted( $check, $code, false ) ) { $results[$check] = array(); continue; } @@ -407,7 +477,8 @@ ENDS; */ function outputWiki() { $detailText = ''; - $rows[] = '! Language !! Code !! Total !! ' . implode( ' !! ', array_diff( $this->checks, $this->nonMessageChecks() ) ); + $rows[] = '! Language !! Code !! Total !! ' . + implode( ' !! ', array_diff( $this->checks, $this->nonMessageChecks() ) ); foreach ( $this->results as $code => $results ) { $detailTextForLang = "==$code==\n"; $numbers = array(); @@ -447,6 +518,7 @@ ENDS; $tableRows = implode( "\n|-\n", $rows ); $version = SpecialVersion::getVersion( 'nodb' ); + // @codingStandardsIgnoreStart Long line. echo <<$version @@ -458,6 +530,7 @@ $tableRows $detailText EOL; + // @codingStandardsIgnoreEnd } /** @@ -539,19 +612,19 @@ class CheckExtensionsCLI extends CheckLanguageCLI { if ( $extension == 'all' ) { foreach ( MessageGroups::singleton()->getGroups() as $group ) { if ( strpos( $group->getId(), 'ext-' ) === 0 && !$group->isMeta() ) { - $this->extensions[] = new extensionLanguages( $group ); + $this->extensions[] = new ExtensionLanguages( $group ); } } } elseif ( $extension == 'wikimedia' ) { $wikimedia = MessageGroups::getGroup( 'ext-0-wikimedia' ); foreach ( $wikimedia->wmfextensions() as $extension ) { $group = MessageGroups::getGroup( $extension ); - $this->extensions[] = new extensionLanguages( $group ); + $this->extensions[] = new ExtensionLanguages( $group ); } } elseif ( $extension == 'flaggedrevs' ) { foreach ( MessageGroups::singleton()->getGroups() as $group ) { if ( strpos( $group->getId(), 'ext-flaggedrevs-' ) === 0 && !$group->isMeta() ) { - $this->extensions[] = new extensionLanguages( $group ); + $this->extensions[] = new ExtensionLanguages( $group ); } } } else { @@ -559,7 +632,7 @@ class CheckExtensionsCLI extends CheckLanguageCLI { foreach ( $extensions as $extension ) { $group = MessageGroups::getGroup( 'ext-' . $extension ); if ( $group ) { - $extension = new extensionLanguages( $group ); + $extension = new ExtensionLanguages( $group ); $this->extensions[] = $extension; } else { print "No such extension $extension.\n"; @@ -603,34 +676,50 @@ class CheckExtensionsCLI extends CheckLanguageCLI { */ protected function help() { return <<