3 * Message cache purging and in-place update handler for specific message page changes
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.
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.
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
23 use Wikimedia\Assert\Assert
;
26 * Message cache purging and in-place update handler for specific message page changes
31 class MessageCacheUpdate
implements DeferrableUpdate
, MergeableUpdate
{
32 /** @var array[] Map of (language code => list of (DB key, DB key without code)) */
33 private $replacements = [];
36 * @param string $code Language code
37 * @param string $title Message cache key with initial uppercase letter
38 * @param string $msg Message cache key with initial uppercase letter and without the code
40 public function __construct( $code, $title, $msg ) {
41 $this->replacements
[$code][] = [ $title, $msg ];
44 public function merge( MergeableUpdate
$update ) {
45 /** @var self $update */
46 Assert
::parameterType( __CLASS__
, $update, '$update' );
47 '@phan-var self $update';
49 foreach ( $update->replacements
as $code => $messages ) {
50 $this->replacements
[$code] = array_merge( $this->replacements
[$code] ??
[], $messages );
54 public function doUpdate() {
55 $messageCache = MessageCache
::singleton();
56 foreach ( $this->replacements
as $code => $replacements ) {
57 $messageCache->refreshAndReplaceInternal( $code, $replacements );