| Total Complexity | 135 |
| Total Lines | 825 |
| Duplicated Lines | 0 % |
| Changes | 21 | ||
| Bugs | 0 | Features | 2 |
Complex classes like OuvrageOptimize often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use OuvrageOptimize, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class OuvrageOptimize |
||
| 32 | { |
||
| 33 | const CONVERT_GOOGLEBOOK_TEMPLATE = false; // change OuvrageOptimizeTest !! |
||
| 34 | |||
| 35 | const WIKI_LANGUAGE = 'fr'; |
||
| 36 | |||
| 37 | protected $original; |
||
| 38 | |||
| 39 | private $wikiPageTitle; |
||
| 40 | |||
| 41 | private $log = []; |
||
| 42 | |||
| 43 | public $notCosmetic = false; |
||
| 44 | |||
| 45 | public $major = false; |
||
| 46 | |||
| 47 | private $ouvrage; |
||
| 48 | |||
| 49 | private $currentTask; |
||
| 50 | |||
| 51 | // todo inject TextUtil + ArticleVersion ou WikiRef |
||
| 52 | public function __construct(OuvrageTemplate $ouvrage, $wikiPageTitle = null) |
||
| 57 | } |
||
| 58 | |||
| 59 | public function doTasks(): self |
||
| 60 | { |
||
| 61 | $this->cleanAndPredictErrorParameters(); |
||
| 62 | |||
| 63 | $this->processAuthors(); |
||
| 64 | |||
| 65 | $this->processTitle(); |
||
| 66 | $this->processEditeur(); |
||
| 67 | $this->processDates(); |
||
| 68 | $this->externalTemplates(); |
||
| 69 | $this->predictFormatByPattern(); |
||
| 70 | |||
| 71 | $this->convertRoman('tome'); |
||
| 72 | $this->convertRoman('volume'); |
||
| 73 | |||
| 74 | $this->processIsbn(); |
||
| 75 | $this->processBnf(); |
||
| 76 | |||
| 77 | $this->processLang(); |
||
| 78 | $this->processLocation(); // 'lieu' |
||
| 79 | |||
| 80 | $this->GoogleBookURL('lire en ligne'); |
||
| 81 | $this->GoogleBookURL('présentation en ligne'); |
||
| 82 | |||
| 83 | return $this; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Todo: injection dep. |
||
| 88 | * Todo : "[s. l.]" sans lieu "s.l.n.d." sans lieu ni date. |
||
| 89 | * |
||
| 90 | * @throws Exception |
||
| 91 | */ |
||
| 92 | private function processLocation() |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | private function processBnf() |
||
| 127 | } |
||
| 128 | |||
| 129 | private function convertRoman(string $param): void |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @throws Exception |
||
| 147 | */ |
||
| 148 | private function processAuthors() |
||
| 149 | { |
||
| 150 | $this->distinguishAuthors(); |
||
| 151 | //$this->fusionFirstNameAndName(); // desactived : no consensus |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Detect and correct multiple authors in same parameter. |
||
| 156 | * Like "auteurs=J. M. Waller, M. Bigger, R. J. Hillocks". |
||
| 157 | * |
||
| 158 | * @throws Exception |
||
| 159 | */ |
||
| 160 | private function distinguishAuthors() |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * todo: move/implement. |
||
| 207 | * |
||
| 208 | * @throws Exception |
||
| 209 | */ |
||
| 210 | private function processLang() |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Validate or correct ISBN. |
||
| 228 | * |
||
| 229 | * @throws Exception |
||
| 230 | */ |
||
| 231 | private function processIsbn() |
||
| 232 | { |
||
| 233 | $isbn = $this->getParam('isbn') ?? ''; |
||
| 234 | |||
| 235 | if (empty($isbn)) { |
||
| 236 | return; |
||
| 237 | } |
||
| 238 | |||
| 239 | $isbnMachine = new IsbnFacade($isbn); |
||
| 240 | |||
| 241 | try { |
||
| 242 | $isbnMachine->validate(); |
||
| 243 | $isbn13 = $isbnMachine->format('ISBN-13'); |
||
| 244 | } catch (Throwable $e) { |
||
| 245 | // ISBN not validated |
||
| 246 | // TODO : bot ISBN invalide (queue, message PD...) |
||
| 247 | $this->setParam( |
||
| 248 | 'isbn invalide', |
||
| 249 | sprintf('%s %s', $isbn, $e->getMessage() ?? '') |
||
| 250 | ); |
||
| 251 | $this->log(sprintf('ISBN invalide: %s', $e->getMessage())); |
||
| 252 | $this->notCosmetic = true; |
||
| 253 | |||
| 254 | // TODO log file ISBNinvalide |
||
| 255 | return; |
||
| 256 | } |
||
| 257 | |||
| 258 | // Si 'isbn2' correspond à ISBN-13 => suppression |
||
| 259 | if (isset($isbn13) |
||
| 260 | && $this->getParam('isbn2') |
||
| 261 | && $this->stripIsbn($this->getParam('isbn2')) === $this->stripIsbn($isbn13) |
||
| 262 | ) { |
||
| 263 | $this->unsetParam('isbn2'); |
||
| 264 | } |
||
| 265 | |||
| 266 | |||
| 267 | // ISBN-10 ? |
||
| 268 | $stripIsbn = $this->stripIsbn($isbn); |
||
| 269 | if (10 === mb_strlen($stripIsbn)) { |
||
| 270 | // ajout des tirets |
||
| 271 | $isbn10pretty = $isbn; |
||
|
1 ignored issue
–
show
|
|||
| 272 | try { |
||
| 273 | $isbn10pretty = $isbnMachine->format('ISBN-10'); |
||
| 274 | if ($isbn10pretty !== $isbn) { |
||
| 275 | $this->notCosmetic = true; |
||
| 276 | } |
||
| 277 | } catch (\Throwable $e) { |
||
| 278 | unset($e); |
||
| 279 | } |
||
| 280 | |||
| 281 | // archivage ISBN-10 dans 'isbn2' |
||
| 282 | if (!$this->getParam('isbn2')) { |
||
| 283 | $this->setParam('isbn2', $isbn10pretty); |
||
| 284 | } |
||
| 285 | // sinon dans 'isbn3' |
||
| 286 | if (!empty($this->getParam('isbn2')) |
||
| 287 | && $this->stripIsbn($this->getParam('isbn2')) !== $stripIsbn |
||
| 288 | && empty($this->getParam('isbn3')) |
||
| 289 | ) { |
||
| 290 | $this->setParam('isbn3', $isbn10pretty); |
||
| 291 | } |
||
| 292 | // delete 'isbn10' (en attendant modification modèle) |
||
| 293 | if (!empty($this->getParam('isbn10')) && $this->stripIsbn($this->getParam('isbn10')) === $stripIsbn) { |
||
| 294 | $this->unsetParam('isbn10'); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | // ISBN correction |
||
| 299 | if ($isbn13 !== $isbn) { |
||
| 300 | $this->setParam('isbn', $isbn13); |
||
| 301 | $this->log('ISBN'); |
||
| 302 | $this->notCosmetic = true; |
||
| 303 | } |
||
| 304 | } |
||
| 305 | |||
| 306 | private function stripIsbn(string $isbn): string |
||
| 307 | { |
||
| 308 | return trim(preg_replace('#[^0-9Xx]#', '', $isbn)); |
||
| 309 | } |
||
| 310 | |||
| 311 | private function processTitle() |
||
| 312 | { |
||
| 313 | $this->currentTask = 'titres'; |
||
| 314 | |||
| 315 | $oldtitre = $this->getParam('titre'); |
||
| 316 | $this->langInTitle(); |
||
| 317 | $this->deWikifyExternalLink('titre'); |
||
| 318 | $this->upperCaseFirstLetter('titre'); |
||
| 319 | $this->typoDeuxPoints('titre'); |
||
| 320 | |||
| 321 | $this->extractSubTitle(); |
||
| 322 | |||
| 323 | // 20-11-2019 : Retiré majuscule à sous-titre |
||
| 324 | |||
| 325 | if ($this->getParam('titre') !== $oldtitre) { |
||
| 326 | $this->log('±titre'); |
||
| 327 | } |
||
| 328 | |||
| 329 | $this->currentTask = 'titre chapitre'; |
||
| 330 | $this->valideNumeroChapitre(); |
||
| 331 | $this->deWikifyExternalLink('titre chapitre'); |
||
| 332 | $this->upperCaseFirstLetter('titre chapitre'); |
||
| 333 | $this->typoDeuxPoints('titre chapitre'); |
||
| 334 | } |
||
| 335 | |||
| 336 | private function detectColon($param): bool |
||
| 337 | { |
||
| 338 | // > 0 don't count a starting colon ":bla" |
||
| 339 | if (!empty($this->getParam($param)) && mb_strrpos($this->getParam('titre'), ':') > 0) { |
||
| 340 | return true; |
||
| 341 | } |
||
| 342 | |||
| 343 | return false; |
||
| 344 | } |
||
| 345 | |||
| 346 | private function extractSubTitle(): void |
||
| 347 | { |
||
| 348 | // FIXED bug [[fu:bar]] |
||
| 349 | if (!$this->getParam('titre') || WikiTextUtil::isWikify($this->getParam('titre'))) { |
||
|
1 ignored issue
–
show
|
|||
| 350 | return; |
||
| 351 | } |
||
| 352 | |||
| 353 | if (!$this->detectColon('titre')) { |
||
| 354 | return; |
||
| 355 | } |
||
| 356 | // Que faire si déjà un sous-titre ? |
||
| 357 | if (!empty($this->getParam('sous-titre'))) { |
||
| 358 | return; |
||
| 359 | } |
||
| 360 | |||
| 361 | // titre>5 and sous-titre>5 and sous-titre<40 |
||
| 362 | if (preg_match('#^(?<titre>[^:]{5,}):(?<st>.{5,40})$#', $this->getParam('titre'), $matches) > 0) { |
||
| 363 | $this->setParam('titre', trim($matches['titre'])); |
||
| 364 | $this->setParam('sous-titre', trim($matches['st'])); |
||
| 365 | $this->log('>sous-titre'); |
||
| 366 | } |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Normalize a Google Book links. |
||
| 371 | * Clean the useless URL parameters or transform into wiki-template. |
||
| 372 | * |
||
| 373 | * @param $param |
||
| 374 | * |
||
| 375 | * @throws Exception |
||
| 376 | */ |
||
| 377 | private function googleBookUrl(string $param): void |
||
| 378 | { |
||
| 379 | $url = $this->getParam($param); |
||
| 380 | if (empty($url) |
||
| 381 | || !GoogleLivresTemplate::isGoogleBookURL($url) |
||
| 382 | ) { |
||
| 383 | return; |
||
| 384 | } |
||
| 385 | |||
| 386 | if (self::CONVERT_GOOGLEBOOK_TEMPLATE) { |
||
| 387 | $template = GoogleLivresTemplate::createFromURL($url); |
||
| 388 | if ($template) { |
||
|
1 ignored issue
–
show
|
|||
| 389 | $this->setParam($param, $template->serialize()); |
||
| 390 | $this->log('{Google}'); |
||
| 391 | $this->notCosmetic = true; |
||
| 392 | |||
| 393 | return; |
||
| 394 | } |
||
| 395 | } |
||
| 396 | |||
| 397 | $goo = GoogleLivresTemplate::simplifyGoogleUrl($url); |
||
| 398 | if (!empty($goo)) { |
||
| 399 | $this->setParam($param, $goo); |
||
| 400 | $this->log('Google'); |
||
| 401 | $this->notCosmetic = true; |
||
| 402 | } |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * - {{lang|...}} dans titre => langue=... puis titre nettoyé |
||
| 407 | * langue=L’utilisation de ce paramètre permet aussi aux synthétiseurs vocaux de reconnaître la langue du titre de |
||
| 408 | * l’ouvrage. |
||
| 409 | * 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. |
||
| 410 | * |
||
| 411 | * @throws Exception |
||
| 412 | */ |
||
| 413 | private function langInTitle() |
||
| 414 | { |
||
| 415 | if (preg_match( |
||
| 416 | '#^{{ ?(?:lang|langue) ?\| ?([a-z-]{2,5}) ?\| ?(?:texte=)?([^{}=]+)(?:\|dir=rtl)?}}$#i', |
||
| 417 | $this->getParam('titre'), |
||
| 418 | $matches |
||
| 419 | ) > 0 |
||
| 420 | ) { |
||
| 421 | $lang = trim($matches[1]); |
||
| 422 | $newtitre = str_replace($matches[0], trim($matches[2]), $this->getParam('titre')); |
||
| 423 | $this->setParam('titre', $newtitre); |
||
| 424 | $this->log('°titre'); |
||
| 425 | if (self::WIKI_LANGUAGE !== $lang && empty($this->getParam('langue'))) { |
||
| 426 | $this->setParam('langue', $lang); |
||
| 427 | $this->log('+langue='.$lang); |
||
| 428 | } |
||
| 429 | } |
||
| 430 | } |
||
| 431 | |||
| 432 | private function processDates() |
||
| 433 | { |
||
| 434 | // dewikification |
||
| 435 | $params = ['date', 'année', 'mois', 'jour']; |
||
| 436 | foreach ($params as $param) { |
||
| 437 | if (WikiTextUtil::isWikify(' '.$this->getParam($param))) { |
||
| 438 | $this->setParam($param, WikiTextUtil::unWikify($this->getParam($param))); |
||
|
1 ignored issue
–
show
|
|||
| 439 | } |
||
| 440 | } |
||
| 441 | |||
| 442 | try { |
||
| 443 | $this->moveDate2Year(); |
||
| 444 | } catch (Exception $e) { |
||
| 445 | dump($e); |
||
| 446 | } |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * todo: move to AbstractWikiTemplate ? |
||
| 451 | * Correction des parametres rejetés à l'hydratation données. |
||
| 452 | * |
||
| 453 | * @throws Exception |
||
| 454 | */ |
||
| 455 | private function cleanAndPredictErrorParameters() |
||
| 456 | { |
||
| 457 | if (empty($this->ouvrage->parametersErrorFromHydrate)) { |
||
| 458 | return; |
||
| 459 | } |
||
| 460 | $allParamsAndAlias = $this->ouvrage->getParamsAndAlias(); |
||
| 461 | |||
| 462 | foreach ($this->ouvrage->parametersErrorFromHydrate as $name => $value) { |
||
| 463 | if (!is_string($name)) { |
||
| 464 | // example : 1 => "ouvrage collectif" from |ouvrage collectif| |
||
| 465 | continue; |
||
| 466 | } |
||
| 467 | |||
| 468 | // delete error parameter if no value |
||
| 469 | if (empty($value)) { |
||
| 470 | unset($this->ouvrage->parametersErrorFromHydrate[$name]); |
||
| 471 | |||
| 472 | continue; |
||
| 473 | } |
||
| 474 | |||
| 475 | $maxDistance = 1; |
||
| 476 | if (mb_strlen($name) >= 4) { |
||
| 477 | $maxDistance = 2; |
||
| 478 | } |
||
| 479 | if (mb_strlen($name) >= 8) { |
||
| 480 | $maxDistance = 3; |
||
| 481 | } |
||
| 482 | |||
| 483 | $predName = TextUtil::predictCorrectParam($name, $allParamsAndAlias, $maxDistance); |
||
| 484 | if ($predName && mb_strlen($name) >= 5) { |
||
| 485 | if (empty($this->getParam($predName))) { |
||
| 486 | $predName = $this->ouvrage->getAliasParam($predName); |
||
| 487 | $this->setParam($predName, $value); |
||
| 488 | $this->log(sprintf('%s⇒%s ?', $name, $predName)); |
||
| 489 | $this->notCosmetic = true; |
||
| 490 | unset($this->ouvrage->parametersErrorFromHydrate[$name]); |
||
| 491 | } |
||
| 492 | } |
||
| 493 | } |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * TODO : return "" instead of null ? |
||
| 498 | * |
||
| 499 | * @param $name |
||
| 500 | * |
||
| 501 | * @return string|null |
||
| 502 | * @throws Exception |
||
| 503 | */ |
||
| 504 | private function getParam(string $name): ?string |
||
| 505 | { |
||
| 506 | return $this->ouvrage->getParam($name); |
||
| 507 | } |
||
| 508 | |||
| 509 | private function setParam($name, $value) |
||
| 510 | { |
||
| 511 | // todo : overwrite setParam() ? |
||
| 512 | if (!empty($value) || $this->ouvrage->getParam($name)) { |
||
| 513 | $this->ouvrage->setParam($name, $value); |
||
| 514 | } |
||
| 515 | } |
||
| 516 | |||
| 517 | private function log(string $string): void |
||
| 518 | { |
||
| 519 | if (!empty($string)) { |
||
| 520 | $this->log[] = trim($string); |
||
| 521 | } |
||
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Bool ? |
||
| 526 | * déwikification du titre : consensus Bistro 27 août 2011 |
||
| 527 | * idem 'titre chapitre'. |
||
| 528 | * |
||
| 529 | * @param string $param |
||
| 530 | * |
||
| 531 | * @throws Exception |
||
| 532 | */ |
||
| 533 | private function deWikifyExternalLink(string $param): void |
||
| 534 | { |
||
| 535 | if (empty($this->getParam($param))) { |
||
| 536 | return; |
||
| 537 | } |
||
| 538 | if (preg_match('#^\[(http[^ \]]+) ([^]]+)]#i', $this->getParam($param), $matches) > 0) { |
||
| 539 | $this->setParam($param, str_replace($matches[0], $matches[2], $this->getParam($param))); |
||
| 540 | $this->log('±'.$param); |
||
| 541 | |||
| 542 | if (in_array($param, ['titre', 'titre chapitre'])) { |
||
| 543 | if (empty($this->getParam('lire en ligne'))) { |
||
| 544 | $this->setParam('lire en ligne', $matches[1]); |
||
| 545 | $this->log('+lire en ligne'); |
||
| 546 | |||
| 547 | return; |
||
| 548 | } |
||
| 549 | $this->log('autre lien externe: '.$matches[1]); |
||
| 550 | } |
||
| 551 | } |
||
| 552 | } |
||
| 553 | |||
| 554 | private function upperCaseFirstLetter($param) |
||
| 555 | { |
||
| 556 | if (empty($this->getParam($param))) { |
||
| 557 | return; |
||
| 558 | } |
||
| 559 | $newValue = TextUtil::mb_ucfirst(trim($this->getParam($param))); |
||
| 560 | $this->setParam($param, $newValue); |
||
| 561 | } |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Typo internationale 'titre : sous-titre'. |
||
| 565 | * Fix fantasy typo of subtitle with '. ' or ' - '. |
||
| 566 | * International Standard Bibliographic Description : |
||
| 567 | * https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Le_Bistro/13_janvier_2016#Modif_du_mod%C3%A8le:Ouvrage. |
||
| 568 | * |
||
| 569 | * @param $param |
||
| 570 | * |
||
| 571 | * @throws Exception |
||
| 572 | */ |
||
| 573 | private function typoDeuxPoints($param) |
||
| 574 | { |
||
| 575 | $origin = $this->getParam($param) ?? ''; |
||
| 576 | if (empty($origin)) { |
||
| 577 | return; |
||
| 578 | } |
||
| 579 | // FIXED bug [[fu:bar]] |
||
| 580 | if (WikiTextUtil::isWikify($origin)) { |
||
| 581 | return; |
||
| 582 | } |
||
| 583 | |||
| 584 | $origin = TextUtil::replaceNonBreakingSpaces($origin); |
||
| 585 | |||
| 586 | $strTitle = $origin; |
||
| 587 | |||
| 588 | // CORRECTING TYPO FANTASY OF SUBTITLE |
||
| 589 | |||
| 590 | // Replace first '.' by ':' if no ': ' and no numbers around (as PHP 7.3) |
||
| 591 | // exlude pattern "blabla... blabla" |
||
| 592 | // TODO: statistics |
||
| 593 | |||
| 594 | // Replace ' - ' or ' / ' (spaced!) by ' : ' if no ':' and no numbers after (as PHP 7.3 or 1939-1945) |
||
| 595 | if (!mb_strpos(':', $strTitle) && preg_match('#.{6,} ?[-/] ?[^0-9)]{6,}#', $strTitle) > 0) { |
||
| 596 | $strTitle = preg_replace('#(.{6,}) [-/] ([^0-9)]{6,})#', '$1 : $2', $strTitle); |
||
| 597 | } |
||
| 598 | |||
| 599 | // international typo style " : " (first occurrence) |
||
| 600 | $strTitle = preg_replace('#[ ]*:[ ]*#', ' : ', $strTitle); |
||
| 601 | |||
| 602 | if ($strTitle !== $origin) { |
||
| 603 | $this->setParam($param, $strTitle); |
||
| 604 | $this->log(sprintf(':%s', $param)); |
||
| 605 | } |
||
| 606 | } |
||
| 607 | |||
| 608 | private function valideNumeroChapitre() |
||
| 609 | { |
||
| 610 | $value = $this->getParam('numéro chapitre'); |
||
| 611 | if (empty($value)) { |
||
| 612 | return; |
||
| 613 | } |
||
| 614 | // "12" ou "VI", {{II}}, II:3 |
||
| 615 | if (preg_match('#^[0-9IVXL\-.:{}]+$#i', $value) > 0) { |
||
| 616 | return; |
||
| 617 | } |
||
| 618 | // déplace vers "titre chapitre" ? |
||
| 619 | if (!$this->getParam('titre chapitre')) { |
||
| 620 | $this->unsetParam('numéro chapitre'); |
||
| 621 | $this->setParam('titre chapitre', $value); |
||
| 622 | } |
||
| 623 | $this->log('≠numéro chapitre'); |
||
| 624 | } |
||
| 625 | |||
| 626 | private function unsetParam($name) |
||
| 629 | } |
||
| 630 | |||
| 631 | /** |
||
| 632 | * TODO move+refac |
||
| 633 | * TODO PlumeTemplate CommentaireBiblioTemplate ExtraitTemplate |
||
| 634 | * Probleme {{commentaire biblio}} <> {{commentaire biblio SRL}} |
||
| 635 | * Generate supplementary templates from obsoletes params. |
||
| 636 | * |
||
| 637 | * @throws Exception |
||
| 638 | */ |
||
| 639 | protected function externalTemplates() |
||
| 694 | } |
||
| 695 | } |
||
| 696 | |||
| 697 | // ---------------------- |
||
| 698 | // ---------------------- |
||
| 699 | // ---------------------- |
||
| 700 | |||
| 701 | /** |
||
| 702 | * Date->année (nécessaire pour OuvrageComplete). |
||
| 703 | * |
||
| 704 | * @throws Exception |
||
| 705 | */ |
||
| 706 | private function moveDate2Year() |
||
| 707 | { |
||
| 708 | $date = $this->getParam('date') ?? false; |
||
| 709 | if ($date) { |
||
| 710 | if (preg_match('#^-?[12][0-9][0-9][0-9]$#', $date)) { |
||
| 711 | $this->setParam('année', $date); |
||
| 712 | $this->unsetParam('date'); |
||
| 713 | //$this->log('>année'); |
||
| 714 | } |
||
| 715 | } |
||
| 716 | } |
||
| 717 | |||
| 718 | private function predictFormatByPattern() |
||
| 719 | { |
||
| 720 | if (($value = $this->getParam('format'))) { |
||
| 721 | // predict if 'format électronique' |
||
| 722 | // format electronique lié au champ 'lire en ligne' |
||
| 723 | // 2015 https://fr.wikipedia.org/wiki/Discussion_mod%C3%A8le:Ouvrage#format,_format_livre,_format_%C3%A9lectronique |
||
| 724 | // if (preg_match('#(pdf|epub|html|kindle|audio|\{\{aud|jpg)#i', $value) > 0) { |
||
| 725 | // |
||
| 726 | // $this->setParam('format électronique', $value); |
||
| 727 | // $this->unsetParam('format'); |
||
| 728 | // $this->log('format:électronique?'); |
||
| 729 | // |
||
| 730 | // return; |
||
| 731 | // } |
||
| 732 | if (preg_match( |
||
| 733 | '#(ill\.|couv\.|in-[0-9]|in-fol|poche|broché|relié|{{unité|{{Dunité|[0-9]{2} ?cm|\|cm}}|vol\.|A4)#i', |
||
| 734 | $value |
||
| 735 | ) > 0 |
||
| 736 | ) { |
||
| 737 | $this->setParam('format livre', $value); |
||
| 738 | $this->unsetParam('format'); |
||
| 739 | $this->log('format:livre?'); |
||
| 740 | $this->notCosmetic = true; |
||
| 741 | } |
||
| 742 | // Certainement 'format électronique'... |
||
| 743 | } |
||
| 744 | } |
||
| 745 | |||
| 746 | /** |
||
| 747 | * @return bool |
||
| 748 | * @throws Exception |
||
| 749 | */ |
||
| 750 | public function checkMajorEdit(): bool |
||
| 751 | { |
||
| 752 | // Correction paramètre |
||
| 753 | if ($this->ouvrage->parametersErrorFromHydrate !== $this->original->parametersErrorFromHydrate) { |
||
| 754 | return true; |
||
| 755 | } |
||
| 756 | // Complétion langue ? |
||
| 757 | if (!empty($this->getParam('langue')) && empty($this->original->getParam('langue')) |
||
| 758 | && self::WIKI_LANGUAGE !== $this->getParam('langue') |
||
| 759 | ) { |
||
| 760 | return true; |
||
| 761 | } |
||
| 762 | // TODO replace conditions ci-dessous par event flagMajor() |
||
| 763 | // Retire le param/value 'langue' (pas major si conversion nom langue) |
||
| 764 | $datOuvrage = $this->ouvrage->toArray(); |
||
| 765 | $datOriginal = $this->original->toArray(); |
||
| 766 | unset($datOriginal['langue'], $datOuvrage['langue']); |
||
| 767 | |||
| 768 | // Modification données |
||
| 769 | if ($datOriginal !== $datOuvrage) { |
||
| 770 | return true; |
||
| 771 | } |
||
| 772 | |||
| 773 | return false; |
||
| 774 | } |
||
| 775 | |||
| 776 | /** |
||
| 777 | * @return array |
||
| 778 | */ |
||
| 779 | public function getLog(): array |
||
| 780 | { |
||
| 781 | return $this->log; |
||
| 782 | } |
||
| 783 | |||
| 784 | /** |
||
| 785 | * @return OuvrageTemplate |
||
| 786 | */ |
||
| 787 | public function getOuvrage(): OuvrageTemplate |
||
| 790 | } |
||
| 791 | |||
| 792 | /** |
||
| 793 | * todo : vérif lien rouge |
||
| 794 | * todo 'lien éditeur' affiché 1x par page |
||
| 795 | * opti : Suppression lien éditeur si c'est l'article de l'éditeur. |
||
| 796 | * |
||
| 797 | * @throws Exception |
||
| 798 | */ |
||
| 799 | private function processEditeur() |
||
| 800 | { |
||
| 801 | $editeur = $this->getParam('éditeur'); |
||
| 802 | if (empty($editeur)) { |
||
| 803 | return; |
||
| 856 | } |
||
| 857 | } |
||
| 858 | } |
||
| 859 |