MediaWiki REL1_33
LCStoreStaticArray.php
Go to the documentation of this file.
1<?php
24
28class LCStoreStaticArray implements LCStore {
30 private $currentLang = null;
31
33 private $data = [];
34
36 private $fname = null;
37
39 private $directory;
40
41 public function __construct( $conf = [] ) {
42 global $wgCacheDirectory;
43
44 $this->directory = $conf['directory'] ?? $wgCacheDirectory;
45 }
46
47 public function startWrite( $code ) {
48 if ( !file_exists( $this->directory ) && !wfMkdirParents( $this->directory, null, __METHOD__ ) ) {
49 throw new MWException( "Unable to create the localisation store " .
50 "directory \"{$this->directory}\"" );
51 }
52
53 $this->currentLang = $code;
54 $this->fname = $this->directory . '/' . $code . '.l10n.php';
55 $this->data[$code] = [];
56 if ( file_exists( $this->fname ) ) {
57 $this->data[$code] = require $this->fname;
58 }
59 }
60
61 public function set( $key, $value ) {
62 $this->data[$this->currentLang][$key] = self::encode( $value );
63 }
64
72 public static function encode( $value ) {
73 if ( is_array( $value ) ) {
74 // [a]rray
75 return [ 'a', array_map( 'LCStoreStaticArray::encode', $value ) ];
76 }
77 if ( is_object( $value ) ) {
78 // [s]erialized
79 return [ 's', serialize( $value ) ];
80 }
81 if ( is_scalar( $value ) || $value === null ) {
82 // Scalar value, written directly without array
83 return $value;
84 }
85
86 throw new RuntimeException( 'Cannot encode ' . var_export( $value, true ) );
87 }
88
96 public static function decode( $encoded ) {
97 if ( !is_array( $encoded ) ) {
98 // Scalar values are written directly without array
99 return $encoded;
100 }
101
102 list( $type, $data ) = $encoded;
103
104 switch ( $type ) {
105 case 'a':
106 return array_map( 'LCStoreStaticArray::decode', $data );
107 case 's':
108 return unserialize( $data );
109 case 'v':
110 // Support: MediaWiki 1.32 and earlier
111 // Backward compatibility with older file format
112 return $data;
113 default:
114 throw new RuntimeException(
115 'Unable to decode ' . var_export( $encoded, true ) );
116 }
117 }
118
119 public function finishWrite() {
120 $writer = new StaticArrayWriter();
121 $out = $writer->create(
122 $this->data[$this->currentLang],
123 'Generated by LCStoreStaticArray.php -- do not edit!'
124 );
125 file_put_contents( $this->fname, $out );
126 $this->currentLang = null;
127 $this->fname = null;
128 }
129
130 public function get( $code, $key ) {
131 if ( !array_key_exists( $code, $this->data ) ) {
132 $fname = $this->directory . '/' . $code . '.l10n.php';
133 if ( !file_exists( $fname ) ) {
134 return null;
135 }
136 $this->data[$code] = require $fname;
137 }
138 $data = $this->data[$code];
139 if ( array_key_exists( $key, $data ) ) {
140 return self::decode( $data[$key] );
141 }
142 return null;
143 }
144}
serialize()
unserialize( $serialized)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgCacheDirectory
Directory for caching data in the local filesystem.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
finishWrite()
Finish a write transaction.
static encode( $value)
Encodes a value into an array format.
string $fname
File name.
static decode( $encoded)
Decode something that was encoded with encode.
array $data
Localisation data.
startWrite( $code)
Start a write transaction.
string $directory
Directory for cache files.
string null $currentLang
Current language code.
MediaWiki exception.
Format a static PHP array to be written to a file.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:855
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:856
Interface for the persistence layer of LocalisationCache.
Definition LCStore.php:38
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
The most up to date schema for the tables in the database will always be tables sql in the maintenance directory
Definition schema.txt:2