r83525 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83524‎ | r83525 | r83526 >
Date:15:39, 8 March 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Add support for pecl syck, which is magnitudes faster and uses less memory.
Like all the other supported yaml implementations, this one has its own bugs that need to be worked around.
Modified paths:
  • /trunk/extensions/Translate/groups/Mifos/Mifos.yaml (modified) (history)
  • /trunk/extensions/Translate/utils/TranslateYaml.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/Mifos/Mifos.yaml
@@ -2,8 +2,7 @@
33 BASIC:
44 namespace: NS_MIFOS
55 class: FileBasedMessageGroup
6 - description: >
7 - {{int:translate-group-desc-mifos}}
 6+ description: "{{int:translate-group-desc-mifos}}"
87
98 FILES:
109 class: JavaFFS
Index: trunk/extensions/Translate/utils/TranslateYaml.php
@@ -60,14 +60,41 @@
6161 switch ( $wgTranslateYamlLibrary ) {
6262 case 'spyc':
6363 require_once( dirname( __FILE__ ) . '/../spyc/spyc.php' );
64 - return spyc_load( $text );
 64+ $yaml = spyc_load( $text );
 65+ return self::fixSpycSpaces( $yaml );
6566 case 'syck':
66 - return self::syckLoad( $text );
 67+ $yaml = self::syckLoad( $text );
 68+ return self::fixSyckBooleans( $yaml );
 69+ case 'syck-pecl':
 70+ $text = preg_replace( '~^(\s*)no(\s*:\s*[a-zA-Z-_]+\s*)$~m', '\1"no"\2', $text );
 71+ return syck_load( $text );
6772 default:
6873 throw new MWException( "Unknown Yaml library" );
6974 }
7075 }
7176
 77+ public static function fixSyckBooleans( &$yaml ) {
 78+ foreach ( $yaml as $key => &$value ) {
 79+ if ( is_array( $value ) ) {
 80+ self::fixSyckBooleans( $value );
 81+ } elseif ( $value === 'yes' ) {
 82+ $value = true;
 83+ }
 84+ }
 85+ return $yaml;
 86+ }
 87+
 88+ public static function fixSpycSpaces( &$yaml ) {
 89+ foreach ( $yaml as $key => &$value ) {
 90+ if ( is_array( $value ) ) {
 91+ self::fixSpycSpaces( $value );
 92+ } elseif ( is_string( $value ) && $key === 'header' ) {
 93+ $value = preg_replace( '~^\*~m', ' *', $value ). "\n";
 94+ }
 95+ }
 96+ return $yaml;
 97+ }
 98+
7299 public static function load( $file ) {
73100 $text = file_get_contents( $file );
74101
@@ -83,6 +110,8 @@
84111 return Spyc::YAMLDump( $text );
85112 case 'syck':
86113 return self::syckDump( $text );
 114+ case 'syck-pecl':
 115+ return syck_dump( $text );
87116 default:
88117 throw new MWException( "Unknown Yaml library" );
89118 }

Status & tagging log