Index: trunk/extensions/Translate/utils/TranslateYaml.php |
— | — | @@ -1,8 +1,9 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | class TranslateYaml { |
4 | | - |
5 | 5 | public static function loadString( $text ) { |
6 | 6 | global $wgTranslateYamlLibrary; |
| 7 | + |
7 | 8 | switch ( $wgTranslateYamlLibrary ) { |
8 | 9 | case 'spyc': |
9 | 10 | require_once( dirname( __FILE__ ) . '/../spyc/spyc.php' ); |
— | — | @@ -16,11 +17,13 @@ |
17 | 18 | |
18 | 19 | public static function load( $file ) { |
19 | 20 | $text = file_get_contents( $file ); |
| 21 | + |
20 | 22 | return self::loadString( $text ); |
21 | 23 | } |
22 | 24 | |
23 | 25 | public static function dump( $text ) { |
24 | 26 | global $wgTranslateYamlLibrary; |
| 27 | + |
25 | 28 | switch ( $wgTranslateYamlLibrary ) { |
26 | 29 | case 'spyc': |
27 | 30 | require_once( dirname( __FILE__ ) . '/../spyc/spyc.php' ); |
— | — | @@ -47,7 +50,9 @@ |
48 | 51 | 'print $fh serialize($yaml);' . |
49 | 52 | 'close($fh);' . |
50 | 53 | "' 2>&1"; |
| 54 | + |
51 | 55 | $out = wfShellExec( $cmd, &$ret ); |
| 56 | + |
52 | 57 | if ( $ret != 0 ) { |
53 | 58 | wfDebugDieBacktrace( "The command '$cmd' died in execution with exit code '$ret': $out" ); |
54 | 59 | } |
— | — | @@ -57,7 +62,7 @@ |
58 | 63 | |
59 | 64 | unlink( $tf ); |
60 | 65 | unlink( "$tf.serialized" ); |
61 | | - |
| 66 | + |
62 | 67 | return $php_data; |
63 | 68 | } |
64 | 69 | |
— | — | @@ -99,7 +104,7 @@ |
100 | 105 | |
101 | 106 | unlink( $tf ); |
102 | 107 | unlink( "$tf.yaml" ); |
103 | | - |
| 108 | + |
104 | 109 | return $yaml; |
105 | 110 | } |
106 | 111 | } |
Index: trunk/extensions/Translate/utils/TranslationHelpers.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | protected function init() { |
19 | 19 | $title = $this->title; |
20 | 20 | list( $page, $code ) = self::figureMessage( $title ); |
21 | | - |
| 21 | + |
22 | 22 | $this->page = $page; |
23 | 23 | $this->targetLanguage = $code; |
24 | 24 | $this->group = self::getMessageGroup( $title->getNamespace(), $page ); |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | public static function figureMessage( Title $title ) { |
28 | 28 | $text = $title->getDBkey(); |
29 | 29 | $pos = strrpos( $text, '/' ); |
| 30 | + |
30 | 31 | if ( $pos === false ) { |
31 | 32 | $code = ''; |
32 | 33 | $key = $text; |
— | — | @@ -33,6 +34,7 @@ |
34 | 35 | $code = substr( $text, $pos + 1 ); |
35 | 36 | $key = substr( $text, 0, $pos ); |
36 | 37 | } |
| 38 | + |
37 | 39 | return array( $key, $code ); |
38 | 40 | } |
39 | 41 | |
— | — | @@ -46,6 +48,7 @@ |
47 | 49 | */ |
48 | 50 | protected static function getMessageGroup( $namespace, $key ) { |
49 | 51 | global $wgRequest; |
| 52 | + |
50 | 53 | $group = $wgRequest->getText( 'loadgroup', '' ); |
51 | 54 | $mg = MessageGroups::getGroup( $group ); |
52 | 55 | |
— | — | @@ -69,14 +72,23 @@ |
70 | 73 | } |
71 | 74 | |
72 | 75 | public function getDefinition() { |
73 | | - if ( $this->definition !== null ) return $this->definition; |
74 | | - if ( $this->group === null ) return; |
| 76 | + if ( $this->definition !== null ) { |
| 77 | + return $this->definition; |
| 78 | + } |
| 79 | + |
| 80 | + if ( $this->group === null ) { |
| 81 | + return; |
| 82 | + } |
| 83 | + |
75 | 84 | $this->definition = $this->group->getMessage( $this->page, 'en' ); |
| 85 | + |
76 | 86 | return $this->definition; |
77 | 87 | } |
78 | 88 | |
79 | 89 | public function getTranslation() { |
80 | | - if ( $this->translation !== null ) return $this->translation; |
| 90 | + if ( $this->translation !== null ) { |
| 91 | + return $this->translation; |
| 92 | + } |
81 | 93 | |
82 | 94 | // Shorter names |
83 | 95 | $page = $this->page; |
— | — | @@ -99,7 +111,9 @@ |
100 | 112 | // Nothing to prefil |
101 | 113 | $translation = ''; |
102 | 114 | } |
| 115 | + |
103 | 116 | $this->translation = $translation; |
| 117 | + |
104 | 118 | return $translation; |
105 | 119 | } |
106 | 120 | |
— | — | @@ -119,12 +133,20 @@ |
120 | 134 | 'definition' => array( $this, 'getDefinitionBox' ), |
121 | 135 | 'check' => array( $this, 'getCheckBox' ), |
122 | 136 | ); |
123 | | - if ( $types !== null ) foreach ( $types as $type ) unset( $all[$type] ); |
124 | 137 | |
| 138 | + if ( $types !== null ) { |
| 139 | + foreach ( $types as $type ) { |
| 140 | + unset( $all[$type] ); |
| 141 | + } |
| 142 | + } |
| 143 | + |
125 | 144 | $boxes = array(); |
126 | 145 | foreach ( $all as $type => $cb ) { |
127 | 146 | $box = call_user_func( $cb ); |
128 | | - if ( $box ) $boxes[$type] = $box; |
| 147 | + |
| 148 | + if ( $box ) { |
| 149 | + $boxes[$type] = $box; |
| 150 | + } |
129 | 151 | } |
130 | 152 | |
131 | 153 | if ( count( $boxes ) ) { |
— | — | @@ -141,12 +163,22 @@ |
142 | 164 | protected function getTmBox() { |
143 | 165 | global $wgTranslateTM; |
144 | 166 | |
145 | | - if ( $wgTranslateTM === false ) return null; |
146 | | - if ( !$this->targetLanguage ) return null; |
147 | | - if ( strval( $this->getDefinition() ) === '' ) return null; |
| 167 | + if ( $wgTranslateTM === false ) { |
| 168 | + return null; |
| 169 | + } |
148 | 170 | |
| 171 | + if ( !$this->targetLanguage ) { |
| 172 | + return null; |
| 173 | + } |
| 174 | + |
| 175 | + if ( strval( $this->getDefinition() ) === '' ) { |
| 176 | + return null; |
| 177 | + } |
| 178 | + |
149 | 179 | $serviceName = 'tmserver'; |
150 | | - if ( self::checkTranslationServiceFailure( $serviceName ) ) return null; |
| 180 | + if ( self::checkTranslationServiceFailure( $serviceName ) ) { |
| 181 | + return null; |
| 182 | + } |
151 | 183 | |
152 | 184 | // Needed data |
153 | 185 | $code = $this->targetLanguage; |
— | — | @@ -167,9 +199,12 @@ |
168 | 200 | |
169 | 201 | if ( $suggestions !== false ) { |
170 | 202 | $suggestions = FormatJson::decode( $suggestions, true ); |
| 203 | + |
171 | 204 | foreach ( $suggestions as $s ) { |
172 | 205 | // No use to suggest them what they are currently viewing |
173 | | - if ( $s['context'] === "$ns:{$this->page}" ) continue; |
| 206 | + if ( $s['context'] === "$ns:{$this->page}" ) { |
| 207 | + continue; |
| 208 | + } |
174 | 209 | |
175 | 210 | $accuracy = wfMsgHtml( 'translate-edit-tmmatch' , sprintf( '%.2f', $s['quality'] ) ); |
176 | 211 | $legend = array( $accuracy => array() ); |
— | — | @@ -192,7 +227,11 @@ |
193 | 228 | foreach ( $sugFields as $field ) { |
194 | 229 | list( $text, $params, $label ) = $field; |
195 | 230 | $legend = array(); |
196 | | - foreach ( $label as $acc => $links ) { $legend[] = $acc . ' ' . implode( " ", $links ); } |
| 231 | + |
| 232 | + foreach ( $label as $acc => $links ) { |
| 233 | + $legend[] = $acc . ' ' . implode( " ", $links ); |
| 234 | + } |
| 235 | + |
197 | 236 | $legend = implode( ' | ', $legend ); |
198 | 237 | $boxes[] = Html::rawElement( 'div', $params, self::legend( $legend ) . $text . self::clear() ) . "\n"; |
199 | 238 | } |
— | — | @@ -208,13 +247,20 @@ |
209 | 248 | protected function getSuggestionBox() { |
210 | 249 | $boxes = (array) $this->getTmBox(); |
211 | 250 | $google = $this->getGoogleSuggestion(); |
212 | | - if ( $google ) $boxes[] = $google; |
| 251 | + |
| 252 | + if ( $google ) { |
| 253 | + $boxes[] = $google; |
| 254 | + } |
| 255 | + |
213 | 256 | $apertium = $this->getApertiumSuggestion(); |
214 | | - if ( $apertium ) $boxes[] = $apertium; |
| 257 | + if ( $apertium ) { |
| 258 | + $boxes[] = $apertium; |
| 259 | + } |
215 | 260 | |
216 | 261 | // Enclose if there is more than one box |
217 | 262 | if ( count( $boxes ) ) { |
218 | 263 | $sep = Html::element( 'hr', array( 'class' => 'mw-translate-sep' ) ); |
| 264 | + |
219 | 265 | return TranslateUtils::fieldset( wfMsgHtml( 'translate-edit-tmsugs' ), |
220 | 266 | implode( "$sep\n", $boxes ), array( 'class' => 'mw-translate-edit-tmsugs' ) ); |
221 | 267 | } else { |
— | — | @@ -226,7 +272,9 @@ |
227 | 273 | global $wgProxyKey, $wgGoogleApiKey, $wgMemc; |
228 | 274 | |
229 | 275 | $serviceName = 'Google'; |
230 | | - if ( self::checkTranslationServiceFailure( $serviceName ) ) return null; |
| 276 | + if ( self::checkTranslationServiceFailure( $serviceName ) ) { |
| 277 | + return null; |
| 278 | + } |
231 | 279 | |
232 | 280 | $code = $this->targetLanguage; |
233 | 281 | $definition = trim( strval( $this->getDefinition() ) ) ; |
— | — | @@ -234,11 +282,19 @@ |
235 | 283 | $memckey = wfMemckey( 'translate-tmsug-badcodes' ); |
236 | 284 | $unsupported = $wgMemc->get( $memckey ); |
237 | 285 | |
238 | | - if ( isset( $unsupported[$code] ) ) return null; |
239 | | - if ( $definition === '' ) return null; |
| 286 | + if ( isset( $unsupported[$code] ) ) { |
| 287 | + return null; |
| 288 | + } |
| 289 | + |
| 290 | + if ( $definition === '' ) { |
| 291 | + return null; |
| 292 | + } |
| 293 | + |
240 | 294 | /* There is 5000 *character* limit, but encoding needs to be taken into |
241 | | - * account. Not sure if this applies also to post method. */ |
242 | | - if ( strlen( rawurlencode( $definition ) ) > 4900 ) return null; |
| 295 | + * account. Not sure if this applies also to post method. */ |
| 296 | + if ( strlen( rawurlencode( $definition ) ) > 4900 ) { |
| 297 | + return null; |
| 298 | + } |
243 | 299 | |
244 | 300 | $path = 'http://ajax.googleapis.com/ajax/services/language/translate'; |
245 | 301 | $options = array(); |
— | — | @@ -250,8 +306,11 @@ |
251 | 307 | // Unique but not identifiable |
252 | 308 | 'userip' => sha1( $wgProxyKey . wfGetIp() ), |
253 | 309 | ); |
254 | | - if ( $wgGoogleApiKey ) $options['postData']['key'] = $wgGoogleApiKey; |
255 | 310 | |
| 311 | + if ( $wgGoogleApiKey ) { |
| 312 | + $options['postData']['key'] = $wgGoogleApiKey; |
| 313 | + } |
| 314 | + |
256 | 315 | $google_json = Http::post( $path, $options ); |
257 | 316 | $response = FormatJson::decode( $google_json ); |
258 | 317 | |
— | — | @@ -259,14 +318,18 @@ |
260 | 319 | wfWarn( __METHOD__ . ': Http::get failed' ); |
261 | 320 | // Most likely a timeout or other general error |
262 | 321 | self::reportTranslationSerficeFailure( $serviceName ); |
| 322 | + |
263 | 323 | return null; |
264 | 324 | } elseif ( !is_object( $response ) ) { |
265 | 325 | wfWarn( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) ); |
266 | 326 | error_log( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) ); |
| 327 | + |
267 | 328 | return null; |
268 | 329 | } |
| 330 | + |
269 | 331 | if ( $response->responseStatus === 200 ) { |
270 | 332 | $text = $this->suggestionField( Sanitizer::decodeCharReferences( $response->responseData->translatedText ) ); |
| 333 | + |
271 | 334 | return Html::rawElement( 'div', null, self::legend( 'Google' ) . $text . self::clear() ); |
272 | 335 | } elseif ( $response->responseDetails === 'invalid translation language pair' ) { |
273 | 336 | $unsupported[$code] = true; |
— | — | @@ -276,6 +339,7 @@ |
277 | 340 | self::reportTranslationSerficeFailure( $serviceName ); |
278 | 341 | wfWarn( __METHOD__ . ': ' . $response->responseDetails ); |
279 | 342 | error_log( __METHOD__ . ': ' . $response->responseDetails ); |
| 343 | + |
280 | 344 | return null; |
281 | 345 | } |
282 | 346 | } |
— | — | @@ -283,9 +347,14 @@ |
284 | 348 | protected function getApertiumSuggestion() { |
285 | 349 | global $wgTranslateApertium, $wgMemc; |
286 | 350 | |
287 | | - if ( !$wgTranslateApertium ) return null; |
| 351 | + if ( !$wgTranslateApertium ) { |
| 352 | + return null; |
| 353 | + } |
| 354 | + |
288 | 355 | $serviceName = 'Apertium'; |
289 | | - if ( self::checkTranslationServiceFailure( $serviceName ) ) return null; |
| 356 | + if ( self::checkTranslationServiceFailure( $serviceName ) ) { |
| 357 | + return null; |
| 358 | + } |
290 | 359 | |
291 | 360 | $page = $this->page; |
292 | 361 | $code = $this->targetLanguage; |
— | — | @@ -297,17 +366,33 @@ |
298 | 367 | if ( !$pairs ) { |
299 | 368 | $pairs = array(); |
300 | 369 | $pairlist = Http::get( $wgTranslateApertium, 5 ); |
301 | | - if ( $pairlist === false ) return null; |
| 370 | + |
| 371 | + if ( $pairlist === false ) { |
| 372 | + return null; |
| 373 | + } |
| 374 | + |
302 | 375 | $pairlist = trim( Sanitizer::stripAllTags( $pairlist ) ); |
303 | 376 | $pairlist = explode( " ", $pairlist ); |
| 377 | + |
304 | 378 | foreach ( $pairlist as $pair ) { |
305 | 379 | $pair = trim( $pair ); |
306 | | - if ( $pair === '' ) continue; |
| 380 | + |
| 381 | + if ( $pair === '' ) { |
| 382 | + continue; |
| 383 | + } |
| 384 | + |
307 | 385 | $languages = explode( '-', $pair ); |
308 | | - if ( count( $languages ) !== 2 ) continue; |
309 | 386 | |
| 387 | + if ( count( $languages ) !== 2 ) { |
| 388 | + continue; |
| 389 | + } |
| 390 | + |
310 | 391 | list( $source, $target ) = $languages; |
311 | | - if ( !isset( $pairs[$target] ) ) $pairs[$target] = array(); |
| 392 | + |
| 393 | + if ( !isset( $pairs[$target] ) ) { |
| 394 | + $pairs[$target] = array(); |
| 395 | + } |
| 396 | + |
312 | 397 | $pairs[$target][$source] = true; |
313 | 398 | } |
314 | 399 | |
— | — | @@ -315,22 +400,36 @@ |
316 | 401 | } |
317 | 402 | |
318 | 403 | $codemap = array( 'no' => 'nb' ); |
319 | | - if ( isset( $codemap[$code] ) ) $code = $codemap[$code]; |
| 404 | + |
| 405 | + if ( isset( $codemap[$code] ) ) { |
| 406 | + $code = $codemap[$code]; |
| 407 | + } |
| 408 | + |
320 | 409 | $code = str_replace( '-', '_', wfBCP47( $code ) ); |
321 | 410 | |
322 | | - if ( !isset( $pairs[$code] ) ) return; |
| 411 | + if ( !isset( $pairs[$code] ) ) { |
| 412 | + return; |
| 413 | + } |
323 | 414 | |
324 | 415 | $suggestions = array(); |
325 | 416 | |
326 | 417 | $codemap = array_flip( $codemap ); |
327 | 418 | foreach ( $pairs[$code] as $candidate => $unused ) { |
328 | 419 | $mwcode = str_replace( '_', '-', strtolower( $candidate ) ); |
329 | | - if ( isset( $codemap[$mwcode] ) ) $mwcode = $codemap[$mwcode]; |
330 | 420 | |
| 421 | + if ( isset( $codemap[$mwcode] ) ) { |
| 422 | + $mwcode = $codemap[$mwcode]; |
| 423 | + } |
| 424 | + |
331 | 425 | $text = TranslateUtils::getMessageContent( $page, $mwcode, $ns ); |
332 | | - if ( $text === null || TranslateEditAddons::hasFuzzyString( $text ) ) continue; |
| 426 | + if ( $text === null || TranslateEditAddons::hasFuzzyString( $text ) ) { |
| 427 | + continue; |
| 428 | + } |
| 429 | + |
333 | 430 | $title = Title::makeTitleSafe( $ns, "$page/$mwcode" ); |
334 | | - if ( $title && TranslateEditAddons::isFuzzy( $title ) ) continue; |
| 431 | + if ( $title && TranslateEditAddons::isFuzzy( $title ) ) { |
| 432 | + continue; |
| 433 | + } |
335 | 434 | |
336 | 435 | $query = array( |
337 | 436 | 'mark' => 0, |
— | — | @@ -347,15 +446,22 @@ |
348 | 447 | $suggestions[] = Html::rawElement( 'div', null, self::legend( "Apertium ($candidate)" ) . $response . self::clear() ); |
349 | 448 | } |
350 | 449 | } |
351 | | - if ( !count( $suggestions ) ) return null; |
| 450 | + |
| 451 | + if ( !count( $suggestions ) ) { |
| 452 | + return null; |
| 453 | + } |
| 454 | + |
352 | 455 | return implode( "\n", $suggestions ); |
353 | 456 | } |
354 | 457 | |
355 | 458 | protected function getDefinitionBox() { |
356 | 459 | $en = $this->getDefinition(); |
357 | | - if ( $en === null ) return null; |
| 460 | + if ( $en === null ) { |
| 461 | + return null; |
| 462 | + } |
358 | 463 | |
359 | 464 | global $wgUser; |
| 465 | + |
360 | 466 | $label = " ()"; |
361 | 467 | $title = $wgUser->getSkin()->link( |
362 | 468 | SpecialPage::getTitleFor( 'Translate' ), |
— | — | @@ -378,32 +484,44 @@ |
379 | 485 | ); |
380 | 486 | |
381 | 487 | $class = array( 'class' => 'mw-sp-translate-edit-definition mw-translate-edit-definition' ); |
| 488 | + |
382 | 489 | return TranslateUtils::fieldset( $label, $msg, $class ); |
383 | 490 | } |
384 | 491 | |
385 | 492 | protected function getCheckBox() { |
386 | 493 | global $wgTranslateDocumentationLanguageCode; |
387 | | - if ( $this->group === null ) return; |
388 | 494 | |
| 495 | + if ( $this->group === null ) { |
| 496 | + return; |
| 497 | + } |
| 498 | + |
389 | 499 | $page = $this->page; |
390 | 500 | $translation = $this->getTranslation(); |
391 | 501 | $code = $this->targetLanguage; |
392 | 502 | $en = $this->getDefinition(); |
393 | 503 | |
394 | | - if ( strval( $translation ) === '' ) return null; |
395 | | - if ( $code === $wgTranslateDocumentationLanguageCode ) return null; |
| 504 | + if ( strval( $translation ) === '' ) { |
| 505 | + return null; |
| 506 | + } |
396 | 507 | |
| 508 | + if ( $code === $wgTranslateDocumentationLanguageCode ) { |
| 509 | + return null; |
| 510 | + } |
| 511 | + |
397 | 512 | $checker = $this->group->getChecker(); |
398 | | - if ( !$checker ) return null; |
| 513 | + if ( !$checker ) { |
| 514 | + return null; |
| 515 | + } |
399 | 516 | |
400 | 517 | $message = new FatMessage( $page, $en ); |
401 | 518 | // Take the contents from edit field as a translation |
402 | 519 | $message->setTranslation( $translation ); |
403 | 520 | |
404 | 521 | $checks = $checker->checkMessage( $message, $code ); |
405 | | - if ( !count( $checks ) ) return null; |
| 522 | + if ( !count( $checks ) ) { |
| 523 | + return null; |
| 524 | + } |
406 | 525 | |
407 | | - |
408 | 526 | $checkMessages = array(); |
409 | 527 | foreach ( $checks as $checkParams ) { |
410 | 528 | array_splice( $checkParams, 1, 0, 'parseinline' ); |
— | — | @@ -426,7 +544,9 @@ |
427 | 545 | $boxes = array(); |
428 | 546 | foreach ( self::getFallbacks( $code ) as $fbcode ) { |
429 | 547 | $text = TranslateUtils::getMessageContent( $page, $fbcode, $ns ); |
430 | | - if ( $text === null ) continue; |
| 548 | + if ( $text === null ) { |
| 549 | + continue; |
| 550 | + } |
431 | 551 | |
432 | 552 | $label = |
433 | 553 | TranslateUtils::getLanguageName( $fbcode, false, $wgLang->getCode() ) . |
— | — | @@ -445,6 +565,7 @@ |
446 | 566 | |
447 | 567 | if ( count( $boxes ) ) { |
448 | 568 | $sep = Html::element( 'hr', array( 'class' => 'mw-translate-sep' ) ); |
| 569 | + |
449 | 570 | return TranslateUtils::fieldset( wfMsgHtml( 'translate-edit-in-other-languages' , $page ), |
450 | 571 | implode( "$sep\n", $boxes ), array( 'class' => 'mw-sp-translate-edit-inother' ) ); |
451 | 572 | } |
— | — | @@ -459,7 +580,10 @@ |
460 | 581 | public function getDocumentationBox() { |
461 | 582 | global $wgTranslateDocumentationLanguageCode, $wgUser, $wgOut; |
462 | 583 | |
463 | | - if ( !$wgTranslateDocumentationLanguageCode ) return null; |
| 584 | + if ( !$wgTranslateDocumentationLanguageCode ) { |
| 585 | + return null; |
| 586 | + } |
| 587 | + |
464 | 588 | $page = $this->page; |
465 | 589 | $ns = $this->title->getNamespace(); |
466 | 590 | |
— | — | @@ -468,6 +592,7 @@ |
469 | 593 | $info = TranslateUtils::getMessageContent( $page, $wgTranslateDocumentationLanguageCode, $ns ); |
470 | 594 | |
471 | 595 | $class = 'mw-sp-translate-edit-info'; |
| 596 | + |
472 | 597 | if ( $info === null ) { |
473 | 598 | $info = wfMsg( 'translate-edit-no-information' ); |
474 | 599 | $class = 'mw-sp-translate-edit-noinfo'; |
— | — | @@ -477,6 +602,7 @@ |
478 | 603 | $reader = $this->group->getReader( 'en' ); |
479 | 604 | if ( $reader ) { |
480 | 605 | global $wgContLang; |
| 606 | + |
481 | 607 | $mykey = $wgContLang->lcfirst( $this->page ); |
482 | 608 | $data = $reader->parseFile(); |
483 | 609 | $help = GettextFormatWriter::formatcomments( @$data[$mykey]['comments'], false, @$data[$mykey]['flags'] ); |
— | — | @@ -489,6 +615,7 @@ |
490 | 616 | $contents = $wgOut->parse( $info ); |
491 | 617 | // Remove whatever block element wrapup the parser likes to add |
492 | 618 | $contents = preg_replace( '~^<([a-z]+)>(.*)</\1>$~us', '\2', $contents ); |
| 619 | + |
493 | 620 | return TranslateUtils::fieldset( |
494 | 621 | wfMsgHtml( 'translate-edit-information', $edit , $page ), $contents, array( 'class' => $class ) |
495 | 622 | ); |
— | — | @@ -496,7 +623,9 @@ |
497 | 624 | } |
498 | 625 | |
499 | 626 | protected function getPageDiff() { |
500 | | - if ( $this->group instanceof WikiPageMessageGroup ) return null; |
| 627 | + if ( $this->group instanceof WikiPageMessageGroup ) { |
| 628 | + return null; |
| 629 | + } |
501 | 630 | |
502 | 631 | // Shortcuts |
503 | 632 | $code = $this->targetLanguage; |
— | — | @@ -518,26 +647,38 @@ |
519 | 648 | ); |
520 | 649 | |
521 | 650 | $latestRevision = $definitionTitle->getLatestRevID(); |
| 651 | + |
522 | 652 | $translationRevision = $db->selectField( 'revtag', 'rt_value', $conds, __METHOD__ ); |
523 | | - if ( $translationRevision === false ) return null; |
| 653 | + if ( $translationRevision === false ) { |
| 654 | + return null; |
| 655 | + } |
524 | 656 | |
525 | 657 | $oldtext = Revision::newFromTitle( $definitionTitle, $translationRevision )->getText(); |
526 | 658 | $newtext = Revision::newFromTitle( $definitionTitle, $latestRevision )->getText(); |
527 | 659 | |
528 | | - if ( $oldtext === $newtext ) return null; |
| 660 | + if ( $oldtext === $newtext ) { |
| 661 | + return null; |
| 662 | + } |
529 | 663 | |
530 | 664 | $diff = new DifferenceEngine; |
531 | 665 | $diff->setText( $oldtext, $newtext ); |
532 | 666 | $diff->setReducedLineNumbers(); |
533 | 667 | $diff->showDiffStyle(); |
| 668 | + |
534 | 669 | return $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) ); |
535 | 670 | } |
536 | 671 | |
537 | 672 | protected function getTranslationPageDiff() { |
538 | 673 | global $wgEnablePageTranslation; |
539 | | - if ( !$wgEnablePageTranslation ) return null; |
540 | | - if ( !$this->group instanceof WikiPageMessageGroup ) return null; |
541 | 674 | |
| 675 | + if ( !$wgEnablePageTranslation ) { |
| 676 | + return null; |
| 677 | + } |
| 678 | + |
| 679 | + if ( !$this->group instanceof WikiPageMessageGroup ) { |
| 680 | + return null; |
| 681 | + } |
| 682 | + |
542 | 683 | // Shortcuts |
543 | 684 | $code = $this->targetLanguage; |
544 | 685 | $key = $this->page; |
— | — | @@ -546,7 +687,9 @@ |
547 | 688 | $page = TranslatablePage::newFromTitle( $this->group->title ); |
548 | 689 | $rev = $page->getTransRev( "$key/$code" ); |
549 | 690 | $latest = $page->getMarkedTag(); |
550 | | - if ( $rev === $latest ) return null; |
| 691 | + if ( $rev === $latest ) { |
| 692 | + return null; |
| 693 | + } |
551 | 694 | |
552 | 695 | $oldpage = TranslatablePage::newFromRevision( $this->group->title, $rev ); |
553 | 696 | $oldtext = $newtext = null; |
— | — | @@ -562,12 +705,15 @@ |
563 | 706 | } |
564 | 707 | } |
565 | 708 | |
566 | | - if ( $oldtext === $newtext ) return null; |
| 709 | + if ( $oldtext === $newtext ) { |
| 710 | + return null; |
| 711 | + } |
567 | 712 | |
568 | 713 | $diff = new DifferenceEngine; |
569 | 714 | $diff->setText( $oldtext, $newtext ); |
570 | 715 | $diff->setReducedLineNumbers(); |
571 | 716 | $diff->showDiffStyle(); |
| 717 | + |
572 | 718 | return $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) ); |
573 | 719 | } |
574 | 720 | |
— | — | @@ -586,7 +732,12 @@ |
587 | 733 | $preference = $wgUser->getOption( 'translate-editlangs' ); |
588 | 734 | if ( $preference !== 'default' ) { |
589 | 735 | $fallbacks = array_map( 'trim', explode( ',', $preference ) ); |
590 | | - foreach ( $fallbacks as $k => $v ) if ( $v === $code ) unset( $fallbacks[$k] ); |
| 736 | + foreach ( $fallbacks as $k => $v ) { |
| 737 | + if ( $v === $code ) { |
| 738 | + unset( $fallbacks[$k] ); |
| 739 | + } |
| 740 | + } |
| 741 | + |
591 | 742 | return $fallbacks; |
592 | 743 | } |
593 | 744 | |
— | — | @@ -622,6 +773,7 @@ |
623 | 774 | } else { |
624 | 775 | $attributes['class'] = 'mw-sp-translate-edit-committed'; |
625 | 776 | } |
| 777 | + |
626 | 778 | if ( mb_strlen( $msg ) < 100 && !$title ) { |
627 | 779 | $attributes['class'] = 'mw-sp-translate-in-other-small'; |
628 | 780 | } |
— | — | @@ -650,14 +802,17 @@ |
651 | 803 | 'onclick' => "jQuery('#$target').val(jQuery('#$source').text()).focus(); return false;", |
652 | 804 | 'href' => '#' |
653 | 805 | ); |
| 806 | + |
654 | 807 | return Html::element( 'a', $params, '↓' ); |
655 | 808 | } |
656 | 809 | |
657 | 810 | public function suggestionField( $contents ) { |
658 | 811 | static $counter = 0; |
| 812 | + |
659 | 813 | $counter++; |
660 | 814 | $id = "tmsug-" . wfTimestamp() . "-$counter"; |
661 | 815 | $contents = TranslateUtils::convertWhiteSpaceToHTML( $contents ); |
| 816 | + |
662 | 817 | return $this->adder( $id ) . "\n" . Html::rawElement( 'span', array( 'id' => $id ), $contents ); |
663 | 818 | } |
664 | 819 | |
— | — | @@ -696,7 +851,9 @@ |
697 | 852 | * Checks whether the given service has exceeded failure count */ |
698 | 853 | public static function checkTranslationServiceFailure( $service ) { |
699 | 854 | global $wgMemc; |
| 855 | + |
700 | 856 | $key = wfMemckey( "translate-service-$service" ); |
| 857 | + |
701 | 858 | // Both false and null are converted to zero, which is desirable |
702 | 859 | return intval( $wgMemc->get( $key ) ) >= self::$serviceFailureCount; |
703 | 860 | } |
— | — | @@ -705,12 +862,14 @@ |
706 | 863 | * Increases the failure count for a given service */ |
707 | 864 | public static function reportTranslationSerficeFailure( $service ) { |
708 | 865 | global $wgMemc; |
| 866 | + |
709 | 867 | $key = wfMemckey( "translate-service-$service" ); |
710 | 868 | // Both false and null are converted to zero, which is desirable. |
711 | 869 | /* FIXME: not atomic, but the default incr() implemention seems to |
712 | 870 | * ignore expiry time */ |
713 | 871 | $count = intval( $wgMemc->get( $key ) ); |
714 | 872 | $wgMemc->set( $key, $count + 1, self::$serviceFailurePeriod ); |
| 873 | + |
715 | 874 | /* By using >= we expose if something is still increasing failure |
716 | 875 | * count if we are over the limit */ |
717 | 876 | if ( $count + 1 >= self::$serviceFailureCount ) { |
Index: trunk/extensions/Translate/utils/JsSelectToInput.js |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | function appendFromSelect(selectid,targetid) { |
3 | | - var select = document.getElementById(selectid); |
4 | | - var target = document.getElementById(targetid); |
5 | | - if(!target || !select) return |
6 | | - var atxt = select.options[select.selectedIndex].value; |
7 | | - if(!atxt) return |
8 | | - /* Ugly hack */ |
9 | | - target.value = target.value.replace(/default/, '' ); |
10 | | - if(target.value.replace(/[\s\t\n]/ig,'') != '') atxt = ', ' + atxt; |
11 | | - target.value += atxt; |
12 | | -} |
\ No newline at end of file |
| 3 | + var select = document.getElementById(selectid); |
| 4 | + var target = document.getElementById(targetid); |
| 5 | + if(!target || !select) return |
| 6 | + var atxt = select.options[select.selectedIndex].value; |
| 7 | + if(!atxt) return |
| 8 | + /* Ugly hack */ |
| 9 | + target.value = target.value.replace(/default/, '' ); |
| 10 | + if(target.value.replace(/[\s\t\n]/ig,'') != '') atxt = ', ' + atxt; |
| 11 | + target.value += atxt; |
| 12 | +} |
Index: trunk/extensions/Translate/utils/MessageGroupCache.php |
— | — | @@ -22,16 +22,19 @@ |
23 | 23 | |
24 | 24 | public function getKeys( $code = 'en' ) { |
25 | 25 | $cache = $this->open( $code ); |
| 26 | + |
26 | 27 | return unserialize( $cache->get( $this->specialKey( 'keys' ) ) ); |
27 | 28 | } |
28 | 29 | |
29 | 30 | public function getTimestamp( $code = 'en' ) { |
30 | 31 | $cache = $this->open( $code ); |
| 32 | + |
31 | 33 | return $cache->get( $this->specialKey( 'timestamp' ) ); |
32 | 34 | } |
33 | 35 | |
34 | 36 | public function get( $key, $code = 'en' ) { |
35 | 37 | $cache = $this->open( $code ); |
| 38 | + |
36 | 39 | return $cache->get( $key ); |
37 | 40 | } |
38 | 41 | |
— | — | @@ -53,19 +56,23 @@ |
54 | 57 | |
55 | 58 | protected function open( $code ) { |
56 | 59 | if ( $code !== $this->code || !$this->cache ) { |
57 | | - if ( $this->cache ) $this->cache->close(); |
| 60 | + if ( $this->cache ) { |
| 61 | + $this->cache->close(); |
| 62 | + } |
| 63 | + |
58 | 64 | $this->cache = CdbReader::open( $this->getCacheFileName( $code ) ); |
59 | 65 | } |
| 66 | + |
60 | 67 | return $this->cache; |
61 | 68 | } |
62 | 69 | |
63 | 70 | protected function getCacheFileName( $code ) { |
64 | 71 | global $wgCacheDirectory; |
| 72 | + |
65 | 73 | return "$wgCacheDirectory/translate_groupcache-{$this->group}-$code.cdb"; |
66 | 74 | } |
67 | 75 | |
68 | 76 | protected function specialKey( $key ) { |
69 | 77 | return "<|$key#>"; |
70 | 78 | } |
71 | | - |
72 | | -} |
\ No newline at end of file |
| 79 | +} |
Index: trunk/extensions/Translate/utils/ToolBox.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 3 | |
5 | 4 | class TranslateToolbox { |
6 | 5 | /** |
Index: trunk/extensions/Translate/utils/HTMLJsSelectToInputField.php |
— | — | @@ -3,37 +3,51 @@ |
4 | 4 | class HTMLJsSelectToInputField extends HTMLTextField { |
5 | 5 | function getInputHTML( $value ) { |
6 | 6 | $input = parent::getInputHTML( $value ); |
| 7 | + |
7 | 8 | if ( isset( $this->mParams['select'] ) ) { |
8 | 9 | $input .= ' ' . $this->mParams['select']->getHtmlAndPrepareJs(); |
9 | 10 | } |
| 11 | + |
10 | 12 | return $input; |
11 | 13 | } |
12 | 14 | |
13 | 15 | function tidy( $value ) { |
14 | 16 | $value = array_map( 'trim', explode( ',', $value ) ); |
15 | 17 | $value = array_unique( array_filter( $value ) ); |
| 18 | + |
16 | 19 | return $value; |
17 | 20 | } |
18 | 21 | |
19 | 22 | function validate( $value, $alldata ) { |
20 | 23 | $p = parent::validate( $value, $alldata ); |
21 | | - if ( $p !== true ) return $p; |
22 | 24 | |
23 | | - if ( !isset( $this->mParams['valid-values'] ) ) return true; |
| 25 | + if ( $p !== true ) { |
| 26 | + return $p; |
| 27 | + } |
24 | 28 | |
25 | | - if ( $value === 'default' ) return true; |
| 29 | + if ( !isset( $this->mParams['valid-values'] ) ) { |
| 30 | + return true; |
| 31 | + } |
26 | 32 | |
| 33 | + if ( $value === 'default' ) { |
| 34 | + return true; |
| 35 | + } |
| 36 | + |
27 | 37 | $codes = $this->tidy( $value ); |
28 | 38 | $valid = array_flip( $this->mParams['valid-values'] ); |
| 39 | + |
29 | 40 | foreach ( $codes as $code ) { |
30 | | - if ( !isset( $valid[$code] ) ) |
| 41 | + if ( !isset( $valid[$code] ) ) { |
31 | 42 | return wfMsgExt( 'translate-pref-editassistlang-bad', 'parse', $code ); |
| 43 | + } |
32 | 44 | } |
| 45 | + |
33 | 46 | return true; |
34 | 47 | } |
35 | 48 | |
36 | 49 | function filter( $value, $alldata ) { |
37 | 50 | $value = parent::filter( $value, $alldata ); |
| 51 | + |
38 | 52 | return implode( ', ', $this->tidy( $value ) ); |
39 | 53 | } |
40 | | -} |
\ No newline at end of file |
| 54 | +} |
Index: trunk/extensions/Translate/utils/MemoryCache.php |
— | — | @@ -9,7 +9,9 @@ |
10 | 10 | public function __construct( $table ) { |
11 | 11 | $this->table = $table; |
12 | 12 | $this->key = wfMemcKey( $this->table ); |
| 13 | + |
13 | 14 | global $wgMemc; |
| 15 | + |
14 | 16 | $this->memc = $wgMemc; |
15 | 17 | } |
16 | 18 | |
— | — | @@ -19,22 +21,34 @@ |
20 | 22 | |
21 | 23 | public function get( $group, $code ) { |
22 | 24 | $this->load(); |
23 | | - if ( !isset( $this->cache[$group][$code] ) ) return false; |
| 25 | + |
| 26 | + if ( !isset( $this->cache[$group][$code] ) ) { |
| 27 | + return false; |
| 28 | + } |
| 29 | + |
24 | 30 | return explode( ',', $this->cache[$group][$code] ); |
25 | 31 | } |
26 | 32 | |
27 | 33 | public function set( $group, $code, $value ) { |
28 | 34 | $this->load(); |
29 | | - if ( !isset( $this->cache[$group] ) ) $this->cache[$group] = array(); |
| 35 | + |
| 36 | + if ( !isset( $this->cache[$group] ) ) { |
| 37 | + $this->cache[$group] = array(); |
| 38 | + } |
| 39 | + |
30 | 40 | $this->cache[$group][$code] = implode( ',', $value ); |
31 | 41 | } |
32 | 42 | |
33 | 43 | public function clear( $group, $code ) { |
34 | 44 | $this->load(); |
35 | | - if ( isset( $this->cache[$group][$code] ) ) |
| 45 | + |
| 46 | + if ( isset( $this->cache[$group][$code] ) ) { |
36 | 47 | unset( $this->cache[$group][$code] ); |
37 | | - if ( isset( $this->cache[$group] ) && !count( $this->cache[$group] ) ) |
| 48 | + } |
| 49 | + |
| 50 | + if ( isset( $this->cache[$group] ) && !count( $this->cache[$group] ) ) { |
38 | 51 | unset( $this->cache[$group] ); |
| 52 | + } |
39 | 53 | } |
40 | 54 | |
41 | 55 | public function commit() { |
— | — | @@ -45,7 +59,10 @@ |
46 | 60 | protected function load() { |
47 | 61 | if ( $this->cache === null ) { |
48 | 62 | $this->cache = $this->memc->get( $this->key ); |
49 | | - if ( !is_array( $this->cache ) ) $this->cache = array(); |
| 63 | + |
| 64 | + if ( !is_array( $this->cache ) ) { |
| 65 | + $this->cache = array(); |
| 66 | + } |
50 | 67 | } |
51 | 68 | } |
52 | 69 | |
— | — | @@ -54,4 +71,4 @@ |
55 | 72 | $this->memc->set( $this->key, $this->cache ); |
56 | 73 | } |
57 | 74 | } |
58 | | -} |
\ No newline at end of file |
| 75 | +} |
Index: trunk/extensions/Translate/utils/MessageTable.php |
— | — | @@ -6,8 +6,8 @@ |
7 | 7 | * @copyright Copyright © 2007-2009 Niklas Laxström |
8 | 8 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
9 | 9 | */ |
| 10 | + |
10 | 11 | class MessageTable { |
11 | | - |
12 | 12 | protected $reviewMode = false; |
13 | 13 | protected $collection = null; |
14 | 14 | protected $group = null; |
— | — | @@ -39,17 +39,24 @@ |
40 | 40 | } |
41 | 41 | |
42 | 42 | public function setHeaderTextMessage( $type, $value ) { |
43 | | - if ( !isset( $this->headers[$type] ) ) throw new MWException( "Unexpected type $type" ); |
| 43 | + if ( !isset( $this->headers[$type] ) ) { |
| 44 | + throw new MWException( "Unexpected type $type" ); |
| 45 | + } |
| 46 | + |
44 | 47 | $this->headers[$type] = array( 'msg', $value ); |
45 | 48 | } |
46 | 49 | |
47 | 50 | public function setHeaderText( $type, $value ) { |
48 | | - if ( !isset( $this->headers[$type] ) ) throw new MWException( "Unexpected type $type" ); |
| 51 | + if ( !isset( $this->headers[$type] ) ) { |
| 52 | + throw new MWException( "Unexpected type $type" ); |
| 53 | + } |
| 54 | + |
49 | 55 | $this->headers[$type] = array( 'raw', htmlspecialchars( $value ) ); |
50 | 56 | } |
51 | 57 | |
52 | 58 | public function includeAssets() { |
53 | 59 | global $wgOut, $wgScript; |
| 60 | + |
54 | 61 | // Our class |
55 | 62 | $wgOut->addScriptFile( TranslateUtils::assetPath( 'js/quickedit.js' ) ); |
56 | 63 | |
— | — | @@ -82,7 +89,6 @@ |
83 | 90 | $diff->showDiffStyle(); |
84 | 91 | } |
85 | 92 | |
86 | | - |
87 | 93 | public function header() { |
88 | 94 | $tableheader = Xml::openElement( 'table', array( |
89 | 95 | 'class' => 'mw-sp-translate-table' |
— | — | @@ -112,15 +118,18 @@ |
113 | 119 | |
114 | 120 | public function contents() { |
115 | 121 | global $wgUser; |
| 122 | + |
116 | 123 | $sk = $wgUser->getSkin(); |
117 | 124 | |
118 | 125 | $optional = wfMsgHtml( 'translate-optional' ); |
119 | 126 | |
120 | 127 | $batch = new LinkBatch(); |
121 | 128 | $ns = $this->group->getNamespace(); |
| 129 | + |
122 | 130 | foreach ( $this->collection->keys() as $key ) { |
123 | 131 | $batch->add( $ns, $key ); |
124 | 132 | } |
| 133 | + |
125 | 134 | $batch->execute(); |
126 | 135 | |
127 | 136 | $output = ''; |
— | — | @@ -139,6 +148,7 @@ |
140 | 149 | } |
141 | 150 | |
142 | 151 | global $wgLang; |
| 152 | + |
143 | 153 | $niceTitle = htmlspecialchars( $wgLang->truncate( $key, - 30 ) ); |
144 | 154 | |
145 | 155 | $tools['edit'] = $sk->link( |
— | — | @@ -153,7 +163,9 @@ |
154 | 164 | $anchor = Xml::element( 'a', array( 'id' => $anchor, 'href' => "#$anchor" ), "↓" ); |
155 | 165 | |
156 | 166 | $extra = ''; |
157 | | - if ( $m->hasTag( 'optional' ) ) $extra = '<br />' . $optional; |
| 167 | + if ( $m->hasTag( 'optional' ) ) { |
| 168 | + $extra = '<br />' . $optional; |
| 169 | + } |
158 | 170 | |
159 | 171 | $leftColumn = $anchor . $tools['edit'] . $extra; |
160 | 172 | |
— | — | @@ -173,7 +185,6 @@ |
174 | 186 | Xml::tags( 'td', $rclasses, TranslateUtils::convertWhiteSpaceToHTML( $message ) ) |
175 | 187 | ); |
176 | 188 | } |
177 | | - |
178 | 189 | } |
179 | 190 | |
180 | 191 | return $output; |
— | — | @@ -181,13 +192,14 @@ |
182 | 193 | |
183 | 194 | public function fullTable() { |
184 | 195 | $this->includeAssets(); |
| 196 | + |
185 | 197 | return $this->header() . $this->contents() . '</table>'; |
186 | 198 | } |
187 | 199 | |
188 | | - |
189 | | - |
190 | 200 | protected function headerText( $type ) { |
191 | | - if ( !isset( $this->headers[$type] ) ) throw new MWException( "Unexpected type $type" ); |
| 201 | + if ( !isset( $this->headers[$type] ) ) { |
| 202 | + throw new MWException( "Unexpected type $type" ); |
| 203 | + } |
192 | 204 | |
193 | 205 | list( $format, $value ) = $this->headers[$type]; |
194 | 206 | if ( $format === 'msg' ) { |
— | — | @@ -202,7 +214,7 @@ |
203 | 215 | protected function keyToTitle( $key ) { |
204 | 216 | $titleText = TranslateUtils::title( $key, $this->collection->code ); |
205 | 217 | $namespace = $this->group->getNamespace(); |
| 218 | + |
206 | 219 | return Title::makeTitle( $namespace, $titleText ); |
207 | 220 | } |
208 | | - |
209 | | -} |
\ No newline at end of file |
| 221 | +} |
Index: trunk/extensions/Translate/utils/JsSelectToInput.php |
— | — | @@ -1,6 +1,5 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | - |
5 | 4 | class JsSelectToInput { |
6 | 5 | protected $targetId, $sourceId; |
7 | 6 | protected $select; |
— | — | @@ -40,15 +39,16 @@ |
41 | 40 | if ( is_callable( array( $select, 'getAttribute' ) ) ) { |
42 | 41 | $this->sourceId = $select->getAttribute['id']; |
43 | 42 | } |
| 43 | + |
44 | 44 | if ( !$this->sourceId ) { |
45 | 45 | throw new MWException( "ID needs to be specified for the selector" ); |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | | - |
50 | 49 | self::injectJs(); |
51 | 50 | $html = $this->getButton( $this->msg, $this->sourceId, $this->targetId ); |
52 | 51 | $html .= $this->select->getHtml(); |
| 52 | + |
53 | 53 | return $html; |
54 | 54 | } |
55 | 55 | |
— | — | @@ -60,15 +60,19 @@ |
61 | 61 | 'value' => wfMsg( $msg ), |
62 | 62 | 'onclick' => "appendFromSelect( '$source', '$target' );" |
63 | 63 | ) ); |
| 64 | + |
64 | 65 | return $html; |
65 | 66 | } |
66 | 67 | |
67 | 68 | public static function injectJs() { |
68 | 69 | static $done = false; |
69 | | - if ( $done ) return; |
70 | 70 | |
| 71 | + if ( $done ) { |
| 72 | + return; |
| 73 | + } |
| 74 | + |
71 | 75 | global $wgOut; |
| 76 | + |
72 | 77 | $wgOut->addScriptFile( TranslateUtils::assetPath( 'utils/JsSelectToInput.js' ) ); |
73 | 78 | } |
74 | | - |
75 | | -} |
\ No newline at end of file |
| 79 | +} |
Index: trunk/extensions/Translate/utils/MemProfile.php |
— | — | @@ -12,8 +12,10 @@ |
13 | 13 | |
14 | 14 | $wgMemUse = array(); |
15 | 15 | $wgMemStack = 0; |
| 16 | + |
16 | 17 | function wfMemIn( $a ) { |
17 | 18 | global $wgLang, $wgMemUse, $wgMemStack; |
| 19 | + |
18 | 20 | $mem = memory_get_usage(); |
19 | 21 | $memR = memory_get_usage(); |
20 | 22 | |
— | — | @@ -29,6 +31,7 @@ |
30 | 32 | |
31 | 33 | function wfMemOut( $a ) { |
32 | 34 | global $wgLang, $wgMemUse, $wgMemStack; |
| 35 | + |
33 | 36 | $mem = memory_get_usage(); |
34 | 37 | $memR = memory_get_usage(); |
35 | 38 | |
Index: trunk/extensions/Translate/utils/TranslationEditPage.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * This class together with some javascript implements the ajax translation |
6 | 5 | * page. |
— | — | @@ -8,6 +7,7 @@ |
9 | 8 | * @copyright Copyright © 2009 Niklas Laxström |
10 | 9 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
11 | 10 | */ |
| 11 | + |
12 | 12 | class TranslationEditPage { |
13 | 13 | // Instance of an Title object |
14 | 14 | protected $title; |
— | — | @@ -22,7 +22,11 @@ |
23 | 23 | |
24 | 24 | public static function newFromRequest( WebRequest $request ) { |
25 | 25 | $title = Title::newFromText( $request->getText( 'page' ) ); |
26 | | - if ( !$title ) return null; |
| 26 | + |
| 27 | + if ( !$title ) { |
| 28 | + return null; |
| 29 | + } |
| 30 | + |
27 | 31 | return new self( $title ); |
28 | 32 | } |
29 | 33 | |
— | — | @@ -43,6 +47,7 @@ |
44 | 48 | $helpers->setTextareaId( $id ); |
45 | 49 | |
46 | 50 | global $wgServer, $wgScriptPath, $wgOut; |
| 51 | + |
47 | 52 | $wgOut->disable(); |
48 | 53 | |
49 | 54 | $translation = $helpers->getTranslation(); |
— | — | @@ -57,8 +62,11 @@ |
58 | 63 | |
59 | 64 | $hidden = array(); |
60 | 65 | $hidden[] = Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ); |
61 | | - if ( isset( $data['revisions'][0]['timestamp'] ) ) |
| 66 | + |
| 67 | + if ( isset( $data['revisions'][0]['timestamp'] ) ) { |
62 | 68 | $hidden[] = Xml::hidden( 'basetimestamp', $data['revisions'][0]['timestamp'] ); |
| 69 | + } |
| 70 | + |
63 | 71 | $hidden[] = Xml::hidden( 'starttimestamp', $data['starttimestamp'] ); |
64 | 72 | $hidden[] = Xml::hidden( 'token', $data['edittoken'] ); |
65 | 73 | $hidden[] = Xml::hidden( 'format', 'json' ); |
— | — | @@ -68,8 +76,16 @@ |
69 | 77 | $save = Xml::submitButton( wfMsg( 'savearticle' ), array( 'style' => 'font-weight:bold' ) ); |
70 | 78 | $saveAndNext = Xml::submitButton( wfMsg( 'translate-js-next' ), array( 'class' => 'mw-translate-next' ) ); |
71 | 79 | $skip = Html::element( 'input', array( 'class' => 'mw-translate-skip', 'type' => 'button', 'value' => wfMsg( 'translate-js-skip' ) ) ); |
| 80 | + |
72 | 81 | if ( $this->getTitle()->exists() ) { |
73 | | - $history = Html::element( 'input', array( 'class' => 'mw-translate-history', 'type' => 'button', 'value' => wfMsg( 'translate-js-history' ) ) ); |
| 82 | + $history = Html::element( |
| 83 | + 'input', |
| 84 | + array( |
| 85 | + 'class' => 'mw-translate-history', |
| 86 | + 'type' => 'button', |
| 87 | + 'value' => wfMsg( 'translate-js-history' ) |
| 88 | + ) |
| 89 | + ); |
74 | 90 | } else { |
75 | 91 | $history = ''; |
76 | 92 | } |
— | — | @@ -108,18 +124,24 @@ |
109 | 125 | $data = $api->getResultData(); |
110 | 126 | $data = $data['query']['pages']; |
111 | 127 | $data = array_shift( $data ); |
| 128 | + |
112 | 129 | return $data; |
113 | 130 | } |
114 | 131 | |
115 | 132 | public static function jsEdit( Title $title, $group = "" ) { |
116 | 133 | global $wgUser; |
117 | 134 | |
118 | | - if ( !$wgUser->isAllowed( 'translate' ) ) return array(); |
119 | | - if ( !$wgUser->getOption( 'translate-jsedit' ) ) return array(); |
| 135 | + if ( !$wgUser->isAllowed( 'translate' ) ) { |
| 136 | + return array(); |
| 137 | + } |
120 | 138 | |
| 139 | + if ( !$wgUser->getOption( 'translate-jsedit' ) ) { |
| 140 | + return array(); |
| 141 | + } |
| 142 | + |
121 | 143 | $jsTitle = Xml::escapeJsString( $title->getPrefixedDbKey() ); |
122 | 144 | $jsGroup = Xml::escapeJsString( $group ); |
| 145 | + |
123 | 146 | return array( 'onclick' => "return trlOpenJsEdit( \"$jsTitle\", \"$jsGroup\" );" ); |
124 | 147 | } |
125 | | - |
126 | | -} |
\ No newline at end of file |
| 148 | +} |
Index: trunk/extensions/Translate/utils/UserToggles.php |
— | — | @@ -31,7 +31,6 @@ |
32 | 32 | $select = self::languageSelector(); |
33 | 33 | $select->setTargetId( 'mw-input-translate-editlangs' ); |
34 | 34 | |
35 | | - |
36 | 35 | $languages = Language::getLanguageNames( false ); |
37 | 36 | |
38 | 37 | $preferences['translate-editlangs'] = array( |
— | — | @@ -58,6 +57,7 @@ |
59 | 58 | |
60 | 59 | protected static function languageSelector() { |
61 | 60 | global $wgLang; |
| 61 | + |
62 | 62 | if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) { |
63 | 63 | $languages = LanguageNames::getNames( $wgLang->getCode(), |
64 | 64 | LanguageNames::FALLBACK_NORMAL |
— | — | @@ -75,6 +75,7 @@ |
76 | 76 | |
77 | 77 | $jsSelect = new JsSelectToInput( $selector ); |
78 | 78 | $jsSelect->setSourceId( 'mw-language-selector' ); |
| 79 | + |
79 | 80 | return $jsSelect; |
80 | 81 | } |
81 | 82 | } |
Index: trunk/extensions/Translate/utils/MessageWebImporter.php |
— | — | @@ -31,6 +31,7 @@ |
32 | 32 | |
33 | 33 | public function getUser() { |
34 | 34 | global $wgUser; |
| 35 | + |
35 | 36 | return $this->user ? $this->user : $wgUser; |
36 | 37 | } |
37 | 38 | |
— | — | @@ -146,7 +147,9 @@ |
147 | 148 | } |
148 | 149 | |
149 | 150 | // No changes at all, ignore |
150 | | - if ( strval( $old ) === strval( $value ) ) continue; |
| 151 | + if ( strval( $old ) === strval( $value ) ) { |
| 152 | + continue; |
| 153 | + } |
151 | 154 | |
152 | 155 | if ( $old === false ) { |
153 | 156 | $name = wfMsgHtml( 'translate-manage-import-new', |
— | — | @@ -160,6 +163,7 @@ |
161 | 164 | $type = 'changed'; |
162 | 165 | |
163 | 166 | global $wgRequest; |
| 167 | + |
164 | 168 | # Spaces don't seem to survive round trip in addition to dots |
165 | 169 | # which are silently handled in getVal |
166 | 170 | $safekey = str_replace( ' ', '_', $key ); |
— | — | @@ -172,6 +176,7 @@ |
173 | 177 | } |
174 | 178 | |
175 | 179 | global $wgLang; |
| 180 | + |
176 | 181 | if ( $action === null ) { |
177 | 182 | $message = wfMsgExt( 'translate-manage-inconsistent', 'parseinline', wfEscapeWikiText( "action-$type-$key" ) ); |
178 | 183 | $changed[] = "<li>$message</li></ul>"; |
— | — | @@ -297,13 +302,14 @@ |
298 | 303 | $comment = wfMsgForContentNoTrans( 'translate-manage-conflict-summary' ); |
299 | 304 | $message = self::makeTextFuzzy( $message ); |
300 | 305 | } |
| 306 | + |
301 | 307 | return self::doImport( $title, $message, $comment, $user, $editFlags ); |
302 | 308 | |
303 | 309 | } elseif ( $action === 'ignore' ) { |
304 | 310 | return array( 'translate-manage-import-ignore', $key ); |
305 | | - |
306 | 311 | } elseif ( $action === 'fuzzy' && $code !== 'en' ) { |
307 | 312 | $message = self::makeTextFuzzy( $message ); |
| 313 | + |
308 | 314 | return self::doImport( $title, $message, $comment, $user, $editFlags ); |
309 | 315 | } elseif ( $action === 'fuzzy' && $code == 'en' ) { |
310 | 316 | return self::doFuzzy( $title, $message, $comment, $user, $editFlags ); |
— | — | @@ -344,7 +350,7 @@ |
345 | 351 | |
346 | 352 | $namespace = $title->getNamespace(); |
347 | 353 | $titleText = $dbw->escapeLike( $titleText ); |
348 | | - $conds= array( |
| 354 | + $conds = array( |
349 | 355 | 'page_namespace' => $namespace, |
350 | 356 | 'page_latest=rev_id', |
351 | 357 | 'rev_text_id=old_id', |
— | — | @@ -369,7 +375,7 @@ |
370 | 376 | $ttitle = Title::makeTitle( $row->page_namespace, $row->page_title ); |
371 | 377 | |
372 | 378 | // No fuzzy for English original |
373 | | - if( $ttitle->getSubpageText() == 'en' ) { |
| 379 | + if ( $ttitle->getSubpageText() == 'en' ) { |
374 | 380 | // Use imported text, not database text. |
375 | 381 | $text = $message; |
376 | 382 | } else { |
— | — | @@ -419,6 +425,7 @@ |
420 | 426 | */ |
421 | 427 | public static function makeTranslationTitle( $group, $key, $code ) { |
422 | 428 | $ns = $group->getNamespace(); |
| 429 | + |
423 | 430 | return Title::makeTitleSafe( $ns, "$key/$code" ); |
424 | 431 | } |
425 | 432 | |
— | — | @@ -439,6 +446,7 @@ |
440 | 447 | $items = new TagContainer(); |
441 | 448 | $items[] = new HtmlTag( 'div', new RawHtml( $legend ), $legendParams ); |
442 | 449 | $items[] = new HtmlTag( 'div', new RawHtml( $content ), $contentParams ); |
| 450 | + |
443 | 451 | return new HtmlTag( 'div', $items, $containerParams ); |
444 | 452 | } |
445 | 453 | |
— | — | @@ -451,6 +459,7 @@ |
452 | 460 | */ |
453 | 461 | public static function makeTextFuzzy( $message ) { |
454 | 462 | $message = str_replace( TRANSLATE_FUZZY, '', $message ); |
| 463 | + |
455 | 464 | return TRANSLATE_FUZZY . $message; |
456 | 465 | } |
457 | 466 | } |
Index: trunk/extensions/Translate/utils/Html.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * HTML builder class which wraps around Html::rawElement(). |
6 | 5 | * Most of the functions are dual purpose. With no value (or null value) they |
— | — | @@ -9,6 +8,7 @@ |
10 | 9 | * <code>$tag = new HtmlTag( 'div' ); $div = $div->content( 'foo' )->style( 'color', 'red' );</code> |
11 | 10 | * Note: relies on implicit toString conversion (PHP >= 5.2) |
12 | 11 | */ |
| 12 | + |
13 | 13 | class HtmlTag { |
14 | 14 | public $tag = 'div'; |
15 | 15 | public $content = ''; |
— | — | @@ -36,9 +36,12 @@ |
37 | 37 | * @return Mixed The tag name or self; |
38 | 38 | */ |
39 | 39 | public function tag( $value = null ) { |
40 | | - if ( $value === null ) return $this->tag; |
| 40 | + if ( $value === null ) { |
| 41 | + return $this->tag; |
| 42 | + } |
41 | 43 | |
42 | 44 | $this->tag = (string) $this->assert( 'is_string', $value ); |
| 45 | + |
43 | 46 | return $this; |
44 | 47 | } |
45 | 48 | |
— | — | @@ -48,7 +51,9 @@ |
49 | 52 | * @return Mixed The content as a string or self. |
50 | 53 | */ |
51 | 54 | public function content( $value = null ) { |
52 | | - if ( $value === null ) return $this->content; |
| 55 | + if ( $value === null ) { |
| 56 | + return $this->content; |
| 57 | + } |
53 | 58 | |
54 | 59 | if ( $value instanceof HtmlTag || $value instanceof RawHtml || $value instanceof TagContainer ) { |
55 | 60 | $this->content = $value; |
— | — | @@ -65,9 +70,12 @@ |
66 | 71 | * @return Array The paramater array. |
67 | 72 | */ |
68 | 73 | public function params( $value = null ) { |
69 | | - if ( $value === null ) return $this->params; |
| 74 | + if ( $value === null ) { |
| 75 | + return $this->params; |
| 76 | + } |
70 | 77 | |
71 | 78 | $this->params = (array) $this->assert( 'is_array', $value ); |
| 79 | + |
72 | 80 | return $this; |
73 | 81 | } |
74 | 82 | |
— | — | @@ -79,6 +87,7 @@ |
80 | 88 | */ |
81 | 89 | public function param( $name, $value = null ) { |
82 | 90 | $name = (string) $this->assert( 'is_string', $name ); |
| 91 | + |
83 | 92 | if ( $value === null ) { |
84 | 93 | return isset( $this->params[$name] ) ? $this->params[$name] : null; |
85 | 94 | } |
— | — | @@ -88,6 +97,7 @@ |
89 | 98 | } else { |
90 | 99 | $this->params[$name] = $this->assert( 'is_string', $value ); |
91 | 100 | } |
| 101 | + |
92 | 102 | return $this; |
93 | 103 | } |
94 | 104 | |
— | — | @@ -100,6 +110,7 @@ |
101 | 111 | */ |
102 | 112 | public function style( $name, $value = null ) { |
103 | 113 | $name = (string) $this->assert( 'is_string', $name ); |
| 114 | + |
104 | 115 | if ( $value === null ) { |
105 | 116 | return isset( $this->style[$name] ) ? $this->style[$name] : null; |
106 | 117 | } |
— | — | @@ -109,6 +120,7 @@ |
110 | 121 | } else { |
111 | 122 | $this->style[$name] = $this->assert( 'is_string', $value ); |
112 | 123 | } |
| 124 | + |
113 | 125 | return $this; |
114 | 126 | } |
115 | 127 | |
— | — | @@ -128,8 +140,11 @@ |
129 | 141 | // Collapse styles |
130 | 142 | $params = $this->params; |
131 | 143 | $style = $this->collapseStyles(); |
132 | | - if ( $style ) $params['style'] = $style; |
133 | 144 | |
| 145 | + if ( $style ) { |
| 146 | + $params['style'] = $style; |
| 147 | + } |
| 148 | + |
134 | 149 | if ( is_object( $this->content ) ) { |
135 | 150 | return Html::rawElement( $this->tag, $params, $this->content ); |
136 | 151 | } else { |
— | — | @@ -161,7 +176,10 @@ |
162 | 177 | $style .= "$name: $val;"; |
163 | 178 | } |
164 | 179 | |
165 | | - if ( $style !== '' ) return $style; |
| 180 | + if ( $style !== '' ) { |
| 181 | + return $style; |
| 182 | + } |
| 183 | + |
166 | 184 | return false; |
167 | 185 | } |
168 | 186 | |
— | — | @@ -174,20 +192,25 @@ |
175 | 193 | */ |
176 | 194 | protected function assert( $function, $value, $result = true ) { |
177 | 195 | if ( $function === 'is_string' ) { |
178 | | - if ( is_int( $value ) || is_float( $value ) ) $value = (string) $value; |
| 196 | + if ( is_int( $value ) || is_float( $value ) ) { |
| 197 | + $value = (string) $value; |
| 198 | + } |
179 | 199 | } |
180 | 200 | |
181 | 201 | $real_result = call_user_func( $function, $value ); |
182 | | - if ( $real_result === $result ) return $value; |
| 202 | + if ( $real_result === $result ) { |
| 203 | + return $value; |
| 204 | + } |
| 205 | + |
183 | 206 | $msg = __METHOD__ . ":expecting $function to be $result"; |
184 | 207 | if ( $this->strict ) { |
185 | 208 | throw new MWException( $msg ); |
186 | 209 | } else { |
187 | 210 | wfWarn( $msg ); |
| 211 | + |
188 | 212 | return $value; |
189 | 213 | } |
190 | 214 | } |
191 | | - |
192 | 215 | } |
193 | 216 | |
194 | 217 | /** |
— | — | @@ -220,8 +243,11 @@ |
221 | 244 | |
222 | 245 | public function __toString() { |
223 | 246 | $output = ''; |
224 | | - foreach ( $this->tags as $tag ) |
| 247 | + |
| 248 | + foreach ( $this->tags as $tag ) { |
225 | 249 | $output .= $tag . "\n"; |
| 250 | + } |
| 251 | + |
226 | 252 | return $output; |
227 | 253 | } |
228 | 254 | |
— | — | @@ -233,13 +259,16 @@ |
234 | 260 | $this->tags[$offset] = $value; |
235 | 261 | } |
236 | 262 | } |
| 263 | + |
237 | 264 | public function offsetExists( $offset ) { |
238 | 265 | return isset( $this->tags[$offset] ); |
239 | 266 | } |
| 267 | + |
240 | 268 | public function offsetUnset( $offset ) { |
241 | 269 | unset( $this->tags[$offset] ); |
242 | 270 | } |
| 271 | + |
243 | 272 | public function offsetGet( $offset ) { |
244 | 273 | return isset( $this->tags[$offset] ) ? $this->tags[$offset] : null; |
245 | 274 | } |
246 | | -} |
\ No newline at end of file |
| 275 | +} |
Index: trunk/extensions/Translate/utils/Font.php |
— | — | @@ -1,19 +1,20 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * Wrapper around font-config to get useful ttf font given a language code. |
6 | 5 | * Uses wfShellExec, wfEscapeShellArg and wfDebugLog from MediaWiki. |
7 | 6 | * @author Niklas Laxström, 2008 |
8 | 7 | * @license PD |
9 | 8 | */ |
| 9 | + |
10 | 10 | class FCFontFinder { |
11 | | - |
12 | 11 | public static function find( $code ) { |
13 | 12 | $code = wfEscapeShellArg( ":lang=$code" ); |
14 | 13 | $ok = 0; |
15 | 14 | $cmd = "fc-match $code"; |
16 | 15 | $suggestion = wfShellExec( $cmd, $ok ); |
| 16 | + |
17 | 17 | wfDebugLog( 'fcfont', "$cmd returned $ok" ); |
| 18 | + |
18 | 19 | if ( $ok !== 0 ) { |
19 | 20 | wfDebugLog( 'fcfont', "fc-match error output: $suggestion" ); |
20 | 21 | return false; |
— | — | @@ -21,6 +22,7 @@ |
22 | 23 | |
23 | 24 | $pattern = '/^(.*?): "(.*)" "(.*)"$/'; |
24 | 25 | $matches = array(); |
| 26 | + |
25 | 27 | if ( !preg_match( $pattern, $suggestion, $matches ) ) { |
26 | 28 | wfDebugLog( 'fcfont', "fc-match: return format not understood: $suggestion" ); |
27 | 29 | return false; |
— | — | @@ -37,6 +39,7 @@ |
38 | 40 | $candidates = trim( wfShellExec( $cmd, $ok ) ); |
39 | 41 | |
40 | 42 | wfDebugLog( 'fcfont', "$cmd returned $ok" ); |
| 43 | + |
41 | 44 | if ( $ok !== 0 ) { |
42 | 45 | wfDebugLog( 'fcfont', "fc-list error output: $candidates" ); |
43 | 46 | return false; |
— | — | @@ -45,7 +48,9 @@ |
46 | 49 | # trim spaces |
47 | 50 | $files = array_map( 'trim', explode( "\n", $candidates ) ); |
48 | 51 | $count = count( $files ); |
49 | | - if ( !$count ) wfDebugLog( 'fcfont', "fc-list got zero canditates: $candidates" ); |
| 52 | + if ( !$count ) { |
| 53 | + wfDebugLog( 'fcfont', "fc-list got zero canditates: $candidates" ); |
| 54 | + } |
50 | 55 | |
51 | 56 | # remove the trailing ":" |
52 | 57 | $chosen = substr( $files[0], 0, -1 ); |
— | — | @@ -53,5 +58,4 @@ |
54 | 59 | wfDebugLog( 'fcfont', "fc-list got $count candidates; using $chosen" ); |
55 | 60 | return $chosen; |
56 | 61 | } |
57 | | - |
58 | | -} |
\ No newline at end of file |
| 62 | +} |
Index: trunk/extensions/Translate/utils/MessageIndexRebuilder.php |
— | — | @@ -22,7 +22,10 @@ |
23 | 23 | STDOUT( "Working with ", 'main' ); |
24 | 24 | |
25 | 25 | foreach ( $groups as $g ) { |
26 | | - if ( !$g->exists() ) continue; |
| 26 | + if ( !$g->exists() ) { |
| 27 | + continue; |
| 28 | + } |
| 29 | + |
27 | 30 | # Skip meta thingies |
28 | 31 | if ( $g->isMeta() ) { |
29 | 32 | $postponed[] = $g; |
— | — | @@ -37,7 +40,9 @@ |
38 | 41 | } |
39 | 42 | |
40 | 43 | global $wgCacheDirectory; |
| 44 | + |
41 | 45 | $filename = "$wgCacheDirectory/translate_messageindex.cdb"; |
| 46 | + |
42 | 47 | $writer = CdbWriter::open( $filename ); |
43 | 48 | $writer->set( 'map', serialize( $hugearray ) ); |
44 | 49 | $writer->close(); |
— | — | @@ -46,6 +51,7 @@ |
47 | 52 | protected static function checkAndAdd( &$hugearray, $g, $ignore = false ) { |
48 | 53 | if ( $g instanceof MessageGroupBase ) { |
49 | 54 | $cache = new MessageGroupCache( $g ); |
| 55 | + |
50 | 56 | if ( $cache->exists() ) { |
51 | 57 | $keys = $cache->getKeys(); |
52 | 58 | } else { |
— | — | @@ -53,7 +59,11 @@ |
54 | 60 | } |
55 | 61 | } else { |
56 | 62 | $messages = $g->getDefinitions(); |
57 | | - if ( !is_array( $messages ) ) continue; |
| 63 | + |
| 64 | + if ( !is_array( $messages ) ) { |
| 65 | + continue; |
| 66 | + } |
| 67 | + |
58 | 68 | $keys = array_keys( $messages ); |
59 | 69 | } |
60 | 70 | |
Index: trunk/extensions/Translate/utils/StringMatcher.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | interface StringMangler { |
4 | 5 | public static function EmptyMatcher(); |
5 | 6 | public function setConf( $configuration ); |
— | — | @@ -9,7 +10,6 @@ |
10 | 11 | public function unMangle( $data ); |
11 | 12 | } |
12 | 13 | |
13 | | - |
14 | 14 | class StringMatcher implements StringMangler { |
15 | 15 | protected $sPrefix = ''; |
16 | 16 | protected $aExact = array(); |
— | — | @@ -46,21 +46,30 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | public function match( $string ) { |
50 | | - if ( in_array( $string, $this->aExact ) ) return true; |
| 50 | + if ( in_array( $string, $this->aExact ) ) { |
| 51 | + return true; |
| 52 | + } |
51 | 53 | |
52 | 54 | foreach ( $this->aPrefix as $prefix => $len ) { |
53 | | - if ( strncmp( $string, $prefix, $len ) === 0 ) return true; |
| 55 | + if ( strncmp( $string, $prefix, $len ) === 0 ) { |
| 56 | + return true; |
| 57 | + } |
54 | 58 | } |
55 | 59 | |
56 | 60 | foreach ( $this->aRegex as $regex ) { |
57 | | - if ( preg_match( $regex, $string ) ) return true; |
| 61 | + if ( preg_match( $regex, $string ) ) { |
| 62 | + return true; |
| 63 | + } |
58 | 64 | } |
59 | 65 | |
60 | 66 | return false; |
61 | 67 | } |
62 | 68 | |
63 | 69 | public function mangle( $data ) { |
64 | | - if ( !$this->sPrefix ) { return $data; } |
| 70 | + if ( !$this->sPrefix ) { |
| 71 | + return $data; |
| 72 | + } |
| 73 | + |
65 | 74 | if ( is_array( $data ) ) { |
66 | 75 | return $this->mangleArray( $data ); |
67 | 76 | } elseif ( is_string( $data ) ) { |
— | — | @@ -73,7 +82,10 @@ |
74 | 83 | } |
75 | 84 | |
76 | 85 | public function unMangle( $data ) { |
77 | | - if ( !$this->sPrefix ) { return $data; } |
| 86 | + if ( !$this->sPrefix ) { |
| 87 | + return $data; |
| 88 | + } |
| 89 | + |
78 | 90 | if ( is_array( $data ) ) { |
79 | 91 | return $this->mangleArray( $data, true ); |
80 | 92 | } elseif ( is_string( $data ) ) { |
— | — | @@ -85,7 +97,6 @@ |
86 | 98 | } |
87 | 99 | } |
88 | 100 | |
89 | | - |
90 | 101 | protected function mangleString( $string, $reverse = false ) { |
91 | 102 | if ( $reverse ) { |
92 | 103 | return $this->unMangleString( $string ); |
Index: trunk/extensions/Translate/utils/TranslationMemoryUpdater.php |
— | — | @@ -1,31 +1,40 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | | -* |
| 4 | +* Class for updating the Translation Memory |
6 | 5 | */ |
| 6 | + |
7 | 7 | class TranslationMemoryUpdater { |
8 | | - |
9 | 8 | public static function update( $article, $user, $text, $summary, $minor, $_, $_, $flags, $revision ) { |
10 | 9 | global $wgContLang; |
11 | 10 | |
12 | 11 | $dbw = self::getDatabaseHandle(); |
13 | 12 | // Not in use or misconfigured |
14 | | - if ( $dbw === null ) return true; |
| 13 | + if ( $dbw === null ) { |
| 14 | + return true; |
| 15 | + } |
15 | 16 | |
16 | 17 | $title = $article->getTitle(); |
17 | 18 | // Something we are not interested in at all |
18 | | - if ( !TranslateEditAddons::isMessageNamespace( $title ) ) return true; |
| 19 | + if ( !TranslateEditAddons::isMessageNamespace( $title ) ) { |
| 20 | + return true; |
| 21 | + } |
19 | 22 | |
20 | 23 | list( $key, $code, $group ) = TranslateEditAddons::getKeyCodeGroup( $title ); |
21 | 24 | // Unknown message, we cannot handle. We need definition. |
22 | | - if ( !$group || !$code ) return true; |
| 25 | + if ( !$group || !$code ) { |
| 26 | + return true; |
| 27 | + } |
23 | 28 | |
24 | 29 | // Skip definitions to not slow down mass imports etc. |
25 | 30 | // These will be added when first translation is made |
26 | | - if ( $code === 'en' ) return true; |
| 31 | + if ( $code === 'en' ) { |
| 32 | + return true; |
| 33 | + } |
27 | 34 | |
28 | 35 | // Skip fuzzy messages |
29 | | - if ( TranslateEditAddons::hasFuzzyString( $text ) ) return true; |
| 36 | + if ( TranslateEditAddons::hasFuzzyString( $text ) ) { |
| 37 | + return true; |
| 38 | + } |
30 | 39 | |
31 | 40 | $ns_text = $wgContLang->getNsText( $group->getNamespace() ); |
32 | 41 | $definition = $group->getMessage( $key, 'en' ); |
— | — | @@ -33,7 +42,7 @@ |
34 | 43 | wfDebugLog( 'tmserver', "Unable to get definition for $ns_text:$key/$code" ); |
35 | 44 | return true; |
36 | 45 | } |
37 | | - |
| 46 | + |
38 | 47 | $tmDefinition = array( |
39 | 48 | 'text' => $definition, |
40 | 49 | 'context' => "$ns_text:$key", |
— | — | @@ -68,11 +77,13 @@ |
69 | 78 | return true; |
70 | 79 | } |
71 | 80 | |
72 | | - |
73 | 81 | public static function getDatabaseHandle() { |
74 | 82 | global $wgTranslateTM; |
75 | | - if ( !isset( $wgTranslateTM['database'] ) ) return null; |
76 | 83 | |
| 84 | + if ( !isset( $wgTranslateTM['database'] ) ) { |
| 85 | + return null; |
| 86 | + } |
| 87 | + |
77 | 88 | $database = $wgTranslateTM['database']; |
78 | 89 | |
79 | 90 | if ( !is_string( $database ) ) { |
— | — | @@ -92,5 +103,4 @@ |
93 | 104 | |
94 | 105 | return new DatabaseSqliteStandalone( $database ); |
95 | 106 | } |
96 | | - |
97 | | -} |
\ No newline at end of file |
| 107 | +} |
Index: trunk/extensions/Translate/utils/TranslationStats.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | * @copyright Copyright © 2010, Niklas Laxström, Siebrand Mazeland |
11 | 11 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
12 | 12 | */ |
| 13 | + |
13 | 14 | class TranslationStats { |
14 | 15 | /** |
15 | 16 | * Returns translated percentage for message group in given |
Index: trunk/extensions/Translate/utils/ResourceLoader.php |
— | — | @@ -1,13 +1,12 @@ |
2 | 2 | <?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 3 | |
5 | 4 | class ResourceLoader { |
6 | | - |
7 | 5 | public static function loadVariableFromPHPFile( $_filename, $_variable ) { |
8 | 6 | if ( !file_exists( $_filename ) ) { |
9 | 7 | return null; |
10 | 8 | } else { |
11 | 9 | require( $_filename ); |
| 10 | + |
12 | 11 | return isset( $$_variable ) ? $$_variable : null; |
13 | 12 | } |
14 | 13 | } |
Index: trunk/extensions/Translate/ffs/Xliff.php |
— | — | @@ -64,6 +64,7 @@ |
65 | 65 | $w->writeAttribute( 'id', $key ); |
66 | 66 | $w->writeElement( 'source', $m->definition() ); |
67 | 67 | $translation = $m->translatiom(); |
| 68 | + |
68 | 69 | if ( $translation !== null ) { |
69 | 70 | $w->writeElement( 'target', $translation ); |
70 | 71 | } |
— | — | @@ -81,4 +82,4 @@ |
82 | 83 | $w->endElement(); // </xliff> |
83 | 84 | fwrite( $handle, $w->outputMemory( true ) ); |
84 | 85 | } |
85 | | -} |
\ No newline at end of file |
| 86 | +} |
Index: trunk/extensions/Translate/ffs/Simple.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | protected function parseHeader() { |
43 | 43 | $authors = array(); |
44 | 44 | $staticHeader = ''; |
| 45 | + |
45 | 46 | if ( $this->filename !== false ) { |
46 | 47 | $handle = fopen( $this->filename, "rt" ); |
47 | 48 | $state = 0; |
— | — | @@ -60,7 +61,10 @@ |
61 | 62 | $authors[] = substr( $line, $prefixLength ); |
62 | 63 | } |
63 | 64 | } elseif ( $state === 1 ) { |
64 | | - if ( $line === self::SEPARATOR ) break; // End of static header, if any |
| 65 | + if ( $line === self::SEPARATOR ) { |
| 66 | + break; // End of static header, if any |
| 67 | + } |
| 68 | + |
65 | 69 | $staticHeader .= $line; |
66 | 70 | } |
67 | 71 | } |
— | — | @@ -87,14 +91,10 @@ |
88 | 92 | } |
89 | 93 | |
90 | 94 | return $messages; |
91 | | - |
92 | 95 | } |
93 | | - |
94 | | - |
95 | 96 | } |
96 | 97 | |
97 | 98 | class SimpleFormatWriter { |
98 | | - |
99 | 99 | const SEPARATOR = '----'; |
100 | 100 | const AUTHORPREFIX = 'Author: '; |
101 | 101 | |
— | — | @@ -131,12 +131,14 @@ |
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | | - |
136 | 135 | public function fileExport( array $languages, $targetDirectory ) { |
137 | 136 | foreach ( $languages as $code ) { |
138 | 137 | $messages = $this->getMessagesForExport( $this->group, $code ); |
139 | | - if ( !count( $messages ) ) continue; |
140 | 138 | |
| 139 | + if ( !count( $messages ) ) { |
| 140 | + continue; |
| 141 | + } |
| 142 | + |
141 | 143 | $filename = $this->group->getMessageFile( $code ); |
142 | 144 | $target = $targetDirectory . '/' . $filename; |
143 | 145 | |
— | — | @@ -166,6 +168,7 @@ |
167 | 169 | rewind( $handle ); |
168 | 170 | $data = stream_get_contents( $handle ); |
169 | 171 | fclose( $handle ); |
| 172 | + |
170 | 173 | return $data; |
171 | 174 | } |
172 | 175 | |
— | — | @@ -176,6 +179,7 @@ |
177 | 180 | $collection->filter( 'hastranslation', false ); |
178 | 181 | $collection->loadTranslations(); |
179 | 182 | $this->addAuthors( $collection->getAuthors(), $code ); |
| 183 | + |
180 | 184 | return $collection; |
181 | 185 | } |
182 | 186 | |
— | — | @@ -195,6 +199,7 @@ |
196 | 200 | |
197 | 201 | public function filterAuthors( array $authors, $code, $groupId ) { |
198 | 202 | global $wgTranslateAuthorBlacklist; |
| 203 | + |
199 | 204 | foreach ( $authors as $i => $v ) { |
200 | 205 | $hash = "$groupId;$code;$v"; |
201 | 206 | |
— | — | @@ -218,7 +223,6 @@ |
219 | 224 | } |
220 | 225 | |
221 | 226 | return $authors; |
222 | | - |
223 | 227 | } |
224 | 228 | |
225 | 229 | protected function formatAuthors( $prefix, $code ) { |
— | — | @@ -228,7 +232,9 @@ |
229 | 233 | $groupId = $this->group->getId(); |
230 | 234 | $authors = $this->authors[$code]; |
231 | 235 | $authors = $this->filterAuthors( $authors, $code, $groupId ); |
232 | | - if ( empty( $authors ) ) return ''; |
| 236 | + if ( empty( $authors ) ) { |
| 237 | + return ''; |
| 238 | + } |
233 | 239 | |
234 | 240 | sort( $authors ); |
235 | 241 | |
— | — | @@ -236,6 +242,7 @@ |
237 | 243 | foreach ( $authors as $a ) { |
238 | 244 | $s[] = $prefix . $a; |
239 | 245 | } |
| 246 | + |
240 | 247 | return implode( "\n", $s ) . "\n"; |
241 | 248 | } |
242 | 249 | |
— | — | @@ -257,6 +264,7 @@ |
258 | 265 | protected function getLanguageNames( $code ) { |
259 | 266 | $name = TranslateUtils::getLanguageName( $code ); |
260 | 267 | $native = TranslateUtils::getLanguageName( $code, true ); |
| 268 | + |
261 | 269 | return array( $name, $native ); |
262 | 270 | } |
263 | | -} |
\ No newline at end of file |
| 271 | +} |
Index: trunk/extensions/Translate/ffs/PhpVariables.php |
— | — | @@ -17,7 +17,6 @@ |
18 | 18 | * Second section (if any) is returned verbatim. |
19 | 19 | */ |
20 | 20 | class PhpVariablesFormatReader extends SimpleFormatReader { |
21 | | - |
22 | 21 | /** |
23 | 22 | * Reads all \@author tags from the file and returns array of authors. |
24 | 23 | * |
— | — | @@ -30,9 +29,11 @@ |
31 | 30 | if ( $this->filename === false ) { |
32 | 31 | return array(); |
33 | 32 | } |
| 33 | + |
34 | 34 | $contents = file_get_contents( $this->filename ); |
35 | 35 | $m = array(); |
36 | 36 | $count = preg_match_all( '/@author (.*)/', $contents, $m ); |
| 37 | + |
37 | 38 | return $m[1]; |
38 | 39 | } |
39 | 40 | |
— | — | @@ -107,6 +108,7 @@ |
108 | 109 | $value = str_replace( array( "\'", "\\\\" ), array( "'", "\\" ), $_[2] ); |
109 | 110 | $messages[$key] = $value; |
110 | 111 | } |
| 112 | + |
111 | 113 | return $messages; |
112 | 114 | } |
113 | 115 | } |
Index: trunk/extensions/Translate/ffs/WikiExtension.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 3 | /** |
5 | 4 | * Multiple language wiki file format handler. |
6 | 5 | * |
— | — | @@ -55,8 +54,9 @@ |
56 | 55 | } |
57 | 56 | } |
58 | 57 | |
59 | | - if ( $unknown ) |
| 58 | + if ( $unknown ) { |
60 | 59 | $sections[] = implode( "\n", $unknown ); |
| 60 | + } |
61 | 61 | |
62 | 62 | return array( $header, $sections ); |
63 | 63 | } |
— | — | @@ -65,12 +65,14 @@ |
66 | 66 | if ( $this->filename === false ) { |
67 | 67 | return array(); |
68 | 68 | } |
| 69 | + |
69 | 70 | $ { $this->variableName } = array(); |
70 | 71 | require( $this->filename ); |
71 | 72 | $messages = $ { $this->variableName } ; |
72 | 73 | foreach ( $messages as $code => $value ) { |
73 | 74 | $messages[$code] = $mangler->mangle( $value ); |
74 | 75 | } |
| 76 | + |
75 | 77 | return $messages; |
76 | 78 | } |
77 | 79 | } |
— | — | @@ -116,6 +118,7 @@ |
117 | 119 | rewind( $handle ); |
118 | 120 | $data = stream_get_contents( $handle ); |
119 | 121 | fclose( $handle ); |
| 122 | + |
120 | 123 | return $data; |
121 | 124 | } |
122 | 125 | |
— | — | @@ -128,7 +131,10 @@ |
129 | 132 | |
130 | 133 | $__languages = Language::getLanguageNames( false ); |
131 | 134 | foreach ( array_keys( $__languages ) as $code ) { |
132 | | - if ( $code === 'en' || $code === 'qqq' ) continue; |
| 135 | + if ( $code === 'en' || $code === 'qqq' ) { |
| 136 | + continue; |
| 137 | + } |
| 138 | + |
133 | 139 | $this->exportSection( $handle, $code, $languages ); |
134 | 140 | } |
135 | 141 | } |
— | — | @@ -136,7 +142,6 @@ |
137 | 143 | protected function exportSection( $handle, $code, array $languages ) { |
138 | 144 | // Never export en, just copy it verbatim |
139 | 145 | if ( in_array( $code, $languages ) && $code !== 'en' ) { |
140 | | - |
141 | 146 | // Parse authors only if we regenerate section |
142 | 147 | if ( isset( $this->sections[$code] ) ) { |
143 | 148 | $authors = $this->parseAuthorsFromString( $this->sections[$code] ); |
— | — | @@ -153,11 +158,13 @@ |
154 | 159 | protected function writeSection( $handle, $code ) { |
155 | 160 | $messages = $this->getMessagesForExport( $this->group, $code ); |
156 | 161 | $messages = $this->makeExportArray( $messages ); |
| 162 | + |
157 | 163 | if ( count( $messages ) ) { |
158 | 164 | list( $name, $native ) = $this->getLanguageNames( $code ); |
159 | 165 | $authors = $this->formatAuthors( ' * @author ', $code ); |
160 | | - if ( !empty( $authors ) ) |
| 166 | + if ( !empty( $authors ) ) { |
161 | 167 | $authors = "\n$authors"; |
| 168 | + } |
162 | 169 | |
163 | 170 | fwrite( $handle, "/** $name ($native)$authors */\n" ); |
164 | 171 | fwrite( $handle, "\${$this->variableName}['$code'] = array(\n" ); |
— | — | @@ -168,6 +175,7 @@ |
169 | 176 | |
170 | 177 | public function parseAuthorsFromString( $string ) { |
171 | 178 | $count = preg_match_all( '/@author (.*)/', $string, $m ); |
| 179 | + |
172 | 180 | return $m[1]; |
173 | 181 | } |
174 | 182 | |
Index: trunk/extensions/Translate/ffs/Java.php |
— | — | @@ -16,7 +16,6 @@ |
17 | 17 | * Second section (if any) is returned verbatim. |
18 | 18 | */ |
19 | 19 | class JavaFormatReader extends SimpleFormatReader { |
20 | | - |
21 | 20 | /** |
22 | 21 | * Inherited from SimpleFormatReader, which parses whole header in one pass. |
23 | 22 | * Basically the same, with different author prefix and separator between |
— | — | @@ -78,15 +77,21 @@ |
79 | 78 | |
80 | 79 | # This format works nicely with line based parsing |
81 | 80 | $lines = array_map( 'trim', file( $this->filename ) ); |
82 | | - if ( !$lines ) { return null; } |
| 81 | + if ( !$lines ) { |
| 82 | + return null; |
| 83 | + } |
83 | 84 | |
84 | 85 | $messages = array(); |
85 | 86 | |
86 | 87 | foreach ( $lines as $line ) { |
87 | | - if ( $line === '' || !strpos( $line, '=' ) || $line[0] === '#' ) { continue; } |
| 88 | + if ( $line === '' || !strpos( $line, '=' ) || $line[0] === '#' ) { |
| 89 | + continue; |
| 90 | + } |
| 91 | + |
88 | 92 | list( $key, $value ) = explode( '=', $line, 2 ); |
89 | 93 | $messages[$mangler->mangle( trim( $key ) )] = trim( $value ); |
90 | 94 | } |
| 95 | + |
91 | 96 | return $messages; |
92 | 97 | } |
93 | 98 | } |
— | — | @@ -95,12 +100,12 @@ |
96 | 101 | * Very simple writer for exporting messages to Java property files from wiki. |
97 | 102 | */ |
98 | 103 | class JavaFormatWriter extends SimpleFormatWriter { |
99 | | - |
100 | 104 | /** |
101 | 105 | * Inherited. Very simplistic header with timestamp. |
102 | 106 | */ |
103 | 107 | public function makeHeader( $handle, $code ) { |
104 | 108 | global $wgSitename; |
| 109 | + |
105 | 110 | list( $name, $native ) = $this->getLanguageNames( $code ); |
106 | 111 | $authors = $this->formatAuthors( '# Author: ', $code ); |
107 | 112 | $when = wfTimestamp( TS_ISO_8601 ); |
— | — | @@ -129,5 +134,4 @@ |
130 | 135 | fwrite( $handle, "$key=$value\n" ); |
131 | 136 | } |
132 | 137 | } |
133 | | - |
134 | | -} |
\ No newline at end of file |
| 138 | +} |
Index: trunk/extensions/Translate/ffs/OpenLayers.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * OpenLayers JavaScript language class file format handler. |
6 | 5 | * |
— | — | @@ -9,7 +8,6 @@ |
10 | 9 | */ |
11 | 10 | |
12 | 11 | class OpenLayersFormatReader extends SimpleFormatReader { |
13 | | - |
14 | 12 | private static function unescapeJsString( $string ) { |
15 | 13 | // See ECMA 262 section 7.8.4 for string literal format |
16 | 14 | $pairs = array( |
— | — | @@ -34,12 +32,14 @@ |
35 | 33 | "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER |
36 | 34 | ); |
37 | 35 | $pairs = array_flip( $pairs ); |
| 36 | + |
38 | 37 | return strtr( $string, $pairs ); |
39 | 38 | } |
40 | 39 | |
41 | 40 | private function leftTrim( $string ) { |
42 | 41 | $string = ltrim( $string ); |
43 | 42 | $string = ltrim( $string, '"' ); |
| 43 | + |
44 | 44 | return $string; |
45 | 45 | } |
46 | 46 | |
— | — | @@ -99,11 +99,9 @@ |
100 | 100 | |
101 | 101 | return $messages; |
102 | 102 | } |
103 | | - |
104 | 103 | } |
105 | 104 | |
106 | 105 | class OpenLayersFormatWriter extends SimpleFormatWriter { |
107 | | - |
108 | 106 | /** |
109 | 107 | * Export a languages messages. |
110 | 108 | * @param $target File handler. |
— | — | @@ -118,6 +116,7 @@ |
119 | 117 | $authors = $collection->getAuthors(); |
120 | 118 | $authors = $this->filterAuthors( $authors, $collection->code, $this->group->getId() ); |
121 | 119 | $authorList = ''; |
| 120 | + |
122 | 121 | foreach ( $authors as $author ) { |
123 | 122 | $authorList .= " * - $author\n"; |
124 | 123 | } |
— | — | @@ -164,5 +163,4 @@ |
165 | 164 | // File terminator. |
166 | 165 | fwrite( $target, '});' ); |
167 | 166 | } |
168 | | - |
169 | 167 | } |
Index: trunk/extensions/Translate/ffs/Wiki.php |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | $contents = file_get_contents( $this->filename ); |
27 | 27 | $m = array(); |
28 | 28 | $count = preg_match_all( '/@author (.*)/', $contents, $m ); |
| 29 | + |
29 | 30 | return $m[1]; |
30 | 31 | } |
31 | 32 | |
— | — | @@ -32,6 +33,7 @@ |
33 | 34 | if ( $this->filename === false ) { |
34 | 35 | return ''; |
35 | 36 | } |
| 37 | + |
36 | 38 | $contents = file_get_contents( $this->filename ); |
37 | 39 | |
38 | 40 | /** FIXME: handle the case where the first comment is missing */ |
— | — | @@ -39,10 +41,21 @@ |
40 | 42 | |
41 | 43 | $start = strpos( $contents, '*/' ); |
42 | 44 | $end = strpos( $contents, '$messages' ); |
43 | | - if ( $start === false ) return ''; |
44 | | - if ( $start === $end ) return ''; |
| 45 | + |
| 46 | + if ( $start === false ) { |
| 47 | + return ''; |
| 48 | + } |
| 49 | + |
| 50 | + if ( $start === $end ) { |
| 51 | + return ''; |
| 52 | + } |
| 53 | + |
45 | 54 | $start += 2; // Get over the comment ending |
46 | | - if ( $end === false ) return trim( substr( $contents, $start ) ); |
| 55 | + |
| 56 | + if ( $end === false ) { |
| 57 | + return trim( substr( $contents, $start ) ); |
| 58 | + } |
| 59 | + |
47 | 60 | return trim( substr( $contents, $start, $end - $start ) ); |
48 | 61 | } |
49 | 62 | |
— | — | @@ -50,8 +63,10 @@ |
51 | 64 | if ( $this->filename === false ) { |
52 | 65 | return array(); |
53 | 66 | } |
| 67 | + |
54 | 68 | $ { $this->variableName } = array(); |
55 | 69 | require( $this->filename ); |
| 70 | + |
56 | 71 | return $mangler->mangle( $ { $this->variableName } ); |
57 | 72 | } |
58 | 73 | |
— | — | @@ -95,6 +110,7 @@ |
96 | 111 | if ( !$dir ) { |
97 | 112 | $this->writeMessagesBlock( $handle, $messages ); |
98 | 113 | fwrite( $handle, ");\n" ); |
| 114 | + |
99 | 115 | return; |
100 | 116 | } |
101 | 117 | |
— | — | @@ -175,8 +191,12 @@ |
176 | 192 | protected function exportItemPad( $handle, $key, $value, $pad = 0 ) { |
177 | 193 | # Add the key name |
178 | 194 | fwrite( $handle, "'$key'" ); |
| 195 | + |
179 | 196 | # Add the appropriate block whitespace |
180 | | - if ( $pad ) fwrite( $handle, str_repeat( ' ', $pad - strlen( $key ) ) ); |
| 197 | + if ( $pad ) { |
| 198 | + fwrite( $handle, str_repeat( ' ', $pad - strlen( $key ) ) ); |
| 199 | + } |
| 200 | + |
181 | 201 | fwrite( $handle, ' => ' ); |
182 | 202 | |
183 | 203 | if ( $this->commaToArray ) { |
— | — | @@ -203,11 +223,9 @@ |
204 | 224 | |
205 | 225 | # It is safe to use '-quoting, unless there is '-quote in the text |
206 | 226 | if ( strpos( $value, $single ) !== false ) { |
207 | | - |
208 | 227 | # In case there is no variables that need to be escaped, just use "-quote |
209 | 228 | if ( strpos( $value, $double ) === false && !preg_match( '/\$[^0-9]/', $value ) ) { |
210 | 229 | $quote = $double; |
211 | | - |
212 | 230 | # Something needs quoting, pick the quote which causes less quoting |
213 | 231 | } else { |
214 | 232 | $doubleEsc = substr_count( $value, $double ) + substr_count( $value, '$' ); |
Index: trunk/extensions/Translate/ffs/Gettext.php |
— | — | @@ -1,15 +1,16 @@ |
2 | 2 | <?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 3 | |
5 | 4 | class GettextPluralException extends MwException { } |
6 | 5 | |
7 | 6 | class GettextFormatReader extends SimpleFormatReader { |
8 | 7 | protected $pot = false; |
| 8 | + |
9 | 9 | public function setPotMode( $value ) { |
10 | 10 | $this->pot = $value; |
11 | 11 | } |
12 | 12 | |
13 | 13 | protected $prefix = ''; |
| 14 | + |
14 | 15 | public function setPrefix( $value ) { |
15 | 16 | $this->prefix = $value; |
16 | 17 | } |
— | — | @@ -23,10 +24,16 @@ |
24 | 25 | if ( $this->filename === false ) { |
25 | 26 | return ''; |
26 | 27 | } |
| 28 | + |
27 | 29 | $data = file_get_contents( $this->filename ); |
28 | 30 | $start = (int) strpos( $data, '# --' ); |
29 | | - if ( $start ) $start += 5; |
| 31 | + |
| 32 | + if ( $start ) { |
| 33 | + $start += 5; |
| 34 | + } |
| 35 | + |
30 | 36 | $end = (int) strpos( $data, "msgid" ); |
| 37 | + |
31 | 38 | return substr( $data, $start, $end - $start ); |
32 | 39 | } |
33 | 40 | |
— | — | @@ -34,8 +41,10 @@ |
35 | 42 | if ( $this->filename === false ) { |
36 | 43 | return array(); |
37 | 44 | } |
| 45 | + |
38 | 46 | $data = file_get_contents( $this->filename ); |
39 | 47 | $parse = GettextFFS::parseGettextData( $data ); |
| 48 | + |
40 | 49 | return $parse['TEMPLATE']; |
41 | 50 | } |
42 | 51 | |
— | — | @@ -43,7 +52,9 @@ |
44 | 53 | if ( $this->filename === false ) { |
45 | 54 | return array(); |
46 | 55 | } |
| 56 | + |
47 | 57 | $data = file_get_contents( $this->filename ); |
| 58 | + |
48 | 59 | return GettextFFS::parseGettextData( $data ); |
49 | 60 | } |
50 | 61 | |
— | — | @@ -51,6 +62,7 @@ |
52 | 63 | public function parseMessages( StringMangler $mangler ) { |
53 | 64 | $defs = $this->parseFile(); |
54 | 65 | $messages = array(); |
| 66 | + |
55 | 67 | foreach ( $defs as $key => $def ) { |
56 | 68 | if ( $this->pot ) { |
57 | 69 | $messages[$key] = $def['id']; |
— | — | @@ -60,9 +72,9 @@ |
61 | 73 | } |
62 | 74 | } |
63 | 75 | } |
| 76 | + |
64 | 77 | return $messages; |
65 | 78 | } |
66 | | - |
67 | 79 | } |
68 | 80 | |
69 | 81 | class GettextFormatWriter extends SimpleFormatWriter { |
— | — | @@ -72,17 +84,18 @@ |
73 | 85 | public function load( $code ) { |
74 | 86 | $reader = $this->group->getReader( $code ); |
75 | 87 | $readerEn = $this->group->getReader( 'en' ); |
| 88 | + |
76 | 89 | if ( $reader instanceof GettextFormatReader ) { |
77 | 90 | $this->addAuthors( $reader->parseAuthors(), $code ); |
78 | 91 | $this->staticHeader = $reader->parseStaticHeader(); |
79 | 92 | $this->owndata = $reader->parseFileExt(); |
80 | 93 | } |
| 94 | + |
81 | 95 | if ( $readerEn instanceof GettextFormatReader ) { |
82 | 96 | $this->data = $readerEn->parseFile(); |
83 | 97 | } |
84 | 98 | } |
85 | 99 | |
86 | | - |
87 | 100 | public function exportLanguage( $handle, MessageCollection $messages ) { |
88 | 101 | global $wgSitename, $wgServer, $wgTranslateDocumentationLanguageCode; |
89 | 102 | |
— | — | @@ -133,10 +146,14 @@ |
134 | 147 | |
135 | 148 | $translation = $m->translation(); |
136 | 149 | # CASE2: no translation |
137 | | - if ( $translation === null ) $translation = ''; |
| 150 | + if ( $translation === null ) { |
| 151 | + $translation = ''; |
| 152 | + } |
138 | 153 | |
139 | 154 | # CASE3: optional messages; accept only if different |
140 | | - if ( $m->hasTag( 'optional' ) ) $flags[] = 'x-optional'; |
| 155 | + if ( $m->hasTag( 'optional' ) ) { |
| 156 | + $flags[] = 'x-optional'; |
| 157 | + } |
141 | 158 | |
142 | 159 | # Remove explicit fuzzy markings from the translation before export |
143 | 160 | $flags = array(); |
— | — | @@ -144,6 +161,7 @@ |
145 | 162 | if ( isset( $this->data[$key]['flags'] ) ) { |
146 | 163 | $flags = $this->data[$key]['flags']; |
147 | 164 | } |
| 165 | + |
148 | 166 | if ( strpos( $translation, TRANSLATE_FUZZY ) !== false ) { |
149 | 167 | $translation = str_replace( TRANSLATE_FUZZY, '', $translation ); |
150 | 168 | $flags[] = 'fuzzy'; |
— | — | @@ -172,7 +190,6 @@ |
173 | 191 | } |
174 | 192 | |
175 | 193 | fwrite( $handle, $this->formatmsg( $m->definition(), $translation, $ckey, $pluralForms ) ); |
176 | | - |
177 | 194 | } |
178 | 195 | |
179 | 196 | return $out; |
— | — | @@ -184,6 +201,7 @@ |
185 | 202 | $line = addcslashes( $line, '\\"' ); |
186 | 203 | $line = str_replace( "\n", '\n', $line ); |
187 | 204 | $line = '"' . $line . '"'; |
| 205 | + |
188 | 206 | return $line; |
189 | 207 | } |
190 | 208 | |
— | — | @@ -199,12 +217,17 @@ |
200 | 218 | } |
201 | 219 | |
202 | 220 | // Ensure there is always something |
203 | | - if ( !count( $comments ) ) $comments[':'][] = ''; |
| 221 | + if ( !count( $comments ) ) { |
| 222 | + $comments[':'][] = ''; |
| 223 | + } |
204 | 224 | |
205 | 225 | $order = array( '', '.', ':', ',', '|' ); |
206 | 226 | $output = array(); |
207 | 227 | foreach ( $order as $type ) { |
208 | | - if ( !isset( $comments[$type] ) ) continue; |
| 228 | + if ( !isset( $comments[$type] ) ) { |
| 229 | + continue; |
| 230 | + } |
| 231 | + |
209 | 232 | foreach ( $comments[$type] as $value ) { |
210 | 233 | $output[] = "#$type $value"; |
211 | 234 | } |
— | — | @@ -217,7 +240,9 @@ |
218 | 241 | $output = array(); |
219 | 242 | |
220 | 243 | // FIXME: very ugly hack to allow gettext plurals to be exported. |
221 | | - if ( $msgstr == '{{PLURAL:GETTEXT|}}' ) return ''; |
| 244 | + if ( $msgstr == '{{PLURAL:GETTEXT|}}' ) { |
| 245 | + return ''; |
| 246 | + } |
222 | 247 | |
223 | 248 | if ( $msgctxt ) { |
224 | 249 | $output[] = 'msgctxt ' . $this->escape( $msgctxt ); |
— | — | @@ -250,6 +275,7 @@ |
251 | 276 | } |
252 | 277 | |
253 | 278 | $out = implode( "\n", $output ) . "\n\n"; |
| 279 | + |
254 | 280 | return $out; |
255 | 281 | |
256 | 282 | } |
— | — | @@ -266,7 +292,11 @@ |
267 | 293 | for ( $i = 0; $i < $forms; $i++ ) { |
268 | 294 | $plurals = array(); |
269 | 295 | $match = preg_match_all( '/{{PLURAL:GETTEXT\|(.*)}}/iU', $text, $plurals ); |
270 | | - if ( !$match ) throw new GettextPluralException( "Failed to parse plural for: $text" ); |
| 296 | + |
| 297 | + if ( !$match ) { |
| 298 | + throw new GettextPluralException( "Failed to parse plural for: $text" ); |
| 299 | + } |
| 300 | + |
271 | 301 | $pluralForm = $text; |
272 | 302 | foreach ( $plurals[0] as $index => $definition ) { |
273 | 303 | $parsedFormsArray = explode( '|', $plurals[1][$index] ); |
— | — | @@ -282,15 +312,12 @@ |
283 | 313 | |
284 | 314 | return $splitPlurals; |
285 | 315 | } |
286 | | - |
287 | 316 | } |
288 | 317 | |
289 | 318 | class GettextFFS extends SimpleFFS { |
290 | | - |
291 | 319 | // |
292 | 320 | // READ |
293 | 321 | // |
294 | | - |
295 | 322 | public function readFromVariable( $data ) { |
296 | 323 | $authors = $messages = array(); |
297 | 324 | |
— | — | @@ -357,7 +384,10 @@ |
358 | 385 | |
359 | 386 | // Then parse the messages |
360 | 387 | foreach ( $sections as $section ) { |
361 | | - if ( trim( $section ) === '' ) continue; |
| 388 | + if ( trim( $section ) === '' ) { |
| 389 | + continue; |
| 390 | + } |
| 391 | + |
362 | 392 | /* These inactive section are of no interest to us. Multiline mode |
363 | 393 | * is needed because there may be flags or other annoying stuff |
364 | 394 | * before the commented out sections. |
— | — | @@ -482,7 +512,9 @@ |
483 | 513 | */ |
484 | 514 | public static function generateKeyFromItem( $item ) { |
485 | 515 | $lang = Language::factory( 'en' ); |
| 516 | + |
486 | 517 | global $wgLegalTitleChars; |
| 518 | + |
487 | 519 | $hash = sha1( $item['ctxt'] . $item['id'] ); |
488 | 520 | $snippet = $item['id']; |
489 | 521 | $snippet = preg_replace( "/[^$wgLegalTitleChars]/", ' ', $snippet ); |
— | — | @@ -490,6 +522,7 @@ |
491 | 523 | $snippet = preg_replace( "/ {2,}/", ' ', $snippet ); |
492 | 524 | $snippet = $lang->truncate( $snippet, 30, '' ); |
493 | 525 | $snippet = str_replace( ' ', '_', trim( $snippet ) ); |
| 526 | + |
494 | 527 | return "$hash-$snippet"; |
495 | 528 | } |
496 | 529 | |
— | — | @@ -503,6 +536,7 @@ |
504 | 537 | $quotePattern = '/(^"|"$\n?)/m'; |
505 | 538 | $data = preg_replace( $quotePattern, '', $data ); |
506 | 539 | $data = stripcslashes( $data ); |
| 540 | + |
507 | 541 | if ( preg_match( '/\s$/', $data ) ) { |
508 | 542 | if ( $whitespace === 'mark' ) |
509 | 543 | $data .= '\\'; |
— | — | @@ -512,6 +546,7 @@ |
513 | 547 | // FIXME: only triggered if there is trailing whitespace |
514 | 548 | throw new MWException( 'Unknown action for whitespace' ); |
515 | 549 | } |
| 550 | + |
516 | 551 | return $data; |
517 | 552 | } |
518 | 553 | |
— | — | @@ -521,13 +556,13 @@ |
522 | 557 | list( $key, $value ) = explode( ': ', $line, 2 ); |
523 | 558 | $tags[$key] = $value; |
524 | 559 | } |
| 560 | + |
525 | 561 | return $tags; |
526 | 562 | } |
527 | 563 | |
528 | 564 | // |
529 | 565 | // WRITE |
530 | 566 | // |
531 | | - |
532 | 567 | protected function writeReal( MessageCollection $collection ) { |
533 | 568 | throw new MWException( 'Not implemented' ); |
534 | 569 | $output = $this->doHeader( $collection ); |
— | — | @@ -540,21 +575,28 @@ |
541 | 576 | $key = $mangler->unmangle( $key ); |
542 | 577 | $value = $m->translation(); |
543 | 578 | $value = str_replace( TRANSLATE_FUZZY, '', $value ); |
544 | | - if ( $value === '' ) continue; |
545 | 579 | |
| 580 | + if ( $value === '' ) { |
| 581 | + continue; |
| 582 | + } |
| 583 | + |
546 | 584 | $messages[$key] = $value; |
547 | 585 | } |
| 586 | + |
548 | 587 | $output .= TranslateSpyc::dump( $messages ); |
| 588 | + |
549 | 589 | return $output; |
550 | 590 | } |
551 | 591 | |
552 | 592 | protected function doHeader( MessageCollection $collection ) { |
553 | 593 | global $wgSitename; |
| 594 | + |
554 | 595 | $code = $collection->code; |
555 | 596 | $name = TranslateUtils::getLanguageName( $code ); |
556 | 597 | $native = TranslateUtils::getLanguageName( $code, true ); |
557 | 598 | $output = "# Messages for $name ($native)\n"; |
558 | 599 | $output .= "# Exported from $wgSitename\n"; |
| 600 | + |
559 | 601 | return $output; |
560 | 602 | } |
561 | 603 | |
— | — | @@ -562,10 +604,11 @@ |
563 | 605 | $output = ''; |
564 | 606 | $authors = $collection->getAuthors(); |
565 | 607 | $authors = $this->filterAuthors( $authors, $collection->code ); |
| 608 | + |
566 | 609 | foreach ( $authors as $author ) { |
567 | 610 | $output .= "# Author: $author\n"; |
568 | 611 | } |
| 612 | + |
569 | 613 | return $output; |
570 | 614 | } |
571 | | - |
572 | | -} |
\ No newline at end of file |
| 615 | +} |
Index: trunk/extensions/Translate/spyc/spyc.php |
— | — | @@ -10,25 +10,25 @@ |
11 | 11 | * @package Spyc |
12 | 12 | */ |
13 | 13 | |
14 | | -if (!function_exists('spyc_load')) { |
| 14 | +if ( !function_exists( 'spyc_load' ) ) { |
15 | 15 | /** |
16 | 16 | * Parses YAML to array. |
17 | 17 | * @param string $string YAML string. |
18 | 18 | * @return array |
19 | 19 | */ |
20 | | - function spyc_load ($string) { |
21 | | - return Spyc::YAMLLoadString($string); |
| 20 | + function spyc_load ( $string ) { |
| 21 | + return Spyc::YAMLLoadString( $string ); |
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | | -if (!function_exists('spyc_load_file')) { |
| 25 | +if ( !function_exists( 'spyc_load_file' ) ) { |
26 | 26 | /** |
27 | 27 | * Parses YAML to array. |
28 | 28 | * @param string $file Path to YAML file. |
29 | 29 | * @return array |
30 | 30 | */ |
31 | | - function spyc_load_file ($file) { |
32 | | - return Spyc::YAMLLoad($file); |
| 31 | + function spyc_load_file ( $file ) { |
| 32 | + return Spyc::YAMLLoad( $file ); |
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
— | — | @@ -105,8 +105,8 @@ |
106 | 106 | * @param string $input |
107 | 107 | * @return array |
108 | 108 | */ |
109 | | - public function load ($input) { |
110 | | - return $this->__loadString($input); |
| 109 | + public function load ( $input ) { |
| 110 | + return $this->__loadString( $input ); |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
— | — | @@ -114,8 +114,8 @@ |
115 | 115 | * @param string $file |
116 | 116 | * @return array |
117 | 117 | */ |
118 | | - public function loadFile ($file) { |
119 | | - return $this->__load($file); |
| 118 | + public function loadFile ( $file ) { |
| 119 | + return $this->__load( $file ); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
— | — | @@ -133,9 +133,9 @@ |
134 | 134 | * @return array |
135 | 135 | * @param string $input Path of YAML file or string containing YAML |
136 | 136 | */ |
137 | | - public static function YAMLLoad($input) { |
| 137 | + public static function YAMLLoad( $input ) { |
138 | 138 | $Spyc = new Spyc; |
139 | | - return $Spyc->__load($input); |
| 139 | + return $Spyc->__load( $input ); |
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
— | — | @@ -157,9 +157,9 @@ |
158 | 158 | * @return array |
159 | 159 | * @param string $input String containing YAML |
160 | 160 | */ |
161 | | - public static function YAMLLoadString($input) { |
| 161 | + public static function YAMLLoadString( $input ) { |
162 | 162 | $Spyc = new Spyc; |
163 | | - return $Spyc->__loadString($input); |
| 163 | + return $Spyc->__loadString( $input ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
— | — | @@ -182,9 +182,9 @@ |
183 | 183 | * @param int $indent Pass in false to use the default, which is 2 |
184 | 184 | * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) |
185 | 185 | */ |
186 | | - public static function YAMLDump($array,$indent = false,$wordwrap = false) { |
| 186 | + public static function YAMLDump( $array, $indent = false, $wordwrap = false ) { |
187 | 187 | $spyc = new Spyc; |
188 | | - return $spyc->dump($array,$indent,$wordwrap); |
| 188 | + return $spyc->dump( $array, $indent, $wordwrap ); |
189 | 189 | } |
190 | 190 | |
191 | 191 | |
— | — | @@ -208,18 +208,18 @@ |
209 | 209 | * @param int $indent Pass in false to use the default, which is 2 |
210 | 210 | * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) |
211 | 211 | */ |
212 | | - public function dump($array,$indent = false,$wordwrap = false) { |
| 212 | + public function dump( $array, $indent = false, $wordwrap = false ) { |
213 | 213 | // Dumps to some very clean YAML. We'll have to add some more features |
214 | 214 | // and options soon. And better support for folding. |
215 | 215 | |
216 | 216 | // New features and options. |
217 | | - if ($indent === false or !is_numeric($indent)) { |
| 217 | + if ( $indent === false or !is_numeric( $indent ) ) { |
218 | 218 | $this->_dumpIndent = 2; |
219 | 219 | } else { |
220 | 220 | $this->_dumpIndent = $indent; |
221 | 221 | } |
222 | 222 | |
223 | | - if ($wordwrap === false or !is_numeric($wordwrap)) { |
| 223 | + if ( $wordwrap === false or !is_numeric( $wordwrap ) ) { |
224 | 224 | $this->_dumpWordWrap = 40; |
225 | 225 | } else { |
226 | 226 | $this->_dumpWordWrap = $wordwrap; |
— | — | @@ -229,13 +229,13 @@ |
230 | 230 | $string = "---\n"; |
231 | 231 | |
232 | 232 | // Start at the base of the array and move through it. |
233 | | - if ($array) { |
| 233 | + if ( $array ) { |
234 | 234 | $array = (array)$array; |
235 | | - $first_key = key($array); |
| 235 | + $first_key = key( $array ); |
236 | 236 | |
237 | 237 | $previous_key = -1; |
238 | | - foreach ($array as $key => $value) { |
239 | | - $string .= $this->_yamlize($key,$value,0,$previous_key, $first_key); |
| 238 | + foreach ( $array as $key => $value ) { |
| 239 | + $string .= $this->_yamlize( $key, $value, 0, $previous_key, $first_key ); |
240 | 240 | $previous_key = $key; |
241 | 241 | } |
242 | 242 | } |
— | — | @@ -250,20 +250,20 @@ |
251 | 251 | * @param $value The value of the item |
252 | 252 | * @param $indent The indent of the current node |
253 | 253 | */ |
254 | | - private function _yamlize($key,$value,$indent, $previous_key = -1, $first_key = 0) { |
255 | | - if (is_array($value)) { |
256 | | - if (empty ($value)) |
257 | | - return $this->_dumpNode($key, array(), $indent, $previous_key, $first_key); |
| 254 | + private function _yamlize( $key, $value, $indent, $previous_key = -1, $first_key = 0 ) { |
| 255 | + if ( is_array( $value ) ) { |
| 256 | + if ( empty ( $value ) ) |
| 257 | + return $this->_dumpNode( $key, array(), $indent, $previous_key, $first_key ); |
258 | 258 | // It has children. What to do? |
259 | 259 | // Make it the right kind of item |
260 | | - $string = $this->_dumpNode($key, null, $indent, $previous_key, $first_key); |
| 260 | + $string = $this->_dumpNode( $key, null, $indent, $previous_key, $first_key ); |
261 | 261 | // Add the indent |
262 | 262 | $indent += $this->_dumpIndent; |
263 | 263 | // Yamlize the array |
264 | | - $string .= $this->_yamlizeArray($value,$indent); |
265 | | - } elseif (!is_array($value)) { |
| 264 | + $string .= $this->_yamlizeArray( $value, $indent ); |
| 265 | + } elseif ( !is_array( $value ) ) { |
266 | 266 | // It doesn't have children. Yip. |
267 | | - $string = $this->_dumpNode($key, $value, $indent, $previous_key, $first_key); |
| 267 | + $string = $this->_dumpNode( $key, $value, $indent, $previous_key, $first_key ); |
268 | 268 | } |
269 | 269 | return $string; |
270 | 270 | } |
— | — | @@ -275,13 +275,13 @@ |
276 | 276 | * @param $array The array you want to convert |
277 | 277 | * @param $indent The indent of the current level |
278 | 278 | */ |
279 | | - private function _yamlizeArray($array,$indent) { |
280 | | - if (is_array($array)) { |
| 279 | + private function _yamlizeArray( $array, $indent ) { |
| 280 | + if ( is_array( $array ) ) { |
281 | 281 | $string = ''; |
282 | 282 | $previous_key = -1; |
283 | | - $first_key = key($array); |
284 | | - foreach ($array as $key => $value) { |
285 | | - $string .= $this->_yamlize($key, $value, $indent, $previous_key, $first_key); |
| 283 | + $first_key = key( $array ); |
| 284 | + foreach ( $array as $key => $value ) { |
| 285 | + $string .= $this->_yamlize( $key, $value, $indent, $previous_key, $first_key ); |
286 | 286 | $previous_key = $key; |
287 | 287 | } |
288 | 288 | return $string; |
— | — | @@ -298,38 +298,38 @@ |
299 | 299 | * @param $value The value of the item |
300 | 300 | * @param $indent The indent of the current node |
301 | 301 | */ |
302 | | - private function _dumpNode($key, $value, $indent, $previous_key = -1, $first_key = 0) { |
| 302 | + private function _dumpNode( $key, $value, $indent, $previous_key = -1, $first_key = 0 ) { |
303 | 303 | // do some folding here, for blocks |
304 | | - if (is_string ($value) && ((strpos($value,"\n") !== false || strpos($value,": ") !== false || strpos($value,"- ") !== false || |
305 | | - strpos($value,"*") !== false || strpos($value,"#") !== false || strpos($value,"<") !== false || strpos($value,">") !== false || strpos ($value, ' ') !== false || |
306 | | - strpos($value,"[") !== false || strpos($value,"]") !== false || strpos($value,"{") !== false || strpos($value,"}") !== false) || substr ($value, -1, 1) == ':') |
| 304 | + if ( is_string ( $value ) && ( ( strpos( $value, "\n" ) !== false || strpos( $value, ": " ) !== false || strpos( $value, "- " ) !== false || |
| 305 | + strpos( $value, "*" ) !== false || strpos( $value, "#" ) !== false || strpos( $value, "<" ) !== false || strpos( $value, ">" ) !== false || strpos ( $value, ' ' ) !== false || |
| 306 | + strpos( $value, "[" ) !== false || strpos( $value, "]" ) !== false || strpos( $value, "{" ) !== false || strpos( $value, "}" ) !== false ) || substr ( $value, -1, 1 ) == ':' ) |
307 | 307 | ) { |
308 | | - $value = $this->_doLiteralBlock($value,$indent); |
| 308 | + $value = $this->_doLiteralBlock( $value, $indent ); |
309 | 309 | } else { |
310 | | - $value = $this->_doFolding($value,$indent); |
| 310 | + $value = $this->_doFolding( $value, $indent ); |
311 | 311 | } |
312 | 312 | |
313 | | - if ($value === array()) $value = '[ ]'; |
314 | | - if (in_array ($value, array ('true', 'TRUE', 'false', 'FALSE', 'y', 'Y', 'n', 'N', 'null', 'NULL'), true)) { |
315 | | - $value = $this->_doLiteralBlock($value,$indent); |
| 313 | + if ( $value === array() ) $value = '[ ]'; |
| 314 | + if ( in_array ( $value, array ( 'true', 'TRUE', 'false', 'FALSE', 'y', 'Y', 'n', 'N', 'null', 'NULL' ), true ) ) { |
| 315 | + $value = $this->_doLiteralBlock( $value, $indent ); |
316 | 316 | } |
317 | | - if (trim ($value) != $value) |
318 | | - $value = $this->_doLiteralBlock($value,$indent); |
| 317 | + if ( trim ( $value ) != $value ) |
| 318 | + $value = $this->_doLiteralBlock( $value, $indent ); |
319 | 319 | |
320 | | - if (is_bool($value)) { |
321 | | - $value = ($value) ? "true" : "false"; |
| 320 | + if ( is_bool( $value ) ) { |
| 321 | + $value = ( $value ) ? "true" : "false"; |
322 | 322 | } |
323 | 323 | |
324 | | - $spaces = str_repeat(' ',$indent); |
| 324 | + $spaces = str_repeat( ' ', $indent ); |
325 | 325 | |
326 | | - if (is_int($key) && $key - 1 == $previous_key && $first_key===0) { |
| 326 | + if ( is_int( $key ) && $key - 1 == $previous_key && $first_key === 0 ) { |
327 | 327 | // It's a sequence |
328 | | - $string = $spaces.'- '.$value."\n"; |
| 328 | + $string = $spaces . '- ' . $value . "\n"; |
329 | 329 | } else { |
330 | | - if ($first_key===0) throw new Exception('Keys are all screwy. The first one was zero, now it\'s "'. $key .'"'); |
| 330 | + if ( $first_key === 0 ) throw new Exception( 'Keys are all screwy. The first one was zero, now it\'s "' . $key . '"' ); |
331 | 331 | // It's mapped |
332 | | - if (strpos($key, ":") !== false) { $key = '"' . $key . '"'; } |
333 | | - $string = $spaces.$key.': '.$value."\n"; |
| 332 | + if ( strpos( $key, ":" ) !== false ) { $key = '"' . $key . '"'; } |
| 333 | + $string = $spaces . $key . ': ' . $value . "\n"; |
334 | 334 | } |
335 | 335 | return $string; |
336 | 336 | } |
— | — | @@ -341,20 +341,20 @@ |
342 | 342 | * @param $value |
343 | 343 | * @param $indent int The value of the indent |
344 | 344 | */ |
345 | | - private function _doLiteralBlock($value,$indent) { |
346 | | - if ($value === "\n") return '\n'; |
347 | | - if (strpos($value, "\n") === false && strpos($value, "'") === false) { |
348 | | - return sprintf ("'%s'", $value); |
| 345 | + private function _doLiteralBlock( $value, $indent ) { |
| 346 | + if ( $value === "\n" ) return '\n'; |
| 347 | + if ( strpos( $value, "\n" ) === false && strpos( $value, "'" ) === false ) { |
| 348 | + return sprintf ( "'%s'", $value ); |
349 | 349 | } |
350 | | - if (strpos($value, "\n") === false && strpos($value, '"') === false) { |
351 | | - return sprintf ('"%s"', $value); |
| 350 | + if ( strpos( $value, "\n" ) === false && strpos( $value, '"' ) === false ) { |
| 351 | + return sprintf ( '"%s"', $value ); |
352 | 352 | } |
353 | | - $exploded = explode("\n",$value); |
| 353 | + $exploded = explode( "\n", $value ); |
354 | 354 | $newValue = '|'; |
355 | 355 | $indent += $this->_dumpIndent; |
356 | | - $spaces = str_repeat(' ',$indent); |
357 | | - foreach ($exploded as $line) { |
358 | | - $newValue .= "\n" . $spaces . ($line); |
| 356 | + $spaces = str_repeat( ' ', $indent ); |
| 357 | + foreach ( $exploded as $line ) { |
| 358 | + $newValue .= "\n" . $spaces . ( $line ); |
359 | 359 | } |
360 | 360 | return $newValue; |
361 | 361 | } |
— | — | @@ -365,16 +365,16 @@ |
366 | 366 | * @return string |
367 | 367 | * @param $value The string you wish to fold |
368 | 368 | */ |
369 | | - private function _doFolding($value,$indent) { |
| 369 | + private function _doFolding( $value, $indent ) { |
370 | 370 | // Don't do anything if wordwrap is set to 0 |
371 | 371 | |
372 | | - if ($this->_dumpWordWrap !== 0 && is_string ($value) && strlen($value) > $this->_dumpWordWrap) { |
| 372 | + if ( $this->_dumpWordWrap !== 0 && is_string ( $value ) && strlen( $value ) > $this->_dumpWordWrap ) { |
373 | 373 | $indent += $this->_dumpIndent; |
374 | | - $indent = str_repeat(' ',$indent); |
375 | | - $wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent"); |
376 | | - $value = ">\n".$indent.$wrapped; |
| 374 | + $indent = str_repeat( ' ', $indent ); |
| 375 | + $wrapped = wordwrap( $value, $this->_dumpWordWrap, "\n$indent" ); |
| 376 | + $value = ">\n" . $indent . $wrapped; |
377 | 377 | } else { |
378 | | - if ($this->setting_dump_force_quotes && is_string ($value)) |
| 378 | + if ( $this->setting_dump_force_quotes && is_string ( $value ) ) |
379 | 379 | $value = '"' . $value . '"'; |
380 | 380 | } |
381 | 381 | |
— | — | @@ -384,69 +384,69 @@ |
385 | 385 | |
386 | 386 | // LOADING FUNCTIONS |
387 | 387 | |
388 | | - private function __load($input) { |
389 | | - $Source = $this->loadFromSource($input); |
390 | | - return $this->loadWithSource($Source); |
| 388 | + private function __load( $input ) { |
| 389 | + $Source = $this->loadFromSource( $input ); |
| 390 | + return $this->loadWithSource( $Source ); |
391 | 391 | } |
392 | 392 | |
393 | | - private function __loadString($input) { |
394 | | - $Source = $this->loadFromString($input); |
395 | | - return $this->loadWithSource($Source); |
| 393 | + private function __loadString( $input ) { |
| 394 | + $Source = $this->loadFromString( $input ); |
| 395 | + return $this->loadWithSource( $Source ); |
396 | 396 | } |
397 | 397 | |
398 | | - private function loadWithSource($Source) { |
399 | | - if (empty ($Source)) return array(); |
400 | | - if ($this->setting_use_syck_is_possible && function_exists ('syck_load')) { |
401 | | - $array = syck_load (implode ('', $Source)); |
402 | | - return is_array($array) ? $array : array(); |
| 398 | + private function loadWithSource( $Source ) { |
| 399 | + if ( empty ( $Source ) ) return array(); |
| 400 | + if ( $this->setting_use_syck_is_possible && function_exists ( 'syck_load' ) ) { |
| 401 | + $array = syck_load ( implode ( '', $Source ) ); |
| 402 | + return is_array( $array ) ? $array : array(); |
403 | 403 | } |
404 | 404 | |
405 | 405 | $this->path = array(); |
406 | 406 | $this->result = array(); |
407 | 407 | |
408 | | - $cnt = count($Source); |
409 | | - for ($i = 0; $i < $cnt; $i++) { |
| 408 | + $cnt = count( $Source ); |
| 409 | + for ( $i = 0; $i < $cnt; $i++ ) { |
410 | 410 | $line = $Source[$i]; |
411 | 411 | |
412 | | - $this->indent = strlen($line) - strlen(ltrim($line)); |
413 | | - $tempPath = $this->getParentPathByIndent($this->indent); |
414 | | - $line = self::stripIndent($line, $this->indent); |
415 | | - if (self::isComment($line)) continue; |
416 | | - if (self::isEmpty($line)) continue; |
| 412 | + $this->indent = strlen( $line ) - strlen( ltrim( $line ) ); |
| 413 | + $tempPath = $this->getParentPathByIndent( $this->indent ); |
| 414 | + $line = self::stripIndent( $line, $this->indent ); |
| 415 | + if ( self::isComment( $line ) ) continue; |
| 416 | + if ( self::isEmpty( $line ) ) continue; |
417 | 417 | $this->path = $tempPath; |
418 | 418 | |
419 | | - $literalBlockStyle = self::startsLiteralBlock($line); |
420 | | - if ($literalBlockStyle) { |
421 | | - $line = rtrim ($line, $literalBlockStyle . " \n"); |
| 419 | + $literalBlockStyle = self::startsLiteralBlock( $line ); |
| 420 | + if ( $literalBlockStyle ) { |
| 421 | + $line = rtrim ( $line, $literalBlockStyle . " \n" ); |
422 | 422 | $literalBlock = ''; |
423 | 423 | $line .= $this->LiteralPlaceHolder; |
424 | 424 | |
425 | | - while (++$i < $cnt && $this->literalBlockContinues($Source[$i], $this->indent)) { |
426 | | - $literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle); |
| 425 | + while ( ++$i < $cnt && $this->literalBlockContinues( $Source[$i], $this->indent ) ) { |
| 426 | + $literalBlock = $this->addLiteralLine( $literalBlock, $Source[$i], $literalBlockStyle ); |
427 | 427 | } |
428 | 428 | $i--; |
429 | 429 | } |
430 | 430 | |
431 | | - while (++$i < $cnt && self::greedilyNeedNextLine($line)) { |
432 | | - $line = rtrim ($line, " \n\t\r") . ' ' . ltrim ($Source[$i], " \t"); |
| 431 | + while ( ++$i < $cnt && self::greedilyNeedNextLine( $line ) ) { |
| 432 | + $line = rtrim ( $line, " \n\t\r" ) . ' ' . ltrim ( $Source[$i], " \t" ); |
433 | 433 | } |
434 | 434 | $i--; |
435 | 435 | |
436 | 436 | |
437 | 437 | |
438 | | - if (strpos ($line, '#')) { |
439 | | - if (strpos ($line, '"') === false && strpos ($line, "'") === false) |
440 | | - $line = preg_replace('/\s+#(.+)$/','',$line); |
| 438 | + if ( strpos ( $line, '#' ) ) { |
| 439 | + if ( strpos ( $line, '"' ) === false && strpos ( $line, "'" ) === false ) |
| 440 | + $line = preg_replace( '/\s+#(.+)$/', '', $line ); |
441 | 441 | } |
442 | 442 | |
443 | | - $lineArray = $this->_parseLine($line); |
| 443 | + $lineArray = $this->_parseLine( $line ); |
444 | 444 | |
445 | | - if ($literalBlockStyle) |
446 | | - $lineArray = $this->revertLiteralPlaceHolder ($lineArray, $literalBlock); |
| 445 | + if ( $literalBlockStyle ) |
| 446 | + $lineArray = $this->revertLiteralPlaceHolder ( $lineArray, $literalBlock ); |
447 | 447 | |
448 | | - $this->addArray($lineArray, $this->indent); |
| 448 | + $this->addArray( $lineArray, $this->indent ); |
449 | 449 | |
450 | | - foreach ($this->delayedPath as $indent => $delayedPath) |
| 450 | + foreach ( $this->delayedPath as $indent => $delayedPath ) |
451 | 451 | $this->path[$indent] = $delayedPath; |
452 | 452 | |
453 | 453 | $this->delayedPath = array(); |
— | — | @@ -455,17 +455,17 @@ |
456 | 456 | return $this->result; |
457 | 457 | } |
458 | 458 | |
459 | | - private function loadFromSource ($input) { |
460 | | - if (!empty($input) && strpos($input, "\n") === false && file_exists($input)) |
461 | | - return file($input); |
| 459 | + private function loadFromSource ( $input ) { |
| 460 | + if ( !empty( $input ) && strpos( $input, "\n" ) === false && file_exists( $input ) ) |
| 461 | + return file( $input ); |
462 | 462 | |
463 | | - return $this->loadFromString($input); |
| 463 | + return $this->loadFromString( $input ); |
464 | 464 | } |
465 | 465 | |
466 | | - private function loadFromString ($input) { |
467 | | - $lines = explode("\n",$input); |
468 | | - foreach ($lines as $k => $_) { |
469 | | - $lines[$k] = rtrim ($_, "\r"); |
| 466 | + private function loadFromString ( $input ) { |
| 467 | + $lines = explode( "\n", $input ); |
| 468 | + foreach ( $lines as $k => $_ ) { |
| 469 | + $lines[$k] = rtrim ( $_, "\r" ); |
470 | 470 | } |
471 | 471 | return $lines; |
472 | 472 | } |
— | — | @@ -476,33 +476,33 @@ |
477 | 477 | * @return array |
478 | 478 | * @param string $line A line from the YAML file |
479 | 479 | */ |
480 | | - private function _parseLine($line) { |
481 | | - if (!$line) return array(); |
482 | | - $line = trim($line); |
483 | | - if (!$line) return array(); |
| 480 | + private function _parseLine( $line ) { |
| 481 | + if ( !$line ) return array(); |
| 482 | + $line = trim( $line ); |
| 483 | + if ( !$line ) return array(); |
484 | 484 | |
485 | 485 | $array = array(); |
486 | 486 | |
487 | | - $group = $this->nodeContainsGroup($line); |
488 | | - if ($group) { |
489 | | - $this->addGroup($line, $group); |
490 | | - $line = $this->stripGroup ($line, $group); |
| 487 | + $group = $this->nodeContainsGroup( $line ); |
| 488 | + if ( $group ) { |
| 489 | + $this->addGroup( $line, $group ); |
| 490 | + $line = $this->stripGroup ( $line, $group ); |
491 | 491 | } |
492 | 492 | |
493 | | - if ($this->startsMappedSequence($line)) |
494 | | - return $this->returnMappedSequence($line); |
| 493 | + if ( $this->startsMappedSequence( $line ) ) |
| 494 | + return $this->returnMappedSequence( $line ); |
495 | 495 | |
496 | | - if ($this->startsMappedValue($line)) |
497 | | - return $this->returnMappedValue($line); |
| 496 | + if ( $this->startsMappedValue( $line ) ) |
| 497 | + return $this->returnMappedValue( $line ); |
498 | 498 | |
499 | | - if ($this->isArrayElement($line)) |
500 | | - return $this->returnArrayElement($line); |
| 499 | + if ( $this->isArrayElement( $line ) ) |
| 500 | + return $this->returnArrayElement( $line ); |
501 | 501 | |
502 | | - if ($this->isPlainArray($line)) |
503 | | - return $this->returnPlainArray($line); |
| 502 | + if ( $this->isPlainArray( $line ) ) |
| 503 | + return $this->returnPlainArray( $line ); |
504 | 504 | |
505 | 505 | |
506 | | - return $this->returnKeyValuePair($line); |
| 506 | + return $this->returnKeyValuePair( $line ); |
507 | 507 | |
508 | 508 | } |
509 | 509 | |
— | — | @@ -512,92 +512,92 @@ |
513 | 513 | * @param string $value |
514 | 514 | * @return mixed |
515 | 515 | */ |
516 | | - private function _toType($value) { |
517 | | - if ($value === '') return null; |
| 516 | + private function _toType( $value ) { |
| 517 | + if ( $value === '' ) return null; |
518 | 518 | $first_character = $value[0]; |
519 | | - $last_character = substr($value, -1, 1); |
| 519 | + $last_character = substr( $value, -1, 1 ); |
520 | 520 | |
521 | 521 | $is_quoted = false; |
522 | 522 | do { |
523 | | - if (!$value) break; |
524 | | - if ($first_character != '"' && $first_character != "'") break; |
525 | | - if ($last_character != '"' && $last_character != "'") break; |
| 523 | + if ( !$value ) break; |
| 524 | + if ( $first_character != '"' && $first_character != "'" ) break; |
| 525 | + if ( $last_character != '"' && $last_character != "'" ) break; |
526 | 526 | $is_quoted = true; |
527 | | - } while (0); |
| 527 | + } while ( 0 ); |
528 | 528 | |
529 | | - if ($is_quoted) |
530 | | - return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\'\'' => '\'', '\\\'' => '\'')); |
| 529 | + if ( $is_quoted ) |
| 530 | + return strtr( substr ( $value, 1, -1 ), array ( '\\"' => '"', '\'\'' => '\'', '\\\'' => '\'' ) ); |
531 | 531 | |
532 | | - if (strpos($value, ' #') !== false && !$is_quoted) |
533 | | - $value = preg_replace('/\s+#(.+)$/','',$value); |
| 532 | + if ( strpos( $value, ' #' ) !== false && !$is_quoted ) |
| 533 | + $value = preg_replace( '/\s+#(.+)$/', '', $value ); |
534 | 534 | |
535 | | - if (!$is_quoted) $value = str_replace('\n', "\n", $value); |
| 535 | + if ( !$is_quoted ) $value = str_replace( '\n', "\n", $value ); |
536 | 536 | |
537 | | - if ($first_character == '[' && $last_character == ']') { |
| 537 | + if ( $first_character == '[' && $last_character == ']' ) { |
538 | 538 | // Take out strings sequences and mappings |
539 | | - $innerValue = trim(substr ($value, 1, -1)); |
540 | | - if ($innerValue === '') return array(); |
541 | | - $explode = $this->_inlineEscape($innerValue); |
| 539 | + $innerValue = trim( substr ( $value, 1, -1 ) ); |
| 540 | + if ( $innerValue === '' ) return array(); |
| 541 | + $explode = $this->_inlineEscape( $innerValue ); |
542 | 542 | // Propagate value array |
543 | 543 | $value = array(); |
544 | | - foreach ($explode as $v) { |
545 | | - $value[] = $this->_toType($v); |
| 544 | + foreach ( $explode as $v ) { |
| 545 | + $value[] = $this->_toType( $v ); |
546 | 546 | } |
547 | 547 | return $value; |
548 | 548 | } |
549 | 549 | |
550 | | - if (strpos($value,': ')!==false && $first_character != '{') { |
551 | | - $array = explode(': ',$value); |
552 | | - $key = trim($array[0]); |
553 | | - array_shift($array); |
554 | | - $value = trim(implode(': ',$array)); |
555 | | - $value = $this->_toType($value); |
556 | | - return array($key => $value); |
| 550 | + if ( strpos( $value, ': ' ) !== false && $first_character != '{' ) { |
| 551 | + $array = explode( ': ', $value ); |
| 552 | + $key = trim( $array[0] ); |
| 553 | + array_shift( $array ); |
| 554 | + $value = trim( implode( ': ', $array ) ); |
| 555 | + $value = $this->_toType( $value ); |
| 556 | + return array( $key => $value ); |
557 | 557 | } |
558 | 558 | |
559 | | - if ($first_character == '{' && $last_character == '}') { |
560 | | - $innerValue = trim(substr ($value, 1, -1)); |
561 | | - if ($innerValue === '') return array(); |
| 559 | + if ( $first_character == '{' && $last_character == '}' ) { |
| 560 | + $innerValue = trim( substr ( $value, 1, -1 ) ); |
| 561 | + if ( $innerValue === '' ) return array(); |
562 | 562 | // Inline Mapping |
563 | 563 | // Take out strings sequences and mappings |
564 | | - $explode = $this->_inlineEscape($innerValue); |
| 564 | + $explode = $this->_inlineEscape( $innerValue ); |
565 | 565 | // Propagate value array |
566 | 566 | $array = array(); |
567 | | - foreach ($explode as $v) { |
568 | | - $SubArr = $this->_toType($v); |
569 | | - if (empty($SubArr)) continue; |
570 | | - if (is_array ($SubArr)) { |
571 | | - $array[key($SubArr)] = $SubArr[key($SubArr)]; continue; |
| 567 | + foreach ( $explode as $v ) { |
| 568 | + $SubArr = $this->_toType( $v ); |
| 569 | + if ( empty( $SubArr ) ) continue; |
| 570 | + if ( is_array ( $SubArr ) ) { |
| 571 | + $array[key( $SubArr )] = $SubArr[key( $SubArr )]; continue; |
572 | 572 | } |
573 | 573 | $array[] = $SubArr; |
574 | 574 | } |
575 | 575 | return $array; |
576 | 576 | } |
577 | 577 | |
578 | | - if ($value == 'null' || $value == 'NULL' || $value == 'Null' || $value == '' || $value == '~') { |
| 578 | + if ( $value == 'null' || $value == 'NULL' || $value == 'Null' || $value == '' || $value == '~' ) { |
579 | 579 | return null; |
580 | 580 | } |
581 | 581 | |
582 | | - if (intval($first_character) > 0 && preg_match ('/^[1-9]+[0-9]*$/', $value)) { |
| 582 | + if ( intval( $first_character ) > 0 && preg_match ( '/^[1-9]+[0-9]*$/', $value ) ) { |
583 | 583 | $intvalue = (int)$value; |
584 | | - if ($intvalue != PHP_INT_MAX) |
| 584 | + if ( $intvalue != PHP_INT_MAX ) |
585 | 585 | $value = $intvalue; |
586 | 586 | return $value; |
587 | 587 | } |
588 | 588 | |
589 | | - if (in_array($value, |
590 | | - array('true', 'on', '+', 'yes', 'y', 'True', 'TRUE', 'On', 'ON', 'YES', 'Yes', 'Y'))) { |
| 589 | + if ( in_array( $value, |
| 590 | + array( 'true', 'on', '+', 'yes', 'y', 'True', 'TRUE', 'On', 'ON', 'YES', 'Yes', 'Y' ) ) ) { |
591 | 591 | return true; |
592 | 592 | } |
593 | 593 | |
594 | | - if (in_array(strtolower($value), |
595 | | - array('false', 'off', '-', 'no', 'n'))) { |
| 594 | + if ( in_array( strtolower( $value ), |
| 595 | + array( 'false', 'off', '-', 'no', 'n' ) ) ) { |
596 | 596 | return false; |
597 | 597 | } |
598 | 598 | |
599 | | - if (is_numeric($value)) { |
600 | | - if ($value === '0') return 0; |
601 | | - if (trim ($value, 0) === $value) |
| 599 | + if ( is_numeric( $value ) ) { |
| 600 | + if ( $value === '0' ) return 0; |
| 601 | + if ( trim ( $value, 0 ) === $value ) |
602 | 602 | $value = (float)$value; |
603 | 603 | return $value; |
604 | 604 | } |
— | — | @@ -610,7 +610,7 @@ |
611 | 611 | * @access private |
612 | 612 | * @return array |
613 | 613 | */ |
614 | | - private function _inlineEscape($inline) { |
| 614 | + private function _inlineEscape( $inline ) { |
615 | 615 | // There's gotta be a cleaner way to do this... |
616 | 616 | // While pure sequences seem to be nesting just fine, |
617 | 617 | // pure mappings and mappings with sequences inside can't go very |
— | — | @@ -622,42 +622,42 @@ |
623 | 623 | |
624 | 624 | // Check for strings |
625 | 625 | $regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/'; |
626 | | - if (preg_match_all($regex,$inline,$strings)) { |
| 626 | + if ( preg_match_all( $regex, $inline, $strings ) ) { |
627 | 627 | $saved_strings = $strings[0]; |
628 | | - $inline = preg_replace($regex,'YAMLString',$inline); |
| 628 | + $inline = preg_replace( $regex, 'YAMLString', $inline ); |
629 | 629 | } |
630 | | - unset($regex); |
| 630 | + unset( $regex ); |
631 | 631 | |
632 | 632 | $i = 0; |
633 | 633 | do { |
634 | 634 | |
635 | 635 | // Check for sequences |
636 | | - while (preg_match('/\[([^{}\[\]]+)\]/U',$inline,$matchseqs)) { |
| 636 | + while ( preg_match( '/\[([^{}\[\]]+)\]/U', $inline, $matchseqs ) ) { |
637 | 637 | $seqs[] = $matchseqs[0]; |
638 | | - $inline = preg_replace('/\[([^{}\[\]]+)\]/U', ('YAMLSeq' . (count($seqs) - 1) . 's'), $inline, 1); |
| 638 | + $inline = preg_replace( '/\[([^{}\[\]]+)\]/U', ( 'YAMLSeq' . ( count( $seqs ) - 1 ) . 's' ), $inline, 1 ); |
639 | 639 | } |
640 | 640 | |
641 | 641 | // Check for mappings |
642 | | - while (preg_match('/{([^\[\]{}]+)}/U',$inline,$matchmaps)) { |
| 642 | + while ( preg_match( '/{([^\[\]{}]+)}/U', $inline, $matchmaps ) ) { |
643 | 643 | $maps[] = $matchmaps[0]; |
644 | | - $inline = preg_replace('/{([^\[\]{}]+)}/U', ('YAMLMap' . (count($maps) - 1) . 's'), $inline, 1); |
| 644 | + $inline = preg_replace( '/{([^\[\]{}]+)}/U', ( 'YAMLMap' . ( count( $maps ) - 1 ) . 's' ), $inline, 1 ); |
645 | 645 | } |
646 | 646 | |
647 | | - if ($i++ >= 10) break; |
| 647 | + if ( $i++ >= 10 ) break; |
648 | 648 | |
649 | | - } while (strpos ($inline, '[') !== false || strpos ($inline, '{') !== false); |
| 649 | + } while ( strpos ( $inline, '[' ) !== false || strpos ( $inline, '{' ) !== false ); |
650 | 650 | |
651 | | - $explode = explode(', ',$inline); |
| 651 | + $explode = explode( ', ', $inline ); |
652 | 652 | $stringi = 0; $i = 0; |
653 | 653 | |
654 | | - while (1) { |
| 654 | + while ( 1 ) { |
655 | 655 | |
656 | 656 | // Re-add the sequences |
657 | | - if (!empty($seqs)) { |
658 | | - foreach ($explode as $key => $value) { |
659 | | - if (strpos($value,'YAMLSeq') !== false) { |
660 | | - foreach ($seqs as $seqk => $seq) { |
661 | | - $explode[$key] = str_replace(('YAMLSeq'.$seqk.'s'),$seq,$value); |
| 657 | + if ( !empty( $seqs ) ) { |
| 658 | + foreach ( $explode as $key => $value ) { |
| 659 | + if ( strpos( $value, 'YAMLSeq' ) !== false ) { |
| 660 | + foreach ( $seqs as $seqk => $seq ) { |
| 661 | + $explode[$key] = str_replace( ( 'YAMLSeq' . $seqk . 's' ), $seq, $value ); |
662 | 662 | $value = $explode[$key]; |
663 | 663 | } |
664 | 664 | } |
— | — | @@ -665,11 +665,11 @@ |
666 | 666 | } |
667 | 667 | |
668 | 668 | // Re-add the mappings |
669 | | - if (!empty($maps)) { |
670 | | - foreach ($explode as $key => $value) { |
671 | | - if (strpos($value,'YAMLMap') !== false) { |
672 | | - foreach ($maps as $mapk => $map) { |
673 | | - $explode[$key] = str_replace(('YAMLMap'.$mapk.'s'), $map, $value); |
| 669 | + if ( !empty( $maps ) ) { |
| 670 | + foreach ( $explode as $key => $value ) { |
| 671 | + if ( strpos( $value, 'YAMLMap' ) !== false ) { |
| 672 | + foreach ( $maps as $mapk => $map ) { |
| 673 | + $explode[$key] = str_replace( ( 'YAMLMap' . $mapk . 's' ), $map, $value ); |
674 | 674 | $value = $explode[$key]; |
675 | 675 | } |
676 | 676 | } |
— | — | @@ -678,11 +678,11 @@ |
679 | 679 | |
680 | 680 | |
681 | 681 | // Re-add the strings |
682 | | - if (!empty($saved_strings)) { |
683 | | - foreach ($explode as $key => $value) { |
684 | | - while (strpos($value,'YAMLString') !== false) { |
685 | | - $explode[$key] = preg_replace('/YAMLString/',$saved_strings[$stringi],$value, 1); |
686 | | - unset($saved_strings[$stringi]); |
| 682 | + if ( !empty( $saved_strings ) ) { |
| 683 | + foreach ( $explode as $key => $value ) { |
| 684 | + while ( strpos( $value, 'YAMLString' ) !== false ) { |
| 685 | + $explode[$key] = preg_replace( '/YAMLString/', $saved_strings[$stringi], $value, 1 ); |
| 686 | + unset( $saved_strings[$stringi] ); |
687 | 687 | ++$stringi; |
688 | 688 | $value = $explode[$key]; |
689 | 689 | } |
— | — | @@ -690,72 +690,72 @@ |
691 | 691 | } |
692 | 692 | |
693 | 693 | $finished = true; |
694 | | - foreach ($explode as $key => $value) { |
695 | | - if (strpos($value,'YAMLSeq') !== false) { |
| 694 | + foreach ( $explode as $key => $value ) { |
| 695 | + if ( strpos( $value, 'YAMLSeq' ) !== false ) { |
696 | 696 | $finished = false; break; |
697 | 697 | } |
698 | | - if (strpos($value,'YAMLMap') !== false) { |
| 698 | + if ( strpos( $value, 'YAMLMap' ) !== false ) { |
699 | 699 | $finished = false; break; |
700 | 700 | } |
701 | | - if (strpos($value,'YAMLString') !== false) { |
| 701 | + if ( strpos( $value, 'YAMLString' ) !== false ) { |
702 | 702 | $finished = false; break; |
703 | 703 | } |
704 | 704 | } |
705 | | - if ($finished) break; |
| 705 | + if ( $finished ) break; |
706 | 706 | |
707 | 707 | $i++; |
708 | | - if ($i > 10) |
| 708 | + if ( $i > 10 ) |
709 | 709 | break; // Prevent infinite loops. |
710 | 710 | } |
711 | 711 | |
712 | 712 | return $explode; |
713 | 713 | } |
714 | 714 | |
715 | | - private function literalBlockContinues ($line, $lineIndent) { |
716 | | - if (!trim($line)) return true; |
717 | | - if (strlen($line) - strlen(ltrim($line)) > $lineIndent) return true; |
| 715 | + private function literalBlockContinues ( $line, $lineIndent ) { |
| 716 | + if ( !trim( $line ) ) return true; |
| 717 | + if ( strlen( $line ) - strlen( ltrim( $line ) ) > $lineIndent ) return true; |
718 | 718 | return false; |
719 | 719 | } |
720 | 720 | |
721 | | - private function referenceContentsByAlias ($alias) { |
| 721 | + private function referenceContentsByAlias ( $alias ) { |
722 | 722 | do { |
723 | | - if (!isset($this->SavedGroups[$alias])) { echo "Bad group name: $alias."; break; } |
| 723 | + if ( !isset( $this->SavedGroups[$alias] ) ) { echo "Bad group name: $alias."; break; } |
724 | 724 | $groupPath = $this->SavedGroups[$alias]; |
725 | 725 | $value = $this->result; |
726 | | - foreach ($groupPath as $k) { |
| 726 | + foreach ( $groupPath as $k ) { |
727 | 727 | $value = $value[$k]; |
728 | 728 | } |
729 | | - } while (false); |
| 729 | + } while ( false ); |
730 | 730 | return $value; |
731 | 731 | } |
732 | 732 | |
733 | | - private function addArrayInline ($array, $indent) { |
| 733 | + private function addArrayInline ( $array, $indent ) { |
734 | 734 | $CommonGroupPath = $this->path; |
735 | | - if (empty ($array)) return false; |
| 735 | + if ( empty ( $array ) ) return false; |
736 | 736 | |
737 | | - foreach ($array as $k => $_) { |
738 | | - $this->addArray(array($k => $_), $indent); |
| 737 | + foreach ( $array as $k => $_ ) { |
| 738 | + $this->addArray( array( $k => $_ ), $indent ); |
739 | 739 | $this->path = $CommonGroupPath; |
740 | 740 | } |
741 | 741 | return true; |
742 | 742 | } |
743 | 743 | |
744 | | - private function addArray ($incoming_data, $incoming_indent) { |
| 744 | + private function addArray ( $incoming_data, $incoming_indent ) { |
745 | 745 | |
746 | 746 | // print_r ($incoming_data); |
747 | 747 | |
748 | | - if (count ($incoming_data) > 1) |
749 | | - return $this->addArrayInline ($incoming_data, $incoming_indent); |
| 748 | + if ( count ( $incoming_data ) > 1 ) |
| 749 | + return $this->addArrayInline ( $incoming_data, $incoming_indent ); |
750 | 750 | |
751 | | - $key = key ($incoming_data); |
752 | | - $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null; |
753 | | - if ($key === '__!YAMLZero') $key = '0'; |
| 751 | + $key = key ( $incoming_data ); |
| 752 | + $value = isset( $incoming_data[$key] ) ? $incoming_data[$key] : null; |
| 753 | + if ( $key === '__!YAMLZero' ) $key = '0'; |
754 | 754 | |
755 | | - if ($incoming_indent == 0 && !$this->_containsGroupAlias && !$this->_containsGroupAnchor) { // Shortcut for root-level values. |
756 | | - if ($key || $key === '' || $key === '0') { |
| 755 | + if ( $incoming_indent == 0 && !$this->_containsGroupAlias && !$this->_containsGroupAnchor ) { // Shortcut for root-level values. |
| 756 | + if ( $key || $key === '' || $key === '0' ) { |
757 | 757 | $this->result[$key] = $value; |
758 | 758 | } else { |
759 | | - $this->result[] = $value; end ($this->result); $key = key ($this->result); |
| 759 | + $this->result[] = $value; end ( $this->result ); $key = key ( $this->result ); |
760 | 760 | } |
761 | 761 | $this->path[$incoming_indent] = $key; |
762 | 762 | return; |
— | — | @@ -766,44 +766,44 @@ |
767 | 767 | $history = array(); |
768 | 768 | // Unfolding inner array tree. |
769 | 769 | $history[] = $_arr = $this->result; |
770 | | - foreach ($this->path as $k) { |
| 770 | + foreach ( $this->path as $k ) { |
771 | 771 | $history[] = $_arr = $_arr[$k]; |
772 | 772 | } |
773 | 773 | |
774 | | - if ($this->_containsGroupAlias) { |
775 | | - $value = $this->referenceContentsByAlias($this->_containsGroupAlias); |
| 774 | + if ( $this->_containsGroupAlias ) { |
| 775 | + $value = $this->referenceContentsByAlias( $this->_containsGroupAlias ); |
776 | 776 | $this->_containsGroupAlias = false; |
777 | 777 | } |
778 | 778 | |
779 | 779 | |
780 | 780 | // Adding string or numeric key to the innermost level or $this->arr. |
781 | | - if (is_string($key) && $key == '<<') { |
782 | | - if (!is_array ($_arr)) { $_arr = array (); } |
| 781 | + if ( is_string( $key ) && $key == '<<' ) { |
| 782 | + if ( !is_array ( $_arr ) ) { $_arr = array (); } |
783 | 783 | |
784 | | - $_arr = array_merge ($_arr, $value); |
785 | | - } else if ($key || $key === '' || $key === '0') { |
| 784 | + $_arr = array_merge ( $_arr, $value ); |
| 785 | + } else if ( $key || $key === '' || $key === '0' ) { |
786 | 786 | $_arr[$key] = $value; |
787 | 787 | } else { |
788 | | - if (!is_array ($_arr)) { $_arr = array ($value); $key = 0; } |
789 | | - else { $_arr[] = $value; end ($_arr); $key = key ($_arr); } |
| 788 | + if ( !is_array ( $_arr ) ) { $_arr = array ( $value ); $key = 0; } |
| 789 | + else { $_arr[] = $value; end ( $_arr ); $key = key ( $_arr ); } |
790 | 790 | } |
791 | 791 | |
792 | | - $reverse_path = array_reverse($this->path); |
793 | | - $reverse_history = array_reverse ($history); |
| 792 | + $reverse_path = array_reverse( $this->path ); |
| 793 | + $reverse_history = array_reverse ( $history ); |
794 | 794 | $reverse_history[0] = $_arr; |
795 | | - $cnt = count($reverse_history) - 1; |
796 | | - for ($i = 0; $i < $cnt; $i++) { |
797 | | - $reverse_history[$i+1][$reverse_path[$i]] = $reverse_history[$i]; |
| 795 | + $cnt = count( $reverse_history ) - 1; |
| 796 | + for ( $i = 0; $i < $cnt; $i++ ) { |
| 797 | + $reverse_history[$i + 1][$reverse_path[$i]] = $reverse_history[$i]; |
798 | 798 | } |
799 | 799 | $this->result = $reverse_history[$cnt]; |
800 | 800 | |
801 | 801 | $this->path[$incoming_indent] = $key; |
802 | 802 | |
803 | | - if ($this->_containsGroupAnchor) { |
| 803 | + if ( $this->_containsGroupAnchor ) { |
804 | 804 | $this->SavedGroups[$this->_containsGroupAnchor] = $this->path; |
805 | | - if (is_array ($value)) { |
806 | | - $k = key ($value); |
807 | | - if (!is_int ($k)) { |
| 805 | + if ( is_array ( $value ) ) { |
| 806 | + $k = key ( $value ); |
| 807 | + if ( !is_int ( $k ) ) { |
808 | 808 | $this->SavedGroups[$this->_containsGroupAnchor][$incoming_indent + 2] = $k; |
809 | 809 | } |
810 | 810 | } |
— | — | @@ -812,209 +812,209 @@ |
813 | 813 | |
814 | 814 | } |
815 | 815 | |
816 | | - private static function startsLiteralBlock ($line) { |
817 | | - $lastChar = substr (trim($line), -1); |
818 | | - if ($lastChar != '>' && $lastChar != '|') return false; |
819 | | - if ($lastChar == '|') return $lastChar; |
| 816 | + private static function startsLiteralBlock ( $line ) { |
| 817 | + $lastChar = substr ( trim( $line ), -1 ); |
| 818 | + if ( $lastChar != '>' && $lastChar != '|' ) return false; |
| 819 | + if ( $lastChar == '|' ) return $lastChar; |
820 | 820 | // HTML tags should not be counted as literal blocks. |
821 | | - if (preg_match ('#<.*?>$#', $line)) return false; |
| 821 | + if ( preg_match ( '#<.*?>$#', $line ) ) return false; |
822 | 822 | return $lastChar; |
823 | 823 | } |
824 | 824 | |
825 | | - private static function greedilyNeedNextLine($line) { |
826 | | - $line = trim ($line); |
827 | | - if (!strlen($line)) return false; |
828 | | - if (substr ($line, -1, 1) == ']') return false; |
829 | | - if ($line[0] == '[') return true; |
830 | | - if (preg_match ('#^[^:]+?:\s*\[#', $line)) return true; |
| 825 | + private static function greedilyNeedNextLine( $line ) { |
| 826 | + $line = trim ( $line ); |
| 827 | + if ( !strlen( $line ) ) return false; |
| 828 | + if ( substr ( $line, -1, 1 ) == ']' ) return false; |
| 829 | + if ( $line[0] == '[' ) return true; |
| 830 | + if ( preg_match ( '#^[^:]+?:\s*\[#', $line ) ) return true; |
831 | 831 | return false; |
832 | 832 | } |
833 | 833 | |
834 | | - private function addLiteralLine ($literalBlock, $line, $literalBlockStyle) { |
835 | | - $line = self::stripIndent($line); |
836 | | - $line = rtrim ($line, "\r\n\t ") . "\n"; |
837 | | - if ($literalBlockStyle == '|') { |
| 834 | + private function addLiteralLine ( $literalBlock, $line, $literalBlockStyle ) { |
| 835 | + $line = self::stripIndent( $line ); |
| 836 | + $line = rtrim ( $line, "\r\n\t " ) . "\n"; |
| 837 | + if ( $literalBlockStyle == '|' ) { |
838 | 838 | return $literalBlock . $line; |
839 | 839 | } |
840 | | - if (strlen($line) == 0) |
841 | | - return rtrim($literalBlock, ' ') . "\n"; |
842 | | - if ($line == "\n" && $literalBlockStyle == '>') { |
843 | | - return rtrim ($literalBlock, " \t") . "\n"; |
| 840 | + if ( strlen( $line ) == 0 ) |
| 841 | + return rtrim( $literalBlock, ' ' ) . "\n"; |
| 842 | + if ( $line == "\n" && $literalBlockStyle == '>' ) { |
| 843 | + return rtrim ( $literalBlock, " \t" ) . "\n"; |
844 | 844 | } |
845 | | - if ($line != "\n") |
846 | | - $line = trim ($line, "\r\n ") . " "; |
| 845 | + if ( $line != "\n" ) |
| 846 | + $line = trim ( $line, "\r\n " ) . " "; |
847 | 847 | return $literalBlock . $line; |
848 | 848 | } |
849 | 849 | |
850 | | - function revertLiteralPlaceHolder ($lineArray, $literalBlock) { |
851 | | - foreach ($lineArray as $k => $_) { |
852 | | - if (is_array($_)) |
853 | | - $lineArray[$k] = $this->revertLiteralPlaceHolder ($_, $literalBlock); |
854 | | - else if (substr($_, -1 * strlen ($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder) |
855 | | - $lineArray[$k] = rtrim ($literalBlock, " \r\n"); |
| 850 | + function revertLiteralPlaceHolder ( $lineArray, $literalBlock ) { |
| 851 | + foreach ( $lineArray as $k => $_ ) { |
| 852 | + if ( is_array( $_ ) ) |
| 853 | + $lineArray[$k] = $this->revertLiteralPlaceHolder ( $_, $literalBlock ); |
| 854 | + else if ( substr( $_, -1 * strlen ( $this->LiteralPlaceHolder ) ) == $this->LiteralPlaceHolder ) |
| 855 | + $lineArray[$k] = rtrim ( $literalBlock, " \r\n" ); |
856 | 856 | } |
857 | 857 | return $lineArray; |
858 | 858 | } |
859 | 859 | |
860 | | - private static function stripIndent ($line, $indent = -1) { |
861 | | - if ($indent == -1) $indent = strlen($line) - strlen(ltrim($line)); |
862 | | - return substr ($line, $indent); |
| 860 | + private static function stripIndent ( $line, $indent = -1 ) { |
| 861 | + if ( $indent == -1 ) $indent = strlen( $line ) - strlen( ltrim( $line ) ); |
| 862 | + return substr ( $line, $indent ); |
863 | 863 | } |
864 | 864 | |
865 | | - private function getParentPathByIndent ($indent) { |
866 | | - if ($indent == 0) return array(); |
| 865 | + private function getParentPathByIndent ( $indent ) { |
| 866 | + if ( $indent == 0 ) return array(); |
867 | 867 | $linePath = $this->path; |
868 | 868 | do { |
869 | | - end($linePath); $lastIndentInParentPath = key($linePath); |
870 | | - if ($indent <= $lastIndentInParentPath) array_pop ($linePath); |
871 | | - } while ($indent <= $lastIndentInParentPath); |
| 869 | + end( $linePath ); $lastIndentInParentPath = key( $linePath ); |
| 870 | + if ( $indent <= $lastIndentInParentPath ) array_pop ( $linePath ); |
| 871 | + } while ( $indent <= $lastIndentInParentPath ); |
872 | 872 | return $linePath; |
873 | 873 | } |
874 | 874 | |
875 | 875 | |
876 | | - private function clearBiggerPathValues ($indent) { |
| 876 | + private function clearBiggerPathValues ( $indent ) { |
877 | 877 | |
878 | 878 | |
879 | | - if ($indent == 0) $this->path = array(); |
880 | | - if (empty ($this->path)) return true; |
| 879 | + if ( $indent == 0 ) $this->path = array(); |
| 880 | + if ( empty ( $this->path ) ) return true; |
881 | 881 | |
882 | | - foreach ($this->path as $k => $_) { |
883 | | - if ($k > $indent) unset ($this->path[$k]); |
| 882 | + foreach ( $this->path as $k => $_ ) { |
| 883 | + if ( $k > $indent ) unset ( $this->path[$k] ); |
884 | 884 | } |
885 | 885 | |
886 | 886 | return true; |
887 | 887 | } |
888 | 888 | |
889 | 889 | |
890 | | - private static function isComment ($line) { |
891 | | - if (!$line) return false; |
892 | | - if ($line[0] == '#') return true; |
893 | | - if (trim($line, " \r\n\t") == '---') return true; |
| 890 | + private static function isComment ( $line ) { |
| 891 | + if ( !$line ) return false; |
| 892 | + if ( $line[0] == '#' ) return true; |
| 893 | + if ( trim( $line, " \r\n\t" ) == '---' ) return true; |
894 | 894 | return false; |
895 | 895 | } |
896 | 896 | |
897 | | - private static function isEmpty ($line) { |
898 | | - return (trim ($line) === ''); |
| 897 | + private static function isEmpty ( $line ) { |
| 898 | + return ( trim ( $line ) === '' ); |
899 | 899 | } |
900 | 900 | |
901 | 901 | |
902 | | - private function isArrayElement ($line) { |
903 | | - if (!$line) return false; |
904 | | - if ($line[0] != '-') return false; |
905 | | - if (strlen ($line) > 3) |
906 | | - if (substr($line,0,3) == '---') return false; |
| 902 | + private function isArrayElement ( $line ) { |
| 903 | + if ( !$line ) return false; |
| 904 | + if ( $line[0] != '-' ) return false; |
| 905 | + if ( strlen ( $line ) > 3 ) |
| 906 | + if ( substr( $line, 0, 3 ) == '---' ) return false; |
907 | 907 | |
908 | 908 | return true; |
909 | 909 | } |
910 | 910 | |
911 | | - private function isHashElement ($line) { |
912 | | - return strpos($line, ':'); |
| 911 | + private function isHashElement ( $line ) { |
| 912 | + return strpos( $line, ':' ); |
913 | 913 | } |
914 | 914 | |
915 | | - private function isLiteral ($line) { |
916 | | - if ($this->isArrayElement($line)) return false; |
917 | | - if ($this->isHashElement($line)) return false; |
| 915 | + private function isLiteral ( $line ) { |
| 916 | + if ( $this->isArrayElement( $line ) ) return false; |
| 917 | + if ( $this->isHashElement( $line ) ) return false; |
918 | 918 | return true; |
919 | 919 | } |
920 | 920 | |
921 | 921 | |
922 | | - private static function unquote ($value) { |
923 | | - if (!$value) return $value; |
924 | | - if (!is_string($value)) return $value; |
925 | | - if ($value[0] == '\'') return trim ($value, '\''); |
926 | | - if ($value[0] == '"') return trim ($value, '"'); |
| 922 | + private static function unquote ( $value ) { |
| 923 | + if ( !$value ) return $value; |
| 924 | + if ( !is_string( $value ) ) return $value; |
| 925 | + if ( $value[0] == '\'' ) return trim ( $value, '\'' ); |
| 926 | + if ( $value[0] == '"' ) return trim ( $value, '"' ); |
927 | 927 | return $value; |
928 | 928 | } |
929 | 929 | |
930 | | - private function startsMappedSequence ($line) { |
931 | | - return ($line[0] == '-' && substr ($line, -1, 1) == ':'); |
| 930 | + private function startsMappedSequence ( $line ) { |
| 931 | + return ( $line[0] == '-' && substr ( $line, -1, 1 ) == ':' ); |
932 | 932 | } |
933 | 933 | |
934 | | - private function returnMappedSequence ($line) { |
| 934 | + private function returnMappedSequence ( $line ) { |
935 | 935 | $array = array(); |
936 | | - $key = self::unquote(trim(substr($line,1,-1))); |
| 936 | + $key = self::unquote( trim( substr( $line, 1, -1 ) ) ); |
937 | 937 | $array[$key] = array(); |
938 | | - $this->delayedPath = array(strpos ($line, $key) + $this->indent => $key); |
939 | | - return array($array); |
| 938 | + $this->delayedPath = array( strpos ( $line, $key ) + $this->indent => $key ); |
| 939 | + return array( $array ); |
940 | 940 | } |
941 | 941 | |
942 | | - private function returnMappedValue ($line) { |
| 942 | + private function returnMappedValue ( $line ) { |
943 | 943 | $array = array(); |
944 | | - $key = self::unquote (trim(substr($line,0,-1))); |
| 944 | + $key = self::unquote ( trim( substr( $line, 0, -1 ) ) ); |
945 | 945 | $array[$key] = ''; |
946 | 946 | return $array; |
947 | 947 | } |
948 | 948 | |
949 | | - private function startsMappedValue ($line) { |
950 | | - return (substr ($line, -1, 1) == ':'); |
| 949 | + private function startsMappedValue ( $line ) { |
| 950 | + return ( substr ( $line, -1, 1 ) == ':' ); |
951 | 951 | } |
952 | 952 | |
953 | | - private function isPlainArray ($line) { |
954 | | - return ($line[0] == '[' && substr ($line, -1, 1) == ']'); |
| 953 | + private function isPlainArray ( $line ) { |
| 954 | + return ( $line[0] == '[' && substr ( $line, -1, 1 ) == ']' ); |
955 | 955 | } |
956 | 956 | |
957 | | - private function returnPlainArray ($line) { |
958 | | - return $this->_toType($line); |
959 | | - } |
| 957 | + private function returnPlainArray ( $line ) { |
| 958 | + return $this->_toType( $line ); |
| 959 | + } |
960 | 960 | |
961 | | - private function returnKeyValuePair ($line) { |
| 961 | + private function returnKeyValuePair ( $line ) { |
962 | 962 | $array = array(); |
963 | 963 | $key = ''; |
964 | | - if (strpos ($line, ':')) { |
| 964 | + if ( strpos ( $line, ':' ) ) { |
965 | 965 | // It's a key/value pair most likely |
966 | 966 | // If the key is in double quotes pull it out |
967 | | - if (($line[0] == '"' || $line[0] == "'") && preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) { |
968 | | - $value = trim(str_replace($matches[1],'',$line)); |
| 967 | + if ( ( $line[0] == '"' || $line[0] == "'" ) && preg_match( '/^(["\'](.*)["\'](\s)*:)/', $line, $matches ) ) { |
| 968 | + $value = trim( str_replace( $matches[1], '', $line ) ); |
969 | 969 | $key = $matches[2]; |
970 | 970 | } else { |
971 | 971 | // Do some guesswork as to the key and the value |
972 | | - $explode = explode(':',$line); |
973 | | - $key = trim($explode[0]); |
974 | | - array_shift($explode); |
975 | | - $value = trim(implode(':',$explode)); |
| 972 | + $explode = explode( ':', $line ); |
| 973 | + $key = trim( $explode[0] ); |
| 974 | + array_shift( $explode ); |
| 975 | + $value = trim( implode( ':', $explode ) ); |
976 | 976 | } |
977 | 977 | // Set the type of the value. Int, string, etc |
978 | | - $value = $this->_toType($value); |
979 | | - if ($key === '0') $key = '__!YAMLZero'; |
| 978 | + $value = $this->_toType( $value ); |
| 979 | + if ( $key === '0' ) $key = '__!YAMLZero'; |
980 | 980 | $array[$key] = $value; |
981 | 981 | } else { |
982 | | - $array = array ($line); |
| 982 | + $array = array ( $line ); |
983 | 983 | } |
984 | 984 | return $array; |
985 | 985 | |
986 | 986 | } |
987 | 987 | |
988 | 988 | |
989 | | - private function returnArrayElement ($line) { |
990 | | - if (strlen($line) <= 1) return array(array()); // Weird %) |
| 989 | + private function returnArrayElement ( $line ) { |
| 990 | + if ( strlen( $line ) <= 1 ) return array( array() ); // Weird %) |
991 | 991 | $array = array(); |
992 | | - $value = trim(substr($line,1)); |
993 | | - $value = $this->_toType($value); |
| 992 | + $value = trim( substr( $line, 1 ) ); |
| 993 | + $value = $this->_toType( $value ); |
994 | 994 | $array[] = $value; |
995 | 995 | return $array; |
996 | 996 | } |
997 | 997 | |
998 | 998 | |
999 | | - private function nodeContainsGroup ($line) { |
| 999 | + private function nodeContainsGroup ( $line ) { |
1000 | 1000 | $symbolsForReference = 'A-z0-9_\-'; |
1001 | | - if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-) |
1002 | | - if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1]; |
1003 | | - if ($line[0] == '*' && preg_match('/^(\*['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1]; |
1004 | | - if (preg_match('/(&['.$symbolsForReference.']+)$/', $line, $matches)) return $matches[1]; |
1005 | | - if (preg_match('/(\*['.$symbolsForReference.']+$)/', $line, $matches)) return $matches[1]; |
1006 | | - if (preg_match ('#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches)) return $matches[1]; |
| 1001 | + if ( strpos( $line, '&' ) === false && strpos( $line, '*' ) === false ) return false; // Please die fast ;-) |
| 1002 | + if ( $line[0] == '&' && preg_match( '/^(&[' . $symbolsForReference . ']+)/', $line, $matches ) ) return $matches[1]; |
| 1003 | + if ( $line[0] == '*' && preg_match( '/^(\*[' . $symbolsForReference . ']+)/', $line, $matches ) ) return $matches[1]; |
| 1004 | + if ( preg_match( '/(&[' . $symbolsForReference . ']+)$/', $line, $matches ) ) return $matches[1]; |
| 1005 | + if ( preg_match( '/(\*[' . $symbolsForReference . ']+$)/', $line, $matches ) ) return $matches[1]; |
| 1006 | + if ( preg_match ( '#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches ) ) return $matches[1]; |
1007 | 1007 | return false; |
1008 | 1008 | |
1009 | 1009 | } |
1010 | 1010 | |
1011 | | - private function addGroup ($line, $group) { |
1012 | | - if ($group[0] == '&') $this->_containsGroupAnchor = substr ($group, 1); |
1013 | | - if ($group[0] == '*') $this->_containsGroupAlias = substr ($group, 1); |
1014 | | - //print_r ($this->path); |
| 1011 | + private function addGroup ( $line, $group ) { |
| 1012 | + if ( $group[0] == '&' ) $this->_containsGroupAnchor = substr ( $group, 1 ); |
| 1013 | + if ( $group[0] == '*' ) $this->_containsGroupAlias = substr ( $group, 1 ); |
| 1014 | + // print_r ($this->path); |
1015 | 1015 | } |
1016 | 1016 | |
1017 | | - private function stripGroup ($line, $group) { |
1018 | | - $line = trim(str_replace($group, '', $line)); |
| 1017 | + private function stripGroup ( $line, $group ) { |
| 1018 | + $line = trim( str_replace( $group, '', $line ) ); |
1019 | 1019 | return $line; |
1020 | 1020 | } |
1021 | 1021 | } |
— | — | @@ -1022,13 +1022,13 @@ |
1023 | 1023 | // Enable use of Spyc from command line |
1024 | 1024 | // The syntax is the following: php spyc.php spyc.yaml |
1025 | 1025 | |
1026 | | -define ('SPYC_FROM_COMMAND_LINE', false); |
| 1026 | +define ( 'SPYC_FROM_COMMAND_LINE', false ); |
1027 | 1027 | |
1028 | 1028 | do { |
1029 | | - if (!SPYC_FROM_COMMAND_LINE) break; |
1030 | | - if (empty ($_SERVER['argc']) || $_SERVER['argc'] < 2) break; |
1031 | | - if (empty ($_SERVER['PHP_SELF']) || $_SERVER['PHP_SELF'] != 'spyc.php') break; |
| 1029 | + if ( !SPYC_FROM_COMMAND_LINE ) break; |
| 1030 | + if ( empty ( $_SERVER['argc'] ) || $_SERVER['argc'] < 2 ) break; |
| 1031 | + if ( empty ( $_SERVER['PHP_SELF'] ) || $_SERVER['PHP_SELF'] != 'spyc.php' ) break; |
1032 | 1032 | $file = $argv[1]; |
1033 | | - printf ("Spyc loading file: %s\n", $file); |
1034 | | - print_r (spyc_load_file ($file)); |
1035 | | -} while (0); |
\ No newline at end of file |
| 1033 | + printf ( "Spyc loading file: %s\n", $file ); |
| 1034 | + print_r ( spyc_load_file ( $file ) ); |
| 1035 | +} while ( 0 ); |
\ No newline at end of file |
Index: trunk/extensions/Translate/MessageCollection.php |
— | — | @@ -333,6 +333,7 @@ |
334 | 334 | } |
335 | 335 | |
336 | 336 | $this->dbInfo = array(); // Something iterable |
| 337 | + |
337 | 338 | if ( !count( $keys ) ) { |
338 | 339 | return; |
339 | 340 | } |
Index: trunk/extensions/Translate/scripts/toolserver-export.php |
— | — | @@ -43,11 +43,19 @@ |
44 | 44 | } |
45 | 45 | |
46 | 46 | list( $key, $code ) = TranslateUtils::figureMessage( $r->page_title ); |
47 | | - if ( $key === '' ) continue; |
48 | | - if ( $code === '' ) continue; |
49 | 47 | |
| 48 | + if ( $key === '' ) { |
| 49 | + continue; |
| 50 | + } |
| 51 | + |
| 52 | + if ( $code === '' ) { |
| 53 | + continue; |
| 54 | + } |
| 55 | + |
50 | 56 | $group = @$index[strtolower( "{$r->page_namespace}:$key" )]; |
51 | | - if ( $group === null ) continue; |
| 57 | + if ( $group === null ) { |
| 58 | + continue; |
| 59 | + } |
52 | 60 | |
53 | 61 | $from = array( "\\", "\n", "\t" ); |
54 | 62 | $to = array( "\\\\", "\\\n", "\\\t" ); |
Index: trunk/extensions/Translate/scripts/messageDust.php |
— | — | @@ -19,10 +19,11 @@ |
20 | 20 | $invalid = array(); |
21 | 21 | |
22 | 22 | foreach ( $rows as $row ) { |
23 | | - |
24 | 23 | list( $key, $code ) = TranslateUtils::figureMessage( $row->page_title ); |
25 | 24 | |
26 | | - if ( !$code ) $code = 'en'; |
| 25 | + if ( !$code ) { |
| 26 | + $code = 'en'; |
| 27 | + } |
27 | 28 | |
28 | 29 | $mg = TranslateUtils::messageKeyToGroup( $row->page_namespace, $key ); |
29 | 30 | $ns = $wgContLang->getNsText( $row->page_namespace ); |
— | — | @@ -37,9 +38,13 @@ |
38 | 39 | $invalid[$code][] = "[[$ns:$key/$code]]"; |
39 | 40 | } |
40 | 41 | |
41 | | - if ( !isset( $owners[$owner] ) ) $owners[$owner] = 0; |
| 42 | + if ( !isset( $owners[$owner] ) ) { |
| 43 | + $owners[$owner] = 0; |
| 44 | + } |
| 45 | + |
42 | 46 | $owners[$owner]++; |
43 | 47 | } |
| 48 | + |
44 | 49 | $rows->free(); |
45 | 50 | |
46 | 51 | ksort( $owners ); |
Index: trunk/extensions/Translate/scripts/fuzzy.php |
— | — | @@ -31,7 +31,9 @@ |
32 | 32 | exit( 1 ); |
33 | 33 | } |
34 | 34 | |
35 | | -if ( isset( $options['help'] ) ) showUsage(); |
| 35 | +if ( isset( $options['help'] ) ) { |
| 36 | + showUsage(); |
| 37 | +} |
36 | 38 | |
37 | 39 | $bot = new FuzzyBot( $args ); |
38 | 40 | |
— | — | @@ -40,10 +42,18 @@ |
41 | 43 | $_skipLanguages = array_map( 'trim', explode( ',', $options['skiplanguages'] ) ); |
42 | 44 | $bot->skipLanguages = $_skipLanguages; |
43 | 45 | } |
44 | | -if ( isset( $options['norc'] ) ) $cs->norc = true; |
45 | | -if ( isset( $options['comment'] ) ) $bot->comment = $options['comment']; |
46 | | -if ( isset( $options['really'] ) ) $bot->dryrun = false; |
| 46 | +if ( isset( $options['norc'] ) ) { |
| 47 | + $cs->norc = true; |
| 48 | +} |
47 | 49 | |
| 50 | +if ( isset( $options['comment'] ) ) { |
| 51 | + $bot->comment = $options['comment']; |
| 52 | +} |
| 53 | + |
| 54 | +if ( isset( $options['really'] ) ) { |
| 55 | + $bot->dryrun = false; |
| 56 | +} |
| 57 | + |
48 | 58 | $bot->execute(); |
49 | 59 | |
50 | 60 | class FuzzyBot { |
— | — | @@ -127,6 +137,7 @@ |
128 | 138 | |
129 | 139 | public function getImportUser() { |
130 | 140 | static $user = null; |
| 141 | + |
131 | 142 | if ( $user === null ) { |
132 | 143 | global $wgTranslateFuzzyBotName; |
133 | 144 | $user = User::newFromName( $wgTranslateFuzzyBotName ); |
— | — | @@ -142,6 +153,7 @@ |
143 | 154 | |
144 | 155 | private function updateMessage( $title, $text, $dryrun, $comment = null ) { |
145 | 156 | global $wgTranslateDocumentationLanguageCode, $wgUser; |
| 157 | + |
146 | 158 | $oldUser = $wgUser; |
147 | 159 | $wgUser = $this->getImportUser(); |
148 | 160 | |
Index: trunk/extensions/Translate/scripts/createCheckIndex.php |
— | — | @@ -107,4 +107,3 @@ |
108 | 108 | $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ ); |
109 | 109 | } |
110 | 110 | } |
111 | | - |
Index: trunk/extensions/Translate/scripts/cli.inc |
— | — | @@ -17,8 +17,11 @@ |
18 | 18 | |
19 | 19 | function STDOUT( $str, $channel = null, $force = false ) { |
20 | 20 | global $options; |
21 | | - if ( isset($options['quiet']) &&!$force ) return; |
22 | 21 | |
| 22 | + if ( isset($options['quiet']) &&!$force ) { |
| 23 | + return; |
| 24 | + } |
| 25 | + |
23 | 26 | static $lastChannel = null; |
24 | 27 | static $lineStart = true; |
25 | 28 | |
— | — | @@ -26,10 +29,16 @@ |
27 | 30 | fwrite( STDOUT, $str ); |
28 | 31 | } elseif ( $str === false ) { |
29 | 32 | // Cleanup |
30 | | - if ( !$lineStart ) fwrite( STDOUT, "\n" ); |
| 33 | + if ( !$lineStart ) { |
| 34 | + fwrite( STDOUT, "\n" ); |
| 35 | + } |
| 36 | + |
31 | 37 | return; |
32 | 38 | } else { |
33 | | - if ( !$lineStart ) fwrite( STDOUT, "\n" ); |
| 39 | + if ( !$lineStart ) { |
| 40 | + fwrite( STDOUT, "\n" ); |
| 41 | + } |
| 42 | + |
34 | 43 | fwrite( STDOUT, $str ); |
35 | 44 | } |
36 | 45 | |
— | — | @@ -38,6 +47,7 @@ |
39 | 48 | fwrite( STDOUT, "\n" ); |
40 | 49 | $lineStart = true; |
41 | 50 | } |
| 51 | + |
42 | 52 | $lastChannel = $channel; |
43 | 53 | } |
44 | 54 | |
— | — | @@ -47,9 +57,7 @@ |
48 | 58 | |
49 | 59 | register_shutdown_function('STDOUT', false); |
50 | 60 | |
51 | | - |
52 | 61 | class Cli { |
53 | | - |
54 | 62 | public static function parseLanguageCodes( /* string */ $codes ) { |
55 | 63 | $langs = array_map( 'trim', explode( ',', $codes ) ); |
56 | 64 | if ( $langs[0] === '*' ) { |
— | — | @@ -57,6 +65,7 @@ |
58 | 66 | ksort($languages); |
59 | 67 | $langs = array_keys($languages); |
60 | 68 | } |
| 69 | + |
61 | 70 | return $langs; |
62 | 71 | } |
63 | | -} |
\ No newline at end of file |
| 72 | +} |
Index: trunk/extensions/Translate/scripts/tm-export.php |
— | — | @@ -16,7 +16,6 @@ |
17 | 17 | define( 'TRANSLATE_CLI', 1 ); |
18 | 18 | require_once( "$IP/maintenance/Maintenance.php" ); |
19 | 19 | |
20 | | - |
21 | 20 | class TMExport extends Maintenance { |
22 | 21 | public function __construct() { |
23 | 22 | parent::__construct(); |
— | — | @@ -39,7 +38,10 @@ |
40 | 39 | unset( $languages['en'] ); |
41 | 40 | |
42 | 41 | foreach ( $groups as $id => $group ) { |
43 | | - if ( $group->isMeta() ) continue; |
| 42 | + if ( $group->isMeta() ) { |
| 43 | + continue; |
| 44 | + } |
| 45 | + |
44 | 46 | $this->output( "Processing: {$group->getLabel()} ", $id ); |
45 | 47 | $capitalized = MWNamespace::isCapitalized( $group->getNamespace() ); |
46 | 48 | $ns_text = $wgContLang->getNsText( $group->getNamespace() ); |
— | — | @@ -63,7 +65,9 @@ |
64 | 66 | |
65 | 67 | $res = $dbr->select( $tables, $vars, $conds, __METHOD__ ); |
66 | 68 | // Assure that there is at least one translation |
67 | | - if ( $res->numRows() < 1 ) continue; |
| 69 | + if ( $res->numRows() < 1 ) { |
| 70 | + continue; |
| 71 | + } |
68 | 72 | |
69 | 73 | $insert = array( |
70 | 74 | 'text' => $definition, |
— | — | @@ -98,7 +102,6 @@ |
99 | 103 | $dbw->commit(); |
100 | 104 | } // each group> |
101 | 105 | } |
102 | | - |
103 | 106 | } |
104 | 107 | |
105 | 108 | $maintClass = 'TMExport'; |
Index: trunk/extensions/Translate/scripts/magic-export.php |
— | — | @@ -45,14 +45,15 @@ |
46 | 46 | exit( 1 ); |
47 | 47 | } |
48 | 48 | |
49 | | - |
50 | 49 | $langs = Cli::parseLanguageCodes( '*' ); |
51 | 50 | $groups = MessageGroups::singleton()->getGroups(); |
52 | 51 | |
53 | 52 | $type = $options['type'] ; |
54 | 53 | |
55 | 54 | foreach ( $groups as $group ) { |
56 | | - if ( !$group instanceof ExtensionMessageGroup ) continue; |
| 55 | + if ( !$group instanceof ExtensionMessageGroup ) { |
| 56 | + continue; |
| 57 | + } |
57 | 58 | |
58 | 59 | if ( $type === 'special' ) { |
59 | 60 | $filename = $group->getAliasFile(); |
— | — | @@ -60,10 +61,15 @@ |
61 | 62 | $filename = $group->getMagicFile(); |
62 | 63 | } |
63 | 64 | |
64 | | - if ( $filename === null ) continue; |
| 65 | + if ( $filename === null ) { |
| 66 | + continue; |
| 67 | + } |
65 | 68 | |
66 | 69 | $file = "$wgTranslateExtensionDirectory/$filename"; |
67 | | - if ( !file_exists( $file ) ) continue; |
| 70 | + if ( !file_exists( $file ) ) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + |
68 | 74 | STDOUT( "Processing {$group->getLabel()}... ", $group->getId() ); |
69 | 75 | |
70 | 76 | $input = file_get_contents( $file ) . "\n"; |
— | — | @@ -74,19 +80,21 @@ |
75 | 81 | |
76 | 82 | foreach ( $langs as $l ) { |
77 | 83 | switch ( $options['type'] ) { |
78 | | - case 'special': |
79 | | - $o = new SpecialPageAliasesCM( $l ); |
80 | | - break; |
81 | | - case 'magic': |
82 | | - $o = new MagicWordsCM( $l ); |
83 | | - break; |
84 | | - default: |
85 | | - STDERR( "Invalid type: must be one of: special, magic" ); |
86 | | - exit( 1 ); |
| 84 | + case 'special': |
| 85 | + $o = new SpecialPageAliasesCM( $l ); |
| 86 | + break; |
| 87 | + case 'magic': |
| 88 | + $o = new MagicWordsCM( $l ); |
| 89 | + break; |
| 90 | + default: |
| 91 | + STDERR( "Invalid type: must be one of: special, magic" ); |
| 92 | + exit( 1 ); |
87 | 93 | } |
88 | 94 | |
89 | 95 | $export = $o->export( $group->getId() ); |
90 | | - if ( $export === '' ) continue; |
| 96 | + if ( $export === '' ) { |
| 97 | + continue; |
| 98 | + } |
91 | 99 | |
92 | 100 | # remove useles comment |
93 | 101 | $export = preg_replace( "~^# .*$\n~m", '', $export ); |
Index: trunk/extensions/Translate/scripts/createMessageIndex.php |
— | — | @@ -33,4 +33,4 @@ |
34 | 34 | showUsage(); |
35 | 35 | } |
36 | 36 | |
37 | | -MessageIndexRebuilder::execute(); |
\ No newline at end of file |
| 37 | +MessageIndexRebuilder::execute(); |
Index: trunk/extensions/Translate/scripts/populateFuzzy.php |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 10 | * @file |
11 | 11 | */ |
| 12 | + |
12 | 13 | require( dirname( __FILE__ ) . '/cli.inc' ); |
13 | 14 | |
14 | 15 | $db = wfGetDB( DB_MASTER ); |
— | — | @@ -18,14 +19,12 @@ |
19 | 20 | exit(); |
20 | 21 | } |
21 | 22 | |
22 | | - |
23 | 23 | $count = $db->selectField( 'page', 'count(*)', array( 'page_namespace' => $wgTranslateMessageNamespaces ), __METHOD__ ); |
24 | 24 | if ( !$count ) { |
25 | 25 | echo "Nothing to update"; |
26 | 26 | exit(); |
27 | 27 | } |
28 | 28 | |
29 | | - |
30 | 29 | $tables = array( 'page', 'text', 'revision' ); |
31 | 30 | $fields = array( 'page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags' ); |
32 | 31 | $conds = array( |
— | — | @@ -41,7 +40,11 @@ |
42 | 41 | echo "$offset/$count\n"; |
43 | 42 | $options = array( 'LIMIT' => $limit, 'OFFSET' => $offset ); |
44 | 43 | $res = $db->select( $tables, $fields, $conds, __METHOD__, $options ); |
45 | | - if ( !$res->numRows() ) break; |
| 44 | + |
| 45 | + if ( !$res->numRows() ) { |
| 46 | + break; |
| 47 | + } |
| 48 | + |
46 | 49 | foreach ( $res as $r ) { |
47 | 50 | $text = Revision::getRevisionText( $r ); |
48 | 51 | if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) { |
— | — | @@ -52,8 +55,8 @@ |
53 | 56 | ); |
54 | 57 | } |
55 | 58 | } |
| 59 | + |
56 | 60 | $offset += $limit; |
57 | 61 | |
58 | 62 | $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ ); |
59 | 63 | } |
60 | | - |
Index: trunk/extensions/Translate/scripts/pagetranslation-test-parser.php |
— | — | @@ -17,7 +17,6 @@ |
18 | 18 | } |
19 | 19 | require_once( "$IP/maintenance/Maintenance.php" ); |
20 | 20 | |
21 | | - |
22 | 21 | class PageTranslationParserTester extends Maintenance { |
23 | 22 | public function __construct() { |
24 | 23 | parent::__construct(); |
— | — | @@ -74,11 +73,10 @@ |
75 | 74 | if ( file_exists( "$pattern.pttest" ) ) { |
76 | 75 | require( "$pattern.pttest" ); |
77 | 76 | } |
78 | | - |
79 | 77 | } |
80 | 78 | } |
81 | 79 | |
82 | 80 | } |
83 | 81 | |
84 | 82 | $maintClass = 'PageTranslationParserTester'; |
85 | | -require_once( DO_MAINTENANCE ); |
\ No newline at end of file |
| 83 | +require_once( DO_MAINTENANCE ); |
Index: trunk/extensions/Translate/scripts/sync-group.php |
— | — | @@ -32,7 +32,9 @@ |
33 | 33 | exit( 1 ); |
34 | 34 | } |
35 | 35 | |
36 | | -if ( isset( $options['help'] ) ) showUsage(); |
| 36 | +if ( isset( $options['help'] ) ) { |
| 37 | + showUsage(); |
| 38 | +} |
37 | 39 | |
38 | 40 | if ( !isset( $options['group'] ) ) { |
39 | 41 | STDERR( "ESG1: Message group id must be supplied with group parameter." ); |
— | — | @@ -91,17 +93,32 @@ |
92 | 94 | } else { |
93 | 95 | $file = $group->getMessageFileWithPath( $code ); |
94 | 96 | } |
95 | | - if ( !$file ) continue; |
96 | 97 | |
97 | | - if ( !file_exists( $file ) ) continue; |
| 98 | + if ( !$file ) { |
| 99 | + continue; |
| 100 | + } |
98 | 101 | |
| 102 | + if ( !file_exists( $file ) ) { |
| 103 | + continue; |
| 104 | + } |
| 105 | + |
99 | 106 | $cs = new ChangeSyncer( $group ); |
100 | | - if ( isset( $options['norc'] ) ) $cs->norc = true; |
101 | | - if ( isset( $options['noask'] ) ) $cs->interactive = false; |
102 | | - if ( isset( $options['nocolor'] ) ) $cs->nocolor = true; |
| 107 | + if ( isset( $options['norc'] ) ) { |
| 108 | + $cs->norc = true; |
| 109 | + } |
103 | 110 | |
| 111 | + if ( isset( $options['noask'] ) ) { |
| 112 | + $cs->interactive = false; |
| 113 | + } |
| 114 | + |
| 115 | + if ( isset( $options['nocolor'] ) ) { |
| 116 | + $cs->nocolor = true; |
| 117 | + } |
| 118 | + |
104 | 119 | $ts = $cs->getTimestampsFromSvn( $file ); |
105 | | - if ( !$ts ) $ts = $cs->getTimestampsFromFs( $file ); |
| 120 | + if ( !$ts ) { |
| 121 | + $ts = $cs->getTimestampsFromFs( $file ); |
| 122 | + } |
106 | 123 | |
107 | 124 | STDOUT( "Modify time for $code: " . wfTimestamp( TS_ISO_8601, $ts ) ); |
108 | 125 | |
— | — | @@ -126,8 +143,10 @@ |
127 | 144 | $file = escapeshellarg( $file ); |
128 | 145 | $retval = 0; |
129 | 146 | $output = wfShellExec( "svn info $file 2>/dev/null", $retval ); |
130 | | - if ( $retval ) return false; |
131 | 147 | |
| 148 | + if ( $retval ) { |
| 149 | + return false; |
| 150 | + } |
132 | 151 | |
133 | 152 | $matches = array(); |
134 | 153 | // PHP doesn't allow foo || return false; |
— | — | @@ -136,21 +155,30 @@ |
137 | 156 | // PHP (for being an ass)! |
138 | 157 | $regex = '^Last Changed Date: (.*) \('; |
139 | 158 | $ok = preg_match( "~$regex~m", $output, $matches ); |
140 | | - if ( $ok ) return strtotime( $matches[1] ); |
| 159 | + if ( $ok ) { |
| 160 | + return strtotime( $matches[1] ); |
| 161 | + } |
141 | 162 | |
142 | 163 | return false; |
143 | 164 | } |
144 | 165 | |
145 | 166 | public function getTimestampsFromFs( $file ) { |
146 | | - if ( !file_exists( $file ) ) return false; |
| 167 | + if ( !file_exists( $file ) ) { |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
147 | 171 | $stat = stat( $file ); |
| 172 | + |
148 | 173 | return $stat['mtime']; |
149 | 174 | } |
150 | 175 | |
151 | 176 | public function checkConflicts( $code, $startTs = false, $endTs = false, $changeTs = false ) { |
152 | 177 | $messages = $this->group->load( $code ); |
153 | | - if ( !count( $messages ) ) return; |
154 | 178 | |
| 179 | + if ( !count( $messages ) ) { |
| 180 | + return; |
| 181 | + } |
| 182 | + |
155 | 183 | $collection = $this->group->initCollection( $code ); |
156 | 184 | $collection->filter( 'ignored' ); |
157 | 185 | $collection->loadTranslations(); |
— | — | @@ -178,7 +206,9 @@ |
179 | 207 | |
180 | 208 | $current = str_replace( TRANSLATE_FUZZY, '', $collection[$key]->translation() ); |
181 | 209 | $translation = str_replace( TRANSLATE_FUZZY, '', $translation ); |
182 | | - if ( $translation === $current ) continue; |
| 210 | + if ( $translation === $current ) { |
| 211 | + continue; |
| 212 | + } |
183 | 213 | |
184 | 214 | STDOUT( "Conflict in " . $this->color( 'bold', $page ) . "!", $page ); |
185 | 215 | |
— | — | @@ -228,7 +258,10 @@ |
229 | 259 | |
230 | 260 | } |
231 | 261 | |
232 | | - if ( !$this->interactive ) continue; |
| 262 | + if ( !$this->interactive ) { |
| 263 | + continue; |
| 264 | + } |
| 265 | + |
233 | 266 | STDOUT( " →Needs manual resolution", $page ); |
234 | 267 | STDOUT( "Source translation at $changeDate:" ); |
235 | 268 | STDOUT( $this->color( 'blue', $translation ) . "\n" ); |
— | — | @@ -239,11 +272,16 @@ |
240 | 273 | STDOUT( "Resolution: [S]kip [I]mport [C]onflict: ", 'foo' ); |
241 | 274 | $action = fgets( STDIN ); |
242 | 275 | $action = strtoupper( trim( $action ) ); |
243 | | - if ( $action === 'S' ) break; |
| 276 | + |
| 277 | + if ( $action === 'S' ) { |
| 278 | + break; |
| 279 | + } |
| 280 | + |
244 | 281 | if ( $action === 'I' ) { |
245 | 282 | $this->import( $title, $translation, 'Updating translation from external source' ); |
246 | 283 | break; |
247 | 284 | } |
| 285 | + |
248 | 286 | if ( $action === 'C' ) { |
249 | 287 | $this->import( $title, TRANSLATE_FUZZY . $translation, 'Edit conflict between wiki and source' ); |
250 | 288 | break; |
— | — | @@ -272,7 +310,9 @@ |
273 | 311 | $revision = Revision::newFromTitle( $title ); |
274 | 312 | while ( $revision ) { |
275 | 313 | // No need to go back further |
276 | | - if ( $startTs && $wikiTs && ( $wikiTs < $startTs ) ) break; |
| 314 | + if ( $startTs && $wikiTs && ( $wikiTs < $startTs ) ) { |
| 315 | + break; |
| 316 | + } |
277 | 317 | |
278 | 318 | if ( $revision->getRawUserText() === $wgTranslateFuzzyBotName ) { |
279 | 319 | $revision = $revision->getPrevious(); |
— | — | @@ -288,8 +328,10 @@ |
289 | 329 | |
290 | 330 | public function getImportUser() { |
291 | 331 | static $user = null; |
| 332 | + |
292 | 333 | if ( $user === null ) { |
293 | 334 | global $wgTranslateFuzzyBotName; |
| 335 | + |
294 | 336 | $user = User::newFromName( $wgTranslateFuzzyBotName ); |
295 | 337 | |
296 | 338 | if ( !$user->isLoggedIn() ) { |
— | — | @@ -303,11 +345,14 @@ |
304 | 346 | |
305 | 347 | public function import( $title, $translation, $comment ) { |
306 | 348 | global $wgUser; |
| 349 | + |
307 | 350 | $old = $wgUser; |
308 | 351 | $wgUser = $this->getImportUser(); |
309 | 352 | |
310 | 353 | $flags = EDIT_FORCE_BOT; |
311 | | - if ( $this->norc ) $flags |= EDIT_SUPPRESS_RC; |
| 354 | + if ( $this->norc ) { |
| 355 | + $flags |= EDIT_SUPPRESS_RC; |
| 356 | + } |
312 | 357 | |
313 | 358 | $article = new Article( $title ); |
314 | 359 | STDOUT( "Importing {$title->getPrefixedText()}: ", $title ); |
Index: trunk/extensions/Translate/scripts/groupStatistics.php |
— | — | @@ -174,7 +174,9 @@ |
175 | 175 | showUsage(); |
176 | 176 | } |
177 | 177 | |
178 | | -if ( !isset( $options['output'] ) ) $options['output'] = 'default'; |
| 178 | +if ( !isset( $options['output'] ) ) { |
| 179 | + $options['output'] = 'default'; |
| 180 | +} |
179 | 181 | |
180 | 182 | /** Print a usage message*/ |
181 | 183 | function showUsage() { |
— | — | @@ -250,6 +252,7 @@ |
251 | 253 | if ( isset( $options['most'] ) && isset( $localisedWeights[$options['most']] ) ) { |
252 | 254 | $reportScore = true; |
253 | 255 | $weights = array(); |
| 256 | + |
254 | 257 | foreach ( $localisedWeights[$options['most']] as $weight ) { |
255 | 258 | $weights[] = $weight; |
256 | 259 | } |
Index: trunk/extensions/Translate/scripts/alias-export.php |
— | — | @@ -49,7 +49,10 @@ |
50 | 50 | $groups = MessageGroups::singleton()->getGroups(); |
51 | 51 | |
52 | 52 | foreach ( $groups as $group ) { |
53 | | - if ( !$group instanceof ExtensionMessageGroup ) continue; |
| 53 | + if ( !$group instanceof ExtensionMessageGroup ) { |
| 54 | + continue; |
| 55 | + } |
| 56 | + |
54 | 57 | $file = $group->getAliasFile(); |
55 | 58 | |
56 | 59 | $groupId = $group->getId(); |
— | — | @@ -58,6 +61,7 @@ |
59 | 62 | // Fake a group |
60 | 63 | $group = new AliasMessageGroup( $group->getId() ); |
61 | 64 | $group->setMessageFile( $file ); |
| 65 | + |
62 | 66 | // FIXME: getVariableNameAlias() is not read from mediawiki-defines.txt here apparently. |
63 | 67 | // Hacked this one exception in for now |
64 | 68 | if ( $groupId == 'ext-wikilog' ) { |
Index: trunk/extensions/Translate/scripts/languageeditstats.php |
— | — | @@ -69,6 +69,7 @@ |
70 | 70 | $pos = strrpos( $text, '/' ); |
71 | 71 | $code = substr( $text, $pos + 1 ); |
72 | 72 | $key = substr( $text, 0, $pos ); |
| 73 | + |
73 | 74 | return array( $key, $code ); |
74 | 75 | } |
75 | 76 | |
— | — | @@ -82,11 +83,16 @@ |
83 | 84 | $codes = array(); |
84 | 85 | foreach ( $rows as $_ ) { |
85 | 86 | // Filter out edits by $wgTranslateFuzzyBotName |
86 | | - if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) continue; |
| 87 | + if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) { |
| 88 | + continue; |
| 89 | + } |
87 | 90 | |
88 | 91 | list( , $code ) = figureMessage( $_->rc_title ); |
89 | 92 | |
90 | | - if ( !isset( $codes[$code] ) ) $codes[$code] = 0; |
| 93 | + if ( !isset( $codes[$code] ) ) { |
| 94 | + $codes[$code] = 0; |
| 95 | + } |
| 96 | + |
91 | 97 | $codes[$code]++; |
92 | 98 | } |
93 | 99 | |
— | — | @@ -95,6 +101,9 @@ |
96 | 102 | arsort( $codes ); |
97 | 103 | $i = 0; |
98 | 104 | foreach ( $codes as $code => $num ) { |
99 | | - if ( $i++ === $top ) break; |
| 105 | + if ( $i++ === $top ) { |
| 106 | + break; |
| 107 | + } |
| 108 | + |
100 | 109 | STDOUT( "$code\t$num" ); |
101 | 110 | } |
Index: trunk/extensions/Translate/scripts/poimport.php |
— | — | @@ -27,7 +27,10 @@ |
28 | 28 | exit( 1 ); |
29 | 29 | } |
30 | 30 | |
31 | | -if ( isset( $options['help'] ) ) showUsage(); |
| 31 | +if ( isset( $options['help'] ) ) { |
| 32 | + showUsage(); |
| 33 | +} |
| 34 | + |
32 | 35 | if ( !isset( $options['file'] ) ) { |
33 | 36 | STDERR( "You need to specify input file" ); |
34 | 37 | exit( 1 ); |
— | — | @@ -60,7 +63,6 @@ |
61 | 64 | * supported. |
62 | 65 | */ |
63 | 66 | class PoImporter { |
64 | | - |
65 | 67 | /** |
66 | 68 | * Path to file to parse. |
67 | 69 | */ |
— | — | @@ -125,8 +127,11 @@ |
126 | 128 | if ( preg_match( "/^msgctxt\s($poformat)/mx", $section, $matches ) ) { |
127 | 129 | // Remove quoting |
128 | 130 | $key = preg_replace( $quotePattern, '', $matches[1] ); |
| 131 | + |
129 | 132 | // Ignore unknown keys |
130 | | - if ( !isset( $contents[$key] ) ) continue; |
| 133 | + if ( !isset( $contents[$key] ) ) { |
| 134 | + continue; |
| 135 | + } |
131 | 136 | } else { |
132 | 137 | continue; |
133 | 138 | } |
— | — | @@ -163,9 +168,7 @@ |
164 | 169 | } |
165 | 170 | |
166 | 171 | return array( $changes, $groupId ); |
167 | | - |
168 | 172 | } |
169 | | - |
170 | 173 | } |
171 | 174 | |
172 | 175 | /** |
— | — | @@ -223,6 +226,7 @@ |
224 | 227 | */ |
225 | 228 | private function updateMessage( $namespace, $title, $text ) { |
226 | 229 | global $wgTitle, $wgArticle; |
| 230 | + |
227 | 231 | $wgTitle = Title::makeTitleSafe( $namespace, $title ); |
228 | 232 | |
229 | 233 | STDOUT( "Updating {$wgTitle->getPrefixedText()}... ", $title ); |
Index: trunk/extensions/Translate/scripts/autoexport.php |
— | — | @@ -78,9 +78,9 @@ |
79 | 79 | $threshold = false; |
80 | 80 | } |
81 | 81 | |
82 | | - |
83 | 82 | $rows = TranslateUtils::translationChanges( $hours, true ); |
84 | 83 | $exports = array(); |
| 84 | + |
85 | 85 | foreach ( $rows as $row ) { |
86 | 86 | $group = false; |
87 | 87 | $code = false; |
— | — | @@ -89,11 +89,14 @@ |
90 | 90 | list( $pieces, ) = explode( '/', $wgContLang->lcfirst( $row->rc_title ), 2 ); |
91 | 91 | |
92 | 92 | $mg = TranslateUtils::messageKeyToGroup( $row->rc_namespace, $pieces ); |
93 | | - if ( !is_null( $mg ) ) $group = $mg; |
| 93 | + if ( !is_null( $mg ) ) { |
| 94 | + $group = $mg; |
| 95 | + } |
94 | 96 | |
95 | 97 | if ( strpos( $row->rc_title, '/' ) !== false ) { |
96 | 98 | $code = $row->lang; |
97 | 99 | } |
| 100 | + |
98 | 101 | if ( $group && ( !count( $groupsFilter ) || in_array( $group, $groupsFilter ) ) ) { |
99 | 102 | if ( $code && !in_array( $code, $skip ) ) { |
100 | 103 | $exports[$group][$code] = true; |
— | — | @@ -109,7 +112,9 @@ |
110 | 113 | sort( $languages ); |
111 | 114 | $languages = checkThreshold( $group, $languages, $threshold ); |
112 | 115 | |
113 | | - if ( !count( $languages ) ) continue; |
| 116 | + if ( !count( $languages ) ) { |
| 117 | + continue; |
| 118 | + } |
114 | 119 | |
115 | 120 | $languagelist = implode( ', ', $languages ); |
116 | 121 | STDOUT( str_replace( |
— | — | @@ -120,6 +125,7 @@ |
121 | 126 | if ( $summarize ) { |
122 | 127 | list( $group, ) = explode( '-', $group, 2 ); |
123 | 128 | } |
| 129 | + |
124 | 130 | if ( isset( $notice[$group] ) ) { |
125 | 131 | $notice[$group] = array_merge( $notice[$group], $languages ); |
126 | 132 | } else { |
— | — | @@ -128,7 +134,10 @@ |
129 | 135 | } |
130 | 136 | |
131 | 137 | function checkThreshold( $group, $languages, $threshold ) { |
132 | | - if ( $threshold === false ) return $languages; |
| 138 | + if ( $threshold === false ) { |
| 139 | + return $languages; |
| 140 | + } |
| 141 | + |
133 | 142 | $qualify = array(); |
134 | 143 | |
135 | 144 | $g = MessageGroups::singleton()->getGroup( $group ); |
— | — | @@ -143,10 +152,12 @@ |
144 | 153 | $collection->filter( 'translated', false ); |
145 | 154 | $translated = count( $collection ); |
146 | 155 | |
147 | | - if ( $translated / $total > $threshold / 100 ) $qualify[] = $code; |
| 156 | + if ( $translated / $total > $threshold / 100 ) { |
| 157 | + $qualify[] = $code; |
| 158 | + } |
148 | 159 | } |
| 160 | + |
149 | 161 | return $qualify; |
150 | | - |
151 | 162 | } |
152 | 163 | |
153 | 164 | foreach ( $notice as $group => $languages ) { |
Index: trunk/extensions/Translate/scripts/mwcore-export.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | STDERR( "You need to specify target directory" ); |
37 | 37 | exit( 1 ); |
38 | 38 | } |
| 39 | + |
39 | 40 | if ( !isset( $options['lang'] ) ) { |
40 | 41 | STDERR( "You need to specify languages to export" ); |
41 | 42 | exit( 1 ); |
— | — | @@ -55,30 +56,33 @@ |
56 | 57 | $group = MessageGroups::getGroup( 'core' ); |
57 | 58 | |
58 | 59 | foreach ( $langs as $l ) { |
59 | | - |
60 | 60 | $o = null; |
61 | 61 | switch ( $options['type'] ) { |
62 | | - case 'special': |
63 | | - $o = new SpecialPageAliasesCM( $l ); |
64 | | - break; |
65 | | - case 'magic': |
66 | | - $o = new MagicWordsCM( $l ); |
67 | | - break; |
68 | | - case 'namespace': |
69 | | - $o = new NamespaceCM( $l ); |
70 | | - break; |
71 | | - default: |
72 | | - STDERR( "Invalid type: must be one of special, magic, namespace" ); |
73 | | - exit( 1 ); |
| 62 | + case 'special': |
| 63 | + $o = new SpecialPageAliasesCM( $l ); |
| 64 | + break; |
| 65 | + case 'magic': |
| 66 | + $o = new MagicWordsCM( $l ); |
| 67 | + break; |
| 68 | + case 'namespace': |
| 69 | + $o = new NamespaceCM( $l ); |
| 70 | + break; |
| 71 | + default: |
| 72 | + STDERR( "Invalid type: must be one of special, magic, namespace" ); |
| 73 | + exit( 1 ); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $export = $o->export( 'core' ); |
77 | | - if ( $export === '' ) continue; |
| 77 | + if ( $export === '' ) { |
| 78 | + continue; |
| 79 | + } |
78 | 80 | |
79 | 81 | $matches = array(); |
80 | 82 | preg_match( '~^(\$[a-zA-Z]+)\s*=~m', $export, $matches ); |
81 | 83 | |
82 | | - if ( !isset( $matches[1] ) ) continue; |
| 84 | + if ( !isset( $matches[1] ) ) { |
| 85 | + continue; |
| 86 | + } |
83 | 87 | |
84 | 88 | # remove useles comment |
85 | 89 | $export = preg_replace( "~^# .*$\n~m", '', $export ); |
— | — | @@ -120,4 +124,4 @@ |
121 | 125 | |
122 | 126 | file_put_contents( $outFile, $data ); |
123 | 127 | } |
124 | | -} |
\ No newline at end of file |
| 128 | +} |
Index: trunk/extensions/Translate/MessageChecks.php |
— | — | @@ -79,13 +79,19 @@ |
80 | 80 | public function checkMessage( TMessage $message, $code ) { |
81 | 81 | $warningsArray = array(); |
82 | 82 | $messages = array( $message ); |
| 83 | + |
83 | 84 | foreach ( $this->checks as $check ) { |
84 | 85 | call_user_func_array( $check, array( $messages, $code, &$warningsArray ) ); |
85 | 86 | } |
| 87 | + |
86 | 88 | $warningsArray = $this->filterWarnings( $warningsArray ); |
87 | | - if ( !count( $warningsArray ) ) return array(); |
| 89 | + if ( !count( $warningsArray ) ) { |
| 90 | + return array(); |
| 91 | + } |
| 92 | + |
88 | 93 | $warnings = $warningsArray[$message->key()]; |
89 | 94 | $warnings = $this->fixMessageParams( $warnings ); |
| 95 | + |
90 | 96 | return $warnings; |
91 | 97 | } |
92 | 98 | |
— | — | @@ -98,7 +104,9 @@ |
99 | 105 | $messages = array( $message ); |
100 | 106 | foreach ( $this->checks as $check ) { |
101 | 107 | call_user_func_array( $check, array( $messages, $code, &$warningsArray ) ); |
102 | | - if ( count( $warningsArray ) ) return true; |
| 108 | + if ( count( $warningsArray ) ) { |
| 109 | + return true; |
| 110 | + } |
103 | 111 | } |
104 | 112 | |
105 | 113 | return false; |
— | — | @@ -116,11 +124,12 @@ |
117 | 125 | foreach ( $warnings as $wkey => $warning ) { |
118 | 126 | $check = array_shift( $warning ); |
119 | 127 | foreach ( self::$globalBlacklist as $pattern ) { |
120 | | - if ( !$this->match( $pattern['group'], $groupId ) ) continue; |
121 | | - if ( !$this->match( $pattern['check'], $check[0] ) ) continue; |
| 128 | + if ( !$this->match( $pattern['group'], $groupId ) ) continue; |
| 129 | + if ( !$this->match( $pattern['check'], $check[0] ) ) continue; |
122 | 130 | if ( !$this->match( $pattern['subcheck'], $check[1] ) ) continue; |
123 | | - if ( !$this->match( $pattern['message'], $check[2] ) ) continue; |
124 | | - if ( !$this->match( $pattern['code'], $check[3] ) ) continue; |
| 131 | + if ( !$this->match( $pattern['message'], $check[2] ) ) continue; |
| 132 | + if ( !$this->match( $pattern['code'], $check[3] ) ) continue; |
| 133 | + |
125 | 134 | unset( $warningsArray[$mkey][$wkey] ); |
126 | 135 | } |
127 | 136 | } |
Index: trunk/extensions/Translate/tests/pagetranslation/FailDoubleOpen.ptfile |
— | — | @@ -1,3 +1,3 @@ |
2 | 2 | <translate> |
3 | 3 | <translate> |
4 | | -</translate> |
\ No newline at end of file |
| 4 | +</translate> |
Index: trunk/extensions/Translate/tests/pagetranslation/Simple.pttest |
— | — | @@ -1,4 +1,3 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
5 | | - |
Index: trunk/extensions/Translate/tests/pagetranslation/FailNotAtomic.ptfile |
— | — | @@ -2,4 +2,4 @@ |
3 | 3 | <translate> |
4 | 4 | This is not fun! |
5 | 5 | </div> |
6 | | -</translate> |
\ No newline at end of file |
| 6 | +</translate> |
Index: trunk/extensions/Translate/tests/pagetranslation/NowikiOnly.pttest |
— | — | @@ -4,4 +4,4 @@ |
5 | 5 | |
6 | 6 | if ( $parse->countSections() !== 0 ) { |
7 | 7 | $this->output( "Testfile $filename failed misc tests... number of sections should be zero" ); |
8 | | -} |
\ No newline at end of file |
| 8 | +} |
Index: trunk/extensions/Translate/tests/pagetranslation/FailSectionMarkerPlace.ptfile |
— | — | @@ -1,3 +1,3 @@ |
2 | 2 | <translate> |
3 | 3 | Once upon time <!--T:1--> there was a planet called meow. |
4 | | -</translate> |
\ No newline at end of file |
| 4 | +</translate> |
Index: trunk/extensions/Translate/tests/pagetranslation/FailTags2.ptfile |
— | — | @@ -7,4 +7,4 @@ |
8 | 8 | <translate> |
9 | 9 | Cow |
10 | 10 | </translate> |
11 | | -</translate> |
\ No newline at end of file |
| 11 | +</translate> |
Index: trunk/extensions/Translate/tests/pagetranslation/FailEmptySection.ptfile |
— | — | @@ -1,4 +1,4 @@ |
2 | 2 | <translate> |
3 | 3 | <!--T:1--> |
4 | 4 | |
5 | | -</translate> |
\ No newline at end of file |
| 5 | +</translate> |
Index: trunk/extensions/Translate/FFS.php |
— | — | @@ -232,7 +232,6 @@ |
233 | 233 | // |
234 | 234 | // READ |
235 | 235 | // |
236 | | - |
237 | 236 | public function readFromVariable( $data ) { |
238 | 237 | $data = self::fixNewLines( $data ); |
239 | 238 | $lines = array_map( 'ltrim', explode( "\n", $data ) ); |
Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -93,6 +93,7 @@ |
94 | 94 | $messages = $reader->parseMessages( $this->mangler ); |
95 | 95 | return $messages ? $messages : array(); |
96 | 96 | } |
| 97 | + |
97 | 98 | return array(); |
98 | 99 | } |
99 | 100 | |
— | — | @@ -107,6 +108,7 @@ |
108 | 109 | if ( !is_array( $defs ) ) { |
109 | 110 | throw new MWException( "Unable to load definitions for " . $this->getLabel() ); |
110 | 111 | } |
| 112 | + |
111 | 113 | return $defs; |
112 | 114 | } |
113 | 115 | |
— | — | @@ -132,16 +134,21 @@ |
133 | 135 | $this->messages[$code] = self::normaliseKeys( $this->load( $code ) ); |
134 | 136 | } |
135 | 137 | $key = strtolower( str_replace( ' ', '_', $key ) ); |
| 138 | + |
136 | 139 | return isset( $this->messages[$code][$key] ) ? $this->messages[$code][$key] : null; |
137 | 140 | } |
138 | 141 | |
139 | 142 | public static function normaliseKeys( $array ) { |
140 | | - if ( !is_array( $array ) ) return null; |
| 143 | + if ( !is_array( $array ) ) { |
| 144 | + return null; |
| 145 | + } |
| 146 | + |
141 | 147 | $new = array(); |
142 | 148 | foreach ( $array as $key => $v ) { |
143 | 149 | $key = strtolower( str_replace( ' ', '_', $key ) ); |
144 | 150 | $new[$key] = $v; |
145 | 151 | } |
| 152 | + |
146 | 153 | return $new; |
147 | 154 | } |
148 | 155 | |
— | — | @@ -273,11 +280,13 @@ |
274 | 281 | |
275 | 282 | return $ourDefs; |
276 | 283 | } |
| 284 | + |
277 | 285 | return $this->getDefinitions(); |
278 | 286 | } |
279 | 287 | |
280 | 288 | public function getMessageFile( $code ) { |
281 | 289 | $code = ucfirst( str_replace( '-', '_', $code ) ); |
| 290 | + |
282 | 291 | return "Messages$code.php"; |
283 | 292 | } |
284 | 293 | |
— | — | @@ -295,6 +304,7 @@ |
296 | 305 | |
297 | 306 | public function getBools() { |
298 | 307 | require( $this->getMetaDataPrefix() . '/messageTypes.inc' ); |
| 308 | + |
299 | 309 | return array( |
300 | 310 | 'optional' => $this->mangler->mangle( $wgOptionalMessages ), |
301 | 311 | 'ignored' => $this->mangler->mangle( $wgIgnoredMessages ), |
— | — | @@ -462,7 +472,6 @@ |
463 | 473 | |
464 | 474 | public function getMagicFile() { return $this->magicFile; } |
465 | 475 | public function setMagicFile( $file ) { $this->magicFile = $file; } |
466 | | - |
467 | 476 | } |
468 | 477 | |
469 | 478 | class AliasMessageGroup extends ExtensionMessageGroup { |
— | — | @@ -538,6 +547,7 @@ |
539 | 548 | $writer = new WikiExtensionFormatWriter( $this ); |
540 | 549 | $writer->variableName = $this->getVariableName(); |
541 | 550 | $writer->commaToArray = true; |
| 551 | + |
542 | 552 | return $writer; |
543 | 553 | } |
544 | 554 | } |
— | — | @@ -626,7 +636,6 @@ |
627 | 637 | return $group; |
628 | 638 | } |
629 | 639 | |
630 | | - |
631 | 640 | public function getReader( $code ) { |
632 | 641 | $reader = new GettextFormatReader( $this->getMessageFileWithPath( $code ) ); |
633 | 642 | $reader->setPrefix( $this->prefix ); |
— | — | @@ -712,7 +721,6 @@ |
713 | 722 | |
714 | 723 | $this->title = $title; |
715 | 724 | $this->namespaces = array( NS_TRANSLATIONS, NS_TRANSLATIONS_TALK ); |
716 | | - |
717 | 725 | } |
718 | 726 | |
719 | 727 | public function getDefinitions() { |
— | — | @@ -858,6 +866,7 @@ |
859 | 867 | self::init(); |
860 | 868 | |
861 | 869 | global $wgTranslateEC, $wgTranslateAC, $wgTranslateCC; |
| 870 | + |
862 | 871 | if ( in_array( $id, $wgTranslateEC ) ) { |
863 | 872 | $creater = $wgTranslateAC[$id]; |
864 | 873 | if ( is_array( $creater ) ) { |
— | — | @@ -884,6 +893,7 @@ |
885 | 894 | public $classes = array(); |
886 | 895 | private function __construct() { |
887 | 896 | self::init(); |
| 897 | + |
888 | 898 | global $wgTranslateEC, $wgTranslateCC; |
889 | 899 | |
890 | 900 | $all = array_merge( $wgTranslateEC, array_keys( $wgTranslateCC ) ); |
Index: trunk/extensions/Translate/Message.php |
— | — | @@ -85,4 +85,4 @@ |
86 | 86 | public function infile() { |
87 | 87 | return $this->infile; |
88 | 88 | } |
89 | | -} |
\ No newline at end of file |
| 89 | +} |
Index: trunk/extensions/Translate/tag/TPParse.php |
— | — | @@ -67,6 +67,7 @@ |
68 | 68 | } |
69 | 69 | |
70 | 70 | } |
| 71 | + |
71 | 72 | return $sections; |
72 | 73 | } |
73 | 74 | |
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | // Only called form hook |
36 | 36 | public static function injectCss( $outputpage, $text ) { |
37 | 37 | TranslateUtils::injectCSS(); |
| 38 | + |
38 | 39 | return true; |
39 | 40 | } |
40 | 41 | |
— | — | @@ -324,6 +325,7 @@ |
325 | 326 | // No group means that the page is currently not |
326 | 327 | // registered to any page translation message groups |
327 | 328 | $result = array( 'tpt-unknown-page' ); |
| 329 | + |
328 | 330 | return false; |
329 | 331 | } |
330 | 332 | |
— | — | @@ -344,6 +346,7 @@ |
345 | 347 | $page->getTitle()->getPrefixedText(), |
346 | 348 | $page->getTranslationUrl( $code ) |
347 | 349 | ); |
| 350 | + |
348 | 351 | return false; |
349 | 352 | } |
350 | 353 | } |
— | — | @@ -439,6 +442,7 @@ |
440 | 443 | ) . Html::element( 'hr' ); |
441 | 444 | |
442 | 445 | global $wgOut; |
| 446 | + |
443 | 447 | $wgOut->addHTML( $legend ); |
444 | 448 | } |
445 | 449 | |
— | — | @@ -469,6 +473,7 @@ |
470 | 474 | $wrap = '<div style="font-size: x-small; text-align: center" class="mw-translate-fuzzy">$1</div>'; |
471 | 475 | $wgOut->wrapWikiMsg( $wrap, array( 'tpt-translation-intro-fuzzy' ) ); |
472 | 476 | } |
| 477 | + |
473 | 478 | $wgOut->addHTML( '<hr />' ); |
474 | 479 | } |
475 | 480 | |
Index: trunk/extensions/Translate/tag/TPSection.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | * @copyright Copyright © 2009 Niklas Laxström |
8 | 8 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
9 | 9 | */ |
| 10 | + |
10 | 11 | class TPSection { |
11 | 12 | public $id, $name, $text, $type; |
12 | 13 | |
Index: trunk/extensions/Translate/tag/TranslatablePage.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * Class to parse translatable wiki pages. |
6 | 5 | * |
— | — | @@ -7,6 +6,7 @@ |
8 | 7 | * @copyright Copyright © 2009-2010 Niklas Laxström |
9 | 8 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 9 | */ |
| 10 | + |
11 | 11 | class TranslatablePage { |
12 | 12 | /** |
13 | 13 | * Title of the page. |
— | — | @@ -49,6 +49,7 @@ |
50 | 50 | $obj = new self( $title ); |
51 | 51 | $obj->text = $text; |
52 | 52 | $obj->source = 'text'; |
| 53 | + |
53 | 54 | return $obj; |
54 | 55 | } |
55 | 56 | |
— | — | @@ -67,6 +68,7 @@ |
68 | 69 | $obj = new self( $title ); |
69 | 70 | $obj->source = 'revision'; |
70 | 71 | $obj->revision = $revision; |
| 72 | + |
71 | 73 | return $obj; |
72 | 74 | } |
73 | 75 | |
— | — | @@ -77,6 +79,7 @@ |
78 | 80 | public static function newFromTitle( Title $title ) { |
79 | 81 | $obj = new self( $title ); |
80 | 82 | $obj->source = 'title'; |
| 83 | + |
81 | 84 | return $obj; |
82 | 85 | } |
83 | 86 | |
— | — | @@ -406,6 +409,7 @@ |
407 | 410 | 'group' => 'page|' . $this->getTitle()->getPrefixedText(), |
408 | 411 | 'task' => 'view' |
409 | 412 | ); |
| 413 | + |
410 | 414 | if ( $code ) { |
411 | 415 | $params['language'] = $code; |
412 | 416 | } |
— | — | @@ -452,6 +456,7 @@ |
453 | 457 | public function getTranslationPercentages( $force = false ) { |
454 | 458 | // Check the memory cache, as this is very slow to calculate |
455 | 459 | global $wgMemc, $wgRequest; |
| 460 | + |
456 | 461 | $memcKey = wfMemcKey( 'pt', 'status', $this->getTitle()->getPrefixedText() ); |
457 | 462 | $cache = $wgMemc->get( $memcKey ); |
458 | 463 | |
— | — | @@ -483,6 +488,7 @@ |
484 | 489 | |
485 | 490 | // Content language is always up-to-date |
486 | 491 | global $wgContLang; |
| 492 | + |
487 | 493 | $temp[$wgContLang->getCode()] = 1.00; |
488 | 494 | |
489 | 495 | $wgMemc->set( $memcKey, $temp, 60 * 60 * 12 ); |
— | — | @@ -554,6 +560,7 @@ |
555 | 561 | } |
556 | 562 | |
557 | 563 | global $wgTranslateStaticTags; |
| 564 | + |
558 | 565 | if ( is_array( $wgTranslateStaticTags ) ) { |
559 | 566 | return $wgTranslateStaticTags[$tag]; |
560 | 567 | } |
— | — | @@ -610,6 +617,7 @@ |
611 | 618 | */ |
612 | 619 | class TPException extends MWException { |
613 | 620 | protected $msg = null; |
| 621 | + |
614 | 622 | public function __construct( $msg ) { |
615 | 623 | $this->msg = $msg; |
616 | 624 | parent::__construct( call_user_func_array( 'wfMsg', $msg ) ); |
Index: trunk/extensions/Translate/tag/RenderJob.php |
— | — | @@ -57,6 +57,7 @@ |
58 | 58 | |
59 | 59 | // User hack |
60 | 60 | global $wgUser; |
| 61 | + |
61 | 62 | $oldUser = $wgUser; |
62 | 63 | $wgUser = $user; |
63 | 64 | |
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php |
— | — | @@ -38,18 +38,21 @@ |
39 | 39 | // Check permissions |
40 | 40 | if ( !$this->user->isAllowed( 'pagetranslation' ) ) { |
41 | 41 | $wgOut->permissionRequired( 'pagetranslation' ); |
| 42 | + |
42 | 43 | return; |
43 | 44 | } |
44 | 45 | |
45 | 46 | // Check permissions |
46 | 47 | if ( !$this->user->matchEditToken( $wgRequest->getText( 'token' ) ) ) { |
47 | 48 | $wgOut->permissionRequired( 'pagetranslation' ); |
| 49 | + |
48 | 50 | return; |
49 | 51 | } |
50 | 52 | |
51 | 53 | // We are processing some specific page |
52 | 54 | if ( !$title->exists() ) { |
53 | 55 | $wgOut->addWikiMsg( 'tpt-nosuchpage', $title->getPrefixedText() ); |
| 56 | + |
54 | 57 | return; |
55 | 58 | } |
56 | 59 | |
— | — | @@ -57,6 +60,7 @@ |
58 | 61 | $page = TranslatablePage::newFromTitle( $title ); |
59 | 62 | $page->removeTags(); |
60 | 63 | $wgOut->addWikiMsg( 'tpt-unmarked', $title->getPrefixedText() ); |
| 64 | + |
61 | 65 | return; |
62 | 66 | } |
63 | 67 | |
— | — | @@ -68,12 +72,14 @@ |
69 | 73 | $page = TranslatablePage::newFromRevision( $title, $revision ); |
70 | 74 | if ( !$page instanceof TranslatablePage ) { |
71 | 75 | $wgOut->addWikiMsg( 'tpt-notsuitable', $title->getPrefixedText(), $revision ); |
| 76 | + |
72 | 77 | return; |
73 | 78 | } |
74 | 79 | |
75 | 80 | if ( $revision !== $title->getLatestRevID() ) { |
76 | 81 | // We do want to notify the reviewer if the underlying page changes during review |
77 | 82 | $wgOut->addWikiMsg( 'tpt-oldrevision', $title->getPrefixedText(), $revision ); |
| 83 | + |
78 | 84 | return; |
79 | 85 | } |
80 | 86 | |
— | — | @@ -81,6 +87,7 @@ |
82 | 88 | if ( $lastrev !== false && $lastrev === $revision ) { |
83 | 89 | $wgOut->addWikiMsg( 'tpt-already-marked' ); |
84 | 90 | $this->listPages(); |
| 91 | + |
85 | 92 | return; |
86 | 93 | } |
87 | 94 | |
— | — | @@ -282,6 +289,7 @@ |
283 | 290 | } |
284 | 291 | |
285 | 292 | global $wgLang; |
| 293 | + |
286 | 294 | return $wgLang->semicolonList( $actions ); |
287 | 295 | } |
288 | 296 | |
— | — | @@ -443,7 +451,10 @@ |
444 | 452 | $changed = array(); |
445 | 453 | |
446 | 454 | foreach ( $sections as $s ) { |
447 | | - if ( $s->type === 'changed' ) $changed[] = $s->name; |
| 455 | + if ( $s->type === 'changed' ) { |
| 456 | + $changed[] = $s->name; |
| 457 | + } |
| 458 | + |
448 | 459 | $inserts[] = array( |
449 | 460 | 'trs_page' => $page->getTitle()->getArticleId(), |
450 | 461 | 'trs_key' => $s->name, |