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 printTitle(string $title): void |
48
|
|
|
{ |
49
|
|
|
echo "---------------------\n"; |
50
|
|
|
echo date('d-m-Y H:i:s') . ' ' . Color::BG_CYAN . " $title " . Color::NORMAL . "\n"; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function canProcessTitleArticle(string $title, ?string $text): bool |
54
|
|
|
{ |
55
|
|
|
if (empty($text)) { |
56
|
|
|
echo "Skip : page vide\n"; |
57
|
|
|
$this->memorizeAndSaveAnalyzedTitle($title); |
|
|
|
|
58
|
|
|
|
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
if (static::SKIP_LASTEDIT_BY_BOT && $this->pageAction->getLastEditor() === getenv('BOT_NAME')) { |
|
|
|
|
62
|
|
|
echo "Skip : bot est le dernier éditeur\n"; |
63
|
|
|
$this->memorizeAndSaveAnalyzedTitle($title); |
64
|
|
|
|
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
if (!$this->checkAllowedNowEdition($title, $text)) { |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return true; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function isSomethingToChange(?string $text, ?string $newText): bool |
75
|
|
|
{ |
76
|
|
|
if (empty($newText)) { |
77
|
|
|
echo "Skip: vide\n"; |
78
|
|
|
|
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
if ($newText === $text) { |
82
|
|
|
echo "Skip: pas de changement\n"; |
83
|
|
|
|
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
} |