1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of dispositif/wikibot application (@github) |
4
|
|
|
* 2019-2023 © Philippe M./Irønie <[email protected]> |
5
|
|
|
* For the full copyright and MIT license information, view the license file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace App\Application; |
11
|
|
|
|
12
|
|
|
use DateTime; |
13
|
|
|
|
14
|
|
|
trait EditSummaryTrait |
15
|
|
|
{ |
16
|
|
|
// Beware !! $importantSummary also defined in Application/OuvrageEditWorker.php |
17
|
|
|
public $importantSummary = []; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* For substantive or ambiguous modifications done. |
21
|
|
|
* |
22
|
|
|
* @param string $tag |
23
|
|
|
*/ |
24
|
|
|
private function addSummaryTag(string $tag) |
25
|
|
|
{ |
26
|
|
|
if (!in_array($tag, $this->importantSummary)) { |
27
|
|
|
$this->importantSummary[] = $tag; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* todo extract |
33
|
|
|
* Generate wiki edition summary. |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public function generateSummary(): string |
37
|
|
|
{ |
38
|
|
|
// Start summary with "WikiBotConfig" when using botFlag, else "*" |
39
|
|
|
$prefix = ($this->botFlag) ? 'bot ' : ''; //🧐 🤖 |
40
|
|
|
// add "/!\" when errorWarning |
41
|
|
|
$prefix .= (empty($this->errorWarning)) ? '' : ' ⚠️'; |
42
|
|
|
$prefix .= (empty($this->featured_article)) ? '' : ' ☆'; // AdQ, BA |
43
|
|
|
|
44
|
|
|
// basic modifs |
45
|
|
|
$citeSummary = implode(' ', $this->citationSummary); |
46
|
|
|
// replace by list of modifs to verify by humans |
47
|
|
|
if (!empty($this->importantSummary)) { |
48
|
|
|
$citeSummary = implode(', ', $this->importantSummary); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$summary = sprintf( |
52
|
|
|
'%s [%s] %s %sx : %s', |
53
|
|
|
trim($prefix), |
54
|
|
|
str_replace('v', '', $this->citationVersion), |
55
|
|
|
trim(self::TASK_NAME), |
56
|
|
|
$this->nbRows, |
57
|
|
|
$citeSummary |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
if (!empty($this->importantSummary)) { |
61
|
|
|
$summary .= '...'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// shrink long summary if no important details to verify |
65
|
|
|
if (empty($this->importantSummary)) { |
66
|
|
|
$length = strlen($summary); |
67
|
|
|
$summary = mb_substr($summary, 0, 80); |
68
|
|
|
$summary .= ($length > strlen($summary)) ? '…' : ''; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// Luck message |
72
|
|
|
if (!$this->luckyState && (new DateTime())->format('H:i') === '11:11') { |
73
|
|
|
$this->luckyState = true; |
|
|
|
|
74
|
|
|
$summary .= self::LUCKY_MESSAGE; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $summary; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|