| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
class LocalisationCacheBulkLoad extends LocalisationCache { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
private $fileCache = []; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
private $mruLangs = []; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
private $maxLoadedLangs = 10; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
protected function readPHPFile( $fileName, $fileType ) { |
| 57 |
$serialize = $fileType === 'core'; |
| 58 |
if ( !isset( $this->fileCache[$fileName][$fileType] ) ) { |
| 59 |
$data = parent::readPHPFile( $fileName, $fileType ); |
| 60 |
|
| 61 |
if ( $serialize ) { |
| 62 |
$encData = serialize( $data ); |
| 63 |
} else { |
| 64 |
$encData = $data; |
| 65 |
} |
| 66 |
|
| 67 |
$this->fileCache[$fileName][$fileType] = $encData; |
| 68 |
|
| 69 |
return $data; |
| 70 |
} elseif ( $serialize ) { |
| 71 |
return unserialize( $this->fileCache[$fileName][$fileType] ); |
| 72 |
} else { |
| 73 |
return $this->fileCache[$fileName][$fileType]; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public function getItem( $code, $key ) { |
| 83 |
unset( $this->mruLangs[$code] ); |
| 84 |
$this->mruLangs[$code] = true; |
| 85 |
|
| 86 |
return parent::getItem( $code, $key ); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public function getSubitem( $code, $key, $subkey ) { |
| 96 |
unset( $this->mruLangs[$code] ); |
| 97 |
$this->mruLangs[$code] = true; |
| 98 |
|
| 99 |
return parent::getSubitem( $code, $key, $subkey ); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public function recache( $code ) { |
| 106 |
parent::recache( $code ); |
| 107 |
unset( $this->mruLangs[$code] ); |
| 108 |
$this->mruLangs[$code] = true; |
| 109 |
$this->trimCache(); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public function unload( $code ) { |
| 116 |
unset( $this->mruLangs[$code] ); |
| 117 |
parent::unload( $code ); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
protected function trimCache() { |
| 124 |
while ( count( $this->data ) > $this->maxLoadedLangs && count( $this->mruLangs ) ) { |
| 125 |
$code = array_key_first( $this->mruLangs ); |
| 126 |
wfDebug( __METHOD__ . ": unloading $code" ); |
| 127 |
$this->unload( $code ); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
} |