From 3a92c858fbf7ae6739a855170328774dd53ca0d5 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Tue, 18 Aug 2009 22:13:31 +0000 Subject: [PATCH] Stylize, reindent, pretty comment blocks, updated command line output --- .../php/maintenance/mergeJavascriptMsg.php | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php b/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php index 66268f255e..29bca682cc 100644 --- a/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php +++ b/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php @@ -1,10 +1,10 @@ $object){ - if( substr( $fname, -3 ) == '.js' ){ - $jsFileText = file_get_contents( $fname ); - $mwPos = strpos( $fname, 'mwEmbed' ) + 7; - $curFileName = substr( $fname, $mwPos ); - if( preg_match( '/loadGM\s*\(\s*{(.*)}\s*\)\s*/siU', //@@todo fix: will break down if someone does }) in their msg text - $jsFileText, - $matches ) ){ +foreach ( $objects as $fname => $object ) { + if ( substr( $fname, - 3 ) == '.js' ) { + $jsFileText = file_get_contents( $fname ); + $mwPos = strpos( $fname, 'mwEmbed' ) + 7; + $curFileName = substr( $fname, $mwPos ); + if ( preg_match( '/loadGM\s*\(\s*{(.*)}\s*\)\s*/siU', // @@todo fix: will break down if someone does }) in their msg text + $jsFileText, + $matches ) ) { $msgSet .= doJsonMerge( $matches[1] ); } } } + // rebuild and output to file -if( file_put_contents( $mwLangFilePath, trim( $preFile ) . "\n\t" . trim( $msgSet ) . "\n" . trim( $postFile ) ) ){ - print "updated $mwLangFilePath file\n"; - exit(); +if ( file_put_contents( $mwLangFilePath, trim( $preFile ) . "\n\t" . trim( $msgSet ) . "\n" . trim( $postFile ) ) ) { + print "Updated $mwLangFilePath file\n"; + exit(); } +function doJsonMerge( $json_txt ) { + global $curFileName; -function doJsonMerge( $json_txt ){ - global $curFileName; - - $out = "\n\t/* -\t* js file: {$curFileName} -\t*/\n"; + $out = "\n\t/* + \t * js file: {$curFileName} + \t */\n"; $jmsg = json_decode( '{' . $json_txt . '}', true ); - if( count( $jmsg ) != 0 ){ - foreach( $jmsg as $k => $v ){ - $out.="\t'{$k}' => '" . str_replace( '\'', '\\\'', $v ) . "',\n"; + if ( count( $jmsg ) != 0 ) { + foreach ( $jmsg as $k => $v ) { + $out .= "\t'{$k}' => '" . str_replace( '\'', '\\\'', $v ) . "',\n"; } return $out; - } else { - print "could not get any json vars from:$curFileName \n"; - return ''; - } -} \ No newline at end of file + } else { + print "Could not get any json vars from $curFileName\n"; + return ''; + } +} -- 2.20.1