Dispositif /
Wikibot
| 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; |
||
| 11 | |||
| 12 | use App\Domain\OptiStatus; |
||
| 13 | use App\Domain\WikiOptimizer\Handlers\AuthorLinkHandler; |
||
| 14 | use App\Domain\WikiOptimizer\Handlers\BnfParamHandler; |
||
| 15 | use App\Domain\WikiOptimizer\Handlers\DateHandler; |
||
| 16 | use App\Domain\WikiOptimizer\Handlers\DistinguishAuthorsHandler; |
||
| 17 | use App\Domain\WikiOptimizer\Handlers\EditeurHandler; |
||
| 18 | use App\Domain\WikiOptimizer\Handlers\EditionCitebookHandler; |
||
| 19 | use App\Domain\WikiOptimizer\Handlers\ExternalTemplateHandler; |
||
| 20 | use App\Domain\WikiOptimizer\Handlers\GoogleBooksUrlHandler; |
||
| 21 | use App\Domain\WikiOptimizer\Handlers\LangParamHandler; |
||
| 22 | use App\Domain\WikiOptimizer\Handlers\LocationHandler; |
||
| 23 | use App\Domain\WikiOptimizer\Handlers\OptimizeHandlerInterface; |
||
| 24 | use App\Domain\WikiOptimizer\Handlers\OuvrageFormatHandler; |
||
| 25 | use App\Domain\WikiOptimizer\Handlers\OuvrageIsbnHandler; |
||
| 26 | use App\Domain\WikiOptimizer\Handlers\PredictErrorParameterHandler; |
||
| 27 | use App\Domain\WikiOptimizer\Handlers\TitleHandler; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Check and correct param value of {ouvrage} wikitemplate, from bibliographic logic rules or prediction. |
||
| 31 | * No request to external API. |
||
| 32 | * Use local library : ISBN check, etc. |
||
| 33 | */ |
||
| 34 | class OuvrageOptimize extends AbstractTemplateOptimizer |
||
| 35 | { |
||
| 36 | final public const CONVERT_GOOGLEBOOK_TEMPLATE = false; // change OuvrageOptimizeTest !! |
||
| 37 | final public const WIKI_LANGUAGE = 'fr'; |
||
| 38 | final public const PUBLISHER_FRWIKI_FILENAME = __DIR__ . '/../resources/data_editors_wiki.json'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var OptiStatus |
||
| 42 | */ |
||
| 43 | protected $optiStatus; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @noinspection PhpParamsInspection |
||
| 47 | */ |
||
| 48 | public function doTasks(): self |
||
| 49 | { |
||
| 50 | $this->optiStatus = new OptiStatus(); // move to AbstractTemplateOptimizer ? |
||
| 51 | $optiStatus = $this->optiStatus; |
||
| 52 | |||
| 53 | // Composite handler |
||
| 54 | $handlers = [ |
||
| 55 | new PredictErrorParameterHandler($this->optiTemplate, $optiStatus), |
||
| 56 | new DistinguishAuthorsHandler($this->optiTemplate, $optiStatus), |
||
| 57 | new LangParamHandler($this->optiTemplate, $optiStatus), |
||
| 58 | (new LangParamHandler($this->optiTemplate, $optiStatus))->setLangParam('langue originale'), |
||
| 59 | new TitleHandler($this->optiTemplate, $optiStatus), |
||
| 60 | new AuthorLinkHandler($this->optiTemplate, $optiStatus), |
||
| 61 | new EditionCitebookHandler($this->optiTemplate, $optiStatus), |
||
| 62 | new EditeurHandler($this->optiTemplate, $optiStatus, $this->wikiPageTitle, $this->log), |
||
| 63 | new DateHandler($this->optiTemplate, $optiStatus), |
||
| 64 | new ExternalTemplateHandler($this->optiTemplate, $optiStatus), |
||
| 65 | new OuvrageFormatHandler($this->optiTemplate, $optiStatus), |
||
| 66 | new OuvrageIsbnHandler($this->optiTemplate, $optiStatus), |
||
| 67 | new BnfParamHandler($this->optiTemplate, $optiStatus), |
||
| 68 | new LocationHandler($this->optiTemplate, $optiStatus, $this->pageListManager), |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 69 | new GoogleBooksUrlHandler($this->optiTemplate, $optiStatus), |
||
| 70 | (new GoogleBooksUrlHandler($this->optiTemplate, $optiStatus)) |
||
| 71 | ->sethandlerParam('présentation en ligne'), |
||
| 72 | new PredictErrorParameterHandler($this->optiTemplate, $optiStatus), |
||
| 73 | new DistinguishAuthorsHandler($this->optiTemplate, $optiStatus), |
||
| 74 | new LangParamHandler($this->optiTemplate, $optiStatus), |
||
| 75 | (new LangParamHandler($this->optiTemplate, $optiStatus))->setLangParam('langue originale'), |
||
| 76 | new TitleHandler($this->optiTemplate, $optiStatus), |
||
| 77 | new AuthorLinkHandler($this->optiTemplate, $optiStatus), |
||
| 78 | new EditionCitebookHandler($this->optiTemplate, $optiStatus), |
||
| 79 | new EditeurHandler($this->optiTemplate, $optiStatus, $this->wikiPageTitle, $this->log), |
||
| 80 | new DateHandler($this->optiTemplate, $optiStatus), |
||
| 81 | new ExternalTemplateHandler($this->optiTemplate, $optiStatus), |
||
| 82 | new OuvrageFormatHandler($this->optiTemplate, $optiStatus), |
||
| 83 | // new OuvrageIsbnHandler($this->optiTemplate, $optiStatus), |
||
| 84 | new BnfParamHandler($this->optiTemplate, $optiStatus), |
||
| 85 | new LocationHandler($this->optiTemplate, $optiStatus, $this->pageListManager), |
||
| 86 | new GoogleBooksUrlHandler($this->optiTemplate, $optiStatus), |
||
| 87 | (new GoogleBooksUrlHandler($this->optiTemplate, $optiStatus)) |
||
| 88 | ->sethandlerParam('présentation en ligne'), |
||
| 89 | ]; |
||
| 90 | |||
| 91 | foreach ($handlers as $handler) { |
||
| 92 | if (!$handler instanceof OptimizeHandlerInterface) { |
||
| 93 | throw new \LogicException('Handler must implement OptimizeHandlerInterface'); |
||
| 94 | } |
||
| 95 | $handler->handle(); |
||
| 96 | } |
||
| 97 | |||
| 98 | return $this; |
||
| 99 | } |
||
| 100 | |||
| 101 | public function isNotCosmetic(): bool |
||
| 102 | { |
||
| 103 | return $this->optiStatus->isNotCosmetic(); |
||
| 104 | } |
||
| 105 | |||
| 106 | public function getOptiStatus(): OptiStatus |
||
| 107 | { |
||
| 108 | return $this->optiStatus; |
||
| 109 | } |
||
| 110 | } |
||
| 111 |