|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of dispositif/wikibot application |
|
4
|
|
|
* 2019 : Philippe M. <[email protected]> |
|
5
|
|
|
* For the full copyright and MIT license information, please view the LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace App\Domain; |
|
11
|
|
|
|
|
12
|
|
|
use App\Domain\Enums\Language; |
|
13
|
|
|
use App\Domain\Models\Wiki\GoogleLivresTemplate; |
|
14
|
|
|
use App\Domain\Publisher\GoogleBooksUtil; |
|
15
|
|
|
use App\Domain\Utils\TextUtil; |
|
16
|
|
|
use App\Domain\Utils\WikiTextUtil; |
|
17
|
|
|
use App\Infrastructure\FileManager; |
|
18
|
|
|
use DomainException; |
|
19
|
|
|
use Exception; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Legacy. |
|
23
|
|
|
* TODO move methods to OuvrageClean setters |
|
24
|
|
|
* TODO AbstractProcess |
|
25
|
|
|
* TODO observer/event (log, MajorEdition) |
|
26
|
|
|
* Class OuvrageProcess. |
|
27
|
|
|
*/ |
|
28
|
|
|
class OuvrageOptimize extends AbstractTemplateOptimizer |
|
29
|
|
|
{ |
|
30
|
|
|
use OptimizeISBNTrait; |
|
31
|
|
|
|
|
32
|
|
|
const CONVERT_GOOGLEBOOK_TEMPLATE = false; // change OuvrageOptimizeTest !! |
|
33
|
|
|
|
|
34
|
|
|
const WIKI_LANGUAGE = 'fr'; |
|
35
|
|
|
|
|
36
|
|
|
protected $originTemplate; |
|
37
|
|
|
|
|
38
|
|
|
protected $wikiPageTitle; |
|
39
|
|
|
|
|
40
|
|
|
protected $summaryLog = []; |
|
41
|
|
|
|
|
42
|
|
|
public $notCosmetic = false; |
|
43
|
|
|
|
|
44
|
|
|
public $major = false; |
|
45
|
|
|
|
|
46
|
|
|
protected $optiTemplate; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return $this |
|
50
|
|
|
* @throws Exception |
|
51
|
|
|
*/ |
|
52
|
|
|
public function doTasks(): self |
|
53
|
|
|
{ |
|
54
|
|
|
$this->cleanAndPredictErrorParameters(); |
|
55
|
|
|
|
|
56
|
|
|
$this->processAuthors(); |
|
57
|
|
|
|
|
58
|
47 |
|
$this->processLang(); |
|
59
|
|
|
$this->processLang('langue originale'); |
|
60
|
47 |
|
|
|
61
|
47 |
|
$this->processTitle(); |
|
62
|
47 |
|
$this->convertLienAuteurTitre(); |
|
63
|
47 |
|
$this->processEditeur(); |
|
64
|
47 |
|
$this->processDates(); |
|
65
|
|
|
$this->externalTemplates(); |
|
66
|
|
|
$this->predictFormatByPattern(); |
|
67
|
|
|
|
|
68
|
|
|
$this->processIsbn(); |
|
69
|
|
|
$this->processBnf(); |
|
70
|
47 |
|
|
|
71
|
|
|
$this->processLocation(); // 'lieu' |
|
72
|
47 |
|
|
|
73
|
|
|
$this->GoogleBookURL('lire en ligne'); |
|
74
|
47 |
|
$this->GoogleBookURL('présentation en ligne'); |
|
75
|
|
|
|
|
76
|
47 |
|
return $this; |
|
77
|
47 |
|
} |
|
78
|
|
|
|
|
79
|
47 |
|
/** |
|
80
|
47 |
|
* Todo: injection dep. |
|
81
|
47 |
|
* Todo : "[s. l.]" sans lieu "s.l.n.d." sans lieu ni date. |
|
82
|
47 |
|
* |
|
83
|
47 |
|
* @throws Exception |
|
84
|
47 |
|
*/ |
|
85
|
|
|
protected function processLocation() |
|
86
|
47 |
|
{ |
|
87
|
47 |
|
$location = $this->getParam('lieu'); |
|
88
|
|
|
if (empty($location)) { |
|
89
|
47 |
|
return; |
|
90
|
|
|
} |
|
91
|
47 |
|
|
|
92
|
47 |
|
// typo and unwikify |
|
93
|
|
|
$memo = $location; |
|
94
|
47 |
|
$location = WikiTextUtil::unWikify($location); |
|
95
|
|
|
$location = TextUtil::mb_ucfirst($location); |
|
96
|
|
|
if ($memo !== $location) { |
|
97
|
|
|
$this->setParam('lieu', $location); |
|
98
|
|
|
$this->addSummaryLog('±lieu'); |
|
99
|
|
|
$this->notCosmetic = true; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
// translation : "London"->"Londres" seulement si langue=fr |
|
103
|
47 |
|
if ($this->hasParamValue('langue') |
|
104
|
|
|
&& $this->getParam('langue') === self::WIKI_LANGUAGE |
|
105
|
47 |
|
) { |
|
106
|
47 |
|
$manager = new FileManager(); |
|
107
|
42 |
|
$row = $manager->findCSVline(__DIR__.'/resources/traduction_ville.csv', $location); |
|
108
|
|
|
if (!empty($row) && !empty($row[1])) { |
|
109
|
|
|
$this->setParam('lieu', $row[1]); |
|
110
|
|
|
$this->addSummaryLog('lieu francisé'); |
|
111
|
5 |
|
$this->notCosmetic = true; |
|
112
|
5 |
|
} |
|
113
|
5 |
|
} |
|
114
|
5 |
|
} |
|
115
|
1 |
|
|
|
116
|
1 |
|
protected function processBnf() |
|
117
|
1 |
|
{ |
|
118
|
|
|
$bnf = $this->getParam('bnf'); |
|
119
|
|
|
if (!$bnf) { |
|
120
|
|
|
return; |
|
121
|
5 |
|
} |
|
122
|
5 |
|
$bnf = str_ireplace('FRBNF', '', $bnf); |
|
123
|
|
|
$this->setParam('bnf', $bnf); |
|
124
|
1 |
|
} |
|
125
|
1 |
|
|
|
126
|
1 |
|
/** |
|
127
|
1 |
|
* @throws Exception |
|
128
|
1 |
|
*/ |
|
129
|
1 |
|
protected function processAuthors() |
|
130
|
|
|
{ |
|
131
|
|
|
$this->distinguishAuthors(); |
|
132
|
5 |
|
//$this->fusionFirstNameAndName(); // desactived : no consensus |
|
133
|
|
|
} |
|
134
|
47 |
|
|
|
135
|
|
|
protected function convertLienAuteurTitre(): void |
|
136
|
47 |
|
{ |
|
137
|
47 |
|
$auteurParams = ['auteur1', 'auteur2', 'auteur2', 'titre']; |
|
138
|
46 |
|
foreach ($auteurParams as $auteurParam) { |
|
139
|
|
|
if ($this->hasParamValue($auteurParam) |
|
140
|
1 |
|
&& $this->hasParamValue('lien '.$auteurParam) |
|
141
|
1 |
|
) { |
|
142
|
1 |
|
$this->setParam( |
|
143
|
|
|
$auteurParam, |
|
144
|
|
|
WikiTextUtil::wikilink( |
|
145
|
|
|
$this->getParam($auteurParam), |
|
|
|
|
|
|
146
|
|
|
$this->getParam('lien '.$auteurParam) |
|
147
|
47 |
|
) |
|
148
|
|
|
); |
|
149
|
47 |
|
$this->unsetParam('lien '.$auteurParam); |
|
150
|
|
|
} |
|
151
|
47 |
|
} |
|
152
|
|
|
} |
|
153
|
47 |
|
|
|
154
|
|
|
/** |
|
155
|
47 |
|
* Detect and correct multiple authors in same parameter. |
|
156
|
47 |
|
* Like "auteurs=J. M. Waller, M. Bigger, R. J. Hillocks". |
|
157
|
47 |
|
* |
|
158
|
47 |
|
* @throws Exception |
|
159
|
|
|
*/ |
|
160
|
1 |
|
protected function distinguishAuthors() |
|
161
|
1 |
|
{ |
|
162
|
1 |
|
// merge params of author 1 |
|
163
|
1 |
|
$auteur1 = $this->getParam('auteur') ?? ''; |
|
164
|
1 |
|
$auteur1 .= $this->getParam('auteurs') ?? ''; |
|
165
|
|
|
$auteur1 .= $this->getParam('prénom1') ?? ''; |
|
166
|
|
|
$auteur1 .= ' '.$this->getParam('nom1') ?? ''; |
|
167
|
1 |
|
$auteur1 = trim($auteur1); |
|
168
|
|
|
// of authors 2 |
|
169
|
|
|
$auteur2 = $this->getParam('auteur2') ?? ''; |
|
170
|
47 |
|
$auteur2 .= $this->getParam('prénom2') ?? ''; |
|
171
|
|
|
$auteur2 .= ' '.$this->getParam('nom2') ?? ''; |
|
172
|
|
|
$auteur2 = trim($auteur2); |
|
173
|
|
|
|
|
174
|
|
|
// skip if wikilink in author |
|
175
|
|
|
if (empty($auteur1) || WikiTextUtil::isWikify($auteur1)) { |
|
176
|
|
|
return; |
|
177
|
|
|
} |
|
178
|
47 |
|
|
|
179
|
|
|
$machine = new PredictAuthors(); |
|
180
|
|
|
$res = $machine->predictAuthorNames($auteur1); |
|
181
|
47 |
|
|
|
182
|
47 |
|
if (1 === count($res)) { |
|
183
|
47 |
|
// auteurs->auteur? |
|
184
|
47 |
|
return; |
|
185
|
47 |
|
} |
|
186
|
|
|
// Many authors... and empty "auteur2" |
|
187
|
47 |
|
if (count($res) >= 2 && empty($auteur2)) { |
|
188
|
47 |
|
// delete author-params |
|
189
|
47 |
|
array_map( |
|
190
|
47 |
|
function ($param) { |
|
191
|
|
|
$this->unsetParam($param); |
|
192
|
|
|
}, |
|
193
|
47 |
|
['auteur', 'auteurs', 'prénom1', 'nom1'] |
|
194
|
42 |
|
); |
|
195
|
|
|
// iterate and edit new values |
|
196
|
|
|
$count = count($res); |
|
197
|
5 |
|
for ($i = 0; $i < $count; ++$i) { |
|
198
|
5 |
|
$this->setParam(sprintf('auteur%s', $i + 1), $res[$i]); |
|
199
|
|
|
} |
|
200
|
5 |
|
$this->addSummaryLog('distinction auteurs'); |
|
201
|
|
|
$this->major = true; |
|
202
|
3 |
|
$this->notCosmetic = true; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
2 |
|
|
|
206
|
|
|
/** |
|
207
|
1 |
|
* todo: move/implement. |
|
208
|
|
|
* |
|
209
|
1 |
|
* @param string|null $param |
|
210
|
1 |
|
* |
|
211
|
1 |
|
* @throws Exception |
|
212
|
|
|
*/ |
|
213
|
|
|
protected function processLang(?string $param = 'langue') |
|
214
|
1 |
|
{ |
|
215
|
1 |
|
$lang = $this->getParam($param) ?? null; |
|
|
|
|
|
|
216
|
1 |
|
|
|
217
|
|
|
if ($lang) { |
|
218
|
1 |
|
$lang2 = Language::all2wiki($lang); |
|
219
|
1 |
|
|
|
220
|
1 |
|
// strip "langue originale=fr" |
|
221
|
|
|
if ('langue originale' === $param && self::WIKI_LANGUAGE === $lang2 |
|
222
|
2 |
|
&& (!$this->getParam('langue') || $this->getParam('langue') === $lang2) |
|
223
|
|
|
) { |
|
224
|
|
|
$this->unsetParam('langue originale'); |
|
225
|
|
|
$this->addSummaryLog('-langue originale'); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
if ($lang2 && $lang !== $lang2) { |
|
229
|
|
|
$this->setParam($param, $lang2); |
|
230
|
|
|
if (self::WIKI_LANGUAGE !== $lang2) { |
|
231
|
47 |
|
$this->addSummaryLog('±'.$param); |
|
232
|
|
|
} |
|
233
|
47 |
|
} |
|
234
|
|
|
} |
|
235
|
47 |
|
} |
|
236
|
6 |
|
|
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
6 |
|
/** |
|
240
|
6 |
|
* Find year of book publication. |
|
241
|
|
|
* |
|
242
|
1 |
|
* @return int|null |
|
243
|
1 |
|
* @throws Exception |
|
244
|
|
|
*/ |
|
245
|
|
|
protected function findBookYear(): ?int |
|
246
|
6 |
|
{ |
|
247
|
4 |
|
$annee = $this->getParam('année'); |
|
248
|
4 |
|
if (!empty($annee) && is_numeric($annee)) { |
|
249
|
3 |
|
return intval($annee); |
|
250
|
|
|
} |
|
251
|
|
|
$date = $this->getParam('date'); |
|
252
|
|
|
if ($date && preg_match('#[^0-9]?([12][0-9][0-9][0-9])[^0-9]?#', $date, $matches) > 0) { |
|
253
|
47 |
|
return intval($matches[1]); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
return null; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
protected function stripIsbn(string $isbn): string |
|
260
|
47 |
|
{ |
|
261
|
|
|
return trim(preg_replace('#[^0-9Xx]#', '', $isbn)); |
|
262
|
47 |
|
} |
|
263
|
47 |
|
|
|
264
|
37 |
|
protected function processTitle() |
|
265
|
|
|
{ |
|
266
|
|
|
$oldtitre = $this->getParam('titre'); |
|
267
|
|
|
$this->langInTitle(); |
|
268
|
10 |
|
$this->deWikifyExternalLink('titre'); |
|
269
|
10 |
|
$this->upperCaseFirstLetter('titre'); |
|
270
|
|
|
$this->typoDeuxPoints('titre'); |
|
271
|
|
|
|
|
272
|
2 |
|
$this->extractSubTitle(); |
|
273
|
2 |
|
|
|
274
|
2 |
|
// 20-11-2019 : Retiré majuscule à sous-titre |
|
275
|
2 |
|
|
|
276
|
2 |
|
if ($this->getParam('titre') !== $oldtitre) { |
|
277
|
2 |
|
$this->addSummaryLog('±titre'); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
$this->valideNumeroChapitre(); |
|
281
|
|
|
$this->deWikifyExternalLink('titre chapitre'); |
|
282
|
|
|
$this->upperCaseFirstLetter('titre chapitre'); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
protected function detectColon($param): bool |
|
286
|
|
|
{ |
|
287
|
|
|
// > 0 don't count a starting colon ":bla" |
|
288
|
|
|
if ($this->hasParamValue($param) && mb_strrpos($this->getParam('titre'), ':') > 0) { |
|
289
|
|
|
return true; |
|
290
|
2 |
|
} |
|
291
|
|
|
|
|
292
|
|
|
return false; |
|
293
|
|
|
} |
|
294
|
8 |
|
|
|
295
|
8 |
|
protected function extractSubTitle(): void |
|
296
|
7 |
|
{ |
|
297
|
1 |
|
// FIXED bug [[fu:bar]] |
|
298
|
|
|
if (!$this->getParam('titre') || WikiTextUtil::isWikify($this->getParam('titre'))) { |
|
299
|
|
|
return; |
|
300
|
1 |
|
} |
|
301
|
1 |
|
|
|
302
|
1 |
|
if (!$this->detectColon('titre')) { |
|
303
|
|
|
return; |
|
304
|
1 |
|
} |
|
305
|
1 |
|
// Que faire si déjà un sous-titre ? |
|
306
|
|
|
if ($this->hasParamValue('sous-titre')) { |
|
307
|
|
|
return; |
|
308
|
1 |
|
} |
|
309
|
|
|
|
|
310
|
|
|
// titre>5 and sous-titre>5 and sous-titre<40 |
|
311
|
|
|
if (preg_match('#^(?<titre>[^:]{5,}):(?<st>.{5,40})$#', $this->getParam('titre'), $matches) > 0) { |
|
312
|
7 |
|
$this->setParam('titre', trim($matches['titre'])); |
|
313
|
7 |
|
$this->setParam('sous-titre', trim($matches['st'])); |
|
314
|
7 |
|
$this->addSummaryLog('>sous-titre'); |
|
315
|
|
|
} |
|
316
|
1 |
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Normalize a Google Book links. |
|
320
|
7 |
|
* Clean the useless URL parameters or transform into wiki-template. |
|
321
|
7 |
|
* |
|
322
|
|
|
* @param $param |
|
323
|
4 |
|
* |
|
324
|
|
|
* @throws Exception |
|
325
|
|
|
*/ |
|
326
|
4 |
|
protected function googleBookUrl(string $param): void |
|
327
|
|
|
{ |
|
328
|
|
|
$url = $this->getParam($param); |
|
329
|
|
|
if (empty($url) |
|
330
|
|
|
|| !GoogleBooksUtil::isGoogleBookURL($url) |
|
331
|
|
|
) { |
|
332
|
4 |
|
return; |
|
333
|
4 |
|
} |
|
334
|
|
|
|
|
335
|
|
|
if (self::CONVERT_GOOGLEBOOK_TEMPLATE) { |
|
336
|
4 |
|
$template = GoogleLivresTemplate::createFromURL($url); |
|
337
|
4 |
|
if ($template) { |
|
338
|
4 |
|
$this->setParam($param, $template->serialize()); |
|
339
|
|
|
$this->addSummaryLog('{Google}'); |
|
340
|
|
|
$this->notCosmetic = true; |
|
341
|
|
|
|
|
342
|
|
|
return; |
|
343
|
4 |
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
try { |
|
347
|
|
|
$goo = GoogleBooksUtil::simplifyGoogleUrl($url); |
|
348
|
|
|
} catch (DomainException $e) { |
|
349
|
7 |
|
// ID manquant ou malformé |
|
350
|
7 |
|
$errorValue = sprintf( |
|
351
|
7 |
|
'%s <!-- ERREUR %s -->', |
|
352
|
|
|
$url, |
|
353
|
|
|
$e->getMessage() |
|
354
|
7 |
|
); |
|
355
|
|
|
$this->setParam($param, $errorValue); |
|
356
|
|
|
$this->addSummaryLog('erreur URL'); |
|
357
|
|
|
$this->notCosmetic = true; |
|
358
|
|
|
$this->major = true; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
if (!empty($goo) && $goo !== $url) { |
|
362
|
10 |
|
$this->setParam($param, $goo); |
|
363
|
|
|
// cleaned tracking parameters in Google URL ? |
|
364
|
10 |
|
if (GoogleBooksUtil::isTrackingUrl($url)) { |
|
365
|
10 |
|
$this->addSummaryLog('tracking'); |
|
366
|
1 |
|
$this->notCosmetic = true; |
|
367
|
|
|
} |
|
368
|
9 |
|
} |
|
369
|
9 |
|
} |
|
370
|
1 |
|
|
|
371
|
|
|
/** |
|
372
|
|
|
* - {{lang|...}} dans titre => langue=... puis titre nettoyé |
|
373
|
8 |
|
* langue=L’utilisation de ce paramètre permet aussi aux synthétiseurs vocaux de reconnaître la langue du titre de |
|
374
|
|
|
* l’ouvrage. |
|
375
|
|
|
* Il est possible d'afficher plusieurs langues, en saisissant le nom séparé par des espaces ou des virgules. La première langue doit être celle du titre. |
|
376
|
9 |
|
* |
|
377
|
|
|
* @throws Exception |
|
378
|
9 |
|
*/ |
|
379
|
|
|
protected function langInTitle(): void |
|
380
|
|
|
{ |
|
381
|
47 |
|
if (preg_match( |
|
382
|
|
|
'#^{{ ?(?:lang|langue) ?\| ?([a-z-]{2,5}) ?\| ?(?:texte=)?([^{}=]+)(?:\|dir=rtl)?}}$#i', |
|
383
|
47 |
|
$this->getParam('titre'), |
|
384
|
47 |
|
$matches |
|
385
|
47 |
|
) > 0 |
|
386
|
47 |
|
) { |
|
387
|
47 |
|
$lang = trim($matches[1]); |
|
388
|
|
|
$newtitre = str_replace($matches[0], trim($matches[2]), $this->getParam('titre')); |
|
389
|
47 |
|
|
|
390
|
|
|
// problème : titre anglais de livre français |
|
391
|
|
|
// => conversion {{lang}} du titre seulement si langue= défini |
|
392
|
|
|
// opti : restreindre à ISBN zone 2 fr ? |
|
393
|
47 |
|
if ($lang === $this->getParam('langue')) { |
|
394
|
5 |
|
$this->setParam('titre', $newtitre); |
|
395
|
|
|
$this->addSummaryLog('°titre'); |
|
396
|
|
|
} |
|
397
|
47 |
|
|
|
398
|
47 |
|
// desactivé à cause de l'exception décrite ci-dessus |
|
399
|
47 |
|
// si langue=VIDE : ajout langue= à partir de langue titre |
|
400
|
47 |
|
// if (self::WIKI_LANGUAGE !== $lang && empty($this->getParam('langue'))) { |
|
401
|
|
|
// $this->setParam('langue', $lang); |
|
402
|
13 |
|
// $this->log('+langue='.$lang); |
|
403
|
|
|
// } |
|
404
|
|
|
} |
|
405
|
13 |
|
} |
|
406
|
3 |
|
|
|
407
|
|
|
protected function processDates() |
|
408
|
|
|
{ |
|
409
|
10 |
|
// dewikification |
|
410
|
|
|
$params = ['date', 'année', 'mois', 'jour']; |
|
411
|
|
|
foreach ($params as $param) { |
|
412
|
47 |
|
if ($this->hasParamValue($param) && WikiTextUtil::isWikify(' '.$this->getParam($param))) { |
|
413
|
|
|
$this->setParam($param, WikiTextUtil::unWikify($this->getParam($param))); |
|
414
|
|
|
} |
|
415
|
47 |
|
} |
|
416
|
34 |
|
|
|
417
|
|
|
try { |
|
418
|
|
|
$this->moveDate2Year(); |
|
419
|
13 |
|
} catch (Exception $e) { |
|
420
|
10 |
|
$this->log->warning('Exception '.$e->getMessage()); |
|
421
|
|
|
} |
|
422
|
|
|
} |
|
423
|
3 |
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* Bool ? |
|
426
|
|
|
* déwikification du titre : consensus Bistro 27 août 2011 |
|
427
|
|
|
* idem 'titre chapitre'. |
|
428
|
3 |
|
* |
|
429
|
3 |
|
* @param string $param |
|
430
|
3 |
|
* |
|
431
|
3 |
|
* @throws Exception |
|
432
|
|
|
*/ |
|
433
|
3 |
|
protected function deWikifyExternalLink(string $param): void |
|
434
|
|
|
{ |
|
435
|
|
|
if (empty($this->getParam($param))) { |
|
436
|
|
|
return; |
|
437
|
|
|
} |
|
438
|
|
|
if (preg_match('#^\[(http[^ \]]+) ([^]]+)]#i', $this->getParam($param), $matches) > 0) { |
|
439
|
|
|
$this->setParam($param, str_replace($matches[0], $matches[2], $this->getParam($param))); |
|
440
|
|
|
$this->addSummaryLog('±'.$param); |
|
441
|
|
|
|
|
442
|
|
|
if (in_array($param, ['titre', 'titre chapitre'])) { |
|
443
|
47 |
|
if (empty($this->getParam('lire en ligne'))) { |
|
444
|
|
|
$this->setParam('lire en ligne', $matches[1]); |
|
445
|
47 |
|
$this->addSummaryLog('+lire en ligne'); |
|
446
|
47 |
|
|
|
447
|
47 |
|
return; |
|
448
|
|
|
} |
|
449
|
47 |
|
$this->addSummaryLog('autre lien externe: '.$matches[1]); |
|
450
|
|
|
} |
|
451
|
|
|
} |
|
452
|
1 |
|
} |
|
453
|
|
|
|
|
454
|
|
|
protected function upperCaseFirstLetter($param) |
|
455
|
|
|
{ |
|
456
|
|
|
if (!$this->hasParamValue($param)) { |
|
457
|
|
|
return; |
|
458
|
|
|
} |
|
459
|
|
|
$newValue = TextUtil::mb_ucfirst(trim($this->getParam($param))); |
|
460
|
|
|
$this->setParam($param, $newValue); |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
1 |
|
* Typo internationale 'titre : sous-titre'. |
|
465
|
|
|
* Fix fantasy typo of subtitle with '. ' or ' - '. |
|
466
|
|
|
* International Standard Bibliographic Description : |
|
467
|
|
|
* https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Le_Bistro/13_janvier_2016#Modif_du_mod%C3%A8le:Ouvrage. |
|
468
|
|
|
* |
|
469
|
|
|
* @param $param |
|
470
|
|
|
* |
|
471
|
|
|
* @throws Exception |
|
472
|
|
|
*/ |
|
473
|
|
|
protected function typoDeuxPoints($param) |
|
474
|
|
|
{ |
|
475
|
|
|
$origin = $this->getParam($param) ?? ''; |
|
476
|
|
|
if (empty($origin)) { |
|
477
|
|
|
return; |
|
478
|
1 |
|
} |
|
479
|
1 |
|
// FIXED bug [[fu:bar]] |
|
480
|
|
|
if (WikiTextUtil::isWikify($origin)) { |
|
481
|
1 |
|
return; |
|
482
|
1 |
|
} |
|
483
|
1 |
|
|
|
484
|
|
|
$origin = TextUtil::replaceNonBreakingSpaces($origin); |
|
485
|
|
|
|
|
486
|
1 |
|
$strTitle = $origin; |
|
487
|
|
|
|
|
488
|
|
|
// CORRECTING TYPO FANTASY OF SUBTITLE |
|
489
|
|
|
|
|
490
|
|
|
// Replace first '.' by ':' if no ': ' and no numbers around (as PHP 7.3) |
|
491
|
|
|
// exlude pattern "blabla... blabla" |
|
492
|
|
|
// TODO: statistics |
|
493
|
|
|
|
|
494
|
|
|
// Replace ' - ' or ' / ' (spaced!) by ' : ' if no ':' and no numbers after (as PHP 7.3 or 1939-1945) |
|
495
|
|
|
if (!mb_strpos(':', $strTitle) && preg_match('#.{6,} ?[-/] ?[^0-9)]{6,}#', $strTitle) > 0) { |
|
496
|
47 |
|
$strTitle = preg_replace('#(.{6,}) [-/] ([^0-9)]{6,})#', '$1 : $2', $strTitle); |
|
497
|
|
|
} |
|
498
|
47 |
|
|
|
499
|
47 |
|
// international typo style " : " (first occurrence) |
|
500
|
47 |
|
$strTitle = preg_replace('#[ ]*:[ ]*#', ' : ', $strTitle); |
|
501
|
47 |
|
|
|
502
|
47 |
|
if ($strTitle !== $origin) { |
|
503
|
|
|
$this->setParam($param, $strTitle); |
|
504
|
|
|
$this->addSummaryLog(sprintf(':%s', $param)); |
|
505
|
|
|
} |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
protected function valideNumeroChapitre() |
|
509
|
|
|
{ |
|
510
|
|
|
$value = $this->getParam('numéro chapitre'); |
|
511
|
|
|
if (empty($value)) { |
|
512
|
|
|
return; |
|
513
|
|
|
} |
|
514
|
|
|
// "12" ou "VI", {{II}}, II:3 |
|
515
|
|
|
if (preg_match('#^[0-9IVXL\-.:{}]+$#i', $value) > 0) { |
|
516
|
|
|
return; |
|
517
|
|
|
} |
|
518
|
|
|
// déplace vers "titre chapitre" ? |
|
519
|
|
|
if (!$this->getParam('titre chapitre')) { |
|
520
|
|
|
$this->unsetParam('numéro chapitre'); |
|
521
|
|
|
$this->setParam('titre chapitre', $value); |
|
522
|
47 |
|
} |
|
523
|
|
|
$this->addSummaryLog('≠numéro chapitre'); |
|
524
|
47 |
|
} |
|
525
|
|
|
|
|
526
|
|
|
/** |
|
527
|
47 |
|
* TODO move+refac |
|
528
|
47 |
|
* TODO CommentaireBiblioTemplate ExtraitTemplate |
|
529
|
47 |
|
* Probleme {{commentaire biblio}} <> {{commentaire biblio SRL}} |
|
530
|
1 |
|
* Generate supplementary templates from obsoletes params. |
|
531
|
|
|
* |
|
532
|
|
|
* @throws Exception |
|
533
|
|
|
*/ |
|
534
|
|
|
protected function externalTemplates() |
|
535
|
47 |
|
{ |
|
536
|
|
|
// "extrait=bla" => {{citation bloc|bla}} |
|
537
|
|
|
if ($this->hasParamValue('extrait')) { |
|
538
|
|
|
$extrait = $this->getParam('extrait'); |
|
539
|
47 |
|
// todo bug {{citation bloc}} si "=" ou "|" dans texte de citation |
|
540
|
|
|
// Legacy : use {{début citation}} ... {{fin citation}} |
|
541
|
|
|
if (preg_match('#[=|]#', $extrait) > 0) { |
|
542
|
|
|
$this->optiTemplate->externalTemplates[] = (object)[ |
|
543
|
|
|
'template' => 'début citation', |
|
544
|
|
|
'1' => '', |
|
545
|
|
|
'raw' => '{{Début citation}}'.$extrait.'{{Fin citation}}', |
|
546
|
|
|
]; |
|
547
|
47 |
|
$this->addSummaryLog('{Début citation}'); |
|
548
|
|
|
$this->notCosmetic = true; |
|
549
|
47 |
|
} else { |
|
550
|
45 |
|
// StdClass |
|
551
|
|
|
$this->optiTemplate->externalTemplates[] = (object)[ |
|
552
|
2 |
|
'template' => 'citation bloc', |
|
553
|
|
|
'1' => $extrait, |
|
554
|
2 |
|
'raw' => '{{Citation bloc|'.$extrait.'}}', |
|
555
|
2 |
|
]; |
|
556
|
|
|
$this->addSummaryLog('{Citation bloc}'); |
|
557
|
1 |
|
$this->notCosmetic = true; |
|
558
|
|
|
} |
|
559
|
|
|
|
|
560
|
|
|
$this->unsetParam('extrait'); |
|
561
|
2 |
|
$this->notCosmetic = true; |
|
562
|
|
|
} |
|
563
|
|
|
|
|
564
|
|
|
// "commentaire=bla" => {{Commentaire biblio|1=bla}} |
|
565
|
|
|
if ($this->hasParamValue('commentaire')) { |
|
566
|
|
|
$commentaire = $this->getParam('commentaire'); |
|
567
|
2 |
|
$this->optiTemplate->externalTemplates[] = (object)[ |
|
568
|
2 |
|
'template' => 'commentaire biblio', |
|
569
|
2 |
|
'1' => $commentaire, |
|
570
|
|
|
'raw' => '{{Commentaire biblio|'.$commentaire.'}}', |
|
571
|
2 |
|
]; |
|
572
|
|
|
$this->unsetParam('commentaire'); |
|
573
|
|
|
$this->addSummaryLog('{commentaire}'); |
|
574
|
|
|
$this->notCosmetic = true; |
|
575
|
2 |
|
} |
|
576
|
2 |
|
} |
|
577
|
2 |
|
|
|
578
|
2 |
|
// ---------------------- |
|
579
|
2 |
|
// ---------------------- |
|
580
|
2 |
|
// ---------------------- |
|
581
|
2 |
|
|
|
582
|
2 |
|
/** |
|
583
|
|
|
* Date->année (nécessaire pour OuvrageComplete). |
|
584
|
|
|
* |
|
585
|
|
|
* @throws Exception |
|
586
|
2 |
|
*/ |
|
587
|
|
|
protected function moveDate2Year() |
|
588
|
|
|
{ |
|
589
|
|
|
$date = $this->getParam('date') ?? false; |
|
590
|
|
|
if ($date) { |
|
591
|
|
|
if (preg_match('#^-?[12][0-9][0-9][0-9]$#', $date)) { |
|
592
|
|
|
$this->setParam('année', $date); |
|
593
|
|
|
$this->unsetParam('date'); |
|
594
|
|
|
//$this->log('>année'); |
|
595
|
|
|
} |
|
596
|
47 |
|
} |
|
597
|
|
|
} |
|
598
|
47 |
|
|
|
599
|
|
|
protected function predictFormatByPattern() |
|
600
|
|
|
{ |
|
601
|
47 |
|
if (($value = $this->getParam('format'))) { |
|
602
|
|
|
// predict if 'format électronique' |
|
603
|
47 |
|
// format electronique lié au champ 'lire en ligne' |
|
604
|
|
|
// 2015 https://fr.wikipedia.org/wiki/Discussion_mod%C3%A8le:Ouvrage#format,_format_livre,_format_%C3%A9lectronique |
|
605
|
|
|
// if (preg_match('#(pdf|epub|html|kindle|audio|\{\{aud|jpg)#i', $value) > 0) { |
|
606
|
35 |
|
// |
|
607
|
|
|
// $this->setParam('format électronique', $value); |
|
608
|
|
|
// $this->unsetParam('format'); |
|
609
|
35 |
|
// $this->log('format:électronique?'); |
|
610
|
35 |
|
// |
|
611
|
|
|
// return; |
|
612
|
35 |
|
// } |
|
613
|
|
|
if (preg_match( |
|
614
|
26 |
|
'#(ill\.|couv\.|in-[0-9]|in-fol|poche|broché|relié|{{unité|{{Dunité|[0-9]{2} ?cm|\|cm}}|vol\.|A4)#i', |
|
615
|
|
|
$value |
|
616
|
26 |
|
) > 0 |
|
617
|
26 |
|
) { |
|
618
|
|
|
$this->setParam('format livre', $value); |
|
619
|
26 |
|
$this->unsetParam('format'); |
|
620
|
|
|
$this->addSummaryLog('format:livre?'); |
|
621
|
|
|
$this->notCosmetic = true; |
|
622
|
|
|
} |
|
623
|
|
|
// Certainement 'format électronique'... |
|
624
|
|
|
} |
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
/** |
|
628
|
|
|
* todo : vérif lien rouge |
|
629
|
|
|
* todo 'lien éditeur' affiché 1x par page |
|
630
|
47 |
|
* opti : Suppression lien éditeur si c'est l'article de l'éditeur. |
|
631
|
|
|
* |
|
632
|
47 |
|
* @throws Exception |
|
633
|
47 |
|
*/ |
|
634
|
|
|
protected function processEditeur() |
|
635
|
15 |
|
{ |
|
636
|
1 |
|
$editeur = $this->getParam('éditeur'); |
|
637
|
1 |
|
if (empty($editeur)) { |
|
638
|
|
|
return; |
|
639
|
1 |
|
} |
|
640
|
1 |
|
|
|
641
|
1 |
|
// FIX bug "GEO Art ([[Prisma Media]]) ; [[Le Monde]]" |
|
642
|
1 |
|
if (preg_match('#\[.*\[.*\[#', $editeur) > 0) { |
|
643
|
|
|
return; |
|
644
|
1 |
|
} |
|
645
|
|
|
// FIX bug "[[Fu|Bar]] bla" => [[Fu|Bar bla]] |
|
646
|
|
|
if (preg_match('#(.+\[\[|\]\].+)#', $editeur) > 0) { |
|
647
|
|
|
return; |
|
648
|
|
|
} |
|
649
|
14 |
|
|
|
650
|
|
|
// [[éditeur]] |
|
651
|
47 |
|
if (preg_match('#\[\[([^|]+)]]#', $editeur, $matches) > 0) { |
|
652
|
|
|
$editeurUrl = $matches[1]; |
|
653
|
47 |
|
} |
|
654
|
47 |
|
// [[bla|éditeur]] |
|
655
|
|
|
if (preg_match('#\[\[([^]|]+)\|.+]]#', $editeur, $matches) > 0) { |
|
656
|
15 |
|
$editeurUrl = $matches[1]; |
|
657
|
15 |
|
} |
|
658
|
15 |
|
|
|
659
|
|
|
// Todo : traitement/suppression des abréviations communes : |
|
660
|
|
|
// ['éd. de ', 'éd. du ', 'éd.', 'ed.', 'Éd. de ', 'Éd.', 'édit.', 'Édit.', '(éd.)', '(ed.)', 'Ltd.'] |
|
661
|
|
|
|
|
662
|
|
|
$editeurStr = WikiTextUtil::unWikify($editeur); |
|
663
|
|
|
// On garde minuscule sur éditeur, pour nuance Éditeur/éditeur permettant de supprimer "éditeur" |
|
664
|
|
|
// ex: "éditions Milan" => "Milan" |
|
665
|
|
|
|
|
666
|
|
|
// Déconseillé : 'lien éditeur' (obsolete 2019) |
|
667
|
|
|
if ($this->hasParamValue('lien éditeur')) { |
|
668
|
|
|
if (empty($editeurUrl)) { |
|
669
|
|
|
$editeurUrl = $this->getParam('lien éditeur'); |
|
670
|
47 |
|
} |
|
671
|
|
|
$this->unsetParam('lien éditeur'); |
|
672
|
47 |
|
} |
|
673
|
47 |
|
|
|
674
|
32 |
|
$newEditeur = $editeurStr; |
|
675
|
|
|
if (!empty($editeurUrl)) { |
|
676
|
|
|
$newEditeur = WikiTextUtil::wikilink($editeurStr, $editeurUrl); |
|
677
|
15 |
|
} |
|
678
|
2 |
|
|
|
679
|
|
|
if ($newEditeur !== $editeur) { |
|
680
|
|
|
$this->setParam('éditeur', $newEditeur); |
|
681
|
13 |
|
$this->addSummaryLog('±éditeur'); |
|
682
|
|
|
$this->notCosmetic = true; |
|
683
|
13 |
|
} |
|
684
|
|
|
} |
|
685
|
|
|
} |
|
686
|
|
|
|