X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2Flanguage%2FcheckLanguage.inc;h=1e4b94a2f649f5b385bb99593100dd8449c894eb;hb=92cc0f4fd2cad9efda4575a040cc26801063e5d9;hp=6a9fcb8919acb34a55ea5868927fe5899fddf5b3;hpb=9ed3a55c09b89930556b2d94f4c71f84aa2f2465;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/language/checkLanguage.inc b/maintenance/language/checkLanguage.inc index 6a9fcb8919..1e4b94a2f6 100644 --- a/maintenance/language/checkLanguage.inc +++ b/maintenance/language/checkLanguage.inc @@ -1,93 +1,723 @@ getMessages( $code ); - $messagesNumber = count( $messages['translated'] ); +/** + * @ingroup MaintenanceLanguage + */ +class CheckLanguageCLI { + protected $code = null; + protected $level = 2; + protected $doLinks = false; + protected $linksPrefix = ''; + protected $wikiCode = 'en'; + protected $checkAll = false; + protected $output = 'plain'; + protected $checks = array(); + protected $L = null; + + protected $results = array(); + + private $includeExif = false; + + /** + * Constructor. + * @param $options Options for script. + */ + public function __construct( Array $options ) { + if ( isset( $options['help'] ) ) { + echo $this->help(); + exit(1); + } + + if ( isset( $options['lang'] ) ) { + $this->code = $options['lang']; + } else { + global $wgLanguageCode; + $this->code = $wgLanguageCode; + } + + if ( isset( $options['level'] ) ) { + $this->level = $options['level']; + } + + $this->doLinks = isset( $options['links'] ); + $this->includeExif = !isset( $options['noexif'] ); + $this->checkAll = isset( $options['all'] ); + + if ( isset( $options['prefix'] ) ) { + $this->linksPrefix = $options['prefix']; + } + + if ( isset( $options['wikilang'] ) ) { + $this->wikiCode = $options['wikilang']; + } + + if ( isset( $options['whitelist'] ) ) { + $this->checks = explode( ',', $options['whitelist'] ); + } elseif ( isset( $options['blacklist'] ) ) { + $this->checks = array_diff( + isset( $options['easy'] ) ? $this->easyChecks() : $this->defaultChecks(), + explode( ',', $options['blacklist'] ) + ); + } elseif ( isset( $options['easy'] ) ) { + $this->checks = $this->easyChecks(); + } else { + $this->checks = $this->defaultChecks(); + } + + if ( isset( $options['output'] ) ) { + $this->output = $options['output']; + } + + $this->L = new languages( $this->includeExif ); + } + + /** + * Get the default checks. + * @return A list of the default checks. + */ + protected function defaultChecks() { + return array( + 'untranslated', 'duplicate', 'obsolete', 'variables', 'empty', 'plural', + 'whitespace', 'xhtml', 'chars', 'links', 'unbalanced', 'namespace', + 'projecttalk', 'magic', 'magic-old', 'magic-over', 'magic-case', + 'special', 'special-old', + ); + } - # Skip the checks if specified - if ( $wgDisplayLevel == 0 ) { - return; + /** + * Get the checks which check other things than messages. + * @return A list of the non-message checks. + */ + protected function nonMessageChecks() { + return array( + 'namespace', 'projecttalk', 'magic', 'magic-old', 'magic-over', + 'magic-case', 'special', 'special-old', + ); } - // Initialize counts - $untranslatedMessagesNumber = $duplicateMessagesNumber = $obsoleteMessagesNumber - = $messagesWithoutVariablesNumber = $messagesWithoutPluralNumber = $emptyMessagesNumber - = $messagesWithWhitespaceNumber = $nonXHTMLMessagesNumber = $messagesWithWrongCharsNumber - = 0; + /** + * Get the checks that can easily be treated by non-speakers of the language. + * @return Array A list of the easy checks. + */ + protected function easyChecks() { + return array( + 'duplicate', 'obsolete', 'empty', 'whitespace', 'xhtml', 'chars', 'magic-old', + 'magic-over', 'magic-case', 'special-old', + ); + } - # Untranslated messages - if ( in_array( 'untranslated', $wgChecks ) ) { - $untranslatedMessages = $languages->getUntranslatedMessages( $code ); - $untranslatedMessagesNumber = count( $untranslatedMessages ); - $languages->outputMessagesList( $untranslatedMessages, $code, "\n$untranslatedMessagesNumber messages of $wgRequiredMessagesNumber are not translated to $code, but exist in en:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage ); + /** + * Get all checks. + * @return An array of all check names mapped to their function names. + */ + protected function getChecks() { + return array( + 'untranslated' => 'getUntranslatedMessages', + 'duplicate' => 'getDuplicateMessages', + 'obsolete' => 'getObsoleteMessages', + 'variables' => 'getMessagesWithMismatchVariables', + 'plural' => 'getMessagesWithoutPlural', + 'empty' => 'getEmptyMessages', + 'whitespace' => 'getMessagesWithWhitespace', + 'xhtml' => 'getNonXHTMLMessages', + 'chars' => 'getMessagesWithWrongChars', + 'links' => 'getMessagesWithDubiousLinks', + 'unbalanced' => 'getMessagesWithUnbalanced', + 'namespace' => 'getUntranslatedNamespaces', + 'projecttalk' => 'getProblematicProjectTalks', + 'magic' => 'getUntranslatedMagicWords', + 'magic-old' => 'getObsoleteMagicWords', + 'magic-over' => 'getOverridingMagicWords', + 'magic-case' => 'getCaseMismatchMagicWords', + 'special' => 'getUntraslatedSpecialPages', + 'special-old' => 'getObsoleteSpecialPages', + ); } - # Duplicate messages - if ( in_array( 'duplicate', $wgChecks ) ) { - $duplicateMessages = $languages->getDuplicateMessages( $code ); - $duplicateMessagesNumber = count( $duplicateMessages ); - $languages->outputMessagesList( $duplicateMessages, $code, "\n$duplicateMessagesNumber messages of $messagesNumber are translated the same in en and $code:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage ); + /** + * Get total count for each check non-messages check. + * @return An array of all check names mapped to a two-element array: + * function name to get the total count and language code or null + * for checked code. + */ + protected function getTotalCount() { + return array( + 'namespace' => array( 'getNamespaceNames', 'en' ), + 'projecttalk' => null, + 'magic' => array( 'getMagicWords', 'en' ), + 'magic-old' => array( 'getMagicWords', null ), + 'magic-over' => array( 'getMagicWords', null ), + 'magic-case' => array( 'getMagicWords', null ), + 'special' => array( 'getSpecialPageAliases', 'en' ), + 'special-old' => array( 'getSpecialPageAliases', null ), + ); } - # Obsolete messages - if ( in_array( 'obsolete', $wgChecks ) ) { - $obsoleteMessages = $messages['obsolete']; - $obsoleteMessagesNumber = count( $obsoleteMessages ); - $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 ); + /** + * Get all check descriptions. + * @return An array of all check names mapped to their descriptions. + */ + protected function getDescriptions() { + 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:', + '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:', + '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:', + '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:', + '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:', + ); } - # Messages without variables - if ( in_array( 'variables', $wgChecks ) ) { - $messagesWithoutVariables = $languages->getMessagesWithoutVariables( $code ); - $messagesWithoutVariablesNumber = count( $messagesWithoutVariables ); - $languages->outputMessagesList( $messagesWithoutVariables, $code, "\n$messagesWithoutVariablesNumber messages of $messagesNumber in $code don't use some variables while en uses them:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage ); + /** + * Get help. + * @return The help string. + */ + protected function help() { + return <<