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\Domain\WikiOptimizer\Handlers; |
11
|
|
|
|
12
|
|
|
use App\Domain\InfrastructurePorts\PageListInterface; |
13
|
|
|
use App\Domain\Models\Wiki\OuvrageTemplate; |
14
|
|
|
use App\Domain\Utils\TextUtil; |
15
|
|
|
use App\Domain\Utils\WikiTextUtil; |
16
|
|
|
use App\Domain\WikiOptimizer\OptiStatus; |
17
|
|
|
use Exception; |
18
|
|
|
|
19
|
|
|
class LocationHandler extends AbstractOuvrageHandler |
20
|
|
|
{ |
21
|
|
|
public const TRANSLATE_CITY_FR = __DIR__ . '/../../resources/traduction_ville.csv'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var PageListInterface |
25
|
|
|
*/ |
26
|
|
|
protected $pageListManager; |
27
|
|
|
|
28
|
|
|
public function __construct(OuvrageTemplate $ouvrage, OptiStatus $summary, PageListInterface $pageListManager) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($ouvrage, $summary); |
31
|
|
|
$this->pageListManager = $pageListManager; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Todo: injection dep. |
36
|
|
|
* Todo : "[s. l.]" sans lieu "s.l.n.d." sans lieu ni date. |
37
|
|
|
* @throws Exception |
38
|
|
|
*/ |
39
|
|
|
public function handle() |
40
|
|
|
{ |
41
|
|
|
$location = $this->getParam('lieu'); |
42
|
|
|
if (empty($location)) { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// typo and unwikify |
47
|
|
|
$memo = $location; |
48
|
|
|
$location = WikiTextUtil::unWikify($location); |
49
|
|
|
$location = TextUtil::mb_ucfirst($location); |
50
|
|
|
if ($memo !== $location) { |
51
|
|
|
$this->setParam('lieu', $location); |
52
|
|
|
$this->addSummaryLog('±lieu'); |
53
|
|
|
$this->optiStatus->setNotCosmetic(true); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// translation : "London"->"Londres" |
57
|
|
|
$row = $this->pageListManager->findCSVline(self::TRANSLATE_CITY_FR, $location); |
|
|
|
|
58
|
|
|
if ($row !== [] && !empty($row[1])) { |
59
|
|
|
$this->setParam('lieu', $row[1]); |
60
|
|
|
$this->addSummaryLog('lieu francisé'); |
61
|
|
|
$this->notCosmetic = true; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |