Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| MessageCacheUpdate | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| merge | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| doUpdate | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Message cache purging and in-place update handler for specific message page changes |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Language; |
| 10 | |
| 11 | use MediaWiki\Deferred\DeferrableUpdate; |
| 12 | use MediaWiki\Deferred\MergeableUpdate; |
| 13 | use MediaWiki\MediaWikiServices; |
| 14 | use Wikimedia\Assert\Assert; |
| 15 | |
| 16 | /** |
| 17 | * Message cache purging and in-place update handler for specific message page changes |
| 18 | * |
| 19 | * @ingroup Language |
| 20 | * @internal For use by MessageCache only. |
| 21 | * @since 1.32 |
| 22 | */ |
| 23 | class MessageCacheUpdate implements DeferrableUpdate, MergeableUpdate { |
| 24 | /** @var array[] Map of (language code => list of (DB key, DB key without code)) */ |
| 25 | private $replacements = []; |
| 26 | |
| 27 | /** |
| 28 | * @param string $code Language code |
| 29 | * @param string $title Message cache key with initial uppercase letter |
| 30 | * @param string $msg Message cache key with initial uppercase letter and without the code |
| 31 | */ |
| 32 | public function __construct( $code, $title, $msg ) { |
| 33 | $this->replacements[$code][] = [ $title, $msg ]; |
| 34 | } |
| 35 | |
| 36 | public function merge( MergeableUpdate $update ) { |
| 37 | /** @var self $update */ |
| 38 | Assert::parameterType( __CLASS__, $update, '$update' ); |
| 39 | '@phan-var self $update'; |
| 40 | |
| 41 | foreach ( $update->replacements as $code => $messages ) { |
| 42 | $this->replacements[$code] = array_merge( $this->replacements[$code] ?? [], $messages ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | public function doUpdate() { |
| 47 | $messageCache = MediaWikiServices::getInstance()->getMessageCache(); |
| 48 | foreach ( $this->replacements as $code => $replacements ) { |
| 49 | $messageCache->refreshAndReplaceInternal( $code, $replacements ); |
| 50 | } |
| 51 | } |
| 52 | } |