r53803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53802‎ | r53803 | r53804 >
Date:13:50, 27 July 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
* Use proper way to hide line numbers from diffs
* FC and BC fixes everywhere
Modified paths:
  • /trunk/extensions/Translate/Groups.php (modified) (history)
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/Translate.css (modified) (history)
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)
  • /trunk/extensions/Translate/scripts/createMessageIndex.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.css
@@ -110,7 +110,7 @@
111111 padding: 0.5em;
112112 }
113113
114 -.mw-tpt-sp-legend {
 114+.mw-tpt-sp-legend, .mw-translate-manage-legend {
115115 font-weight: bold;
116116 }
117117
@@ -118,10 +118,5 @@
119119 font-size: small;
120120 padding-left: 2em;
121121 padding-right: 2em;
122 - padding-bottom: 1ex;
123 -}
124 -
125 -.mw-tpt-sp-markform .diff-lineno, .mw-sp-translate-edit-fields .diff-lineno {
126 - /* Ideally there should be no line numbers in the first place */
127 - display:none;
128 -}
 122+ padding-bottom: 2ex;
 123+}
\ No newline at end of file
Index: trunk/extensions/Translate/scripts/createMessageIndex.php
@@ -41,14 +41,18 @@
4242 function checkAndAdd( $g, $ignore = false ) {
4343 global $hugearray;
4444
45 - $messages = $g->getDefinitions();
 45+ if ( $g instanceof MessageGroupBase ) {
 46+ $messages = $g->load( 'en' );
 47+ } else {
 48+ $messages = $g->getDefinitions();
 49+ }
4650 $id = $g->getId();
4751
4852 if ( !is_array( $messages ) ) continue;
4953
5054 STDOUT( "$id ", 'main' );
5155
52 - $namespace = $g->namespaces[0];
 56+ $namespace = $g->getNamespace();
5357
5458 foreach ( $messages as $key => $data ) {
5559 # Force all keys to lower case, because the case doesn't matter and it is
Index: trunk/extensions/Translate/MessageGroups.php
@@ -200,13 +200,13 @@
201201
202202 public function setConfiguration( $conf ) {}
203203 public function getConfiguration() {}
204 - public function getNamespace() {
205 - return $this->namespaces[0];
 204+ public function getNamespace() { return $this->namespaces[0]; }
 205+ public function getFFS() { return null; }
 206+ public function getTags( $type = null ) {
 207+ $tags = $this->getBools();
 208+ if ( !$type ) return $tags;
 209+ return isset($tags[$type]) ? $tags[$type] : array();
206210 }
207 -
208 - public function getFFS() {
209 - return null;
210 - }
211211 }
212212
213213 class CoreMessageGroup extends MessageGroupOld {
Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -21,8 +21,17 @@
2222 list( $key, $code, $group) = self::getKeyCodeGroup( $wgTitle );
2323 if ( $group === null ) return true;
2424
25 - $defs = $group->getDefinitions();
26 - $skip = array_merge( $group->getIgnored(), $group->getOptional() );
 25+ if ( $group instanceof MessageGroupBase ) {
 26+ $cache = new MessageGroupCache($group);
 27+ if ( !$cache->exists() ) return true;
 28+ $keys = $cache->getKeys();
 29+ $defs = array();
 30+ foreach ( $keys as $key ) $defs[$key] = $cache->get( $key );
 31+ $skip = array_merge( $group->getTags( 'ignored' ), $group->getTags( 'optional' ) );
 32+ } else {
 33+ $defs = $group->getDefinitions();
 34+ $skip = array_merge( $group->getIgnored(), $group->getOptional() );
 35+ }
2736
2837 $next = $prev = $def = null;
2938 foreach ( array_keys( $defs ) as $tkey ) {
@@ -264,7 +273,7 @@
265274 list( $key, $code, $group ) = self::getKeyCodeGroup( $object->mTitle );
266275 if ( $group === null ) return;
267276
268 - list( $nsMain, /* $nsTalk */ ) = $group->namespaces;
 277+ $nsMain = $group->getNamespace();
269278
270279 $en = $group->getMessage( $key, 'en' );
271280 $xx = $group->getMessage( $key, $code );
@@ -357,7 +366,7 @@
358367 $class = 'mw-sp-translate-edit-noinfo';
359368 }
360369
361 - if ( $group->getType() === 'gettext' ) {
 370+ if ( $group instanceof GettextMessageGroup ) {
362371 $reader = $group->getReader( 'en' );
363372 if ( $reader ) {
364373 $data = $reader->parseFile();
@@ -404,6 +413,7 @@
405414 wfLoadExtensionMessages( 'PageTranslation' );
406415 $diff = new DifferenceEngine;
407416 $diff->setText( $oldtext, $newtext );
 417+ $diff->setReducedLineNumbers();
408418 $boxes[] = $diff->getDiff( wfMsgHtml('tpt-diff-old'), wfMsgHtml('tpt-diff-new') );
409419 $diff->showDiffStyle();
410420 }
@@ -498,7 +508,7 @@
499509 list( $key, $code, $group ) = self::getKeyCodeGroup( $title );
500510
501511 // Unknown message, do not handle
502 - if ( !$group ) return true;
 512+ if ( !$group || !$code ) return true;
503513
504514 $cache = new ArrayMemoryCache( 'groupstats' );
505515 $cache->clear( $group->getId(), $code );
@@ -509,12 +519,13 @@
510520 // Check for problems, but only if not fuzzy already
511521 global $wgTranslateDocumentationLanguageCode;
512522 if ( $code !== $wgTranslateDocumentationLanguageCode ) {
513 - $en = $group->getMessage( $key, 'en' );
514 - $message = new FatMessage( $key, $en );
515 - // Take the contents from edit field as a translation
516 - $message->setTranslation( $text );
517523 $checker = $group->getChecker();
518524 if ( $checker ) {
 525+ $en = $group->getMessage( $key, 'en' );
 526+ $message = new FatMessage( $key, $en );
 527+ // Take the contents from edit field as a translation
 528+ $message->setTranslation( $text );
 529+
519530 $checks = $checker->checkMessage( $message, $code );
520531 if ( count( $checks ) ) $fuzzy = true;
521532 }
Index: trunk/extensions/Translate/Groups.php
@@ -17,6 +17,8 @@
1818
1919 public function initCollection( $code );
2020 public function load( $code );
 21+ public function getTags( $type = null );
 22+ public function getMessage( $key, $code );
2123 }
2224
2325 abstract class MessageGroupBase implements MessageGroup {
@@ -57,7 +59,7 @@
5860 if ( $class === null ) return null;
5961 if ( !class_exists($class) ) throw new MWException( "Checker class $class does not exists" );
6062
61 - $checker = new $class();
 63+ $checker = new $class($this);
6264 $checks = $this->getFromConf( 'CHECKER','checks' );
6365 if ( !is_array($checks) ) throw new MWException( "Checker class $class not supplied with proper checks" );
6466
@@ -78,7 +80,6 @@
7981 }
8082
8183 if ( !class_exists($class) ) throw new MWException( "Mangler class $class does not exists" );
82 -
8384 // TODO: branch handling, merge with upper branch keys
8485 $class = $this->getFromConf( 'MANGLER','class' );
8586 $this->mangler = new $class();
@@ -98,40 +99,65 @@
99100 return $collection;
100101 }
101102
 103+ public function getMessage( $key, $code ) {
 104+ $cache = new MessageGroupCache( $this );
 105+ if ( $cache->exists($code) ) {
 106+ $msg = $cache->get( $key, $code );
 107+ if ( $msg === false ) { // Try harder
 108+ $nkey = str_replace( ' ', '_', strtolower( $key ) );
 109+ $keys = $cache->getKeys($code);
 110+ foreach ( $keys as $k ) {
 111+ if ( $nkey === str_replace( ' ', '_', strtolower( $k ) ) ) {
 112+ return $cache->get($k);
 113+ }
 114+ }
 115+ }
 116+ return null;
 117+ } else {
 118+ return null;
 119+ }
 120+ }
 121+
 122+ public function getTags( $type = null ) {
 123+ if ( !isset($this->conf['TAGS']) ) return array();
 124+
 125+ $tags = $this->conf['TAGS'];
 126+ if ( !$type ) return $tags;
 127+
 128+ if ( isset($tags[$type]) ) return $tags[$type];
 129+ return array();
 130+ }
 131+
102132 protected function setTags( MessageCollection $collection ) {
103 - if ( isset($this->conf['TAGS']) ) {
104 - $tags = $this->conf['TAGS'];
105 - if ( !is_array($tags) ) throw new MWException( 'Tags is not an array' );
 133+ $tags = $this->getTags();
106134
107 - $cache = new MessageGroupCache( $this->getId() );
108 - $messageKeys = $cache->getKeys();
 135+ $cache = new MessageGroupCache( $this->getId() );
 136+ $messageKeys = $cache->getKeys();
109137
110 - // Loop trough all tag types
111 - foreach ( $tags as $type => $patterns ) {
112 - $matches = array();
 138+ // Loop trough all tag types
 139+ foreach ( $tags as $type => $patterns ) {
 140+ $matches = array();
113141
114 - // Collect exact keys, no point running them trough string matcher
115 - foreach ( $patterns as $index => $pattern ) {
116 - if ( strpos( $pattern, '*' ) === false ) {
117 - $matches[] = $pattern;
118 - unset($patterns[$index]);
119 - }
 142+ // Collect exact keys, no point running them trough string matcher
 143+ foreach ( $patterns as $index => $pattern ) {
 144+ if ( strpos( $pattern, '*' ) === false ) {
 145+ $matches[] = $pattern;
 146+ unset($patterns[$index]);
120147 }
 148+ }
121149
122 - if ( count($patterns) ) {
123 - // Rest of the keys contain wildcards
124 - $conf = array( 'patterns' => $patterns );
125 - $mangler = new StringMatcher( $conf );
 150+ if ( count($patterns) ) {
 151+ // Rest of the keys contain wildcards
 152+ $mangler = new StringMatcher( '', $patterns );
126153
127 - // Use mangler to find messages that match
128 - foreach ( $messageKeys as $key ) {
129 - if ( $mangler->match($key) ) $matches[] = $key;
130 - }
 154+ // Use mangler to find messages that match
 155+ foreach ( $messageKeys as $key ) {
 156+ if ( $mangler->match($key) ) $matches[] = $key;
131157 }
 158+ }
132159
133 - // Add the combined matches
134 - $collection->setTags( $type, $matches );
135 - }
 160+ // Add the combined matches
 161+ $collection->setTags( $type, $matches );
136162 }
137163 }
138164

Status & tagging log