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\OuvrageEdit; |
11
|
|
|
|
12
|
|
|
use DateTime; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Used only by OuvrageEditWorker. |
16
|
|
|
* TODO make it used by PageWorkStatus instead of OuvrageEditWorker ? Or ImportantSummaryCreator ? |
17
|
|
|
*/ |
18
|
|
|
trait OuvrageEditSummaryTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Generate wiki edition summary. |
22
|
|
|
*/ |
23
|
|
|
protected function generateFinalSummary(): string |
24
|
|
|
{ |
25
|
|
|
$prefix = $this->generatePrefix(); |
26
|
|
|
$citeSummary = $this->getCiteSummary(); |
27
|
|
|
|
28
|
|
|
$summary = sprintf( |
29
|
|
|
'%s [%s] %s %sx : %s', |
30
|
|
|
trim($prefix), |
31
|
|
|
str_replace('v', '', $this->pageWorkStatus->citationVersion), |
32
|
|
|
trim(self::TASK_NAME), |
33
|
|
|
$this->pageWorkStatus->nbRows, |
34
|
|
|
$citeSummary |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$summary = $this->shrinkLongSummaryIfNoImportantDetailsToVerify($summary); |
38
|
|
|
$summary = $this->couldAddLuckMessage($summary); |
39
|
|
|
$this->log->notice($summary); |
40
|
|
|
|
41
|
|
|
return $summary; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Shrink long summary if no important details to verify. |
46
|
|
|
*/ |
47
|
|
|
protected function shrinkLongSummaryIfNoImportantDetailsToVerify(string $summary): string |
48
|
|
|
{ |
49
|
|
|
if (empty($this->pageWorkStatus->importantSummary)) { |
50
|
|
|
$length = strlen($summary); |
51
|
|
|
$summary = mb_substr($summary, 0, 80); |
52
|
|
|
$summary .= ($length > strlen($summary)) ? '…' : ''; |
53
|
|
|
} else { |
54
|
|
|
$summary .= '…'; // ? |
55
|
|
|
} |
56
|
|
|
return $summary; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function couldAddLuckMessage(string $summary): string |
60
|
|
|
{ |
61
|
|
|
if (!$this->pageWorkStatus->luckyState && (new DateTime())->format('H:i') === '11:11') { |
62
|
|
|
$this->pageWorkStatus->luckyState = true; |
63
|
|
|
$summary .= self::LUCKY_MESSAGE; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $summary; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function generatePrefix(): string |
70
|
|
|
{ |
71
|
|
|
$prefix = ($this->pageWorkStatus->botFlag) ? 'bot ' : ''; |
72
|
|
|
$prefix .= (empty($this->pageWorkStatus->errorWarning)) ? '' : ' ⚠️'; |
73
|
|
|
$prefix .= (empty($this->pageWorkStatus->featured_article)) ? '' : ' ☆'; // AdQ, BA |
74
|
|
|
|
75
|
|
|
return $prefix; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Generate list of details about current bot edition. |
80
|
|
|
*/ |
81
|
|
|
protected function getCiteSummary(): string |
82
|
|
|
{ |
83
|
|
|
// basic modifs |
84
|
|
|
$citeSummary = implode(' ', $this->pageWorkStatus->citationSummary); |
85
|
|
|
// replaced by list of modifs to verify by humans |
86
|
|
|
if (!empty($this->pageWorkStatus->importantSummary)) { |
87
|
|
|
$citeSummary = implode(', ', $this->pageWorkStatus->importantSummary); |
88
|
|
|
} |
89
|
|
|
return $citeSummary; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|