Index: trunk/extensions/Translate/utils/MessageIndex.php |
— | — | @@ -60,9 +60,11 @@ |
61 | 61 | self::checkAndAdd( $hugearray, $g, true ); |
62 | 62 | } |
63 | 63 | |
| 64 | + global $wgMemc; |
64 | 65 | foreach ( $hugearray as $ns => $array ) { |
65 | | - wfMkdirParents( dirname( self::file($ns) ) ); |
66 | | - file_put_contents( self::file($ns), serialize( $array ) ); |
| 66 | + $memcKey = wfMemcKey( 'messageindex', $ns ); |
| 67 | + $wgMemc->set( $memcKey, serialize( $array ), 60*60*12 ); |
| 68 | + $cache = $wgMemc->get( $memcKey ); |
67 | 69 | } |
68 | 70 | } |
69 | 71 | |
— | — | @@ -92,32 +94,22 @@ |
93 | 95 | |
94 | 96 | } |
95 | 97 | |
96 | | - protected static function file( $namespace ) { |
97 | | - $dir = realpath( dirname( __FILE__ ) . '/../data' ); |
98 | | - $namepace = MWNamespace::getCanonicalName( $namespace ); |
99 | | - return "$dir/messageindex-$namespace.ser"; |
100 | | - } |
101 | | - |
102 | 98 | protected static function normaliseKey( $key ) { |
103 | | - return str_replace( " ", "_", strtolower( $key ) ); |
| 99 | + global $wgContLang; |
| 100 | + return $wgContLang->ucfirst( str_replace( " ", "_", $key ) ); |
104 | 101 | } |
105 | 102 | |
106 | 103 | protected static function index( $namespace ) { |
107 | | - if ( !isset(self::$cache[$namespace]) ) { |
| 104 | + global $wgMemc; |
| 105 | + $memcKey = wfMemcKey( 'messageindex', $namespace ); |
| 106 | + $cache = unserialize( $wgMemc->get($memcKey) ); |
108 | 107 | |
109 | | - $file = self::file( $namespace ); |
110 | | - if ( !file_exists( $file ) ) { |
111 | | - self::cache( $namespace ); |
112 | | - } |
| 108 | + // Missing? Update it |
| 109 | + if ( !is_array($cache) ) self::cache( $namespace ); |
| 110 | + $cache = unserialize( $wgMemc->get($memcKey) ); |
| 111 | + if ( !is_array($cache) ) throw new MWException( "Caching failed" ); |
113 | 112 | |
114 | | - if ( file_exists( $file ) ) { |
115 | | - self::$cache[$namespace] = unserialize( file_get_contents( $file ) ); |
116 | | - } else { |
117 | | - self::$cache[$namespace] = array(); |
118 | | - wfDebug( __METHOD__ . ": Message index missing." ); |
119 | | - } |
120 | | - } |
| 113 | + return $cache; |
121 | 114 | |
122 | | - return self::$cache[$namespace]; |
123 | 115 | } |
124 | 116 | } |
\ No newline at end of file |