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 LogicException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* For substantive or ambiguous modifications done. |
16
|
|
|
* Move to /Domain ? |
17
|
|
|
*/ |
18
|
|
|
class ImportantSummaryCreator |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var PageWorkStatus |
22
|
|
|
*/ |
23
|
|
|
protected $pageWorkStatus; |
24
|
|
|
|
25
|
|
|
public function __construct(PageWorkStatus $pageWorkStatus) |
26
|
|
|
{ |
27
|
|
|
$this->pageWorkStatus = $pageWorkStatus; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function processPageOuvrage(array $ouvrageData): void |
31
|
|
|
{ |
32
|
|
|
if ($this->pageWorkStatus->getTitle() !== $ouvrageData['page']) { |
33
|
|
|
throw new LogicException('Title mismatch between PageWorkStatus and ouvrageData'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$this->parseParamNotCorrected($ouvrageData['opti']); |
37
|
|
|
|
38
|
|
|
$this->parseOpti($ouvrageData['opti']); |
39
|
|
|
|
40
|
|
|
$this->parseModifs($ouvrageData['modifs']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function parseParamNotCorrected(string $opti) |
44
|
|
|
{ |
45
|
|
|
// paramètre inconnu |
46
|
|
|
if (preg_match_all( |
47
|
|
|
"#\|[^|]+<!-- ?(PARAMETRE [^>]+ N'EXISTE PAS|VALEUR SANS NOM DE PARAMETRE|ERREUR [^>]+) ?-->#", |
48
|
|
|
$opti, |
49
|
|
|
$matches |
50
|
|
|
) > 0 |
51
|
|
|
) { |
52
|
|
|
foreach ($matches[0] as $line) { |
53
|
|
|
$this->addErrorWarning($line); |
54
|
|
|
} |
55
|
|
|
$this->addSummaryTag('paramètre non corrigé'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function addErrorWarning(string $string) |
60
|
|
|
{ |
61
|
|
|
$this->pageWorkStatus->addErrorWarning($string); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function addSummaryTag(string $string) |
65
|
|
|
{ |
66
|
|
|
$this->pageWorkStatus->addSummaryTag($string); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function parseOpti(string $opti): void |
70
|
|
|
{ |
71
|
|
|
// ISBN invalide |
72
|
|
|
if (preg_match("#isbn invalide ?=[^|}]+#i", $opti, $matches) > 0) { |
73
|
|
|
$this->addErrorWarning($matches[0]); |
74
|
|
|
$this->addSummaryTag('ISBN invalide 💩'); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function parseModifs(string $modifs): void |
79
|
|
|
{ |
80
|
|
|
// Edits avec ajout conséquent de donnée |
81
|
|
|
if (preg_match('#distinction des auteurs#', $modifs) > 0) { |
82
|
|
|
$this->pageWorkStatus->botFlag = false; |
83
|
|
|
$this->addSummaryTag('distinction auteurs 🧠'); |
84
|
|
|
} |
85
|
|
|
// prédiction paramètre correct |
86
|
|
|
if (preg_match('#[^,]+(=>|⇒)[^,]+#', $modifs, $matches) > 0) { |
87
|
|
|
$this->addSummaryTag($matches[0]); |
88
|
|
|
} |
89
|
|
|
if (preg_match('#\+\+sous-titre#', $modifs) > 0) { |
90
|
|
|
$this->addSummaryTag('+sous-titre'); |
91
|
|
|
} |
92
|
|
|
if (preg_match('#\+lieu#', $modifs) > 0) { |
93
|
|
|
$this->addSummaryTag('+lieu'); |
94
|
|
|
} |
95
|
|
|
if (preg_match('#tracking#', $modifs) > 0) { |
96
|
|
|
$this->addSummaryTag('tracking'); |
97
|
|
|
} |
98
|
|
|
if (preg_match('#présentation en ligne#', $modifs) > 0) { |
99
|
|
|
$this->addSummaryTag('+présentation en ligne✨'); |
100
|
|
|
} |
101
|
|
|
if (preg_match('#distinction auteurs#', $modifs) > 0) { |
102
|
|
|
$this->addSummaryTag('auteurs 🧠'); |
103
|
|
|
} |
104
|
|
|
if (preg_match('#\+lire en ligne#', $modifs) > 0) { |
105
|
|
|
$this->addSummaryTag('+lire en ligne✨'); |
106
|
|
|
} |
107
|
|
|
if (preg_match('#\+lien #', $modifs) > 0) { |
108
|
|
|
$this->addSummaryTag('wikif'); |
109
|
|
|
} |
110
|
|
|
if (preg_match('#\+éditeur#', $modifs) > 0) { |
111
|
|
|
$this->addSummaryTag('+éditeur'); |
112
|
|
|
} |
113
|
|
|
if (preg_match('#\+lien éditeur#', $modifs) > 0) { |
114
|
|
|
$this->addSummaryTag('wikif'); |
115
|
|
|
} |
116
|
|
|
$this->parseBNFdata($modifs); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// mention BnF si ajout donnée + ajout identifiant bnf= |
120
|
|
|
protected function parseBNFdata(string $modifs): void |
121
|
|
|
{ |
122
|
|
|
if (!empty($this->pageWorkStatus->importantSummary) && preg_match('#BnF#i', $modifs) > 0) { |
123
|
|
|
$this->addSummaryTag('©[[BnF]]'); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |