Debian Codegraph @

includes/deferred/MessageCacheUpdate.php

raw symbols SCIP
1 <?php
2 /**
3 * Message cache purging and in-place update handler for specific message page changes
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Deferred;
24
25 use MediaWiki\MediaWikiServices;
26 use Wikimedia\Assert\Assert;
27
28 /**
29 * Message cache purging and in-place update handler for specific message page changes
30 *
31 * @ingroup Cache
32 * @since 1.32
33 */
34 class MessageCacheUpdate implements DeferrableUpdate, MergeableUpdate {
35 /** @var array[] Map of (language code => list of (DB key, DB key without code)) */
36 private $replacements = [];
37
38 /**
39 * @param string $code Language code
40 * @param string $title Message cache key with initial uppercase letter
41 * @param string $msg Message cache key with initial uppercase letter and without the code
42 */
43 public function __construct( $code, $title, $msg ) {
44 $this->replacements[$code][] = [ $title, $msg ];
45 }
46
47 public function merge( MergeableUpdate $update ) {
48 /** @var self $update */
49 Assert::parameterType( __CLASS__, $update, '$update' );
50 '@phan-var self $update';
51
52 foreach ( $update->replacements as $code => $messages ) {
53 $this->replacements[$code] = array_merge( $this->replacements[$code] ?? [], $messages );
54 }
55 }
56
57 public function doUpdate() {
58 $messageCache = MediaWikiServices::getInstance()->getMessageCache();
59 foreach ( $this->replacements as $code => $replacements ) {
60 $messageCache->refreshAndReplaceInternal( $code, $replacements );
61 }
62 }
63 }
64
65 /** @deprecated class alias since 1.42 */
66 class_alias( MessageCacheUpdate::class, 'MessageCacheUpdate' );