MediaWiki REL1_28
LCStoreDB.php
Go to the documentation of this file.
1<?php
25class LCStoreDB implements LCStore {
26
28 private $currentLang;
30 private $writesDone = false;
32 private $dbw;
34 private $batch = [];
36 private $readOnly = false;
37
38 public function get( $code, $key ) {
39 if ( $this->writesDone && $this->dbw ) {
40 $db = $this->dbw; // see the changes in finishWrite()
41 } else {
42 $db = wfGetDB( DB_REPLICA );
43 }
44
45 $value = $db->selectField(
46 'l10n_cache',
47 'lc_value',
48 [ 'lc_lang' => $code, 'lc_key' => $key ],
49 __METHOD__
50 );
51
52 return ( $value !== false ) ? unserialize( $db->decodeBlob( $value ) ) : null;
53 }
54
55 public function startWrite( $code ) {
56 if ( $this->readOnly ) {
57 return;
58 } elseif ( !$code ) {
59 throw new MWException( __METHOD__ . ": Invalid language \"$code\"" );
60 }
61
62 $this->dbw = wfGetDB( DB_MASTER );
63 $this->readOnly = $this->dbw->isReadOnly();
64
65 $this->currentLang = $code;
66 $this->batch = [];
67 }
68
69 public function finishWrite() {
70 if ( $this->readOnly ) {
71 return;
72 } elseif ( is_null( $this->currentLang ) ) {
73 throw new MWException( __CLASS__ . ': must call startWrite() before finishWrite()' );
74 }
75
76 $this->dbw->startAtomic( __METHOD__ );
77 try {
78 $this->dbw->delete(
79 'l10n_cache',
80 [ 'lc_lang' => $this->currentLang ],
81 __METHOD__
82 );
83 foreach ( array_chunk( $this->batch, 500 ) as $rows ) {
84 $this->dbw->insert( 'l10n_cache', $rows, __METHOD__ );
85 }
86 $this->writesDone = true;
87 } catch ( DBQueryError $e ) {
88 if ( $this->dbw->wasReadOnlyError() ) {
89 $this->readOnly = true; // just avoid site down time
90 } else {
91 throw $e;
92 }
93 }
94 $this->dbw->endAtomic( __METHOD__ );
95
96 $this->currentLang = null;
97 $this->batch = [];
98 }
99
100 public function set( $key, $value ) {
101 if ( $this->readOnly ) {
102 return;
103 } elseif ( is_null( $this->currentLang ) ) {
104 throw new MWException( __CLASS__ . ': must call startWrite() before set()' );
105 }
106
107 $this->batch[] = [
108 'lc_lang' => $this->currentLang,
109 'lc_key' => $key,
110 'lc_value' => $this->dbw->encodeBlob( serialize( $value ) )
111 ];
112 }
113
114}
serialize()
unserialize( $serialized)
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
LCStore implementation which uses the standard DB functions to store data.
Definition LCStoreDB.php:25
bool $readOnly
Definition LCStoreDB.php:36
finishWrite()
Finish a write transaction.
Definition LCStoreDB.php:69
startWrite( $code)
Start a write transaction.
Definition LCStoreDB.php:55
array $batch
Definition LCStoreDB.php:34
IDatabase $dbw
Definition LCStoreDB.php:32
string $currentLang
Definition LCStoreDB.php:28
bool $writesDone
Definition LCStoreDB.php:30
MediaWiki exception.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
the array() calling protocol came about after MediaWiki 1.4rc1.
returning false will NOT prevent logging $e
Definition hooks.txt:2110
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:887
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
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:34
Interface for the persistence layer of LocalisationCache.
Definition LCStore.php:38
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a batch
Definition linkcache.txt:14
const DB_REPLICA
Definition defines.php:22
const DB_MASTER
Definition defines.php:23