MediaWiki REL1_32
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 if ( isset( $conf['directory'] ) ) {
45 $this->directory = $conf['directory'];
46 } else {
48 }
49 }
50
51 public function startWrite( $code ) {
52 if ( !file_exists( $this->directory ) ) {
53 if ( !wfMkdirParents( $this->directory, null, __METHOD__ ) ) {
54 throw new MWException( "Unable to create the localisation store " .
55 "directory \"{$this->directory}\"" );
56 }
57 }
58
59 $this->currentLang = $code;
60 $this->fname = $this->directory . '/' . $code . '.l10n.php';
61 $this->data[$code] = [];
62 if ( file_exists( $this->fname ) ) {
63 $this->data[$code] = require $this->fname;
64 }
65 }
66
67 public function set( $key, $value ) {
68 $this->data[$this->currentLang][$key] = self::encode( $value );
69 }
70
78 public static function encode( $value ) {
79 if ( is_scalar( $value ) || $value === null ) {
80 // [V]alue
81 return [ 'v', $value ];
82 }
83 if ( is_object( $value ) ) {
84 // [S]erialized
85 return [ 's', serialize( $value ) ];
86 }
87 if ( is_array( $value ) ) {
88 // [A]rray
89 return [ 'a', array_map( 'LCStoreStaticArray::encode', $value ) ];
90 }
91
92 throw new RuntimeException( 'Cannot encode ' . var_export( $value, true ) );
93 }
94
102 public static function decode( array $encoded ) {
103 $type = $encoded[0];
104 $data = $encoded[1];
105
106 switch ( $type ) {
107 case 'v':
108 return $data;
109 case 's':
110 return unserialize( $data );
111 case 'a':
112 return array_map( 'LCStoreStaticArray::decode', $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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
serialize()
unserialize( $serialized)
$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.
static decode(array $encoded)
Decode something that was encoded with encode.
string $fname
File name.
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.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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:895
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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:894
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
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))
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN boolean columns are always mapped to as the code does not always treat the column as a and VARBINARY columns should simply be TEXT The only exception is when VARBINARY is used to store true binary data
Definition postgres.txt:43
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