r56668 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56667‎ | r56668 | r56669 >
Date:12:49, 20 September 2009
Author:avar
Status:deferred (Comments)
Tags:
Comment:
Add YamlSyckFFS: A class which shells out to Perl's YAML::Syck. Added because Spyc is crap
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/FFS.php
@@ -398,6 +398,14 @@
399399 }
400400
401401 class YamlFFS extends SimpleFFS {
 402+ protected function YAML_Load( $data ) {
 403+ return TranslateSpyc::loadString( $data );
 404+ }
 405+
 406+ protected function YAML_Dump( $data ) {
 407+ return TranslateSpyc::dump( $data );
 408+ }
 409+
402410 //
403411 // READ
404412 //
@@ -410,7 +418,7 @@
411419 $authors = $matches[1];
412420
413421 # Then messages
414 - $messages = TranslateSpyc::loadString( $data );
 422+ $messages = $this->YAML_Load( $data );
415423 $messages = $this->flatten( $messages );
416424 $messages = $this->group->getMangler()->mangle( $messages );
417425
@@ -441,7 +449,7 @@
442450
443451 $messages = $this->unflatten( $messages );
444452
445 - $output .= TranslateSpyc::dump( $messages );
 453+ $output .= $this->YAML_Dump( $messages );
446454 return $output;
447455 }
448456
@@ -534,3 +542,58 @@
535543 }
536544
537545 }
 546+
 547+class YamlSyckFFS extends YamlFFS {
 548+ protected function YAML_Load( $data ) {
 549+ # Make temporary file
 550+ $td = wfTempDir();
 551+ $tf = tempnam( $td, 'yaml-load-' );
 552+
 553+ # Write to file
 554+ file_put_contents( $tf, $data );
 555+
 556+ $cmd = "perl -MYAML::Syck=LoadFile -MPHP::Serialization=serialize -E '" .
 557+ "my \$yaml = LoadFile(\"$tf\");" .
 558+ "open my \$fh, q[>], q[$tf.serialized] or die qq[Can not open q{$tf.serialized}];" .
 559+ "say $fh serialize(\$yaml);" .
 560+ "close(\$fh);'";
 561+ $ret = shell_exec($cmd);
 562+ if (!isset($cmd)) {
 563+ die("The command '$cmd' died in execution");
 564+ }
 565+
 566+ $serialized = file_get_contents("$tf.serialized");
 567+ $php_data = unserialize($serialized);
 568+
 569+ unlink($tf);
 570+ unlink("$tf.serialized");
 571+
 572+ return $php_data;
 573+ }
 574+
 575+ protected function YAML_Dump( $data ) {
 576+ # Make temporary file
 577+ $td = wfTempDir();
 578+ $tf = tempnam( $td, 'yaml-load-' );
 579+
 580+ # Write to file
 581+ $sdata = serialize( $data );
 582+ file_put_contents( $tf, $sdata );
 583+
 584+ $cmd = "perl -MYAML::Syck=DumpFile -MPHP::Serialization=unserialize -MFile::Slurp=slurp -E '" .
 585+ "my \$serialized = slurp(\"$tf\");" .
 586+ "DumpFile(q[$tf.yaml], \$serialized);'";
 587+ $ret = shell_exec($cmd);
 588+ if (!isset($cmd)) {
 589+ die("The command '$cmd' died in execution");
 590+ }
 591+
 592+ $yaml = file_get_contents("$tf.yaml");
 593+
 594+ unlink($tf);
 595+ unlink("$tf.yaml");
 596+
 597+ return $yaml;
 598+ }
 599+}
 600+

Comments

#Comment by NK45 (talk | contribs)   17:18, 21 September 2009

Think so.

Status & tagging log