r53752 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53751‎ | r53752 | r53753 >
Date:18:05, 25 July 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
Revert to old interface for StringMangler + some other changes
Modified paths:
  • /trunk/extensions/Translate/Groups.php (modified) (history)
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/utils/StringMatcher.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -327,10 +327,6 @@
328328 public function getMessageFile( $code ) { return $this->messageFile; }
329329 public function setMessageFile( $value ) { $this->messageFile = $value; }
330330
331 - public function getMessageFilePath( $code ) {
332 - return $wgTranslateExtensionDirectory;
333 - }
334 -
335331 public function setDescriptionMsg( $key, $url ) {
336332 global $wgLang;
337333
Index: trunk/extensions/Translate/utils/StringMatcher.php
@@ -1,6 +1,7 @@
22 <?php
33 interface StringMangler {
44 public static function EmptyMatcher();
 5+ public function setConf( $configuration );
56
67 // String or array
78 public function match( $string );
@@ -19,22 +20,16 @@
2021 return new StringMatcher( '', array() );
2122 }
2223
23 - public function __construct( $conf ) {
24 - $prefix = '';
25 - $patterns = array();
26 -
27 - if ( isset($conf['prefix']) && is_string($conf['prefix']) ) {
28 - $prefix = $conf['prefix'];
29 - }
30 -
31 - if ( isset($conf['patterns']) && is_array($conf['patterns']) ) {
32 - $patterns = $conf['patterns'];
33 - }
34 -
 24+ public function __construct( $prefix, $patterns = array() ) {
3525 $this->sPrefix = $prefix;
3626 $this->init( $patterns );
3727 }
3828
 29+ public function setConf( $conf ) {
 30+ $this->sPrefix = $conf['prefix'];
 31+ $this->init( $conf['patterns'] );
 32+ }
 33+
3934 protected function init( Array $strings ) {
4035 foreach ( $strings as $string ) {
4136 $pos = strpos( $string, '*' );
Index: trunk/extensions/Translate/Groups.php
@@ -81,7 +81,8 @@
8282
8383 // TODO: branch handling, merge with upper branch keys
8484 $class = $this->getFromConf( 'MANGLER','class' );
85 - $this->mangler = new $class($this->conf['MANGLER']);
 85+ $this->mangler = new $class();
 86+ $this->mangler->setConf( $this->conf['MANGLER'] );
8687 }
8788
8889 return $this->mangler;
@@ -97,20 +98,6 @@
9899 return $collection;
99100 }
100101
101 - public function load( $code ) {
102 - if ( $this->exists() ) {
103 - $cache = new MessageGroupCache( $this->getId() );
104 - if ( !$cache->exists($code) ) return array();
105 - $messages = array();
106 - foreach ( $cache->getKeys($code) as $key ) {
107 - $messages[$key] = $cache->get($key);
108 - }
109 - return $messages;
110 - } else {
111 - throw new MWException( 'Not configured properly' );
112 - }
113 - }
114 -
115102 protected function setTags( MessageCollection $collection ) {
116103 if ( isset($this->conf['TAGS']) ) {
117104 $tags = $this->conf['TAGS'];
@@ -165,23 +152,14 @@
166153 class FileBasedMessageGroup extends MessageGroupBase {
167154 public function exists() {
168155 $ffs = $this->getFFS();
169 - if ( !$ffs ) throw new MWException( 'No FFS defined' );
170156 $data = $ffs->read( 'en' );
171157 return $data && count($data['MESSAGES']);
172158 }
173159
174160 public function load( $code ) {
175 - $cache = new MessageGroupCache( $this->getId() );
176 - if ( $cache->exists() ) {
177 - return parent::load( $code );
178 - } else {
179 - // Short-circuit cache
180 - $ffs = $this->getFFS();
181 - if ( !$ffs ) throw new MWException( 'No FFS defined' );
182 - $data = $ffs->read( $code );
183 -
184 - return $data ? $data['MESSAGES'] : array();
185 - }
 161+ $ffs = $this->getFFS();
 162+ $data = $ffs->read( $code );
 163+ return $data ? $data['MESSAGES'] : array();
186164 }
187165
188166 public function getSourceFilePath( $code ) {
@@ -220,10 +198,6 @@
221199 }
222200 }
223201
224 -/*class CollectionMessageGroup extends MessageGroupBase {
225 -
226 -}*/
227 -
228202 class MediaWikiMessageGroup extends FileBasedMessageGroup {
229203 protected function mapCode( $code ) {
230204 return ucfirst( str_replace( '-', '_', parent::mapCode($code) ) );

Status & tagging log