+ function saveToScript( $array, $hash, $code ) {
+ global $wgCacheDirectory;
+
+ $filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
+ $tempFilename = $filename . '.tmp';
+ wfMkdirParents( $wgCacheDirectory ); // might fail
+
+ wfSuppressWarnings();
+ $file = fopen( $tempFilename, 'w');
+ wfRestoreWarnings();
+
+ if ( !$file ) {
+ wfDebug( "Unable to open local cache file for writing\n" );
+ return;
+ }
+
+ fwrite($file,"<?php\n//$hash\n\n \$this->mCache = array(");
+
+ foreach ($array as $key => $message) {
+ $key = $this->escapeForScript($key);
+ $messages = $this->escapeForScript($message);
+ fwrite($file, "'$key' => '$message',\n");
+ }
+
+ fwrite($file,");\n?>");
+ fclose($file);
+ rename($tempFilename, $filename);
+ }
+
+ function escapeForScript($string) {
+ $string = str_replace( '\\', '\\\\', $string );
+ $string = str_replace( '\'', '\\\'', $string );
+ return $string;
+ }