blob: 6874caef8fdfbe416cc489f1dbf5f658d6ab98a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?php
declare( strict_types = 1 );
namespace MediaWiki\Extension\Translate\Synchronization;
use JsonSerializable;
use MediaWiki\Extension\Translate\Utilities\Json\JsonUnserializable;
use MediaWiki\Extension\Translate\Utilities\Json\JsonUnserializableTrait;
use MessageUpdateJob;
/**
* Store params for MessageUpdateJob.
* @author Abijeet Patro
* @license GPL-2.0-or-later
* @since 2020.06
*/
class MessageUpdateParameter implements JsonSerializable, JsonUnserializable {
use JsonUnserializableTrait;
/** @var string */
private $pageName;
/** @var bool */
private $rename;
/** @var bool */
private $fuzzy;
/** @var string */
private $content;
/** @var string */
private $target;
/** @var string */
private $replacement;
/** @var array|null */
private $otherLangs;
public function __construct( array $params ) {
$this->assignPropsFromArray( $params );
}
public function getPageName(): string {
return $this->pageName;
}
public function isRename(): bool {
return boolval( $this->rename );
}
public function getReplacementValue(): string {
return $this->replacement;
}
public function getTargetValue(): string {
return $this->target;
}
public function getContent(): string {
return $this->content;
}
public function isFuzzy(): bool {
return $this->fuzzy;
}
public function getOtherLangs(): ?array {
return $this->otherLangs;
}
public static function newFromJsonArray( array $params ) {
return new self( $params );
}
/** @return mixed[] */
protected function toJsonArray(): array {
return get_object_vars( $this );
}
private function assignPropsFromArray( array $params ) {
// We are using "rename" as value for $params['rename']
// at some places otherwise this could be simplified to
// $params['rename'] ?? false
$this->rename = isset( $params['rename'] ) && $params['rename'];
$this->fuzzy = $params['fuzzy'];
$this->content = $params['content'];
$this->pageName = $params['title'] ?? $params['pageName'];
if ( $this->rename ) {
$this->target = $params['target'];
$this->replacement = $params['replacement'];
$this->otherLangs = $params['otherLangs'] ?? [];
}
}
/** Create a new instance of the class from MessageUpdateJob */
public static function createFromJob( MessageUpdateJob $job ): self {
$jobParams = $job->getParams();
$jobParams['title'] = $job->getTitle()->getPrefixedDBkey();
return new self( $jobParams );
}
}
class_alias( MessageUpdateParameter::class, '\MediaWiki\Extensions\Translate\MessageUpdateParameter' );
|