r67087 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67086‎ | r67087 | r67088 >
Date:16:55, 30 May 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Ran stylize.php, removed trailing whitespace, updated indentation and code formatting.
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)
  • /trunk/extensions/Translate/Message.php (modified) (history)
  • /trunk/extensions/Translate/MessageChecks.php (modified) (history)
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/ffs/Gettext.php (modified) (history)
  • /trunk/extensions/Translate/ffs/Java.php (modified) (history)
  • /trunk/extensions/Translate/ffs/OpenLayers.php (modified) (history)
  • /trunk/extensions/Translate/ffs/PhpVariables.php (modified) (history)
  • /trunk/extensions/Translate/ffs/Simple.php (modified) (history)
  • /trunk/extensions/Translate/ffs/Wiki.php (modified) (history)
  • /trunk/extensions/Translate/ffs/WikiExtension.php (modified) (history)
  • /trunk/extensions/Translate/ffs/Xliff.php (modified) (history)
  • /trunk/extensions/Translate/scripts/alias-export.php (modified) (history)
  • /trunk/extensions/Translate/scripts/autoexport.php (modified) (history)
  • /trunk/extensions/Translate/scripts/cli.inc (modified) (history)
  • /trunk/extensions/Translate/scripts/createCheckIndex.php (modified) (history)
  • /trunk/extensions/Translate/scripts/createMessageIndex.php (modified) (history)
  • /trunk/extensions/Translate/scripts/fuzzy.php (modified) (history)
  • /trunk/extensions/Translate/scripts/groupStatistics.php (modified) (history)
  • /trunk/extensions/Translate/scripts/languageeditstats.php (modified) (history)
  • /trunk/extensions/Translate/scripts/magic-export.php (modified) (history)
  • /trunk/extensions/Translate/scripts/messageDust.php (modified) (history)
  • /trunk/extensions/Translate/scripts/mwcore-export.php (modified) (history)
  • /trunk/extensions/Translate/scripts/pagetranslation-test-parser.php (modified) (history)
  • /trunk/extensions/Translate/scripts/poimport.php (modified) (history)
  • /trunk/extensions/Translate/scripts/populateFuzzy.php (modified) (history)
  • /trunk/extensions/Translate/scripts/sync-group.php (modified) (history)
  • /trunk/extensions/Translate/scripts/tm-export.php (modified) (history)
  • /trunk/extensions/Translate/scripts/toolserver-export.php (modified) (history)
  • /trunk/extensions/Translate/spyc/spyc.php (modified) (history)
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/RenderJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/tag/TPParse.php (modified) (history)
  • /trunk/extensions/Translate/tag/TPSection.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)
  • /trunk/extensions/Translate/tests/pagetranslation/FailDoubleOpen.ptfile (modified) (history)
  • /trunk/extensions/Translate/tests/pagetranslation/FailEmptySection.ptfile (modified) (history)
  • /trunk/extensions/Translate/tests/pagetranslation/FailNotAtomic.ptfile (modified) (history)
  • /trunk/extensions/Translate/tests/pagetranslation/FailSectionMarkerPlace.ptfile (modified) (history)
  • /trunk/extensions/Translate/tests/pagetranslation/FailTags2.ptfile (modified) (history)
  • /trunk/extensions/Translate/tests/pagetranslation/NowikiOnly.pttest (modified) (history)
  • /trunk/extensions/Translate/tests/pagetranslation/Simple.pttest (modified) (history)
  • /trunk/extensions/Translate/utils/Font.php (modified) (history)
  • /trunk/extensions/Translate/utils/HTMLJsSelectToInputField.php (modified) (history)
  • /trunk/extensions/Translate/utils/Html.php (modified) (history)
  • /trunk/extensions/Translate/utils/JsSelectToInput.js (modified) (history)
  • /trunk/extensions/Translate/utils/JsSelectToInput.php (modified) (history)
  • /trunk/extensions/Translate/utils/MemProfile.php (modified) (history)
  • /trunk/extensions/Translate/utils/MemoryCache.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageGroupCache.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageIndexRebuilder.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageTable.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageWebImporter.php (modified) (history)
  • /trunk/extensions/Translate/utils/ResourceLoader.php (modified) (history)
  • /trunk/extensions/Translate/utils/StringMatcher.php (modified) (history)
  • /trunk/extensions/Translate/utils/ToolBox.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslateYaml.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationEditPage.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationMemoryUpdater.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationStats.php (modified) (history)
  • /trunk/extensions/Translate/utils/UserToggles.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslateYaml.php
@@ -1,8 +1,9 @@
22 <?php
 3+
34 class TranslateYaml {
4 -
55 public static function loadString( $text ) {
66 global $wgTranslateYamlLibrary;
 7+
78 switch ( $wgTranslateYamlLibrary ) {
89 case 'spyc':
910 require_once( dirname( __FILE__ ) . '/../spyc/spyc.php' );
@@ -16,11 +17,13 @@
1718
1819 public static function load( $file ) {
1920 $text = file_get_contents( $file );
 21+
2022 return self::loadString( $text );
2123 }
2224
2325 public static function dump( $text ) {
2426 global $wgTranslateYamlLibrary;
 27+
2528 switch ( $wgTranslateYamlLibrary ) {
2629 case 'spyc':
2730 require_once( dirname( __FILE__ ) . '/../spyc/spyc.php' );
@@ -47,7 +50,9 @@
4851 'print $fh serialize($yaml);' .
4952 'close($fh);' .
5053 "' 2>&1";
 54+
5155 $out = wfShellExec( $cmd, &$ret );
 56+
5257 if ( $ret != 0 ) {
5358 wfDebugDieBacktrace( "The command '$cmd' died in execution with exit code '$ret': $out" );
5459 }
@@ -57,7 +62,7 @@
5863
5964 unlink( $tf );
6065 unlink( "$tf.serialized" );
61 -
 66+
6267 return $php_data;
6368 }
6469
@@ -99,7 +104,7 @@
100105
101106 unlink( $tf );
102107 unlink( "$tf.yaml" );
103 -
 108+
104109 return $yaml;
105110 }
106111 }
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -17,7 +17,7 @@
1818 protected function init() {
1919 $title = $this->title;
2020 list( $page, $code ) = self::figureMessage( $title );
21 -
 21+
2222 $this->page = $page;
2323 $this->targetLanguage = $code;
2424 $this->group = self::getMessageGroup( $title->getNamespace(), $page );
@@ -26,6 +26,7 @@
2727 public static function figureMessage( Title $title ) {
2828 $text = $title->getDBkey();
2929 $pos = strrpos( $text, '/' );
 30+
3031 if ( $pos === false ) {
3132 $code = '';
3233 $key = $text;
@@ -33,6 +34,7 @@
3435 $code = substr( $text, $pos + 1 );
3536 $key = substr( $text, 0, $pos );
3637 }
 38+
3739 return array( $key, $code );
3840 }
3941
@@ -46,6 +48,7 @@
4749 */
4850 protected static function getMessageGroup( $namespace, $key ) {
4951 global $wgRequest;
 52+
5053 $group = $wgRequest->getText( 'loadgroup', '' );
5154 $mg = MessageGroups::getGroup( $group );
5255
@@ -69,14 +72,23 @@
7073 }
7174
7275 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+
7584 $this->definition = $this->group->getMessage( $this->page, 'en' );
 85+
7686 return $this->definition;
7787 }
7888
7989 public function getTranslation() {
80 - if ( $this->translation !== null ) return $this->translation;
 90+ if ( $this->translation !== null ) {
 91+ return $this->translation;
 92+ }
8193
8294 // Shorter names
8395 $page = $this->page;
@@ -99,7 +111,9 @@
100112 // Nothing to prefil
101113 $translation = '';
102114 }
 115+
103116 $this->translation = $translation;
 117+
104118 return $translation;
105119 }
106120
@@ -119,12 +133,20 @@
120134 'definition' => array( $this, 'getDefinitionBox' ),
121135 'check' => array( $this, 'getCheckBox' ),
122136 );
123 - if ( $types !== null ) foreach ( $types as $type ) unset( $all[$type] );
124137
 138+ if ( $types !== null ) {
 139+ foreach ( $types as $type ) {
 140+ unset( $all[$type] );
 141+ }
 142+ }
 143+
125144 $boxes = array();
126145 foreach ( $all as $type => $cb ) {
127146 $box = call_user_func( $cb );
128 - if ( $box ) $boxes[$type] = $box;
 147+
 148+ if ( $box ) {
 149+ $boxes[$type] = $box;
 150+ }
129151 }
130152
131153 if ( count( $boxes ) ) {
@@ -141,12 +163,22 @@
142164 protected function getTmBox() {
143165 global $wgTranslateTM;
144166
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+ }
148170
 171+ if ( !$this->targetLanguage ) {
 172+ return null;
 173+ }
 174+
 175+ if ( strval( $this->getDefinition() ) === '' ) {
 176+ return null;
 177+ }
 178+
149179 $serviceName = 'tmserver';
150 - if ( self::checkTranslationServiceFailure( $serviceName ) ) return null;
 180+ if ( self::checkTranslationServiceFailure( $serviceName ) ) {
 181+ return null;
 182+ }
151183
152184 // Needed data
153185 $code = $this->targetLanguage;
@@ -167,9 +199,12 @@
168200
169201 if ( $suggestions !== false ) {
170202 $suggestions = FormatJson::decode( $suggestions, true );
 203+
171204 foreach ( $suggestions as $s ) {
172205 // 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+ }
174209
175210 $accuracy = wfMsgHtml( 'translate-edit-tmmatch' , sprintf( '%.2f', $s['quality'] ) );
176211 $legend = array( $accuracy => array() );
@@ -192,7 +227,11 @@
193228 foreach ( $sugFields as $field ) {
194229 list( $text, $params, $label ) = $field;
195230 $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+
197236 $legend = implode( ' | ', $legend );
198237 $boxes[] = Html::rawElement( 'div', $params, self::legend( $legend ) . $text . self::clear() ) . "\n";
199238 }
@@ -208,13 +247,20 @@
209248 protected function getSuggestionBox() {
210249 $boxes = (array) $this->getTmBox();
211250 $google = $this->getGoogleSuggestion();
212 - if ( $google ) $boxes[] = $google;
 251+
 252+ if ( $google ) {
 253+ $boxes[] = $google;
 254+ }
 255+
213256 $apertium = $this->getApertiumSuggestion();
214 - if ( $apertium ) $boxes[] = $apertium;
 257+ if ( $apertium ) {
 258+ $boxes[] = $apertium;
 259+ }
215260
216261 // Enclose if there is more than one box
217262 if ( count( $boxes ) ) {
218263 $sep = Html::element( 'hr', array( 'class' => 'mw-translate-sep' ) );
 264+
219265 return TranslateUtils::fieldset( wfMsgHtml( 'translate-edit-tmsugs' ),
220266 implode( "$sep\n", $boxes ), array( 'class' => 'mw-translate-edit-tmsugs' ) );
221267 } else {
@@ -226,7 +272,9 @@
227273 global $wgProxyKey, $wgGoogleApiKey, $wgMemc;
228274
229275 $serviceName = 'Google';
230 - if ( self::checkTranslationServiceFailure( $serviceName ) ) return null;
 276+ if ( self::checkTranslationServiceFailure( $serviceName ) ) {
 277+ return null;
 278+ }
231279
232280 $code = $this->targetLanguage;
233281 $definition = trim( strval( $this->getDefinition() ) ) ;
@@ -234,11 +282,19 @@
235283 $memckey = wfMemckey( 'translate-tmsug-badcodes' );
236284 $unsupported = $wgMemc->get( $memckey );
237285
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+
240294 /* 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+ }
243299
244300 $path = 'http://ajax.googleapis.com/ajax/services/language/translate';
245301 $options = array();
@@ -250,8 +306,11 @@
251307 // Unique but not identifiable
252308 'userip' => sha1( $wgProxyKey . wfGetIp() ),
253309 );
254 - if ( $wgGoogleApiKey ) $options['postData']['key'] = $wgGoogleApiKey;
255310
 311+ if ( $wgGoogleApiKey ) {
 312+ $options['postData']['key'] = $wgGoogleApiKey;
 313+ }
 314+
256315 $google_json = Http::post( $path, $options );
257316 $response = FormatJson::decode( $google_json );
258317
@@ -259,14 +318,18 @@
260319 wfWarn( __METHOD__ . ': Http::get failed' );
261320 // Most likely a timeout or other general error
262321 self::reportTranslationSerficeFailure( $serviceName );
 322+
263323 return null;
264324 } elseif ( !is_object( $response ) ) {
265325 wfWarn( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) );
266326 error_log( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) );
 327+
267328 return null;
268329 }
 330+
269331 if ( $response->responseStatus === 200 ) {
270332 $text = $this->suggestionField( Sanitizer::decodeCharReferences( $response->responseData->translatedText ) );
 333+
271334 return Html::rawElement( 'div', null, self::legend( 'Google' ) . $text . self::clear() );
272335 } elseif ( $response->responseDetails === 'invalid translation language pair' ) {
273336 $unsupported[$code] = true;
@@ -276,6 +339,7 @@
277340 self::reportTranslationSerficeFailure( $serviceName );
278341 wfWarn( __METHOD__ . ': ' . $response->responseDetails );
279342 error_log( __METHOD__ . ': ' . $response->responseDetails );
 343+
280344 return null;
281345 }
282346 }
@@ -283,9 +347,14 @@
284348 protected function getApertiumSuggestion() {
285349 global $wgTranslateApertium, $wgMemc;
286350
287 - if ( !$wgTranslateApertium ) return null;
 351+ if ( !$wgTranslateApertium ) {
 352+ return null;
 353+ }
 354+
288355 $serviceName = 'Apertium';
289 - if ( self::checkTranslationServiceFailure( $serviceName ) ) return null;
 356+ if ( self::checkTranslationServiceFailure( $serviceName ) ) {
 357+ return null;
 358+ }
290359
291360 $page = $this->page;
292361 $code = $this->targetLanguage;
@@ -297,17 +366,33 @@
298367 if ( !$pairs ) {
299368 $pairs = array();
300369 $pairlist = Http::get( $wgTranslateApertium, 5 );
301 - if ( $pairlist === false ) return null;
 370+
 371+ if ( $pairlist === false ) {
 372+ return null;
 373+ }
 374+
302375 $pairlist = trim( Sanitizer::stripAllTags( $pairlist ) );
303376 $pairlist = explode( " ", $pairlist );
 377+
304378 foreach ( $pairlist as $pair ) {
305379 $pair = trim( $pair );
306 - if ( $pair === '' ) continue;
 380+
 381+ if ( $pair === '' ) {
 382+ continue;
 383+ }
 384+
307385 $languages = explode( '-', $pair );
308 - if ( count( $languages ) !== 2 ) continue;
309386
 387+ if ( count( $languages ) !== 2 ) {
 388+ continue;
 389+ }
 390+
310391 list( $source, $target ) = $languages;
311 - if ( !isset( $pairs[$target] ) ) $pairs[$target] = array();
 392+
 393+ if ( !isset( $pairs[$target] ) ) {
 394+ $pairs[$target] = array();
 395+ }
 396+
312397 $pairs[$target][$source] = true;
313398 }
314399
@@ -315,22 +400,36 @@
316401 }
317402
318403 $codemap = array( 'no' => 'nb' );
319 - if ( isset( $codemap[$code] ) ) $code = $codemap[$code];
 404+
 405+ if ( isset( $codemap[$code] ) ) {
 406+ $code = $codemap[$code];
 407+ }
 408+
320409 $code = str_replace( '-', '_', wfBCP47( $code ) );
321410
322 - if ( !isset( $pairs[$code] ) ) return;
 411+ if ( !isset( $pairs[$code] ) ) {
 412+ return;
 413+ }
323414
324415 $suggestions = array();
325416
326417 $codemap = array_flip( $codemap );
327418 foreach ( $pairs[$code] as $candidate => $unused ) {
328419 $mwcode = str_replace( '_', '-', strtolower( $candidate ) );
329 - if ( isset( $codemap[$mwcode] ) ) $mwcode = $codemap[$mwcode];
330420
 421+ if ( isset( $codemap[$mwcode] ) ) {
 422+ $mwcode = $codemap[$mwcode];
 423+ }
 424+
331425 $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+
333430 $title = Title::makeTitleSafe( $ns, "$page/$mwcode" );
334 - if ( $title && TranslateEditAddons::isFuzzy( $title ) ) continue;
 431+ if ( $title && TranslateEditAddons::isFuzzy( $title ) ) {
 432+ continue;
 433+ }
335434
336435 $query = array(
337436 'mark' => 0,
@@ -347,15 +446,22 @@
348447 $suggestions[] = Html::rawElement( 'div', null, self::legend( "Apertium ($candidate)" ) . $response . self::clear() );
349448 }
350449 }
351 - if ( !count( $suggestions ) ) return null;
 450+
 451+ if ( !count( $suggestions ) ) {
 452+ return null;
 453+ }
 454+
352455 return implode( "\n", $suggestions );
353456 }
354457
355458 protected function getDefinitionBox() {
356459 $en = $this->getDefinition();
357 - if ( $en === null ) return null;
 460+ if ( $en === null ) {
 461+ return null;
 462+ }
358463
359464 global $wgUser;
 465+
360466 $label = " ()";
361467 $title = $wgUser->getSkin()->link(
362468 SpecialPage::getTitleFor( 'Translate' ),
@@ -378,32 +484,44 @@
379485 );
380486
381487 $class = array( 'class' => 'mw-sp-translate-edit-definition mw-translate-edit-definition' );
 488+
382489 return TranslateUtils::fieldset( $label, $msg, $class );
383490 }
384491
385492 protected function getCheckBox() {
386493 global $wgTranslateDocumentationLanguageCode;
387 - if ( $this->group === null ) return;
388494
 495+ if ( $this->group === null ) {
 496+ return;
 497+ }
 498+
389499 $page = $this->page;
390500 $translation = $this->getTranslation();
391501 $code = $this->targetLanguage;
392502 $en = $this->getDefinition();
393503
394 - if ( strval( $translation ) === '' ) return null;
395 - if ( $code === $wgTranslateDocumentationLanguageCode ) return null;
 504+ if ( strval( $translation ) === '' ) {
 505+ return null;
 506+ }
396507
 508+ if ( $code === $wgTranslateDocumentationLanguageCode ) {
 509+ return null;
 510+ }
 511+
397512 $checker = $this->group->getChecker();
398 - if ( !$checker ) return null;
 513+ if ( !$checker ) {
 514+ return null;
 515+ }
399516
400517 $message = new FatMessage( $page, $en );
401518 // Take the contents from edit field as a translation
402519 $message->setTranslation( $translation );
403520
404521 $checks = $checker->checkMessage( $message, $code );
405 - if ( !count( $checks ) ) return null;
 522+ if ( !count( $checks ) ) {
 523+ return null;
 524+ }
406525
407 -
408526 $checkMessages = array();
409527 foreach ( $checks as $checkParams ) {
410528 array_splice( $checkParams, 1, 0, 'parseinline' );
@@ -426,7 +544,9 @@
427545 $boxes = array();
428546 foreach ( self::getFallbacks( $code ) as $fbcode ) {
429547 $text = TranslateUtils::getMessageContent( $page, $fbcode, $ns );
430 - if ( $text === null ) continue;
 548+ if ( $text === null ) {
 549+ continue;
 550+ }
431551
432552 $label =
433553 TranslateUtils::getLanguageName( $fbcode, false, $wgLang->getCode() ) .
@@ -445,6 +565,7 @@
446566
447567 if ( count( $boxes ) ) {
448568 $sep = Html::element( 'hr', array( 'class' => 'mw-translate-sep' ) );
 569+
449570 return TranslateUtils::fieldset( wfMsgHtml( 'translate-edit-in-other-languages' , $page ),
450571 implode( "$sep\n", $boxes ), array( 'class' => 'mw-sp-translate-edit-inother' ) );
451572 }
@@ -459,7 +580,10 @@
460581 public function getDocumentationBox() {
461582 global $wgTranslateDocumentationLanguageCode, $wgUser, $wgOut;
462583
463 - if ( !$wgTranslateDocumentationLanguageCode ) return null;
 584+ if ( !$wgTranslateDocumentationLanguageCode ) {
 585+ return null;
 586+ }
 587+
464588 $page = $this->page;
465589 $ns = $this->title->getNamespace();
466590
@@ -468,6 +592,7 @@
469593 $info = TranslateUtils::getMessageContent( $page, $wgTranslateDocumentationLanguageCode, $ns );
470594
471595 $class = 'mw-sp-translate-edit-info';
 596+
472597 if ( $info === null ) {
473598 $info = wfMsg( 'translate-edit-no-information' );
474599 $class = 'mw-sp-translate-edit-noinfo';
@@ -477,6 +602,7 @@
478603 $reader = $this->group->getReader( 'en' );
479604 if ( $reader ) {
480605 global $wgContLang;
 606+
481607 $mykey = $wgContLang->lcfirst( $this->page );
482608 $data = $reader->parseFile();
483609 $help = GettextFormatWriter::formatcomments( @$data[$mykey]['comments'], false, @$data[$mykey]['flags'] );
@@ -489,6 +615,7 @@
490616 $contents = $wgOut->parse( $info );
491617 // Remove whatever block element wrapup the parser likes to add
492618 $contents = preg_replace( '~^<([a-z]+)>(.*)</\1>$~us', '\2', $contents );
 619+
493620 return TranslateUtils::fieldset(
494621 wfMsgHtml( 'translate-edit-information', $edit , $page ), $contents, array( 'class' => $class )
495622 );
@@ -496,7 +623,9 @@
497624 }
498625
499626 protected function getPageDiff() {
500 - if ( $this->group instanceof WikiPageMessageGroup ) return null;
 627+ if ( $this->group instanceof WikiPageMessageGroup ) {
 628+ return null;
 629+ }
501630
502631 // Shortcuts
503632 $code = $this->targetLanguage;
@@ -518,26 +647,38 @@
519648 );
520649
521650 $latestRevision = $definitionTitle->getLatestRevID();
 651+
522652 $translationRevision = $db->selectField( 'revtag', 'rt_value', $conds, __METHOD__ );
523 - if ( $translationRevision === false ) return null;
 653+ if ( $translationRevision === false ) {
 654+ return null;
 655+ }
524656
525657 $oldtext = Revision::newFromTitle( $definitionTitle, $translationRevision )->getText();
526658 $newtext = Revision::newFromTitle( $definitionTitle, $latestRevision )->getText();
527659
528 - if ( $oldtext === $newtext ) return null;
 660+ if ( $oldtext === $newtext ) {
 661+ return null;
 662+ }
529663
530664 $diff = new DifferenceEngine;
531665 $diff->setText( $oldtext, $newtext );
532666 $diff->setReducedLineNumbers();
533667 $diff->showDiffStyle();
 668+
534669 return $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) );
535670 }
536671
537672 protected function getTranslationPageDiff() {
538673 global $wgEnablePageTranslation;
539 - if ( !$wgEnablePageTranslation ) return null;
540 - if ( !$this->group instanceof WikiPageMessageGroup ) return null;
541674
 675+ if ( !$wgEnablePageTranslation ) {
 676+ return null;
 677+ }
 678+
 679+ if ( !$this->group instanceof WikiPageMessageGroup ) {
 680+ return null;
 681+ }
 682+
542683 // Shortcuts
543684 $code = $this->targetLanguage;
544685 $key = $this->page;
@@ -546,7 +687,9 @@
547688 $page = TranslatablePage::newFromTitle( $this->group->title );
548689 $rev = $page->getTransRev( "$key/$code" );
549690 $latest = $page->getMarkedTag();
550 - if ( $rev === $latest ) return null;
 691+ if ( $rev === $latest ) {
 692+ return null;
 693+ }
551694
552695 $oldpage = TranslatablePage::newFromRevision( $this->group->title, $rev );
553696 $oldtext = $newtext = null;
@@ -562,12 +705,15 @@
563706 }
564707 }
565708
566 - if ( $oldtext === $newtext ) return null;
 709+ if ( $oldtext === $newtext ) {
 710+ return null;
 711+ }
567712
568713 $diff = new DifferenceEngine;
569714 $diff->setText( $oldtext, $newtext );
570715 $diff->setReducedLineNumbers();
571716 $diff->showDiffStyle();
 717+
572718 return $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) );
573719 }
574720
@@ -586,7 +732,12 @@
587733 $preference = $wgUser->getOption( 'translate-editlangs' );
588734 if ( $preference !== 'default' ) {
589735 $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+
591742 return $fallbacks;
592743 }
593744
@@ -622,6 +773,7 @@
623774 } else {
624775 $attributes['class'] = 'mw-sp-translate-edit-committed';
625776 }
 777+
626778 if ( mb_strlen( $msg ) < 100 && !$title ) {
627779 $attributes['class'] = 'mw-sp-translate-in-other-small';
628780 }
@@ -650,14 +802,17 @@
651803 'onclick' => "jQuery('#$target').val(jQuery('#$source').text()).focus(); return false;",
652804 'href' => '#'
653805 );
 806+
654807 return Html::element( 'a', $params, '↓' );
655808 }
656809
657810 public function suggestionField( $contents ) {
658811 static $counter = 0;
 812+
659813 $counter++;
660814 $id = "tmsug-" . wfTimestamp() . "-$counter";
661815 $contents = TranslateUtils::convertWhiteSpaceToHTML( $contents );
 816+
662817 return $this->adder( $id ) . "\n" . Html::rawElement( 'span', array( 'id' => $id ), $contents );
663818 }
664819
@@ -696,7 +851,9 @@
697852 * Checks whether the given service has exceeded failure count */
698853 public static function checkTranslationServiceFailure( $service ) {
699854 global $wgMemc;
 855+
700856 $key = wfMemckey( "translate-service-$service" );
 857+
701858 // Both false and null are converted to zero, which is desirable
702859 return intval( $wgMemc->get( $key ) ) >= self::$serviceFailureCount;
703860 }
@@ -705,12 +862,14 @@
706863 * Increases the failure count for a given service */
707864 public static function reportTranslationSerficeFailure( $service ) {
708865 global $wgMemc;
 866+
709867 $key = wfMemckey( "translate-service-$service" );
710868 // Both false and null are converted to zero, which is desirable.
711869 /* FIXME: not atomic, but the default incr() implemention seems to
712870 * ignore expiry time */
713871 $count = intval( $wgMemc->get( $key ) );
714872 $wgMemc->set( $key, $count + 1, self::$serviceFailurePeriod );
 873+
715874 /* By using >= we expose if something is still increasing failure
716875 * count if we are over the limit */
717876 if ( $count + 1 >= self::$serviceFailureCount ) {
Index: trunk/extensions/Translate/utils/JsSelectToInput.js
@@ -1,11 +1,11 @@
22 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 @@
2323
2424 public function getKeys( $code = 'en' ) {
2525 $cache = $this->open( $code );
 26+
2627 return unserialize( $cache->get( $this->specialKey( 'keys' ) ) );
2728 }
2829
2930 public function getTimestamp( $code = 'en' ) {
3031 $cache = $this->open( $code );
 32+
3133 return $cache->get( $this->specialKey( 'timestamp' ) );
3234 }
3335
3436 public function get( $key, $code = 'en' ) {
3537 $cache = $this->open( $code );
 38+
3639 return $cache->get( $key );
3740 }
3841
@@ -53,19 +56,23 @@
5457
5558 protected function open( $code ) {
5659 if ( $code !== $this->code || !$this->cache ) {
57 - if ( $this->cache ) $this->cache->close();
 60+ if ( $this->cache ) {
 61+ $this->cache->close();
 62+ }
 63+
5864 $this->cache = CdbReader::open( $this->getCacheFileName( $code ) );
5965 }
 66+
6067 return $this->cache;
6168 }
6269
6370 protected function getCacheFileName( $code ) {
6471 global $wgCacheDirectory;
 72+
6573 return "$wgCacheDirectory/translate_groupcache-{$this->group}-$code.cdb";
6674 }
6775
6876 protected function specialKey( $key ) {
6977 return "<|$key#>";
7078 }
71 -
72 -}
\ No newline at end of file
 79+}
Index: trunk/extensions/Translate/utils/ToolBox.php
@@ -1,5 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
54 class TranslateToolbox {
65 /**
Index: trunk/extensions/Translate/utils/HTMLJsSelectToInputField.php
@@ -3,37 +3,51 @@
44 class HTMLJsSelectToInputField extends HTMLTextField {
55 function getInputHTML( $value ) {
66 $input = parent::getInputHTML( $value );
 7+
78 if ( isset( $this->mParams['select'] ) ) {
89 $input .= ' ' . $this->mParams['select']->getHtmlAndPrepareJs();
910 }
 11+
1012 return $input;
1113 }
1214
1315 function tidy( $value ) {
1416 $value = array_map( 'trim', explode( ',', $value ) );
1517 $value = array_unique( array_filter( $value ) );
 18+
1619 return $value;
1720 }
1821
1922 function validate( $value, $alldata ) {
2023 $p = parent::validate( $value, $alldata );
21 - if ( $p !== true ) return $p;
2224
23 - if ( !isset( $this->mParams['valid-values'] ) ) return true;
 25+ if ( $p !== true ) {
 26+ return $p;
 27+ }
2428
25 - if ( $value === 'default' ) return true;
 29+ if ( !isset( $this->mParams['valid-values'] ) ) {
 30+ return true;
 31+ }
2632
 33+ if ( $value === 'default' ) {
 34+ return true;
 35+ }
 36+
2737 $codes = $this->tidy( $value );
2838 $valid = array_flip( $this->mParams['valid-values'] );
 39+
2940 foreach ( $codes as $code ) {
30 - if ( !isset( $valid[$code] ) )
 41+ if ( !isset( $valid[$code] ) ) {
3142 return wfMsgExt( 'translate-pref-editassistlang-bad', 'parse', $code );
 43+ }
3244 }
 45+
3346 return true;
3447 }
3548
3649 function filter( $value, $alldata ) {
3750 $value = parent::filter( $value, $alldata );
 51+
3852 return implode( ', ', $this->tidy( $value ) );
3953 }
40 -}
\ No newline at end of file
 54+}
Index: trunk/extensions/Translate/utils/MemoryCache.php
@@ -9,7 +9,9 @@
1010 public function __construct( $table ) {
1111 $this->table = $table;
1212 $this->key = wfMemcKey( $this->table );
 13+
1314 global $wgMemc;
 15+
1416 $this->memc = $wgMemc;
1517 }
1618
@@ -19,22 +21,34 @@
2022
2123 public function get( $group, $code ) {
2224 $this->load();
23 - if ( !isset( $this->cache[$group][$code] ) ) return false;
 25+
 26+ if ( !isset( $this->cache[$group][$code] ) ) {
 27+ return false;
 28+ }
 29+
2430 return explode( ',', $this->cache[$group][$code] );
2531 }
2632
2733 public function set( $group, $code, $value ) {
2834 $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+
3040 $this->cache[$group][$code] = implode( ',', $value );
3141 }
3242
3343 public function clear( $group, $code ) {
3444 $this->load();
35 - if ( isset( $this->cache[$group][$code] ) )
 45+
 46+ if ( isset( $this->cache[$group][$code] ) ) {
3647 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] ) ) {
3851 unset( $this->cache[$group] );
 52+ }
3953 }
4054
4155 public function commit() {
@@ -45,7 +59,10 @@
4660 protected function load() {
4761 if ( $this->cache === null ) {
4862 $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+ }
5067 }
5168 }
5269
@@ -54,4 +71,4 @@
5572 $this->memc->set( $this->key, $this->cache );
5673 }
5774 }
58 -}
\ No newline at end of file
 75+}
Index: trunk/extensions/Translate/utils/MessageTable.php
@@ -6,8 +6,8 @@
77 * @copyright Copyright © 2007-2009 Niklas Laxström
88 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
99 */
 10+
1011 class MessageTable {
11 -
1212 protected $reviewMode = false;
1313 protected $collection = null;
1414 protected $group = null;
@@ -39,17 +39,24 @@
4040 }
4141
4242 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+
4447 $this->headers[$type] = array( 'msg', $value );
4548 }
4649
4750 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+
4955 $this->headers[$type] = array( 'raw', htmlspecialchars( $value ) );
5056 }
5157
5258 public function includeAssets() {
5359 global $wgOut, $wgScript;
 60+
5461 // Our class
5562 $wgOut->addScriptFile( TranslateUtils::assetPath( 'js/quickedit.js' ) );
5663
@@ -82,7 +89,6 @@
8390 $diff->showDiffStyle();
8491 }
8592
86 -
8793 public function header() {
8894 $tableheader = Xml::openElement( 'table', array(
8995 'class' => 'mw-sp-translate-table'
@@ -112,15 +118,18 @@
113119
114120 public function contents() {
115121 global $wgUser;
 122+
116123 $sk = $wgUser->getSkin();
117124
118125 $optional = wfMsgHtml( 'translate-optional' );
119126
120127 $batch = new LinkBatch();
121128 $ns = $this->group->getNamespace();
 129+
122130 foreach ( $this->collection->keys() as $key ) {
123131 $batch->add( $ns, $key );
124132 }
 133+
125134 $batch->execute();
126135
127136 $output = '';
@@ -139,6 +148,7 @@
140149 }
141150
142151 global $wgLang;
 152+
143153 $niceTitle = htmlspecialchars( $wgLang->truncate( $key, - 30 ) );
144154
145155 $tools['edit'] = $sk->link(
@@ -153,7 +163,9 @@
154164 $anchor = Xml::element( 'a', array( 'id' => $anchor, 'href' => "#$anchor" ), "↓" );
155165
156166 $extra = '';
157 - if ( $m->hasTag( 'optional' ) ) $extra = '<br />' . $optional;
 167+ if ( $m->hasTag( 'optional' ) ) {
 168+ $extra = '<br />' . $optional;
 169+ }
158170
159171 $leftColumn = $anchor . $tools['edit'] . $extra;
160172
@@ -173,7 +185,6 @@
174186 Xml::tags( 'td', $rclasses, TranslateUtils::convertWhiteSpaceToHTML( $message ) )
175187 );
176188 }
177 -
178189 }
179190
180191 return $output;
@@ -181,13 +192,14 @@
182193
183194 public function fullTable() {
184195 $this->includeAssets();
 196+
185197 return $this->header() . $this->contents() . '</table>';
186198 }
187199
188 -
189 -
190200 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+ }
192204
193205 list( $format, $value ) = $this->headers[$type];
194206 if ( $format === 'msg' ) {
@@ -202,7 +214,7 @@
203215 protected function keyToTitle( $key ) {
204216 $titleText = TranslateUtils::title( $key, $this->collection->code );
205217 $namespace = $this->group->getNamespace();
 218+
206219 return Title::makeTitle( $namespace, $titleText );
207220 }
208 -
209 -}
\ No newline at end of file
 221+}
Index: trunk/extensions/Translate/utils/JsSelectToInput.php
@@ -1,6 +1,5 @@
22 <?php
33
4 -
54 class JsSelectToInput {
65 protected $targetId, $sourceId;
76 protected $select;
@@ -40,15 +39,16 @@
4140 if ( is_callable( array( $select, 'getAttribute' ) ) ) {
4241 $this->sourceId = $select->getAttribute['id'];
4342 }
 43+
4444 if ( !$this->sourceId ) {
4545 throw new MWException( "ID needs to be specified for the selector" );
4646 }
4747 }
4848
49 -
5049 self::injectJs();
5150 $html = $this->getButton( $this->msg, $this->sourceId, $this->targetId );
5251 $html .= $this->select->getHtml();
 52+
5353 return $html;
5454 }
5555
@@ -60,15 +60,19 @@
6161 'value' => wfMsg( $msg ),
6262 'onclick' => "appendFromSelect( '$source', '$target' );"
6363 ) );
 64+
6465 return $html;
6566 }
6667
6768 public static function injectJs() {
6869 static $done = false;
69 - if ( $done ) return;
7070
 71+ if ( $done ) {
 72+ return;
 73+ }
 74+
7175 global $wgOut;
 76+
7277 $wgOut->addScriptFile( TranslateUtils::assetPath( 'utils/JsSelectToInput.js' ) );
7378 }
74 -
75 -}
\ No newline at end of file
 79+}
Index: trunk/extensions/Translate/utils/MemProfile.php
@@ -12,8 +12,10 @@
1313
1414 $wgMemUse = array();
1515 $wgMemStack = 0;
 16+
1617 function wfMemIn( $a ) {
1718 global $wgLang, $wgMemUse, $wgMemStack;
 19+
1820 $mem = memory_get_usage();
1921 $memR = memory_get_usage();
2022
@@ -29,6 +31,7 @@
3032
3133 function wfMemOut( $a ) {
3234 global $wgLang, $wgMemUse, $wgMemStack;
 35+
3336 $mem = memory_get_usage();
3437 $memR = memory_get_usage();
3538
Index: trunk/extensions/Translate/utils/TranslationEditPage.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * This class together with some javascript implements the ajax translation
65 * page.
@@ -8,6 +7,7 @@
98 * @copyright Copyright © 2009 Niklas Laxström
109 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1110 */
 11+
1212 class TranslationEditPage {
1313 // Instance of an Title object
1414 protected $title;
@@ -22,7 +22,11 @@
2323
2424 public static function newFromRequest( WebRequest $request ) {
2525 $title = Title::newFromText( $request->getText( 'page' ) );
26 - if ( !$title ) return null;
 26+
 27+ if ( !$title ) {
 28+ return null;
 29+ }
 30+
2731 return new self( $title );
2832 }
2933
@@ -43,6 +47,7 @@
4448 $helpers->setTextareaId( $id );
4549
4650 global $wgServer, $wgScriptPath, $wgOut;
 51+
4752 $wgOut->disable();
4853
4954 $translation = $helpers->getTranslation();
@@ -57,8 +62,11 @@
5863
5964 $hidden = array();
6065 $hidden[] = Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() );
61 - if ( isset( $data['revisions'][0]['timestamp'] ) )
 66+
 67+ if ( isset( $data['revisions'][0]['timestamp'] ) ) {
6268 $hidden[] = Xml::hidden( 'basetimestamp', $data['revisions'][0]['timestamp'] );
 69+ }
 70+
6371 $hidden[] = Xml::hidden( 'starttimestamp', $data['starttimestamp'] );
6472 $hidden[] = Xml::hidden( 'token', $data['edittoken'] );
6573 $hidden[] = Xml::hidden( 'format', 'json' );
@@ -68,8 +76,16 @@
6977 $save = Xml::submitButton( wfMsg( 'savearticle' ), array( 'style' => 'font-weight:bold' ) );
7078 $saveAndNext = Xml::submitButton( wfMsg( 'translate-js-next' ), array( 'class' => 'mw-translate-next' ) );
7179 $skip = Html::element( 'input', array( 'class' => 'mw-translate-skip', 'type' => 'button', 'value' => wfMsg( 'translate-js-skip' ) ) );
 80+
7281 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+ );
7490 } else {
7591 $history = '';
7692 }
@@ -108,18 +124,24 @@
109125 $data = $api->getResultData();
110126 $data = $data['query']['pages'];
111127 $data = array_shift( $data );
 128+
112129 return $data;
113130 }
114131
115132 public static function jsEdit( Title $title, $group = "" ) {
116133 global $wgUser;
117134
118 - if ( !$wgUser->isAllowed( 'translate' ) ) return array();
119 - if ( !$wgUser->getOption( 'translate-jsedit' ) ) return array();
 135+ if ( !$wgUser->isAllowed( 'translate' ) ) {
 136+ return array();
 137+ }
120138
 139+ if ( !$wgUser->getOption( 'translate-jsedit' ) ) {
 140+ return array();
 141+ }
 142+
121143 $jsTitle = Xml::escapeJsString( $title->getPrefixedDbKey() );
122144 $jsGroup = Xml::escapeJsString( $group );
 145+
123146 return array( 'onclick' => "return trlOpenJsEdit( \"$jsTitle\", \"$jsGroup\" );" );
124147 }
125 -
126 -}
\ No newline at end of file
 148+}
Index: trunk/extensions/Translate/utils/UserToggles.php
@@ -31,7 +31,6 @@
3232 $select = self::languageSelector();
3333 $select->setTargetId( 'mw-input-translate-editlangs' );
3434
35 -
3635 $languages = Language::getLanguageNames( false );
3736
3837 $preferences['translate-editlangs'] = array(
@@ -58,6 +57,7 @@
5958
6059 protected static function languageSelector() {
6160 global $wgLang;
 61+
6262 if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
6363 $languages = LanguageNames::getNames( $wgLang->getCode(),
6464 LanguageNames::FALLBACK_NORMAL
@@ -75,6 +75,7 @@
7676
7777 $jsSelect = new JsSelectToInput( $selector );
7878 $jsSelect->setSourceId( 'mw-language-selector' );
 79+
7980 return $jsSelect;
8081 }
8182 }
Index: trunk/extensions/Translate/utils/MessageWebImporter.php
@@ -31,6 +31,7 @@
3232
3333 public function getUser() {
3434 global $wgUser;
 35+
3536 return $this->user ? $this->user : $wgUser;
3637 }
3738
@@ -146,7 +147,9 @@
147148 }
148149
149150 // No changes at all, ignore
150 - if ( strval( $old ) === strval( $value ) ) continue;
 151+ if ( strval( $old ) === strval( $value ) ) {
 152+ continue;
 153+ }
151154
152155 if ( $old === false ) {
153156 $name = wfMsgHtml( 'translate-manage-import-new',
@@ -160,6 +163,7 @@
161164 $type = 'changed';
162165
163166 global $wgRequest;
 167+
164168 # Spaces don't seem to survive round trip in addition to dots
165169 # which are silently handled in getVal
166170 $safekey = str_replace( ' ', '_', $key );
@@ -172,6 +176,7 @@
173177 }
174178
175179 global $wgLang;
 180+
176181 if ( $action === null ) {
177182 $message = wfMsgExt( 'translate-manage-inconsistent', 'parseinline', wfEscapeWikiText( "action-$type-$key" ) );
178183 $changed[] = "<li>$message</li></ul>";
@@ -297,13 +302,14 @@
298303 $comment = wfMsgForContentNoTrans( 'translate-manage-conflict-summary' );
299304 $message = self::makeTextFuzzy( $message );
300305 }
 306+
301307 return self::doImport( $title, $message, $comment, $user, $editFlags );
302308
303309 } elseif ( $action === 'ignore' ) {
304310 return array( 'translate-manage-import-ignore', $key );
305 -
306311 } elseif ( $action === 'fuzzy' && $code !== 'en' ) {
307312 $message = self::makeTextFuzzy( $message );
 313+
308314 return self::doImport( $title, $message, $comment, $user, $editFlags );
309315 } elseif ( $action === 'fuzzy' && $code == 'en' ) {
310316 return self::doFuzzy( $title, $message, $comment, $user, $editFlags );
@@ -344,7 +350,7 @@
345351
346352 $namespace = $title->getNamespace();
347353 $titleText = $dbw->escapeLike( $titleText );
348 - $conds= array(
 354+ $conds = array(
349355 'page_namespace' => $namespace,
350356 'page_latest=rev_id',
351357 'rev_text_id=old_id',
@@ -369,7 +375,7 @@
370376 $ttitle = Title::makeTitle( $row->page_namespace, $row->page_title );
371377
372378 // No fuzzy for English original
373 - if( $ttitle->getSubpageText() == 'en' ) {
 379+ if ( $ttitle->getSubpageText() == 'en' ) {
374380 // Use imported text, not database text.
375381 $text = $message;
376382 } else {
@@ -419,6 +425,7 @@
420426 */
421427 public static function makeTranslationTitle( $group, $key, $code ) {
422428 $ns = $group->getNamespace();
 429+
423430 return Title::makeTitleSafe( $ns, "$key/$code" );
424431 }
425432
@@ -439,6 +446,7 @@
440447 $items = new TagContainer();
441448 $items[] = new HtmlTag( 'div', new RawHtml( $legend ), $legendParams );
442449 $items[] = new HtmlTag( 'div', new RawHtml( $content ), $contentParams );
 450+
443451 return new HtmlTag( 'div', $items, $containerParams );
444452 }
445453
@@ -451,6 +459,7 @@
452460 */
453461 public static function makeTextFuzzy( $message ) {
454462 $message = str_replace( TRANSLATE_FUZZY, '', $message );
 463+
455464 return TRANSLATE_FUZZY . $message;
456465 }
457466 }
Index: trunk/extensions/Translate/utils/Html.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * HTML builder class which wraps around Html::rawElement().
65 * Most of the functions are dual purpose. With no value (or null value) they
@@ -9,6 +8,7 @@
109 * <code>$tag = new HtmlTag( 'div' ); $div = $div->content( 'foo' )->style( 'color', 'red' );</code>
1110 * Note: relies on implicit toString conversion (PHP >= 5.2)
1211 */
 12+
1313 class HtmlTag {
1414 public $tag = 'div';
1515 public $content = '';
@@ -36,9 +36,12 @@
3737 * @return Mixed The tag name or self;
3838 */
3939 public function tag( $value = null ) {
40 - if ( $value === null ) return $this->tag;
 40+ if ( $value === null ) {
 41+ return $this->tag;
 42+ }
4143
4244 $this->tag = (string) $this->assert( 'is_string', $value );
 45+
4346 return $this;
4447 }
4548
@@ -48,7 +51,9 @@
4952 * @return Mixed The content as a string or self.
5053 */
5154 public function content( $value = null ) {
52 - if ( $value === null ) return $this->content;
 55+ if ( $value === null ) {
 56+ return $this->content;
 57+ }
5358
5459 if ( $value instanceof HtmlTag || $value instanceof RawHtml || $value instanceof TagContainer ) {
5560 $this->content = $value;
@@ -65,9 +70,12 @@
6671 * @return Array The paramater array.
6772 */
6873 public function params( $value = null ) {
69 - if ( $value === null ) return $this->params;
 74+ if ( $value === null ) {
 75+ return $this->params;
 76+ }
7077
7178 $this->params = (array) $this->assert( 'is_array', $value );
 79+
7280 return $this;
7381 }
7482
@@ -79,6 +87,7 @@
8088 */
8189 public function param( $name, $value = null ) {
8290 $name = (string) $this->assert( 'is_string', $name );
 91+
8392 if ( $value === null ) {
8493 return isset( $this->params[$name] ) ? $this->params[$name] : null;
8594 }
@@ -88,6 +97,7 @@
8998 } else {
9099 $this->params[$name] = $this->assert( 'is_string', $value );
91100 }
 101+
92102 return $this;
93103 }
94104
@@ -100,6 +110,7 @@
101111 */
102112 public function style( $name, $value = null ) {
103113 $name = (string) $this->assert( 'is_string', $name );
 114+
104115 if ( $value === null ) {
105116 return isset( $this->style[$name] ) ? $this->style[$name] : null;
106117 }
@@ -109,6 +120,7 @@
110121 } else {
111122 $this->style[$name] = $this->assert( 'is_string', $value );
112123 }
 124+
113125 return $this;
114126 }
115127
@@ -128,8 +140,11 @@
129141 // Collapse styles
130142 $params = $this->params;
131143 $style = $this->collapseStyles();
132 - if ( $style ) $params['style'] = $style;
133144
 145+ if ( $style ) {
 146+ $params['style'] = $style;
 147+ }
 148+
134149 if ( is_object( $this->content ) ) {
135150 return Html::rawElement( $this->tag, $params, $this->content );
136151 } else {
@@ -161,7 +176,10 @@
162177 $style .= "$name: $val;";
163178 }
164179
165 - if ( $style !== '' ) return $style;
 180+ if ( $style !== '' ) {
 181+ return $style;
 182+ }
 183+
166184 return false;
167185 }
168186
@@ -174,20 +192,25 @@
175193 */
176194 protected function assert( $function, $value, $result = true ) {
177195 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+ }
179199 }
180200
181201 $real_result = call_user_func( $function, $value );
182 - if ( $real_result === $result ) return $value;
 202+ if ( $real_result === $result ) {
 203+ return $value;
 204+ }
 205+
183206 $msg = __METHOD__ . ":expecting $function to be $result";
184207 if ( $this->strict ) {
185208 throw new MWException( $msg );
186209 } else {
187210 wfWarn( $msg );
 211+
188212 return $value;
189213 }
190214 }
191 -
192215 }
193216
194217 /**
@@ -220,8 +243,11 @@
221244
222245 public function __toString() {
223246 $output = '';
224 - foreach ( $this->tags as $tag )
 247+
 248+ foreach ( $this->tags as $tag ) {
225249 $output .= $tag . "\n";
 250+ }
 251+
226252 return $output;
227253 }
228254
@@ -233,13 +259,16 @@
234260 $this->tags[$offset] = $value;
235261 }
236262 }
 263+
237264 public function offsetExists( $offset ) {
238265 return isset( $this->tags[$offset] );
239266 }
 267+
240268 public function offsetUnset( $offset ) {
241269 unset( $this->tags[$offset] );
242270 }
 271+
243272 public function offsetGet( $offset ) {
244273 return isset( $this->tags[$offset] ) ? $this->tags[$offset] : null;
245274 }
246 -}
\ No newline at end of file
 275+}
Index: trunk/extensions/Translate/utils/Font.php
@@ -1,19 +1,20 @@
22 <?php
3 -
43 /**
54 * Wrapper around font-config to get useful ttf font given a language code.
65 * Uses wfShellExec, wfEscapeShellArg and wfDebugLog from MediaWiki.
76 * @author Niklas Laxström, 2008
87 * @license PD
98 */
 9+
1010 class FCFontFinder {
11 -
1211 public static function find( $code ) {
1312 $code = wfEscapeShellArg( ":lang=$code" );
1413 $ok = 0;
1514 $cmd = "fc-match $code";
1615 $suggestion = wfShellExec( $cmd, $ok );
 16+
1717 wfDebugLog( 'fcfont', "$cmd returned $ok" );
 18+
1819 if ( $ok !== 0 ) {
1920 wfDebugLog( 'fcfont', "fc-match error output: $suggestion" );
2021 return false;
@@ -21,6 +22,7 @@
2223
2324 $pattern = '/^(.*?): "(.*)" "(.*)"$/';
2425 $matches = array();
 26+
2527 if ( !preg_match( $pattern, $suggestion, $matches ) ) {
2628 wfDebugLog( 'fcfont', "fc-match: return format not understood: $suggestion" );
2729 return false;
@@ -37,6 +39,7 @@
3840 $candidates = trim( wfShellExec( $cmd, $ok ) );
3941
4042 wfDebugLog( 'fcfont', "$cmd returned $ok" );
 43+
4144 if ( $ok !== 0 ) {
4245 wfDebugLog( 'fcfont', "fc-list error output: $candidates" );
4346 return false;
@@ -45,7 +48,9 @@
4649 # trim spaces
4750 $files = array_map( 'trim', explode( "\n", $candidates ) );
4851 $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+ }
5055
5156 # remove the trailing ":"
5257 $chosen = substr( $files[0], 0, -1 );
@@ -53,5 +58,4 @@
5459 wfDebugLog( 'fcfont', "fc-list got $count candidates; using $chosen" );
5560 return $chosen;
5661 }
57 -
58 -}
\ No newline at end of file
 62+}
Index: trunk/extensions/Translate/utils/MessageIndexRebuilder.php
@@ -22,7 +22,10 @@
2323 STDOUT( "Working with ", 'main' );
2424
2525 foreach ( $groups as $g ) {
26 - if ( !$g->exists() ) continue;
 26+ if ( !$g->exists() ) {
 27+ continue;
 28+ }
 29+
2730 # Skip meta thingies
2831 if ( $g->isMeta() ) {
2932 $postponed[] = $g;
@@ -37,7 +40,9 @@
3841 }
3942
4043 global $wgCacheDirectory;
 44+
4145 $filename = "$wgCacheDirectory/translate_messageindex.cdb";
 46+
4247 $writer = CdbWriter::open( $filename );
4348 $writer->set( 'map', serialize( $hugearray ) );
4449 $writer->close();
@@ -46,6 +51,7 @@
4752 protected static function checkAndAdd( &$hugearray, $g, $ignore = false ) {
4853 if ( $g instanceof MessageGroupBase ) {
4954 $cache = new MessageGroupCache( $g );
 55+
5056 if ( $cache->exists() ) {
5157 $keys = $cache->getKeys();
5258 } else {
@@ -53,7 +59,11 @@
5460 }
5561 } else {
5662 $messages = $g->getDefinitions();
57 - if ( !is_array( $messages ) ) continue;
 63+
 64+ if ( !is_array( $messages ) ) {
 65+ continue;
 66+ }
 67+
5868 $keys = array_keys( $messages );
5969 }
6070
Index: trunk/extensions/Translate/utils/StringMatcher.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 interface StringMangler {
45 public static function EmptyMatcher();
56 public function setConf( $configuration );
@@ -9,7 +10,6 @@
1011 public function unMangle( $data );
1112 }
1213
13 -
1414 class StringMatcher implements StringMangler {
1515 protected $sPrefix = '';
1616 protected $aExact = array();
@@ -46,21 +46,30 @@
4747 }
4848
4949 public function match( $string ) {
50 - if ( in_array( $string, $this->aExact ) ) return true;
 50+ if ( in_array( $string, $this->aExact ) ) {
 51+ return true;
 52+ }
5153
5254 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+ }
5458 }
5559
5660 foreach ( $this->aRegex as $regex ) {
57 - if ( preg_match( $regex, $string ) ) return true;
 61+ if ( preg_match( $regex, $string ) ) {
 62+ return true;
 63+ }
5864 }
5965
6066 return false;
6167 }
6268
6369 public function mangle( $data ) {
64 - if ( !$this->sPrefix ) { return $data; }
 70+ if ( !$this->sPrefix ) {
 71+ return $data;
 72+ }
 73+
6574 if ( is_array( $data ) ) {
6675 return $this->mangleArray( $data );
6776 } elseif ( is_string( $data ) ) {
@@ -73,7 +82,10 @@
7483 }
7584
7685 public function unMangle( $data ) {
77 - if ( !$this->sPrefix ) { return $data; }
 86+ if ( !$this->sPrefix ) {
 87+ return $data;
 88+ }
 89+
7890 if ( is_array( $data ) ) {
7991 return $this->mangleArray( $data, true );
8092 } elseif ( is_string( $data ) ) {
@@ -85,7 +97,6 @@
8698 }
8799 }
88100
89 -
90101 protected function mangleString( $string, $reverse = false ) {
91102 if ( $reverse ) {
92103 return $this->unMangleString( $string );
Index: trunk/extensions/Translate/utils/TranslationMemoryUpdater.php
@@ -1,31 +1,40 @@
22 <?php
3 -
43 /**
5 -*
 4+* Class for updating the Translation Memory
65 */
 6+
77 class TranslationMemoryUpdater {
8 -
98 public static function update( $article, $user, $text, $summary, $minor, $_, $_, $flags, $revision ) {
109 global $wgContLang;
1110
1211 $dbw = self::getDatabaseHandle();
1312 // Not in use or misconfigured
14 - if ( $dbw === null ) return true;
 13+ if ( $dbw === null ) {
 14+ return true;
 15+ }
1516
1617 $title = $article->getTitle();
1718 // Something we are not interested in at all
18 - if ( !TranslateEditAddons::isMessageNamespace( $title ) ) return true;
 19+ if ( !TranslateEditAddons::isMessageNamespace( $title ) ) {
 20+ return true;
 21+ }
1922
2023 list( $key, $code, $group ) = TranslateEditAddons::getKeyCodeGroup( $title );
2124 // Unknown message, we cannot handle. We need definition.
22 - if ( !$group || !$code ) return true;
 25+ if ( !$group || !$code ) {
 26+ return true;
 27+ }
2328
2429 // Skip definitions to not slow down mass imports etc.
2530 // These will be added when first translation is made
26 - if ( $code === 'en' ) return true;
 31+ if ( $code === 'en' ) {
 32+ return true;
 33+ }
2734
2835 // Skip fuzzy messages
29 - if ( TranslateEditAddons::hasFuzzyString( $text ) ) return true;
 36+ if ( TranslateEditAddons::hasFuzzyString( $text ) ) {
 37+ return true;
 38+ }
3039
3140 $ns_text = $wgContLang->getNsText( $group->getNamespace() );
3241 $definition = $group->getMessage( $key, 'en' );
@@ -33,7 +42,7 @@
3443 wfDebugLog( 'tmserver', "Unable to get definition for $ns_text:$key/$code" );
3544 return true;
3645 }
37 -
 46+
3847 $tmDefinition = array(
3948 'text' => $definition,
4049 'context' => "$ns_text:$key",
@@ -68,11 +77,13 @@
6978 return true;
7079 }
7180
72 -
7381 public static function getDatabaseHandle() {
7482 global $wgTranslateTM;
75 - if ( !isset( $wgTranslateTM['database'] ) ) return null;
7683
 84+ if ( !isset( $wgTranslateTM['database'] ) ) {
 85+ return null;
 86+ }
 87+
7788 $database = $wgTranslateTM['database'];
7889
7990 if ( !is_string( $database ) ) {
@@ -92,5 +103,4 @@
93104
94105 return new DatabaseSqliteStandalone( $database );
95106 }
96 -
97 -}
\ No newline at end of file
 107+}
Index: trunk/extensions/Translate/utils/TranslationStats.php
@@ -9,6 +9,7 @@
1010 * @copyright Copyright © 2010, Niklas Laxström, Siebrand Mazeland
1111 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1212 */
 13+
1314 class TranslationStats {
1415 /**
1516 * Returns translated percentage for message group in given
Index: trunk/extensions/Translate/utils/ResourceLoader.php
@@ -1,13 +1,12 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
54 class ResourceLoader {
6 -
75 public static function loadVariableFromPHPFile( $_filename, $_variable ) {
86 if ( !file_exists( $_filename ) ) {
97 return null;
108 } else {
119 require( $_filename );
 10+
1211 return isset( $$_variable ) ? $$_variable : null;
1312 }
1413 }
Index: trunk/extensions/Translate/ffs/Xliff.php
@@ -64,6 +64,7 @@
6565 $w->writeAttribute( 'id', $key );
6666 $w->writeElement( 'source', $m->definition() );
6767 $translation = $m->translatiom();
 68+
6869 if ( $translation !== null ) {
6970 $w->writeElement( 'target', $translation );
7071 }
@@ -81,4 +82,4 @@
8283 $w->endElement(); // </xliff>
8384 fwrite( $handle, $w->outputMemory( true ) );
8485 }
85 -}
\ No newline at end of file
 86+}
Index: trunk/extensions/Translate/ffs/Simple.php
@@ -41,6 +41,7 @@
4242 protected function parseHeader() {
4343 $authors = array();
4444 $staticHeader = '';
 45+
4546 if ( $this->filename !== false ) {
4647 $handle = fopen( $this->filename, "rt" );
4748 $state = 0;
@@ -60,7 +61,10 @@
6162 $authors[] = substr( $line, $prefixLength );
6263 }
6364 } 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+
6569 $staticHeader .= $line;
6670 }
6771 }
@@ -87,14 +91,10 @@
8892 }
8993
9094 return $messages;
91 -
9295 }
93 -
94 -
9596 }
9697
9798 class SimpleFormatWriter {
98 -
9999 const SEPARATOR = '----';
100100 const AUTHORPREFIX = 'Author: ';
101101
@@ -131,12 +131,14 @@
132132 }
133133 }
134134
135 -
136135 public function fileExport( array $languages, $targetDirectory ) {
137136 foreach ( $languages as $code ) {
138137 $messages = $this->getMessagesForExport( $this->group, $code );
139 - if ( !count( $messages ) ) continue;
140138
 139+ if ( !count( $messages ) ) {
 140+ continue;
 141+ }
 142+
141143 $filename = $this->group->getMessageFile( $code );
142144 $target = $targetDirectory . '/' . $filename;
143145
@@ -166,6 +168,7 @@
167169 rewind( $handle );
168170 $data = stream_get_contents( $handle );
169171 fclose( $handle );
 172+
170173 return $data;
171174 }
172175
@@ -176,6 +179,7 @@
177180 $collection->filter( 'hastranslation', false );
178181 $collection->loadTranslations();
179182 $this->addAuthors( $collection->getAuthors(), $code );
 183+
180184 return $collection;
181185 }
182186
@@ -195,6 +199,7 @@
196200
197201 public function filterAuthors( array $authors, $code, $groupId ) {
198202 global $wgTranslateAuthorBlacklist;
 203+
199204 foreach ( $authors as $i => $v ) {
200205 $hash = "$groupId;$code;$v";
201206
@@ -218,7 +223,6 @@
219224 }
220225
221226 return $authors;
222 -
223227 }
224228
225229 protected function formatAuthors( $prefix, $code ) {
@@ -228,7 +232,9 @@
229233 $groupId = $this->group->getId();
230234 $authors = $this->authors[$code];
231235 $authors = $this->filterAuthors( $authors, $code, $groupId );
232 - if ( empty( $authors ) ) return '';
 236+ if ( empty( $authors ) ) {
 237+ return '';
 238+ }
233239
234240 sort( $authors );
235241
@@ -236,6 +242,7 @@
237243 foreach ( $authors as $a ) {
238244 $s[] = $prefix . $a;
239245 }
 246+
240247 return implode( "\n", $s ) . "\n";
241248 }
242249
@@ -257,6 +264,7 @@
258265 protected function getLanguageNames( $code ) {
259266 $name = TranslateUtils::getLanguageName( $code );
260267 $native = TranslateUtils::getLanguageName( $code, true );
 268+
261269 return array( $name, $native );
262270 }
263 -}
\ No newline at end of file
 271+}
Index: trunk/extensions/Translate/ffs/PhpVariables.php
@@ -17,7 +17,6 @@
1818 * Second section (if any) is returned verbatim.
1919 */
2020 class PhpVariablesFormatReader extends SimpleFormatReader {
21 -
2221 /**
2322 * Reads all \@author tags from the file and returns array of authors.
2423 *
@@ -30,9 +29,11 @@
3130 if ( $this->filename === false ) {
3231 return array();
3332 }
 33+
3434 $contents = file_get_contents( $this->filename );
3535 $m = array();
3636 $count = preg_match_all( '/@author (.*)/', $contents, $m );
 37+
3738 return $m[1];
3839 }
3940
@@ -107,6 +108,7 @@
108109 $value = str_replace( array( "\'", "\\\\" ), array( "'", "\\" ), $_[2] );
109110 $messages[$key] = $value;
110111 }
 112+
111113 return $messages;
112114 }
113115 }
Index: trunk/extensions/Translate/ffs/WikiExtension.php
@@ -1,5 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43 /**
54 * Multiple language wiki file format handler.
65 *
@@ -55,8 +54,9 @@
5655 }
5756 }
5857
59 - if ( $unknown )
 58+ if ( $unknown ) {
6059 $sections[] = implode( "\n", $unknown );
 60+ }
6161
6262 return array( $header, $sections );
6363 }
@@ -65,12 +65,14 @@
6666 if ( $this->filename === false ) {
6767 return array();
6868 }
 69+
6970 $ { $this->variableName } = array();
7071 require( $this->filename );
7172 $messages = $ { $this->variableName } ;
7273 foreach ( $messages as $code => $value ) {
7374 $messages[$code] = $mangler->mangle( $value );
7475 }
 76+
7577 return $messages;
7678 }
7779 }
@@ -116,6 +118,7 @@
117119 rewind( $handle );
118120 $data = stream_get_contents( $handle );
119121 fclose( $handle );
 122+
120123 return $data;
121124 }
122125
@@ -128,7 +131,10 @@
129132
130133 $__languages = Language::getLanguageNames( false );
131134 foreach ( array_keys( $__languages ) as $code ) {
132 - if ( $code === 'en' || $code === 'qqq' ) continue;
 135+ if ( $code === 'en' || $code === 'qqq' ) {
 136+ continue;
 137+ }
 138+
133139 $this->exportSection( $handle, $code, $languages );
134140 }
135141 }
@@ -136,7 +142,6 @@
137143 protected function exportSection( $handle, $code, array $languages ) {
138144 // Never export en, just copy it verbatim
139145 if ( in_array( $code, $languages ) && $code !== 'en' ) {
140 -
141146 // Parse authors only if we regenerate section
142147 if ( isset( $this->sections[$code] ) ) {
143148 $authors = $this->parseAuthorsFromString( $this->sections[$code] );
@@ -153,11 +158,13 @@
154159 protected function writeSection( $handle, $code ) {
155160 $messages = $this->getMessagesForExport( $this->group, $code );
156161 $messages = $this->makeExportArray( $messages );
 162+
157163 if ( count( $messages ) ) {
158164 list( $name, $native ) = $this->getLanguageNames( $code );
159165 $authors = $this->formatAuthors( ' * @author ', $code );
160 - if ( !empty( $authors ) )
 166+ if ( !empty( $authors ) ) {
161167 $authors = "\n$authors";
 168+ }
162169
163170 fwrite( $handle, "/** $name ($native)$authors */\n" );
164171 fwrite( $handle, "\${$this->variableName}['$code'] = array(\n" );
@@ -168,6 +175,7 @@
169176
170177 public function parseAuthorsFromString( $string ) {
171178 $count = preg_match_all( '/@author (.*)/', $string, $m );
 179+
172180 return $m[1];
173181 }
174182
Index: trunk/extensions/Translate/ffs/Java.php
@@ -16,7 +16,6 @@
1717 * Second section (if any) is returned verbatim.
1818 */
1919 class JavaFormatReader extends SimpleFormatReader {
20 -
2120 /**
2221 * Inherited from SimpleFormatReader, which parses whole header in one pass.
2322 * Basically the same, with different author prefix and separator between
@@ -78,15 +77,21 @@
7978
8079 # This format works nicely with line based parsing
8180 $lines = array_map( 'trim', file( $this->filename ) );
82 - if ( !$lines ) { return null; }
 81+ if ( !$lines ) {
 82+ return null;
 83+ }
8384
8485 $messages = array();
8586
8687 foreach ( $lines as $line ) {
87 - if ( $line === '' || !strpos( $line, '=' ) || $line[0] === '#' ) { continue; }
 88+ if ( $line === '' || !strpos( $line, '=' ) || $line[0] === '#' ) {
 89+ continue;
 90+ }
 91+
8892 list( $key, $value ) = explode( '=', $line, 2 );
8993 $messages[$mangler->mangle( trim( $key ) )] = trim( $value );
9094 }
 95+
9196 return $messages;
9297 }
9398 }
@@ -95,12 +100,12 @@
96101 * Very simple writer for exporting messages to Java property files from wiki.
97102 */
98103 class JavaFormatWriter extends SimpleFormatWriter {
99 -
100104 /**
101105 * Inherited. Very simplistic header with timestamp.
102106 */
103107 public function makeHeader( $handle, $code ) {
104108 global $wgSitename;
 109+
105110 list( $name, $native ) = $this->getLanguageNames( $code );
106111 $authors = $this->formatAuthors( '# Author: ', $code );
107112 $when = wfTimestamp( TS_ISO_8601 );
@@ -129,5 +134,4 @@
130135 fwrite( $handle, "$key=$value\n" );
131136 }
132137 }
133 -
134 -}
\ No newline at end of file
 138+}
Index: trunk/extensions/Translate/ffs/OpenLayers.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * OpenLayers JavaScript language class file format handler.
65 *
@@ -9,7 +8,6 @@
109 */
1110
1211 class OpenLayersFormatReader extends SimpleFormatReader {
13 -
1412 private static function unescapeJsString( $string ) {
1513 // See ECMA 262 section 7.8.4 for string literal format
1614 $pairs = array(
@@ -34,12 +32,14 @@
3533 "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER
3634 );
3735 $pairs = array_flip( $pairs );
 36+
3837 return strtr( $string, $pairs );
3938 }
4039
4140 private function leftTrim( $string ) {
4241 $string = ltrim( $string );
4342 $string = ltrim( $string, '"' );
 43+
4444 return $string;
4545 }
4646
@@ -99,11 +99,9 @@
100100
101101 return $messages;
102102 }
103 -
104103 }
105104
106105 class OpenLayersFormatWriter extends SimpleFormatWriter {
107 -
108106 /**
109107 * Export a languages messages.
110108 * @param $target File handler.
@@ -118,6 +116,7 @@
119117 $authors = $collection->getAuthors();
120118 $authors = $this->filterAuthors( $authors, $collection->code, $this->group->getId() );
121119 $authorList = '';
 120+
122121 foreach ( $authors as $author ) {
123122 $authorList .= " * - $author\n";
124123 }
@@ -164,5 +163,4 @@
165164 // File terminator.
166165 fwrite( $target, '});' );
167166 }
168 -
169167 }
Index: trunk/extensions/Translate/ffs/Wiki.php
@@ -25,6 +25,7 @@
2626 $contents = file_get_contents( $this->filename );
2727 $m = array();
2828 $count = preg_match_all( '/@author (.*)/', $contents, $m );
 29+
2930 return $m[1];
3031 }
3132
@@ -32,6 +33,7 @@
3334 if ( $this->filename === false ) {
3435 return '';
3536 }
 37+
3638 $contents = file_get_contents( $this->filename );
3739
3840 /** FIXME: handle the case where the first comment is missing */
@@ -39,10 +41,21 @@
4042
4143 $start = strpos( $contents, '*/' );
4244 $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+
4554 $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+
4760 return trim( substr( $contents, $start, $end - $start ) );
4861 }
4962
@@ -50,8 +63,10 @@
5164 if ( $this->filename === false ) {
5265 return array();
5366 }
 67+
5468 $ { $this->variableName } = array();
5569 require( $this->filename );
 70+
5671 return $mangler->mangle( $ { $this->variableName } );
5772 }
5873
@@ -95,6 +110,7 @@
96111 if ( !$dir ) {
97112 $this->writeMessagesBlock( $handle, $messages );
98113 fwrite( $handle, ");\n" );
 114+
99115 return;
100116 }
101117
@@ -175,8 +191,12 @@
176192 protected function exportItemPad( $handle, $key, $value, $pad = 0 ) {
177193 # Add the key name
178194 fwrite( $handle, "'$key'" );
 195+
179196 # 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+
181201 fwrite( $handle, ' => ' );
182202
183203 if ( $this->commaToArray ) {
@@ -203,11 +223,9 @@
204224
205225 # It is safe to use '-quoting, unless there is '-quote in the text
206226 if ( strpos( $value, $single ) !== false ) {
207 -
208227 # In case there is no variables that need to be escaped, just use "-quote
209228 if ( strpos( $value, $double ) === false && !preg_match( '/\$[^0-9]/', $value ) ) {
210229 $quote = $double;
211 -
212230 # Something needs quoting, pick the quote which causes less quoting
213231 } else {
214232 $doubleEsc = substr_count( $value, $double ) + substr_count( $value, '$' );
Index: trunk/extensions/Translate/ffs/Gettext.php
@@ -1,15 +1,16 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
54 class GettextPluralException extends MwException { }
65
76 class GettextFormatReader extends SimpleFormatReader {
87 protected $pot = false;
 8+
99 public function setPotMode( $value ) {
1010 $this->pot = $value;
1111 }
1212
1313 protected $prefix = '';
 14+
1415 public function setPrefix( $value ) {
1516 $this->prefix = $value;
1617 }
@@ -23,10 +24,16 @@
2425 if ( $this->filename === false ) {
2526 return '';
2627 }
 28+
2729 $data = file_get_contents( $this->filename );
2830 $start = (int) strpos( $data, '# --' );
29 - if ( $start ) $start += 5;
 31+
 32+ if ( $start ) {
 33+ $start += 5;
 34+ }
 35+
3036 $end = (int) strpos( $data, "msgid" );
 37+
3138 return substr( $data, $start, $end - $start );
3239 }
3340
@@ -34,8 +41,10 @@
3542 if ( $this->filename === false ) {
3643 return array();
3744 }
 45+
3846 $data = file_get_contents( $this->filename );
3947 $parse = GettextFFS::parseGettextData( $data );
 48+
4049 return $parse['TEMPLATE'];
4150 }
4251
@@ -43,7 +52,9 @@
4453 if ( $this->filename === false ) {
4554 return array();
4655 }
 56+
4757 $data = file_get_contents( $this->filename );
 58+
4859 return GettextFFS::parseGettextData( $data );
4960 }
5061
@@ -51,6 +62,7 @@
5263 public function parseMessages( StringMangler $mangler ) {
5364 $defs = $this->parseFile();
5465 $messages = array();
 66+
5567 foreach ( $defs as $key => $def ) {
5668 if ( $this->pot ) {
5769 $messages[$key] = $def['id'];
@@ -60,9 +72,9 @@
6173 }
6274 }
6375 }
 76+
6477 return $messages;
6578 }
66 -
6779 }
6880
6981 class GettextFormatWriter extends SimpleFormatWriter {
@@ -72,17 +84,18 @@
7385 public function load( $code ) {
7486 $reader = $this->group->getReader( $code );
7587 $readerEn = $this->group->getReader( 'en' );
 88+
7689 if ( $reader instanceof GettextFormatReader ) {
7790 $this->addAuthors( $reader->parseAuthors(), $code );
7891 $this->staticHeader = $reader->parseStaticHeader();
7992 $this->owndata = $reader->parseFileExt();
8093 }
 94+
8195 if ( $readerEn instanceof GettextFormatReader ) {
8296 $this->data = $readerEn->parseFile();
8397 }
8498 }
8599
86 -
87100 public function exportLanguage( $handle, MessageCollection $messages ) {
88101 global $wgSitename, $wgServer, $wgTranslateDocumentationLanguageCode;
89102
@@ -133,10 +146,14 @@
134147
135148 $translation = $m->translation();
136149 # CASE2: no translation
137 - if ( $translation === null ) $translation = '';
 150+ if ( $translation === null ) {
 151+ $translation = '';
 152+ }
138153
139154 # 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+ }
141158
142159 # Remove explicit fuzzy markings from the translation before export
143160 $flags = array();
@@ -144,6 +161,7 @@
145162 if ( isset( $this->data[$key]['flags'] ) ) {
146163 $flags = $this->data[$key]['flags'];
147164 }
 165+
148166 if ( strpos( $translation, TRANSLATE_FUZZY ) !== false ) {
149167 $translation = str_replace( TRANSLATE_FUZZY, '', $translation );
150168 $flags[] = 'fuzzy';
@@ -172,7 +190,6 @@
173191 }
174192
175193 fwrite( $handle, $this->formatmsg( $m->definition(), $translation, $ckey, $pluralForms ) );
176 -
177194 }
178195
179196 return $out;
@@ -184,6 +201,7 @@
185202 $line = addcslashes( $line, '\\"' );
186203 $line = str_replace( "\n", '\n', $line );
187204 $line = '"' . $line . '"';
 205+
188206 return $line;
189207 }
190208
@@ -199,12 +217,17 @@
200218 }
201219
202220 // Ensure there is always something
203 - if ( !count( $comments ) ) $comments[':'][] = '';
 221+ if ( !count( $comments ) ) {
 222+ $comments[':'][] = '';
 223+ }
204224
205225 $order = array( '', '.', ':', ',', '|' );
206226 $output = array();
207227 foreach ( $order as $type ) {
208 - if ( !isset( $comments[$type] ) ) continue;
 228+ if ( !isset( $comments[$type] ) ) {
 229+ continue;
 230+ }
 231+
209232 foreach ( $comments[$type] as $value ) {
210233 $output[] = "#$type $value";
211234 }
@@ -217,7 +240,9 @@
218241 $output = array();
219242
220243 // 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+ }
222247
223248 if ( $msgctxt ) {
224249 $output[] = 'msgctxt ' . $this->escape( $msgctxt );
@@ -250,6 +275,7 @@
251276 }
252277
253278 $out = implode( "\n", $output ) . "\n\n";
 279+
254280 return $out;
255281
256282 }
@@ -266,7 +292,11 @@
267293 for ( $i = 0; $i < $forms; $i++ ) {
268294 $plurals = array();
269295 $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+
271301 $pluralForm = $text;
272302 foreach ( $plurals[0] as $index => $definition ) {
273303 $parsedFormsArray = explode( '|', $plurals[1][$index] );
@@ -282,15 +312,12 @@
283313
284314 return $splitPlurals;
285315 }
286 -
287316 }
288317
289318 class GettextFFS extends SimpleFFS {
290 -
291319 //
292320 // READ
293321 //
294 -
295322 public function readFromVariable( $data ) {
296323 $authors = $messages = array();
297324
@@ -357,7 +384,10 @@
358385
359386 // Then parse the messages
360387 foreach ( $sections as $section ) {
361 - if ( trim( $section ) === '' ) continue;
 388+ if ( trim( $section ) === '' ) {
 389+ continue;
 390+ }
 391+
362392 /* These inactive section are of no interest to us. Multiline mode
363393 * is needed because there may be flags or other annoying stuff
364394 * before the commented out sections.
@@ -482,7 +512,9 @@
483513 */
484514 public static function generateKeyFromItem( $item ) {
485515 $lang = Language::factory( 'en' );
 516+
486517 global $wgLegalTitleChars;
 518+
487519 $hash = sha1( $item['ctxt'] . $item['id'] );
488520 $snippet = $item['id'];
489521 $snippet = preg_replace( "/[^$wgLegalTitleChars]/", ' ', $snippet );
@@ -490,6 +522,7 @@
491523 $snippet = preg_replace( "/ {2,}/", ' ', $snippet );
492524 $snippet = $lang->truncate( $snippet, 30, '' );
493525 $snippet = str_replace( ' ', '_', trim( $snippet ) );
 526+
494527 return "$hash-$snippet";
495528 }
496529
@@ -503,6 +536,7 @@
504537 $quotePattern = '/(^"|"$\n?)/m';
505538 $data = preg_replace( $quotePattern, '', $data );
506539 $data = stripcslashes( $data );
 540+
507541 if ( preg_match( '/\s$/', $data ) ) {
508542 if ( $whitespace === 'mark' )
509543 $data .= '\\';
@@ -512,6 +546,7 @@
513547 // FIXME: only triggered if there is trailing whitespace
514548 throw new MWException( 'Unknown action for whitespace' );
515549 }
 550+
516551 return $data;
517552 }
518553
@@ -521,13 +556,13 @@
522557 list( $key, $value ) = explode( ': ', $line, 2 );
523558 $tags[$key] = $value;
524559 }
 560+
525561 return $tags;
526562 }
527563
528564 //
529565 // WRITE
530566 //
531 -
532567 protected function writeReal( MessageCollection $collection ) {
533568 throw new MWException( 'Not implemented' );
534569 $output = $this->doHeader( $collection );
@@ -540,21 +575,28 @@
541576 $key = $mangler->unmangle( $key );
542577 $value = $m->translation();
543578 $value = str_replace( TRANSLATE_FUZZY, '', $value );
544 - if ( $value === '' ) continue;
545579
 580+ if ( $value === '' ) {
 581+ continue;
 582+ }
 583+
546584 $messages[$key] = $value;
547585 }
 586+
548587 $output .= TranslateSpyc::dump( $messages );
 588+
549589 return $output;
550590 }
551591
552592 protected function doHeader( MessageCollection $collection ) {
553593 global $wgSitename;
 594+
554595 $code = $collection->code;
555596 $name = TranslateUtils::getLanguageName( $code );
556597 $native = TranslateUtils::getLanguageName( $code, true );
557598 $output = "# Messages for $name ($native)\n";
558599 $output .= "# Exported from $wgSitename\n";
 600+
559601 return $output;
560602 }
561603
@@ -562,10 +604,11 @@
563605 $output = '';
564606 $authors = $collection->getAuthors();
565607 $authors = $this->filterAuthors( $authors, $collection->code );
 608+
566609 foreach ( $authors as $author ) {
567610 $output .= "# Author: $author\n";
568611 }
 612+
569613 return $output;
570614 }
571 -
572 -}
\ No newline at end of file
 615+}
Index: trunk/extensions/Translate/spyc/spyc.php
@@ -10,25 +10,25 @@
1111 * @package Spyc
1212 */
1313
14 -if (!function_exists('spyc_load')) {
 14+if ( !function_exists( 'spyc_load' ) ) {
1515 /**
1616 * Parses YAML to array.
1717 * @param string $string YAML string.
1818 * @return array
1919 */
20 - function spyc_load ($string) {
21 - return Spyc::YAMLLoadString($string);
 20+ function spyc_load ( $string ) {
 21+ return Spyc::YAMLLoadString( $string );
2222 }
2323 }
2424
25 -if (!function_exists('spyc_load_file')) {
 25+if ( !function_exists( 'spyc_load_file' ) ) {
2626 /**
2727 * Parses YAML to array.
2828 * @param string $file Path to YAML file.
2929 * @return array
3030 */
31 - function spyc_load_file ($file) {
32 - return Spyc::YAMLLoad($file);
 31+ function spyc_load_file ( $file ) {
 32+ return Spyc::YAMLLoad( $file );
3333 }
3434 }
3535
@@ -105,8 +105,8 @@
106106 * @param string $input
107107 * @return array
108108 */
109 - public function load ($input) {
110 - return $this->__loadString($input);
 109+ public function load ( $input ) {
 110+ return $this->__loadString( $input );
111111 }
112112
113113 /**
@@ -114,8 +114,8 @@
115115 * @param string $file
116116 * @return array
117117 */
118 - public function loadFile ($file) {
119 - return $this->__load($file);
 118+ public function loadFile ( $file ) {
 119+ return $this->__load( $file );
120120 }
121121
122122 /**
@@ -133,9 +133,9 @@
134134 * @return array
135135 * @param string $input Path of YAML file or string containing YAML
136136 */
137 - public static function YAMLLoad($input) {
 137+ public static function YAMLLoad( $input ) {
138138 $Spyc = new Spyc;
139 - return $Spyc->__load($input);
 139+ return $Spyc->__load( $input );
140140 }
141141
142142 /**
@@ -157,9 +157,9 @@
158158 * @return array
159159 * @param string $input String containing YAML
160160 */
161 - public static function YAMLLoadString($input) {
 161+ public static function YAMLLoadString( $input ) {
162162 $Spyc = new Spyc;
163 - return $Spyc->__loadString($input);
 163+ return $Spyc->__loadString( $input );
164164 }
165165
166166 /**
@@ -182,9 +182,9 @@
183183 * @param int $indent Pass in false to use the default, which is 2
184184 * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
185185 */
186 - public static function YAMLDump($array,$indent = false,$wordwrap = false) {
 186+ public static function YAMLDump( $array, $indent = false, $wordwrap = false ) {
187187 $spyc = new Spyc;
188 - return $spyc->dump($array,$indent,$wordwrap);
 188+ return $spyc->dump( $array, $indent, $wordwrap );
189189 }
190190
191191
@@ -208,18 +208,18 @@
209209 * @param int $indent Pass in false to use the default, which is 2
210210 * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
211211 */
212 - public function dump($array,$indent = false,$wordwrap = false) {
 212+ public function dump( $array, $indent = false, $wordwrap = false ) {
213213 // Dumps to some very clean YAML. We'll have to add some more features
214214 // and options soon. And better support for folding.
215215
216216 // New features and options.
217 - if ($indent === false or !is_numeric($indent)) {
 217+ if ( $indent === false or !is_numeric( $indent ) ) {
218218 $this->_dumpIndent = 2;
219219 } else {
220220 $this->_dumpIndent = $indent;
221221 }
222222
223 - if ($wordwrap === false or !is_numeric($wordwrap)) {
 223+ if ( $wordwrap === false or !is_numeric( $wordwrap ) ) {
224224 $this->_dumpWordWrap = 40;
225225 } else {
226226 $this->_dumpWordWrap = $wordwrap;
@@ -229,13 +229,13 @@
230230 $string = "---\n";
231231
232232 // Start at the base of the array and move through it.
233 - if ($array) {
 233+ if ( $array ) {
234234 $array = (array)$array;
235 - $first_key = key($array);
 235+ $first_key = key( $array );
236236
237237 $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 );
240240 $previous_key = $key;
241241 }
242242 }
@@ -250,20 +250,20 @@
251251 * @param $value The value of the item
252252 * @param $indent The indent of the current node
253253 */
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 );
258258 // It has children. What to do?
259259 // 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 );
261261 // Add the indent
262262 $indent += $this->_dumpIndent;
263263 // 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 ) ) {
266266 // 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 );
268268 }
269269 return $string;
270270 }
@@ -275,13 +275,13 @@
276276 * @param $array The array you want to convert
277277 * @param $indent The indent of the current level
278278 */
279 - private function _yamlizeArray($array,$indent) {
280 - if (is_array($array)) {
 279+ private function _yamlizeArray( $array, $indent ) {
 280+ if ( is_array( $array ) ) {
281281 $string = '';
282282 $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 );
286286 $previous_key = $key;
287287 }
288288 return $string;
@@ -298,38 +298,38 @@
299299 * @param $value The value of the item
300300 * @param $indent The indent of the current node
301301 */
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 ) {
303303 // 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 ) == ':' )
307307 ) {
308 - $value = $this->_doLiteralBlock($value,$indent);
 308+ $value = $this->_doLiteralBlock( $value, $indent );
309309 } else {
310 - $value = $this->_doFolding($value,$indent);
 310+ $value = $this->_doFolding( $value, $indent );
311311 }
312312
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 );
316316 }
317 - if (trim ($value) != $value)
318 - $value = $this->_doLiteralBlock($value,$indent);
 317+ if ( trim ( $value ) != $value )
 318+ $value = $this->_doLiteralBlock( $value, $indent );
319319
320 - if (is_bool($value)) {
321 - $value = ($value) ? "true" : "false";
 320+ if ( is_bool( $value ) ) {
 321+ $value = ( $value ) ? "true" : "false";
322322 }
323323
324 - $spaces = str_repeat(' ',$indent);
 324+ $spaces = str_repeat( ' ', $indent );
325325
326 - if (is_int($key) && $key - 1 == $previous_key && $first_key===0) {
 326+ if ( is_int( $key ) && $key - 1 == $previous_key && $first_key === 0 ) {
327327 // It's a sequence
328 - $string = $spaces.'- '.$value."\n";
 328+ $string = $spaces . '- ' . $value . "\n";
329329 } 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 . '"' );
331331 // 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";
334334 }
335335 return $string;
336336 }
@@ -341,20 +341,20 @@
342342 * @param $value
343343 * @param $indent int The value of the indent
344344 */
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 );
349349 }
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 );
352352 }
353 - $exploded = explode("\n",$value);
 353+ $exploded = explode( "\n", $value );
354354 $newValue = '|';
355355 $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 );
359359 }
360360 return $newValue;
361361 }
@@ -365,16 +365,16 @@
366366 * @return string
367367 * @param $value The string you wish to fold
368368 */
369 - private function _doFolding($value,$indent) {
 369+ private function _doFolding( $value, $indent ) {
370370 // Don't do anything if wordwrap is set to 0
371371
372 - if ($this->_dumpWordWrap !== 0 && is_string ($value) && strlen($value) > $this->_dumpWordWrap) {
 372+ if ( $this->_dumpWordWrap !== 0 && is_string ( $value ) && strlen( $value ) > $this->_dumpWordWrap ) {
373373 $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;
377377 } else {
378 - if ($this->setting_dump_force_quotes && is_string ($value))
 378+ if ( $this->setting_dump_force_quotes && is_string ( $value ) )
379379 $value = '"' . $value . '"';
380380 }
381381
@@ -384,69 +384,69 @@
385385
386386 // LOADING FUNCTIONS
387387
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 );
391391 }
392392
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 );
396396 }
397397
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();
403403 }
404404
405405 $this->path = array();
406406 $this->result = array();
407407
408 - $cnt = count($Source);
409 - for ($i = 0; $i < $cnt; $i++) {
 408+ $cnt = count( $Source );
 409+ for ( $i = 0; $i < $cnt; $i++ ) {
410410 $line = $Source[$i];
411411
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;
417417 $this->path = $tempPath;
418418
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" );
422422 $literalBlock = '';
423423 $line .= $this->LiteralPlaceHolder;
424424
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 );
427427 }
428428 $i--;
429429 }
430430
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" );
433433 }
434434 $i--;
435435
436436
437437
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 );
441441 }
442442
443 - $lineArray = $this->_parseLine($line);
 443+ $lineArray = $this->_parseLine( $line );
444444
445 - if ($literalBlockStyle)
446 - $lineArray = $this->revertLiteralPlaceHolder ($lineArray, $literalBlock);
 445+ if ( $literalBlockStyle )
 446+ $lineArray = $this->revertLiteralPlaceHolder ( $lineArray, $literalBlock );
447447
448 - $this->addArray($lineArray, $this->indent);
 448+ $this->addArray( $lineArray, $this->indent );
449449
450 - foreach ($this->delayedPath as $indent => $delayedPath)
 450+ foreach ( $this->delayedPath as $indent => $delayedPath )
451451 $this->path[$indent] = $delayedPath;
452452
453453 $this->delayedPath = array();
@@ -455,17 +455,17 @@
456456 return $this->result;
457457 }
458458
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 );
462462
463 - return $this->loadFromString($input);
 463+ return $this->loadFromString( $input );
464464 }
465465
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" );
470470 }
471471 return $lines;
472472 }
@@ -476,33 +476,33 @@
477477 * @return array
478478 * @param string $line A line from the YAML file
479479 */
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();
484484
485485 $array = array();
486486
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 );
491491 }
492492
493 - if ($this->startsMappedSequence($line))
494 - return $this->returnMappedSequence($line);
 493+ if ( $this->startsMappedSequence( $line ) )
 494+ return $this->returnMappedSequence( $line );
495495
496 - if ($this->startsMappedValue($line))
497 - return $this->returnMappedValue($line);
 496+ if ( $this->startsMappedValue( $line ) )
 497+ return $this->returnMappedValue( $line );
498498
499 - if ($this->isArrayElement($line))
500 - return $this->returnArrayElement($line);
 499+ if ( $this->isArrayElement( $line ) )
 500+ return $this->returnArrayElement( $line );
501501
502 - if ($this->isPlainArray($line))
503 - return $this->returnPlainArray($line);
 502+ if ( $this->isPlainArray( $line ) )
 503+ return $this->returnPlainArray( $line );
504504
505505
506 - return $this->returnKeyValuePair($line);
 506+ return $this->returnKeyValuePair( $line );
507507
508508 }
509509
@@ -512,92 +512,92 @@
513513 * @param string $value
514514 * @return mixed
515515 */
516 - private function _toType($value) {
517 - if ($value === '') return null;
 516+ private function _toType( $value ) {
 517+ if ( $value === '' ) return null;
518518 $first_character = $value[0];
519 - $last_character = substr($value, -1, 1);
 519+ $last_character = substr( $value, -1, 1 );
520520
521521 $is_quoted = false;
522522 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;
526526 $is_quoted = true;
527 - } while (0);
 527+ } while ( 0 );
528528
529 - if ($is_quoted)
530 - return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\'\'' => '\'', '\\\'' => '\''));
 529+ if ( $is_quoted )
 530+ return strtr( substr ( $value, 1, -1 ), array ( '\\"' => '"', '\'\'' => '\'', '\\\'' => '\'' ) );
531531
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 );
534534
535 - if (!$is_quoted) $value = str_replace('\n', "\n", $value);
 535+ if ( !$is_quoted ) $value = str_replace( '\n', "\n", $value );
536536
537 - if ($first_character == '[' && $last_character == ']') {
 537+ if ( $first_character == '[' && $last_character == ']' ) {
538538 // 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 );
542542 // Propagate value array
543543 $value = array();
544 - foreach ($explode as $v) {
545 - $value[] = $this->_toType($v);
 544+ foreach ( $explode as $v ) {
 545+ $value[] = $this->_toType( $v );
546546 }
547547 return $value;
548548 }
549549
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 );
557557 }
558558
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();
562562 // Inline Mapping
563563 // Take out strings sequences and mappings
564 - $explode = $this->_inlineEscape($innerValue);
 564+ $explode = $this->_inlineEscape( $innerValue );
565565 // Propagate value array
566566 $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;
572572 }
573573 $array[] = $SubArr;
574574 }
575575 return $array;
576576 }
577577
578 - if ($value == 'null' || $value == 'NULL' || $value == 'Null' || $value == '' || $value == '~') {
 578+ if ( $value == 'null' || $value == 'NULL' || $value == 'Null' || $value == '' || $value == '~' ) {
579579 return null;
580580 }
581581
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 ) ) {
583583 $intvalue = (int)$value;
584 - if ($intvalue != PHP_INT_MAX)
 584+ if ( $intvalue != PHP_INT_MAX )
585585 $value = $intvalue;
586586 return $value;
587587 }
588588
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' ) ) ) {
591591 return true;
592592 }
593593
594 - if (in_array(strtolower($value),
595 - array('false', 'off', '-', 'no', 'n'))) {
 594+ if ( in_array( strtolower( $value ),
 595+ array( 'false', 'off', '-', 'no', 'n' ) ) ) {
596596 return false;
597597 }
598598
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 )
602602 $value = (float)$value;
603603 return $value;
604604 }
@@ -610,7 +610,7 @@
611611 * @access private
612612 * @return array
613613 */
614 - private function _inlineEscape($inline) {
 614+ private function _inlineEscape( $inline ) {
615615 // There's gotta be a cleaner way to do this...
616616 // While pure sequences seem to be nesting just fine,
617617 // pure mappings and mappings with sequences inside can't go very
@@ -622,42 +622,42 @@
623623
624624 // Check for strings
625625 $regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/';
626 - if (preg_match_all($regex,$inline,$strings)) {
 626+ if ( preg_match_all( $regex, $inline, $strings ) ) {
627627 $saved_strings = $strings[0];
628 - $inline = preg_replace($regex,'YAMLString',$inline);
 628+ $inline = preg_replace( $regex, 'YAMLString', $inline );
629629 }
630 - unset($regex);
 630+ unset( $regex );
631631
632632 $i = 0;
633633 do {
634634
635635 // Check for sequences
636 - while (preg_match('/\[([^{}\[\]]+)\]/U',$inline,$matchseqs)) {
 636+ while ( preg_match( '/\[([^{}\[\]]+)\]/U', $inline, $matchseqs ) ) {
637637 $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 );
639639 }
640640
641641 // Check for mappings
642 - while (preg_match('/{([^\[\]{}]+)}/U',$inline,$matchmaps)) {
 642+ while ( preg_match( '/{([^\[\]{}]+)}/U', $inline, $matchmaps ) ) {
643643 $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 );
645645 }
646646
647 - if ($i++ >= 10) break;
 647+ if ( $i++ >= 10 ) break;
648648
649 - } while (strpos ($inline, '[') !== false || strpos ($inline, '{') !== false);
 649+ } while ( strpos ( $inline, '[' ) !== false || strpos ( $inline, '{' ) !== false );
650650
651 - $explode = explode(', ',$inline);
 651+ $explode = explode( ', ', $inline );
652652 $stringi = 0; $i = 0;
653653
654 - while (1) {
 654+ while ( 1 ) {
655655
656656 // 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 );
662662 $value = $explode[$key];
663663 }
664664 }
@@ -665,11 +665,11 @@
666666 }
667667
668668 // 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 );
674674 $value = $explode[$key];
675675 }
676676 }
@@ -678,11 +678,11 @@
679679
680680
681681 // 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] );
687687 ++$stringi;
688688 $value = $explode[$key];
689689 }
@@ -690,72 +690,72 @@
691691 }
692692
693693 $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 ) {
696696 $finished = false; break;
697697 }
698 - if (strpos($value,'YAMLMap') !== false) {
 698+ if ( strpos( $value, 'YAMLMap' ) !== false ) {
699699 $finished = false; break;
700700 }
701 - if (strpos($value,'YAMLString') !== false) {
 701+ if ( strpos( $value, 'YAMLString' ) !== false ) {
702702 $finished = false; break;
703703 }
704704 }
705 - if ($finished) break;
 705+ if ( $finished ) break;
706706
707707 $i++;
708 - if ($i > 10)
 708+ if ( $i > 10 )
709709 break; // Prevent infinite loops.
710710 }
711711
712712 return $explode;
713713 }
714714
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;
718718 return false;
719719 }
720720
721 - private function referenceContentsByAlias ($alias) {
 721+ private function referenceContentsByAlias ( $alias ) {
722722 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; }
724724 $groupPath = $this->SavedGroups[$alias];
725725 $value = $this->result;
726 - foreach ($groupPath as $k) {
 726+ foreach ( $groupPath as $k ) {
727727 $value = $value[$k];
728728 }
729 - } while (false);
 729+ } while ( false );
730730 return $value;
731731 }
732732
733 - private function addArrayInline ($array, $indent) {
 733+ private function addArrayInline ( $array, $indent ) {
734734 $CommonGroupPath = $this->path;
735 - if (empty ($array)) return false;
 735+ if ( empty ( $array ) ) return false;
736736
737 - foreach ($array as $k => $_) {
738 - $this->addArray(array($k => $_), $indent);
 737+ foreach ( $array as $k => $_ ) {
 738+ $this->addArray( array( $k => $_ ), $indent );
739739 $this->path = $CommonGroupPath;
740740 }
741741 return true;
742742 }
743743
744 - private function addArray ($incoming_data, $incoming_indent) {
 744+ private function addArray ( $incoming_data, $incoming_indent ) {
745745
746746 // print_r ($incoming_data);
747747
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 );
750750
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';
754754
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' ) {
757757 $this->result[$key] = $value;
758758 } else {
759 - $this->result[] = $value; end ($this->result); $key = key ($this->result);
 759+ $this->result[] = $value; end ( $this->result ); $key = key ( $this->result );
760760 }
761761 $this->path[$incoming_indent] = $key;
762762 return;
@@ -766,44 +766,44 @@
767767 $history = array();
768768 // Unfolding inner array tree.
769769 $history[] = $_arr = $this->result;
770 - foreach ($this->path as $k) {
 770+ foreach ( $this->path as $k ) {
771771 $history[] = $_arr = $_arr[$k];
772772 }
773773
774 - if ($this->_containsGroupAlias) {
775 - $value = $this->referenceContentsByAlias($this->_containsGroupAlias);
 774+ if ( $this->_containsGroupAlias ) {
 775+ $value = $this->referenceContentsByAlias( $this->_containsGroupAlias );
776776 $this->_containsGroupAlias = false;
777777 }
778778
779779
780780 // 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 (); }
783783
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' ) {
786786 $_arr[$key] = $value;
787787 } 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 ); }
790790 }
791791
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 );
794794 $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];
798798 }
799799 $this->result = $reverse_history[$cnt];
800800
801801 $this->path[$incoming_indent] = $key;
802802
803 - if ($this->_containsGroupAnchor) {
 803+ if ( $this->_containsGroupAnchor ) {
804804 $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 ) ) {
808808 $this->SavedGroups[$this->_containsGroupAnchor][$incoming_indent + 2] = $k;
809809 }
810810 }
@@ -812,209 +812,209 @@
813813
814814 }
815815
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;
820820 // HTML tags should not be counted as literal blocks.
821 - if (preg_match ('#<.*?>$#', $line)) return false;
 821+ if ( preg_match ( '#<.*?>$#', $line ) ) return false;
822822 return $lastChar;
823823 }
824824
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;
831831 return false;
832832 }
833833
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 == '|' ) {
838838 return $literalBlock . $line;
839839 }
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";
844844 }
845 - if ($line != "\n")
846 - $line = trim ($line, "\r\n ") . " ";
 845+ if ( $line != "\n" )
 846+ $line = trim ( $line, "\r\n " ) . " ";
847847 return $literalBlock . $line;
848848 }
849849
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" );
856856 }
857857 return $lineArray;
858858 }
859859
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 );
863863 }
864864
865 - private function getParentPathByIndent ($indent) {
866 - if ($indent == 0) return array();
 865+ private function getParentPathByIndent ( $indent ) {
 866+ if ( $indent == 0 ) return array();
867867 $linePath = $this->path;
868868 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 );
872872 return $linePath;
873873 }
874874
875875
876 - private function clearBiggerPathValues ($indent) {
 876+ private function clearBiggerPathValues ( $indent ) {
877877
878878
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;
881881
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] );
884884 }
885885
886886 return true;
887887 }
888888
889889
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;
894894 return false;
895895 }
896896
897 - private static function isEmpty ($line) {
898 - return (trim ($line) === '');
 897+ private static function isEmpty ( $line ) {
 898+ return ( trim ( $line ) === '' );
899899 }
900900
901901
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;
907907
908908 return true;
909909 }
910910
911 - private function isHashElement ($line) {
912 - return strpos($line, ':');
 911+ private function isHashElement ( $line ) {
 912+ return strpos( $line, ':' );
913913 }
914914
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;
918918 return true;
919919 }
920920
921921
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, '"' );
927927 return $value;
928928 }
929929
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 ) == ':' );
932932 }
933933
934 - private function returnMappedSequence ($line) {
 934+ private function returnMappedSequence ( $line ) {
935935 $array = array();
936 - $key = self::unquote(trim(substr($line,1,-1)));
 936+ $key = self::unquote( trim( substr( $line, 1, -1 ) ) );
937937 $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 );
940940 }
941941
942 - private function returnMappedValue ($line) {
 942+ private function returnMappedValue ( $line ) {
943943 $array = array();
944 - $key = self::unquote (trim(substr($line,0,-1)));
 944+ $key = self::unquote ( trim( substr( $line, 0, -1 ) ) );
945945 $array[$key] = '';
946946 return $array;
947947 }
948948
949 - private function startsMappedValue ($line) {
950 - return (substr ($line, -1, 1) == ':');
 949+ private function startsMappedValue ( $line ) {
 950+ return ( substr ( $line, -1, 1 ) == ':' );
951951 }
952952
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 ) == ']' );
955955 }
956956
957 - private function returnPlainArray ($line) {
958 - return $this->_toType($line);
959 - }
 957+ private function returnPlainArray ( $line ) {
 958+ return $this->_toType( $line );
 959+ }
960960
961 - private function returnKeyValuePair ($line) {
 961+ private function returnKeyValuePair ( $line ) {
962962 $array = array();
963963 $key = '';
964 - if (strpos ($line, ':')) {
 964+ if ( strpos ( $line, ':' ) ) {
965965 // It's a key/value pair most likely
966966 // 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 ) );
969969 $key = $matches[2];
970970 } else {
971971 // 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 ) );
976976 }
977977 // 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';
980980 $array[$key] = $value;
981981 } else {
982 - $array = array ($line);
 982+ $array = array ( $line );
983983 }
984984 return $array;
985985
986986 }
987987
988988
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 %)
991991 $array = array();
992 - $value = trim(substr($line,1));
993 - $value = $this->_toType($value);
 992+ $value = trim( substr( $line, 1 ) );
 993+ $value = $this->_toType( $value );
994994 $array[] = $value;
995995 return $array;
996996 }
997997
998998
999 - private function nodeContainsGroup ($line) {
 999+ private function nodeContainsGroup ( $line ) {
10001000 $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];
10071007 return false;
10081008
10091009 }
10101010
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);
10151015 }
10161016
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 ) );
10191019 return $line;
10201020 }
10211021 }
@@ -1022,13 +1022,13 @@
10231023 // Enable use of Spyc from command line
10241024 // The syntax is the following: php spyc.php spyc.yaml
10251025
1026 -define ('SPYC_FROM_COMMAND_LINE', false);
 1026+define ( 'SPYC_FROM_COMMAND_LINE', false );
10271027
10281028 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;
10321032 $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 @@
334334 }
335335
336336 $this->dbInfo = array(); // Something iterable
 337+
337338 if ( !count( $keys ) ) {
338339 return;
339340 }
Index: trunk/extensions/Translate/scripts/toolserver-export.php
@@ -43,11 +43,19 @@
4444 }
4545
4646 list( $key, $code ) = TranslateUtils::figureMessage( $r->page_title );
47 - if ( $key === '' ) continue;
48 - if ( $code === '' ) continue;
4947
 48+ if ( $key === '' ) {
 49+ continue;
 50+ }
 51+
 52+ if ( $code === '' ) {
 53+ continue;
 54+ }
 55+
5056 $group = @$index[strtolower( "{$r->page_namespace}:$key" )];
51 - if ( $group === null ) continue;
 57+ if ( $group === null ) {
 58+ continue;
 59+ }
5260
5361 $from = array( "\\", "\n", "\t" );
5462 $to = array( "\\\\", "\\\n", "\\\t" );
Index: trunk/extensions/Translate/scripts/messageDust.php
@@ -19,10 +19,11 @@
2020 $invalid = array();
2121
2222 foreach ( $rows as $row ) {
23 -
2423 list( $key, $code ) = TranslateUtils::figureMessage( $row->page_title );
2524
26 - if ( !$code ) $code = 'en';
 25+ if ( !$code ) {
 26+ $code = 'en';
 27+ }
2728
2829 $mg = TranslateUtils::messageKeyToGroup( $row->page_namespace, $key );
2930 $ns = $wgContLang->getNsText( $row->page_namespace );
@@ -37,9 +38,13 @@
3839 $invalid[$code][] = "[[$ns:$key/$code]]";
3940 }
4041
41 - if ( !isset( $owners[$owner] ) ) $owners[$owner] = 0;
 42+ if ( !isset( $owners[$owner] ) ) {
 43+ $owners[$owner] = 0;
 44+ }
 45+
4246 $owners[$owner]++;
4347 }
 48+
4449 $rows->free();
4550
4651 ksort( $owners );
Index: trunk/extensions/Translate/scripts/fuzzy.php
@@ -31,7 +31,9 @@
3232 exit( 1 );
3333 }
3434
35 -if ( isset( $options['help'] ) ) showUsage();
 35+if ( isset( $options['help'] ) ) {
 36+ showUsage();
 37+}
3638
3739 $bot = new FuzzyBot( $args );
3840
@@ -40,10 +42,18 @@
4143 $_skipLanguages = array_map( 'trim', explode( ',', $options['skiplanguages'] ) );
4244 $bot->skipLanguages = $_skipLanguages;
4345 }
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+}
4749
 50+if ( isset( $options['comment'] ) ) {
 51+ $bot->comment = $options['comment'];
 52+}
 53+
 54+if ( isset( $options['really'] ) ) {
 55+ $bot->dryrun = false;
 56+}
 57+
4858 $bot->execute();
4959
5060 class FuzzyBot {
@@ -127,6 +137,7 @@
128138
129139 public function getImportUser() {
130140 static $user = null;
 141+
131142 if ( $user === null ) {
132143 global $wgTranslateFuzzyBotName;
133144 $user = User::newFromName( $wgTranslateFuzzyBotName );
@@ -142,6 +153,7 @@
143154
144155 private function updateMessage( $title, $text, $dryrun, $comment = null ) {
145156 global $wgTranslateDocumentationLanguageCode, $wgUser;
 157+
146158 $oldUser = $wgUser;
147159 $wgUser = $this->getImportUser();
148160
Index: trunk/extensions/Translate/scripts/createCheckIndex.php
@@ -107,4 +107,3 @@
108108 $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
109109 }
110110 }
111 -
Index: trunk/extensions/Translate/scripts/cli.inc
@@ -17,8 +17,11 @@
1818
1919 function STDOUT( $str, $channel = null, $force = false ) {
2020 global $options;
21 - if ( isset($options['quiet']) &&!$force ) return;
2221
 22+ if ( isset($options['quiet']) &&!$force ) {
 23+ return;
 24+ }
 25+
2326 static $lastChannel = null;
2427 static $lineStart = true;
2528
@@ -26,10 +29,16 @@
2730 fwrite( STDOUT, $str );
2831 } elseif ( $str === false ) {
2932 // Cleanup
30 - if ( !$lineStart ) fwrite( STDOUT, "\n" );
 33+ if ( !$lineStart ) {
 34+ fwrite( STDOUT, "\n" );
 35+ }
 36+
3137 return;
3238 } else {
33 - if ( !$lineStart ) fwrite( STDOUT, "\n" );
 39+ if ( !$lineStart ) {
 40+ fwrite( STDOUT, "\n" );
 41+ }
 42+
3443 fwrite( STDOUT, $str );
3544 }
3645
@@ -38,6 +47,7 @@
3948 fwrite( STDOUT, "\n" );
4049 $lineStart = true;
4150 }
 51+
4252 $lastChannel = $channel;
4353 }
4454
@@ -47,9 +57,7 @@
4858
4959 register_shutdown_function('STDOUT', false);
5060
51 -
5261 class Cli {
53 -
5462 public static function parseLanguageCodes( /* string */ $codes ) {
5563 $langs = array_map( 'trim', explode( ',', $codes ) );
5664 if ( $langs[0] === '*' ) {
@@ -57,6 +65,7 @@
5866 ksort($languages);
5967 $langs = array_keys($languages);
6068 }
 69+
6170 return $langs;
6271 }
63 -}
\ No newline at end of file
 72+}
Index: trunk/extensions/Translate/scripts/tm-export.php
@@ -16,7 +16,6 @@
1717 define( 'TRANSLATE_CLI', 1 );
1818 require_once( "$IP/maintenance/Maintenance.php" );
1919
20 -
2120 class TMExport extends Maintenance {
2221 public function __construct() {
2322 parent::__construct();
@@ -39,7 +38,10 @@
4039 unset( $languages['en'] );
4140
4241 foreach ( $groups as $id => $group ) {
43 - if ( $group->isMeta() ) continue;
 42+ if ( $group->isMeta() ) {
 43+ continue;
 44+ }
 45+
4446 $this->output( "Processing: {$group->getLabel()} ", $id );
4547 $capitalized = MWNamespace::isCapitalized( $group->getNamespace() );
4648 $ns_text = $wgContLang->getNsText( $group->getNamespace() );
@@ -63,7 +65,9 @@
6466
6567 $res = $dbr->select( $tables, $vars, $conds, __METHOD__ );
6668 // Assure that there is at least one translation
67 - if ( $res->numRows() < 1 ) continue;
 69+ if ( $res->numRows() < 1 ) {
 70+ continue;
 71+ }
6872
6973 $insert = array(
7074 'text' => $definition,
@@ -98,7 +102,6 @@
99103 $dbw->commit();
100104 } // each group>
101105 }
102 -
103106 }
104107
105108 $maintClass = 'TMExport';
Index: trunk/extensions/Translate/scripts/magic-export.php
@@ -45,14 +45,15 @@
4646 exit( 1 );
4747 }
4848
49 -
5049 $langs = Cli::parseLanguageCodes( '*' );
5150 $groups = MessageGroups::singleton()->getGroups();
5251
5352 $type = $options['type'] ;
5453
5554 foreach ( $groups as $group ) {
56 - if ( !$group instanceof ExtensionMessageGroup ) continue;
 55+ if ( !$group instanceof ExtensionMessageGroup ) {
 56+ continue;
 57+ }
5758
5859 if ( $type === 'special' ) {
5960 $filename = $group->getAliasFile();
@@ -60,10 +61,15 @@
6162 $filename = $group->getMagicFile();
6263 }
6364
64 - if ( $filename === null ) continue;
 65+ if ( $filename === null ) {
 66+ continue;
 67+ }
6568
6669 $file = "$wgTranslateExtensionDirectory/$filename";
67 - if ( !file_exists( $file ) ) continue;
 70+ if ( !file_exists( $file ) ) {
 71+ continue;
 72+ }
 73+
6874 STDOUT( "Processing {$group->getLabel()}... ", $group->getId() );
6975
7076 $input = file_get_contents( $file ) . "\n";
@@ -74,19 +80,21 @@
7581
7682 foreach ( $langs as $l ) {
7783 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 );
8793 }
8894
8995 $export = $o->export( $group->getId() );
90 - if ( $export === '' ) continue;
 96+ if ( $export === '' ) {
 97+ continue;
 98+ }
9199
92100 # remove useles comment
93101 $export = preg_replace( "~^# .*$\n~m", '', $export );
Index: trunk/extensions/Translate/scripts/createMessageIndex.php
@@ -33,4 +33,4 @@
3434 showUsage();
3535 }
3636
37 -MessageIndexRebuilder::execute();
\ No newline at end of file
 37+MessageIndexRebuilder::execute();
Index: trunk/extensions/Translate/scripts/populateFuzzy.php
@@ -8,6 +8,7 @@
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 * @file
1111 */
 12+
1213 require( dirname( __FILE__ ) . '/cli.inc' );
1314
1415 $db = wfGetDB( DB_MASTER );
@@ -18,14 +19,12 @@
1920 exit();
2021 }
2122
22 -
2323 $count = $db->selectField( 'page', 'count(*)', array( 'page_namespace' => $wgTranslateMessageNamespaces ), __METHOD__ );
2424 if ( !$count ) {
2525 echo "Nothing to update";
2626 exit();
2727 }
2828
29 -
3029 $tables = array( 'page', 'text', 'revision' );
3130 $fields = array( 'page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags' );
3231 $conds = array(
@@ -41,7 +40,11 @@
4241 echo "$offset/$count\n";
4342 $options = array( 'LIMIT' => $limit, 'OFFSET' => $offset );
4443 $res = $db->select( $tables, $fields, $conds, __METHOD__, $options );
45 - if ( !$res->numRows() ) break;
 44+
 45+ if ( !$res->numRows() ) {
 46+ break;
 47+ }
 48+
4649 foreach ( $res as $r ) {
4750 $text = Revision::getRevisionText( $r );
4851 if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) {
@@ -52,8 +55,8 @@
5356 );
5457 }
5558 }
 59+
5660 $offset += $limit;
5761
5862 $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
5963 }
60 -
Index: trunk/extensions/Translate/scripts/pagetranslation-test-parser.php
@@ -17,7 +17,6 @@
1818 }
1919 require_once( "$IP/maintenance/Maintenance.php" );
2020
21 -
2221 class PageTranslationParserTester extends Maintenance {
2322 public function __construct() {
2423 parent::__construct();
@@ -74,11 +73,10 @@
7574 if ( file_exists( "$pattern.pttest" ) ) {
7675 require( "$pattern.pttest" );
7776 }
78 -
7977 }
8078 }
8179
8280 }
8381
8482 $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 @@
3333 exit( 1 );
3434 }
3535
36 -if ( isset( $options['help'] ) ) showUsage();
 36+if ( isset( $options['help'] ) ) {
 37+ showUsage();
 38+}
3739
3840 if ( !isset( $options['group'] ) ) {
3941 STDERR( "ESG1: Message group id must be supplied with group parameter." );
@@ -91,17 +93,32 @@
9294 } else {
9395 $file = $group->getMessageFileWithPath( $code );
9496 }
95 - if ( !$file ) continue;
9697
97 - if ( !file_exists( $file ) ) continue;
 98+ if ( !$file ) {
 99+ continue;
 100+ }
98101
 102+ if ( !file_exists( $file ) ) {
 103+ continue;
 104+ }
 105+
99106 $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+ }
103110
 111+ if ( isset( $options['noask'] ) ) {
 112+ $cs->interactive = false;
 113+ }
 114+
 115+ if ( isset( $options['nocolor'] ) ) {
 116+ $cs->nocolor = true;
 117+ }
 118+
104119 $ts = $cs->getTimestampsFromSvn( $file );
105 - if ( !$ts ) $ts = $cs->getTimestampsFromFs( $file );
 120+ if ( !$ts ) {
 121+ $ts = $cs->getTimestampsFromFs( $file );
 122+ }
106123
107124 STDOUT( "Modify time for $code: " . wfTimestamp( TS_ISO_8601, $ts ) );
108125
@@ -126,8 +143,10 @@
127144 $file = escapeshellarg( $file );
128145 $retval = 0;
129146 $output = wfShellExec( "svn info $file 2>/dev/null", $retval );
130 - if ( $retval ) return false;
131147
 148+ if ( $retval ) {
 149+ return false;
 150+ }
132151
133152 $matches = array();
134153 // PHP doesn't allow foo || return false;
@@ -136,21 +155,30 @@
137156 // PHP (for being an ass)!
138157 $regex = '^Last Changed Date: (.*) \(';
139158 $ok = preg_match( "~$regex~m", $output, $matches );
140 - if ( $ok ) return strtotime( $matches[1] );
 159+ if ( $ok ) {
 160+ return strtotime( $matches[1] );
 161+ }
141162
142163 return false;
143164 }
144165
145166 public function getTimestampsFromFs( $file ) {
146 - if ( !file_exists( $file ) ) return false;
 167+ if ( !file_exists( $file ) ) {
 168+ return false;
 169+ }
 170+
147171 $stat = stat( $file );
 172+
148173 return $stat['mtime'];
149174 }
150175
151176 public function checkConflicts( $code, $startTs = false, $endTs = false, $changeTs = false ) {
152177 $messages = $this->group->load( $code );
153 - if ( !count( $messages ) ) return;
154178
 179+ if ( !count( $messages ) ) {
 180+ return;
 181+ }
 182+
155183 $collection = $this->group->initCollection( $code );
156184 $collection->filter( 'ignored' );
157185 $collection->loadTranslations();
@@ -178,7 +206,9 @@
179207
180208 $current = str_replace( TRANSLATE_FUZZY, '', $collection[$key]->translation() );
181209 $translation = str_replace( TRANSLATE_FUZZY, '', $translation );
182 - if ( $translation === $current ) continue;
 210+ if ( $translation === $current ) {
 211+ continue;
 212+ }
183213
184214 STDOUT( "Conflict in " . $this->color( 'bold', $page ) . "!", $page );
185215
@@ -228,7 +258,10 @@
229259
230260 }
231261
232 - if ( !$this->interactive ) continue;
 262+ if ( !$this->interactive ) {
 263+ continue;
 264+ }
 265+
233266 STDOUT( " →Needs manual resolution", $page );
234267 STDOUT( "Source translation at $changeDate:" );
235268 STDOUT( $this->color( 'blue', $translation ) . "\n" );
@@ -239,11 +272,16 @@
240273 STDOUT( "Resolution: [S]kip [I]mport [C]onflict: ", 'foo' );
241274 $action = fgets( STDIN );
242275 $action = strtoupper( trim( $action ) );
243 - if ( $action === 'S' ) break;
 276+
 277+ if ( $action === 'S' ) {
 278+ break;
 279+ }
 280+
244281 if ( $action === 'I' ) {
245282 $this->import( $title, $translation, 'Updating translation from external source' );
246283 break;
247284 }
 285+
248286 if ( $action === 'C' ) {
249287 $this->import( $title, TRANSLATE_FUZZY . $translation, 'Edit conflict between wiki and source' );
250288 break;
@@ -272,7 +310,9 @@
273311 $revision = Revision::newFromTitle( $title );
274312 while ( $revision ) {
275313 // No need to go back further
276 - if ( $startTs && $wikiTs && ( $wikiTs < $startTs ) ) break;
 314+ if ( $startTs && $wikiTs && ( $wikiTs < $startTs ) ) {
 315+ break;
 316+ }
277317
278318 if ( $revision->getRawUserText() === $wgTranslateFuzzyBotName ) {
279319 $revision = $revision->getPrevious();
@@ -288,8 +328,10 @@
289329
290330 public function getImportUser() {
291331 static $user = null;
 332+
292333 if ( $user === null ) {
293334 global $wgTranslateFuzzyBotName;
 335+
294336 $user = User::newFromName( $wgTranslateFuzzyBotName );
295337
296338 if ( !$user->isLoggedIn() ) {
@@ -303,11 +345,14 @@
304346
305347 public function import( $title, $translation, $comment ) {
306348 global $wgUser;
 349+
307350 $old = $wgUser;
308351 $wgUser = $this->getImportUser();
309352
310353 $flags = EDIT_FORCE_BOT;
311 - if ( $this->norc ) $flags |= EDIT_SUPPRESS_RC;
 354+ if ( $this->norc ) {
 355+ $flags |= EDIT_SUPPRESS_RC;
 356+ }
312357
313358 $article = new Article( $title );
314359 STDOUT( "Importing {$title->getPrefixedText()}: ", $title );
Index: trunk/extensions/Translate/scripts/groupStatistics.php
@@ -174,7 +174,9 @@
175175 showUsage();
176176 }
177177
178 -if ( !isset( $options['output'] ) ) $options['output'] = 'default';
 178+if ( !isset( $options['output'] ) ) {
 179+ $options['output'] = 'default';
 180+}
179181
180182 /** Print a usage message*/
181183 function showUsage() {
@@ -250,6 +252,7 @@
251253 if ( isset( $options['most'] ) && isset( $localisedWeights[$options['most']] ) ) {
252254 $reportScore = true;
253255 $weights = array();
 256+
254257 foreach ( $localisedWeights[$options['most']] as $weight ) {
255258 $weights[] = $weight;
256259 }
Index: trunk/extensions/Translate/scripts/alias-export.php
@@ -49,7 +49,10 @@
5050 $groups = MessageGroups::singleton()->getGroups();
5151
5252 foreach ( $groups as $group ) {
53 - if ( !$group instanceof ExtensionMessageGroup ) continue;
 53+ if ( !$group instanceof ExtensionMessageGroup ) {
 54+ continue;
 55+ }
 56+
5457 $file = $group->getAliasFile();
5558
5659 $groupId = $group->getId();
@@ -58,6 +61,7 @@
5962 // Fake a group
6063 $group = new AliasMessageGroup( $group->getId() );
6164 $group->setMessageFile( $file );
 65+
6266 // FIXME: getVariableNameAlias() is not read from mediawiki-defines.txt here apparently.
6367 // Hacked this one exception in for now
6468 if ( $groupId == 'ext-wikilog' ) {
Index: trunk/extensions/Translate/scripts/languageeditstats.php
@@ -69,6 +69,7 @@
7070 $pos = strrpos( $text, '/' );
7171 $code = substr( $text, $pos + 1 );
7272 $key = substr( $text, 0, $pos );
 73+
7374 return array( $key, $code );
7475 }
7576
@@ -82,11 +83,16 @@
8384 $codes = array();
8485 foreach ( $rows as $_ ) {
8586 // Filter out edits by $wgTranslateFuzzyBotName
86 - if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) continue;
 87+ if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) {
 88+ continue;
 89+ }
8790
8891 list( , $code ) = figureMessage( $_->rc_title );
8992
90 - if ( !isset( $codes[$code] ) ) $codes[$code] = 0;
 93+ if ( !isset( $codes[$code] ) ) {
 94+ $codes[$code] = 0;
 95+ }
 96+
9197 $codes[$code]++;
9298 }
9399
@@ -95,6 +101,9 @@
96102 arsort( $codes );
97103 $i = 0;
98104 foreach ( $codes as $code => $num ) {
99 - if ( $i++ === $top ) break;
 105+ if ( $i++ === $top ) {
 106+ break;
 107+ }
 108+
100109 STDOUT( "$code\t$num" );
101110 }
Index: trunk/extensions/Translate/scripts/poimport.php
@@ -27,7 +27,10 @@
2828 exit( 1 );
2929 }
3030
31 -if ( isset( $options['help'] ) ) showUsage();
 31+if ( isset( $options['help'] ) ) {
 32+ showUsage();
 33+}
 34+
3235 if ( !isset( $options['file'] ) ) {
3336 STDERR( "You need to specify input file" );
3437 exit( 1 );
@@ -60,7 +63,6 @@
6164 * supported.
6265 */
6366 class PoImporter {
64 -
6567 /**
6668 * Path to file to parse.
6769 */
@@ -125,8 +127,11 @@
126128 if ( preg_match( "/^msgctxt\s($poformat)/mx", $section, $matches ) ) {
127129 // Remove quoting
128130 $key = preg_replace( $quotePattern, '', $matches[1] );
 131+
129132 // Ignore unknown keys
130 - if ( !isset( $contents[$key] ) ) continue;
 133+ if ( !isset( $contents[$key] ) ) {
 134+ continue;
 135+ }
131136 } else {
132137 continue;
133138 }
@@ -163,9 +168,7 @@
164169 }
165170
166171 return array( $changes, $groupId );
167 -
168172 }
169 -
170173 }
171174
172175 /**
@@ -223,6 +226,7 @@
224227 */
225228 private function updateMessage( $namespace, $title, $text ) {
226229 global $wgTitle, $wgArticle;
 230+
227231 $wgTitle = Title::makeTitleSafe( $namespace, $title );
228232
229233 STDOUT( "Updating {$wgTitle->getPrefixedText()}... ", $title );
Index: trunk/extensions/Translate/scripts/autoexport.php
@@ -78,9 +78,9 @@
7979 $threshold = false;
8080 }
8181
82 -
8382 $rows = TranslateUtils::translationChanges( $hours, true );
8483 $exports = array();
 84+
8585 foreach ( $rows as $row ) {
8686 $group = false;
8787 $code = false;
@@ -89,11 +89,14 @@
9090 list( $pieces, ) = explode( '/', $wgContLang->lcfirst( $row->rc_title ), 2 );
9191
9292 $mg = TranslateUtils::messageKeyToGroup( $row->rc_namespace, $pieces );
93 - if ( !is_null( $mg ) ) $group = $mg;
 93+ if ( !is_null( $mg ) ) {
 94+ $group = $mg;
 95+ }
9496
9597 if ( strpos( $row->rc_title, '/' ) !== false ) {
9698 $code = $row->lang;
9799 }
 100+
98101 if ( $group && ( !count( $groupsFilter ) || in_array( $group, $groupsFilter ) ) ) {
99102 if ( $code && !in_array( $code, $skip ) ) {
100103 $exports[$group][$code] = true;
@@ -109,7 +112,9 @@
110113 sort( $languages );
111114 $languages = checkThreshold( $group, $languages, $threshold );
112115
113 - if ( !count( $languages ) ) continue;
 116+ if ( !count( $languages ) ) {
 117+ continue;
 118+ }
114119
115120 $languagelist = implode( ', ', $languages );
116121 STDOUT( str_replace(
@@ -120,6 +125,7 @@
121126 if ( $summarize ) {
122127 list( $group, ) = explode( '-', $group, 2 );
123128 }
 129+
124130 if ( isset( $notice[$group] ) ) {
125131 $notice[$group] = array_merge( $notice[$group], $languages );
126132 } else {
@@ -128,7 +134,10 @@
129135 }
130136
131137 function checkThreshold( $group, $languages, $threshold ) {
132 - if ( $threshold === false ) return $languages;
 138+ if ( $threshold === false ) {
 139+ return $languages;
 140+ }
 141+
133142 $qualify = array();
134143
135144 $g = MessageGroups::singleton()->getGroup( $group );
@@ -143,10 +152,12 @@
144153 $collection->filter( 'translated', false );
145154 $translated = count( $collection );
146155
147 - if ( $translated / $total > $threshold / 100 ) $qualify[] = $code;
 156+ if ( $translated / $total > $threshold / 100 ) {
 157+ $qualify[] = $code;
 158+ }
148159 }
 160+
149161 return $qualify;
150 -
151162 }
152163
153164 foreach ( $notice as $group => $languages ) {
Index: trunk/extensions/Translate/scripts/mwcore-export.php
@@ -35,6 +35,7 @@
3636 STDERR( "You need to specify target directory" );
3737 exit( 1 );
3838 }
 39+
3940 if ( !isset( $options['lang'] ) ) {
4041 STDERR( "You need to specify languages to export" );
4142 exit( 1 );
@@ -55,30 +56,33 @@
5657 $group = MessageGroups::getGroup( 'core' );
5758
5859 foreach ( $langs as $l ) {
59 -
6060 $o = null;
6161 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 );
7474 }
7575
7676 $export = $o->export( 'core' );
77 - if ( $export === '' ) continue;
 77+ if ( $export === '' ) {
 78+ continue;
 79+ }
7880
7981 $matches = array();
8082 preg_match( '~^(\$[a-zA-Z]+)\s*=~m', $export, $matches );
8183
82 - if ( !isset( $matches[1] ) ) continue;
 84+ if ( !isset( $matches[1] ) ) {
 85+ continue;
 86+ }
8387
8488 # remove useles comment
8589 $export = preg_replace( "~^# .*$\n~m", '', $export );
@@ -120,4 +124,4 @@
121125
122126 file_put_contents( $outFile, $data );
123127 }
124 -}
\ No newline at end of file
 128+}
Index: trunk/extensions/Translate/MessageChecks.php
@@ -79,13 +79,19 @@
8080 public function checkMessage( TMessage $message, $code ) {
8181 $warningsArray = array();
8282 $messages = array( $message );
 83+
8384 foreach ( $this->checks as $check ) {
8485 call_user_func_array( $check, array( $messages, $code, &$warningsArray ) );
8586 }
 87+
8688 $warningsArray = $this->filterWarnings( $warningsArray );
87 - if ( !count( $warningsArray ) ) return array();
 89+ if ( !count( $warningsArray ) ) {
 90+ return array();
 91+ }
 92+
8893 $warnings = $warningsArray[$message->key()];
8994 $warnings = $this->fixMessageParams( $warnings );
 95+
9096 return $warnings;
9197 }
9298
@@ -98,7 +104,9 @@
99105 $messages = array( $message );
100106 foreach ( $this->checks as $check ) {
101107 call_user_func_array( $check, array( $messages, $code, &$warningsArray ) );
102 - if ( count( $warningsArray ) ) return true;
 108+ if ( count( $warningsArray ) ) {
 109+ return true;
 110+ }
103111 }
104112
105113 return false;
@@ -116,11 +124,12 @@
117125 foreach ( $warnings as $wkey => $warning ) {
118126 $check = array_shift( $warning );
119127 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;
122130 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+
125134 unset( $warningsArray[$mkey][$wkey] );
126135 }
127136 }
Index: trunk/extensions/Translate/tests/pagetranslation/FailDoubleOpen.ptfile
@@ -1,3 +1,3 @@
22 <translate>
33 <translate>
4 -</translate>
\ No newline at end of file
 4+</translate>
Index: trunk/extensions/Translate/tests/pagetranslation/Simple.pttest
@@ -1,4 +1,3 @@
22 <?php
33
44 if ( !defined( 'MEDIAWIKI' ) ) die();
5 -
Index: trunk/extensions/Translate/tests/pagetranslation/FailNotAtomic.ptfile
@@ -2,4 +2,4 @@
33 <translate>
44 This is not fun!
55 </div>
6 -</translate>
\ No newline at end of file
 6+</translate>
Index: trunk/extensions/Translate/tests/pagetranslation/NowikiOnly.pttest
@@ -4,4 +4,4 @@
55
66 if ( $parse->countSections() !== 0 ) {
77 $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 @@
22 <translate>
33 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 @@
88 <translate>
99 Cow
1010 </translate>
11 -</translate>
\ No newline at end of file
 11+</translate>
Index: trunk/extensions/Translate/tests/pagetranslation/FailEmptySection.ptfile
@@ -1,4 +1,4 @@
22 <translate>
33 <!--T:1-->
44
5 -</translate>
\ No newline at end of file
 5+</translate>
Index: trunk/extensions/Translate/FFS.php
@@ -232,7 +232,6 @@
233233 //
234234 // READ
235235 //
236 -
237236 public function readFromVariable( $data ) {
238237 $data = self::fixNewLines( $data );
239238 $lines = array_map( 'ltrim', explode( "\n", $data ) );
Index: trunk/extensions/Translate/MessageGroups.php
@@ -93,6 +93,7 @@
9494 $messages = $reader->parseMessages( $this->mangler );
9595 return $messages ? $messages : array();
9696 }
 97+
9798 return array();
9899 }
99100
@@ -107,6 +108,7 @@
108109 if ( !is_array( $defs ) ) {
109110 throw new MWException( "Unable to load definitions for " . $this->getLabel() );
110111 }
 112+
111113 return $defs;
112114 }
113115
@@ -132,16 +134,21 @@
133135 $this->messages[$code] = self::normaliseKeys( $this->load( $code ) );
134136 }
135137 $key = strtolower( str_replace( ' ', '_', $key ) );
 138+
136139 return isset( $this->messages[$code][$key] ) ? $this->messages[$code][$key] : null;
137140 }
138141
139142 public static function normaliseKeys( $array ) {
140 - if ( !is_array( $array ) ) return null;
 143+ if ( !is_array( $array ) ) {
 144+ return null;
 145+ }
 146+
141147 $new = array();
142148 foreach ( $array as $key => $v ) {
143149 $key = strtolower( str_replace( ' ', '_', $key ) );
144150 $new[$key] = $v;
145151 }
 152+
146153 return $new;
147154 }
148155
@@ -273,11 +280,13 @@
274281
275282 return $ourDefs;
276283 }
 284+
277285 return $this->getDefinitions();
278286 }
279287
280288 public function getMessageFile( $code ) {
281289 $code = ucfirst( str_replace( '-', '_', $code ) );
 290+
282291 return "Messages$code.php";
283292 }
284293
@@ -295,6 +304,7 @@
296305
297306 public function getBools() {
298307 require( $this->getMetaDataPrefix() . '/messageTypes.inc' );
 308+
299309 return array(
300310 'optional' => $this->mangler->mangle( $wgOptionalMessages ),
301311 'ignored' => $this->mangler->mangle( $wgIgnoredMessages ),
@@ -462,7 +472,6 @@
463473
464474 public function getMagicFile() { return $this->magicFile; }
465475 public function setMagicFile( $file ) { $this->magicFile = $file; }
466 -
467476 }
468477
469478 class AliasMessageGroup extends ExtensionMessageGroup {
@@ -538,6 +547,7 @@
539548 $writer = new WikiExtensionFormatWriter( $this );
540549 $writer->variableName = $this->getVariableName();
541550 $writer->commaToArray = true;
 551+
542552 return $writer;
543553 }
544554 }
@@ -626,7 +636,6 @@
627637 return $group;
628638 }
629639
630 -
631640 public function getReader( $code ) {
632641 $reader = new GettextFormatReader( $this->getMessageFileWithPath( $code ) );
633642 $reader->setPrefix( $this->prefix );
@@ -712,7 +721,6 @@
713722
714723 $this->title = $title;
715724 $this->namespaces = array( NS_TRANSLATIONS, NS_TRANSLATIONS_TALK );
716 -
717725 }
718726
719727 public function getDefinitions() {
@@ -858,6 +866,7 @@
859867 self::init();
860868
861869 global $wgTranslateEC, $wgTranslateAC, $wgTranslateCC;
 870+
862871 if ( in_array( $id, $wgTranslateEC ) ) {
863872 $creater = $wgTranslateAC[$id];
864873 if ( is_array( $creater ) ) {
@@ -884,6 +893,7 @@
885894 public $classes = array();
886895 private function __construct() {
887896 self::init();
 897+
888898 global $wgTranslateEC, $wgTranslateCC;
889899
890900 $all = array_merge( $wgTranslateEC, array_keys( $wgTranslateCC ) );
Index: trunk/extensions/Translate/Message.php
@@ -85,4 +85,4 @@
8686 public function infile() {
8787 return $this->infile;
8888 }
89 -}
\ No newline at end of file
 89+}
Index: trunk/extensions/Translate/tag/TPParse.php
@@ -67,6 +67,7 @@
6868 }
6969
7070 }
 71+
7172 return $sections;
7273 }
7374
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -34,6 +34,7 @@
3535 // Only called form hook
3636 public static function injectCss( $outputpage, $text ) {
3737 TranslateUtils::injectCSS();
 38+
3839 return true;
3940 }
4041
@@ -324,6 +325,7 @@
325326 // No group means that the page is currently not
326327 // registered to any page translation message groups
327328 $result = array( 'tpt-unknown-page' );
 329+
328330 return false;
329331 }
330332
@@ -344,6 +346,7 @@
345347 $page->getTitle()->getPrefixedText(),
346348 $page->getTranslationUrl( $code )
347349 );
 350+
348351 return false;
349352 }
350353 }
@@ -439,6 +442,7 @@
440443 ) . Html::element( 'hr' );
441444
442445 global $wgOut;
 446+
443447 $wgOut->addHTML( $legend );
444448 }
445449
@@ -469,6 +473,7 @@
470474 $wrap = '<div style="font-size: x-small; text-align: center" class="mw-translate-fuzzy">$1</div>';
471475 $wgOut->wrapWikiMsg( $wrap, array( 'tpt-translation-intro-fuzzy' ) );
472476 }
 477+
473478 $wgOut->addHTML( '<hr />' );
474479 }
475480
Index: trunk/extensions/Translate/tag/TPSection.php
@@ -6,6 +6,7 @@
77 * @copyright Copyright © 2009 Niklas Laxström
88 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
99 */
 10+
1011 class TPSection {
1112 public $id, $name, $text, $type;
1213
Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * Class to parse translatable wiki pages.
65 *
@@ -7,6 +6,7 @@
87 * @copyright Copyright © 2009-2010 Niklas Laxström
98 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
109 */
 10+
1111 class TranslatablePage {
1212 /**
1313 * Title of the page.
@@ -49,6 +49,7 @@
5050 $obj = new self( $title );
5151 $obj->text = $text;
5252 $obj->source = 'text';
 53+
5354 return $obj;
5455 }
5556
@@ -67,6 +68,7 @@
6869 $obj = new self( $title );
6970 $obj->source = 'revision';
7071 $obj->revision = $revision;
 72+
7173 return $obj;
7274 }
7375
@@ -77,6 +79,7 @@
7880 public static function newFromTitle( Title $title ) {
7981 $obj = new self( $title );
8082 $obj->source = 'title';
 83+
8184 return $obj;
8285 }
8386
@@ -406,6 +409,7 @@
407410 'group' => 'page|' . $this->getTitle()->getPrefixedText(),
408411 'task' => 'view'
409412 );
 413+
410414 if ( $code ) {
411415 $params['language'] = $code;
412416 }
@@ -452,6 +456,7 @@
453457 public function getTranslationPercentages( $force = false ) {
454458 // Check the memory cache, as this is very slow to calculate
455459 global $wgMemc, $wgRequest;
 460+
456461 $memcKey = wfMemcKey( 'pt', 'status', $this->getTitle()->getPrefixedText() );
457462 $cache = $wgMemc->get( $memcKey );
458463
@@ -483,6 +488,7 @@
484489
485490 // Content language is always up-to-date
486491 global $wgContLang;
 492+
487493 $temp[$wgContLang->getCode()] = 1.00;
488494
489495 $wgMemc->set( $memcKey, $temp, 60 * 60 * 12 );
@@ -554,6 +560,7 @@
555561 }
556562
557563 global $wgTranslateStaticTags;
 564+
558565 if ( is_array( $wgTranslateStaticTags ) ) {
559566 return $wgTranslateStaticTags[$tag];
560567 }
@@ -610,6 +617,7 @@
611618 */
612619 class TPException extends MWException {
613620 protected $msg = null;
 621+
614622 public function __construct( $msg ) {
615623 $this->msg = $msg;
616624 parent::__construct( call_user_func_array( 'wfMsg', $msg ) );
Index: trunk/extensions/Translate/tag/RenderJob.php
@@ -57,6 +57,7 @@
5858
5959 // User hack
6060 global $wgUser;
 61+
6162 $oldUser = $wgUser;
6263 $wgUser = $user;
6364
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -38,18 +38,21 @@
3939 // Check permissions
4040 if ( !$this->user->isAllowed( 'pagetranslation' ) ) {
4141 $wgOut->permissionRequired( 'pagetranslation' );
 42+
4243 return;
4344 }
4445
4546 // Check permissions
4647 if ( !$this->user->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
4748 $wgOut->permissionRequired( 'pagetranslation' );
 49+
4850 return;
4951 }
5052
5153 // We are processing some specific page
5254 if ( !$title->exists() ) {
5355 $wgOut->addWikiMsg( 'tpt-nosuchpage', $title->getPrefixedText() );
 56+
5457 return;
5558 }
5659
@@ -57,6 +60,7 @@
5861 $page = TranslatablePage::newFromTitle( $title );
5962 $page->removeTags();
6063 $wgOut->addWikiMsg( 'tpt-unmarked', $title->getPrefixedText() );
 64+
6165 return;
6266 }
6367
@@ -68,12 +72,14 @@
6973 $page = TranslatablePage::newFromRevision( $title, $revision );
7074 if ( !$page instanceof TranslatablePage ) {
7175 $wgOut->addWikiMsg( 'tpt-notsuitable', $title->getPrefixedText(), $revision );
 76+
7277 return;
7378 }
7479
7580 if ( $revision !== $title->getLatestRevID() ) {
7681 // We do want to notify the reviewer if the underlying page changes during review
7782 $wgOut->addWikiMsg( 'tpt-oldrevision', $title->getPrefixedText(), $revision );
 83+
7884 return;
7985 }
8086
@@ -81,6 +87,7 @@
8288 if ( $lastrev !== false && $lastrev === $revision ) {
8389 $wgOut->addWikiMsg( 'tpt-already-marked' );
8490 $this->listPages();
 91+
8592 return;
8693 }
8794
@@ -282,6 +289,7 @@
283290 }
284291
285292 global $wgLang;
 293+
286294 return $wgLang->semicolonList( $actions );
287295 }
288296
@@ -443,7 +451,10 @@
444452 $changed = array();
445453
446454 foreach ( $sections as $s ) {
447 - if ( $s->type === 'changed' ) $changed[] = $s->name;
 455+ if ( $s->type === 'changed' ) {
 456+ $changed[] = $s->name;
 457+ }
 458+
448459 $inserts[] = array(
449460 'trs_page' => $page->getTitle()->getArticleId(),
450461 'trs_key' => $s->name,

Status & tagging log