Index: trunk/extensions/Translate/FFS.php |
— | — | @@ -398,6 +398,14 @@ |
399 | 399 | } |
400 | 400 | |
401 | 401 | 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 | + |
402 | 410 | // |
403 | 411 | // READ |
404 | 412 | // |
— | — | @@ -410,7 +418,7 @@ |
411 | 419 | $authors = $matches[1]; |
412 | 420 | |
413 | 421 | # Then messages |
414 | | - $messages = TranslateSpyc::loadString( $data ); |
| 422 | + $messages = $this->YAML_Load( $data ); |
415 | 423 | $messages = $this->flatten( $messages ); |
416 | 424 | $messages = $this->group->getMangler()->mangle( $messages ); |
417 | 425 | |
— | — | @@ -441,7 +449,7 @@ |
442 | 450 | |
443 | 451 | $messages = $this->unflatten( $messages ); |
444 | 452 | |
445 | | - $output .= TranslateSpyc::dump( $messages ); |
| 453 | + $output .= $this->YAML_Dump( $messages ); |
446 | 454 | return $output; |
447 | 455 | } |
448 | 456 | |
— | — | @@ -534,3 +542,58 @@ |
535 | 543 | } |
536 | 544 | |
537 | 545 | } |
| 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 | + |