Index: trunk/extensions/Translate/groups/Toolserver/ToolserverTextdomains.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Class for Toolserver Intuition for TranslateWiki.net |
| 4 | + * Class for Toolserver Intuition for Translatewiki.net |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @author Niklas Laxström |
Index: trunk/extensions/Translate/groups/MediaWikiExtensions.php |
— | — | @@ -28,34 +28,63 @@ |
29 | 29 | /// Initialisation function |
30 | 30 | public function init() { |
31 | 31 | if ( $this->groups !== null ) return; |
| 32 | + $groups = $this->parseFile(); |
| 33 | + $this->groups = $this->processGroups( $groups ); |
| 34 | + } |
32 | 35 | |
33 | | - global $wgAutoloadClasses, $IP, $wgTranslateExtensionDirectory; |
| 36 | + /// Makes an group id from extension name |
| 37 | + static function foldId( $name ) { |
| 38 | + return preg_replace( '/\s+/', '', strtolower( $name ) ); |
| 39 | + } |
34 | 40 | |
35 | | - $postfix = 'Configure/load_txt_def/TxtDef.php'; |
36 | | - if ( file_exists( "$IP/extensions/$postfix" ) ) { |
37 | | - $prefix = "$IP/extensions"; |
38 | | - } elseif( file_exists( "$wgTranslateExtensionDirectory/$postfix" ) ) { |
39 | | - $prefix = $wgTranslateExtensionDirectory; |
40 | | - } else { |
41 | | - $prefix = false; |
| 41 | + /// Registers all extensions |
| 42 | + public function addAll() { |
| 43 | + global $wgTranslateAC, $wgTranslateEC; |
| 44 | + $this->init(); |
| 45 | + |
| 46 | + if ( !count( $this->groups ) ) return; |
| 47 | + |
| 48 | + foreach ( $this->groups as $id => $g ) { |
| 49 | + $wgTranslateAC[$id] = array( $this, 'factory' ); |
| 50 | + $wgTranslateEC[] = $id; |
42 | 51 | } |
| 52 | + } |
43 | 53 | |
44 | | - if ( $this->useConfigure && $prefix ) { |
45 | | - $wgAutoloadClasses['TxtDef'] = "$prefix/$postfix"; |
46 | | - $tmp = TxtDef::loadFromFile( "$prefix/Configure/settings/Settings-ext.txt" ); |
47 | | - $configureData = array_combine( array_map( array( __CLASS__, 'foldId' ), array_keys( $tmp ) ), array_values( $tmp ) ); |
| 54 | + public function factory( $id ) { |
| 55 | + $info = $this->groups[$id]; |
| 56 | + $group = ExtensionMessageGroup::factory( $info['name'], $id ); |
| 57 | + $group->setMessageFile( $info['file'] ); |
| 58 | + $group->setPath( $this->path ); |
| 59 | + $group->namespaces = $this->namespaces; |
| 60 | + |
| 61 | + if ( isset( $info['prefix'] ) ) { |
| 62 | + $mangler = new StringMatcher( $info['prefix'], $info['mangle'] ); |
| 63 | + $group->setMangler( $mangler ); |
| 64 | + $info['ignored'] = $mangler->mangle( $info['ignored'] ); |
| 65 | + $info['optional'] = $mangler->mangle( $info['optional'] ); |
| 66 | + } |
| 67 | + |
| 68 | + if ( !empty( $info['var'] ) ) $group->setVariableName( $info['var'] ); |
| 69 | + if ( !empty( $info['optional'] ) ) $group->setOptional( $info['optional'] ); |
| 70 | + if ( !empty( $info['ignored'] ) ) $group->setIgnored( $info['ignored'] ); |
| 71 | + if ( isset( $info['desc'] ) ) { |
| 72 | + $group->setDescription( $info['desc'] ); |
48 | 73 | } else { |
49 | | - $configureData = array(); |
| 74 | + $group->setDescriptionMsg( $info['descmsg'], $info['url'] ); |
50 | 75 | } |
51 | 76 | |
| 77 | + if ( isset( $info['aliasfile'] ) ) $group->setAliasFile( $info['aliasfile'] ); |
| 78 | + if ( isset( $info['magicfile'] ) ) $group->setMagicFile( $info['magicfile'] ); |
| 79 | + |
| 80 | + return $group; |
| 81 | + } |
| 82 | + |
| 83 | + protected function parseFile() { |
52 | 84 | $defines = file_get_contents( $this->definitionFile ); |
53 | | - |
54 | 85 | $linefeed = '(\r\n|\n)'; |
55 | | - |
56 | 86 | $sections = array_map( 'trim', preg_split( "/$linefeed{2,}/", $defines, - 1, PREG_SPLIT_NO_EMPTY ) ); |
| 87 | + $groups = array(); |
57 | 88 | |
58 | | - $groups = $fixedGroups = array(); |
59 | | - |
60 | 89 | foreach ( $sections as $section ) { |
61 | 90 | $lines = array_map( 'trim', preg_split( "/$linefeed/", $section ) ); |
62 | 91 | $newgroup = array(); |
— | — | @@ -115,7 +144,12 @@ |
116 | 145 | } |
117 | 146 | } |
118 | 147 | |
| 148 | + return $groups; |
| 149 | + } |
119 | 150 | |
| 151 | + protected function processGroups( $groups ) { |
| 152 | + $configureData = $this->loadConfigureExtensionData(); |
| 153 | + $fixedGroups = array(); |
120 | 154 | foreach ( $groups as $g ) { |
121 | 155 | if ( !is_array( $g ) ) { |
122 | 156 | $g = array( $g ); |
— | — | @@ -164,54 +198,33 @@ |
165 | 199 | |
166 | 200 | $fixedGroups[$id] = $newgroup; |
167 | 201 | } |
168 | | - |
169 | | - $this->groups = $fixedGroups; |
| 202 | + return $fixedGroups; |
170 | 203 | } |
171 | 204 | |
172 | | - /// Makes an group id from extension name |
173 | | - static function foldId( $name ) { |
174 | | - return preg_replace( '/\s+/', '', strtolower( $name ) ); |
175 | | - } |
176 | | - |
177 | | - /// Registers all extensions |
178 | | - public function addAll() { |
179 | | - global $wgTranslateAC, $wgTranslateEC; |
180 | | - $this->init(); |
181 | | - |
182 | | - if ( !count( $this->groups ) ) return; |
183 | | - |
184 | | - foreach ( $this->groups as $id => $g ) { |
185 | | - $wgTranslateAC[$id] = array( $this, 'factory' ); |
186 | | - $wgTranslateEC[] = $id; |
| 205 | + protected function loadConfigureExtensionData() { |
| 206 | + if ( !$this->useConfigure ) { |
| 207 | + return array(); |
187 | 208 | } |
188 | | - } |
189 | 209 | |
190 | | - public function factory( $id ) { |
191 | | - $info = $this->groups[$id]; |
192 | | - $group = ExtensionMessageGroup::factory( $info['name'], $id ); |
193 | | - $group->setMessageFile( $info['file'] ); |
194 | | - $group->setPath( $this->path ); |
195 | | - $group->namespaces = $this->namespaces; |
| 210 | + global $wgAutoloadClasses, $IP, $wgTranslateExtensionDirectory; |
196 | 211 | |
197 | | - if ( isset( $info['prefix'] ) ) { |
198 | | - $mangler = new StringMatcher( $info['prefix'], $info['mangle'] ); |
199 | | - $group->setMangler( $mangler ); |
200 | | - $info['ignored'] = $mangler->mangle( $info['ignored'] ); |
201 | | - $info['optional'] = $mangler->mangle( $info['optional'] ); |
| 212 | + $postfix = 'Configure/load_txt_def/TxtDef.php'; |
| 213 | + if ( file_exists( "$IP/extensions/$postfix" ) ) { |
| 214 | + $prefix = "$IP/extensions"; |
| 215 | + } elseif( file_exists( "$wgTranslateExtensionDirectory/$postfix" ) ) { |
| 216 | + $prefix = $wgTranslateExtensionDirectory; |
| 217 | + } else { |
| 218 | + $prefix = false; |
202 | 219 | } |
203 | 220 | |
204 | | - if ( !empty( $info['var'] ) ) $group->setVariableName( $info['var'] ); |
205 | | - if ( !empty( $info['optional'] ) ) $group->setOptional( $info['optional'] ); |
206 | | - if ( !empty( $info['ignored'] ) ) $group->setIgnored( $info['ignored'] ); |
207 | | - if ( isset( $info['desc'] ) ) { |
208 | | - $group->setDescription( $info['desc'] ); |
209 | | - } else { |
210 | | - $group->setDescriptionMsg( $info['descmsg'], $info['url'] ); |
| 221 | + if ( $prefix ) { |
| 222 | + $wgAutoloadClasses['TxtDef'] = "$prefix/$postfix"; |
| 223 | + $tmp = TxtDef::loadFromFile( "$prefix/Configure/settings/Settings-ext.txt" ); |
| 224 | + return array_combine( array_map( array( __CLASS__, 'foldId' ), array_keys( $tmp ) ), array_values( $tmp ) ); |
211 | 225 | } |
212 | 226 | |
213 | | - if ( isset( $info['aliasfile'] ) ) $group->setAliasFile( $info['aliasfile'] ); |
214 | | - if ( isset( $info['magicfile'] ) ) $group->setMagicFile( $info['magicfile'] ); |
| 227 | + return array(); |
| 228 | + } |
215 | 229 | |
216 | | - return $group; |
217 | | - } |
| 230 | + |
218 | 231 | } |