|
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\Traits; |
|
11
|
|
|
|
|
12
|
|
|
use App\Application\WikiBotConfig; |
|
13
|
|
|
use Codedungeon\PHPCliColors\Color; |
|
14
|
|
|
use Mediawiki\Api\UsageException; |
|
15
|
|
|
|
|
16
|
|
|
trait BotWorkerTrait |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @throws UsageException |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function checkAllowedNowEdition(string $title, string $text): bool |
|
22
|
|
|
{ |
|
23
|
|
|
$this->bot->checkStopOnTalkpage(true); |
|
24
|
|
|
|
|
25
|
|
|
if (WikiBotConfig::isEditionTemporaryRestrictedOnWiki($text)) { |
|
26
|
|
|
echo "SKIP : protection/3R/travaux.\n"; |
|
27
|
|
|
|
|
28
|
|
|
return false; |
|
29
|
|
|
} |
|
30
|
|
|
if ($this->bot->minutesSinceLastEdit($title) < static::MINUTES_DELAY_AFTER_LAST_HUMAN_EDIT) { |
|
|
|
|
|
|
31
|
|
|
echo sprintf( |
|
32
|
|
|
"SKIP : édition humaine dans les dernières %s minutes\n", |
|
33
|
|
|
static::MINUTES_DELAY_AFTER_LAST_HUMAN_EDIT |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
return false; |
|
37
|
|
|
} |
|
38
|
|
|
if (static::SKIP_ADQ && preg_match('#{{ ?En-tête label ?\| ?AdQ#i', $text)) { |
|
|
|
|
|
|
39
|
|
|
echo "SKIP : AdQ.\n"; // BA ?? |
|
40
|
|
|
|
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function getSummaryText(): string |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->summary->serialize(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function printTitle(string $title): void |
|
53
|
|
|
{ |
|
54
|
|
|
echo "---------------------\n"; |
|
55
|
|
|
echo date('d-m-Y H:i:s') . ' ' . Color::BG_CYAN . " $title " . Color::NORMAL . "\n"; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function canProcessTitleArticle(string $title, ?string $text): bool |
|
59
|
|
|
{ |
|
60
|
|
|
if (empty($text)) { |
|
61
|
|
|
echo "Skip : page vide\n"; |
|
62
|
|
|
$this->memorizeAndSaveAnalyzedTitle($title); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
return false; |
|
65
|
|
|
} |
|
66
|
|
|
if (static::SKIP_LASTEDIT_BY_BOT && $this->pageAction->getLastEditor() === getenv('BOT_NAME')) { |
|
|
|
|
|
|
67
|
|
|
echo "Skip : bot est le dernier éditeur\n"; |
|
68
|
|
|
$this->memorizeAndSaveAnalyzedTitle($title); |
|
69
|
|
|
|
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
if (!$this->checkAllowedNowEdition($title, $text)) { |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function isSomethingToChange(?string $text, ?string $newText): bool |
|
80
|
|
|
{ |
|
81
|
|
|
if (empty($newText)) { |
|
82
|
|
|
echo "Skip: vide\n"; |
|
83
|
|
|
|
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
if ($newText === $text) { |
|
87
|
|
|
echo "Skip: pas de changement\n"; |
|
88
|
|
|
|
|
89
|
|
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return true; |
|
93
|
|
|
} |
|
94
|
|
|
} |