From 5a626d92966fc824d17da475e1a61eb3e8af8934 Mon Sep 17 00:00:00 2001 From: Rotem Liss Date: Tue, 21 Oct 2008 09:29:47 +0000 Subject: [PATCH] * New features for checking languages: Checking namespace names, skin names, magic words and special page aliases. No support for extensions yet. * Code cleanup, whitespace and documentation for the language checking scripts. --- maintenance/language/checkLanguage.inc | 276 +++++++++++++++++------ maintenance/language/checkLanguage.php | 7 +- maintenance/language/languages.inc | 301 ++++++++++++++++++++++--- 3 files changed, 487 insertions(+), 97 deletions(-) diff --git a/maintenance/language/checkLanguage.inc b/maintenance/language/checkLanguage.inc index 44b9159b17..20e395238a 100644 --- a/maintenance/language/checkLanguage.inc +++ b/maintenance/language/checkLanguage.inc @@ -13,20 +13,15 @@ class CheckLanguageCLI { protected $checks = array(); protected $L = null; - protected $defaultChecks = array( - 'untranslated', 'duplicate', 'obsolete', 'variables', 'empty', 'plural', - 'whitespace', 'xhtml', 'chars', 'links', 'unbalanced', - ); - protected $results = array(); private $includeExif = false; /** - * GLOBALS: $wgLanguageCode; + * Constructor. + * @param $options Options for script. */ public function __construct( Array $options ) { - if ( isset( $options['help'] ) ) { echo $this->help(); exit(); @@ -55,11 +50,11 @@ class CheckLanguageCLI { $this->checks = explode( ',', $options['whitelist'] ); } elseif ( isset( $options['blacklist'] ) ) { $this->checks = array_diff( - $this->defaultChecks, + $this->defaultChecks(), explode( ',', $options['blacklist'] ) ); } else { - $this->checks = $this->defaultChecks; + $this->checks = $this->defaultChecks(); } if ( isset($options['output']) ) { @@ -69,38 +64,87 @@ class CheckLanguageCLI { $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', 'skin', 'magic', 'magic-over', 'magic-case', 'special', + ); + } + + /** + * Get the non-message checks. + * @return A list of the non-message checks. + */ + protected function nonMessageChecks() { + return array( + 'namespace', 'projecttalk', 'skin', 'magic', 'magic-over', 'magic-case', + 'special', + ); + } + + /** + * Get all checks. + * @return An array of all check names mapped to their function names. + */ protected function getChecks() { - $checks = array(); - $checks['untranslated'] = 'getUntranslatedMessages'; - $checks['duplicate'] = 'getDuplicateMessages'; - $checks['obsolete'] = 'getObsoleteMessages'; - $checks['variables'] = 'getMessagesWithoutVariables'; - $checks['plural'] = 'getMessagesWithoutPlural'; - $checks['empty'] = 'getEmptyMessages'; - $checks['whitespace'] = 'getMessagesWithWhitespace'; - $checks['xhtml'] = 'getNonXHTMLMessages'; - $checks['chars'] = 'getMessagesWithWrongChars'; - $checks['links'] = 'getMessagesWithDubiousLinks'; - $checks['unbalanced'] = 'getMessagesWithUnbalanced'; - return $checks; + return array( + 'untranslated' => 'getUntranslatedMessages', + 'duplicate' => 'getDuplicateMessages', + 'obsolete' => 'getObsoleteMessages', + 'variables' => 'getMessagesWithoutVariables', + 'plural' => 'getMessagesWithoutPlural', + 'empty' => 'getEmptyMessages', + 'whitespace' => 'getMessagesWithWhitespace', + 'xhtml' => 'getNonXHTMLMessages', + 'chars' => 'getMessagesWithWrongChars', + 'links' => 'getMessagesWithDubiousLinks', + 'unbalanced' => 'getMessagesWithUnbalanced', + 'namespace' => 'getUntranslatedNamespaces', + 'projecttalk' => 'getProblematicProjectTalks', + 'skin' => 'getUntranslatedSkins', + 'magic' => 'getUntranslatedMagicWords', + 'magic-over' => 'getOverridingMagicWords', + 'magic-case' => 'getCaseMismatchMagicWords', + 'special' => 'getUntraslatedSpecialPages', + ); } + /** + * Get all check descriptions. + * @return An array of all check names mapped to their descriptions. + */ protected function getDescriptions() { - $descriptions = array(); - $descriptions['untranslated'] = '$1 message(s) of $2 are not translated to $3, but exist in en:'; - $descriptions['duplicate'] = '$1 message(s) of $2 are translated the same in en and $3:'; - $descriptions['obsolete'] = '$1 message(s) of $2 do not exist in en or are in the ignore list, but are in $3'; - $descriptions['variables'] = '$1 message(s) of $2 in $3 don\'t use some variables that en uses:'; - $descriptions['plural'] = '$1 message(s) of $2 in $3 don\'t use {{plural}} while en uses:'; - $descriptions['empty'] = '$1 message(s) of $2 in $3 are empty or -:'; - $descriptions['whitespace'] = '$1 message(s) of $2 in $3 have trailing whitespace:'; - $descriptions['xhtml'] = '$1 message(s) of $2 in $3 contain illegal XHTML:'; - $descriptions['chars'] = '$1 message(s) of $2 in $3 include hidden chars which should not be used in the messages:'; - $descriptions['links'] = '$1 message(s) of $2 in $3 have problematic link(s):'; - $descriptions['unbalanced'] = '$1 message(s) of $2 in $3 have unbalanced {[]}:'; - return $descriptions; + 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 use some variables that en uses:', + '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:', + 'skin' => '$1 skin name(s) of $2 are not translated to $3, but exist in en:', + 'magic' => '$1 magic word(s) of $2 are not translated to $3, but exist in en:', + '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:', + ); } + /** + * Get help. + * @return The help string. + */ protected function help() { return <<