@chmod( $filename, 0666 );
}
+ function loadFromScript( $hash ) {
+ global $wgLocalMessageCache, $wgDBname;
+ if ( $wgLocalMessageCache === false ) {
+ return;
+ }
+
+ $filename = "$wgLocalMessageCache/messages-$wgDBname";
+
+ wfSuppressWarnings();
+ $file = fopen( $filename, 'r' );
+ wfRestoreWarnings();
+ if ( !$file ) {
+ return;
+ }
+ $localHash=substr(fread($file,40),8);
+ fclose($file);
+ if ($hash!=$localHash) {
+ return;
+ }
+ require("$wgLocalMessageCache/messages-$wgDBname");
+ }
+
+ function saveToScript($array, $hash) {
+ global $wgLocalMessageCache, $wgDBname;
+ if ( $wgLocalMessageCache === false ) {
+ return;
+ }
+
+ $filename = "$wgLocalMessageCache/messages-$wgDBname";
+ $oldUmask = umask( 0 );
+ wfMkdirParents( $wgLocalMessageCache, 0777 );
+ umask( $oldUmask );
+ $file = fopen( $filename.'.tmp', 'w');
+ fwrite($file,"<?php\n//$hash\n\n \$this->mCache = array(");
+
+ $re="/(?<!\\\\)'/";
+ foreach ($array as $key => $message) {
+ fwrite($file, "'". preg_replace($re, "\'", $key).
+ "' => '" . preg_replace( $re, "\'", $message) . "',\n");
+ }
+ fwrite($file,");\n?>");
+ fclose($file);
+ rename($filename.'.tmp',$filename);
+ }
/**
* Loads messages either from memcached or the database, if not disabled
* Returns false for a reportable error, true otherwise
*/
function load() {
- global $wgLocalMessageCache;
+ global $wgLocalMessageCache, $wgLocalMessageCacheSerialized;
if ( $this->mDisable ) {
static $shownDisabled = false;
wfProfileIn( $fname.'-fromlocal' );
$hash = $this->mMemc->get( "{$this->mMemcKey}-hash" );
if ( $hash ) {
- $this->loadFromLocal( $hash );
+ if ($wgLocalMessageCacheSerialized) {
+ $this->loadFromLocal( $hash );
+ } else {
+ $this->loadFromScript( $hash );
+ }
}
wfProfileOut( $fname.'-fromlocal' );
$hash = md5( $serialized );
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
}
- $this->saveToLocal( $serialized, $hash );
+ if ($wgLocalMessageCacheSerialized) {
+ $this->saveToLocal( $serialized,$hash );
+ } else {
+ $this->saveToScript( $this->mCache, $hash );
+ }
}
wfProfileOut( $fname.'-fromcache' );
}
$serialized = serialize( $this->mCache );
$hash = md5( $serialized );
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
- $this->saveToLocal( $serialized, $hash );
+ if ($wgLocalMessageCacheSerialized) {
+ $this->saveToLocal( $serialized,$hash );
+ } else {
+ $this->saveToScript( $this->mCache, $hash );
+ }
}
wfProfileOut( $fname.'-save' );
}
function replace( $title, $text ) {
- global $wgLocalMessageCache, $parserMemc, $wgDBname;
+ global $wgLocalMessageCache, $wgLocalMessageCacheSerialized, $parserMemc, $wgDBname;
$this->lock();
$this->load();
$serialized = serialize( $this->mCache );
$hash = md5( $serialized );
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
- $this->saveToLocal( $serialized, $hash );
+ if ($wgLocalMessageCacheSerialized) {
+ $this->saveToLocal( $serialized,$hash );
+ } else {
+ $this->saveToScript( $this->mCache, $hash );
+ }
}