|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of dispositif/wikibot application (@github) |
|
4
|
|
|
* 2019/2020 © Philippe M. <[email protected]> |
|
5
|
|
|
* For the full copyright and MIT license information, please view the license file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace App\Application; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use App\Infrastructure\DbAdapter; |
|
15
|
|
|
use App\Infrastructure\Logger; |
|
16
|
|
|
use App\Infrastructure\PageList; |
|
17
|
|
|
use App\Infrastructure\ServiceFactory; |
|
18
|
|
|
|
|
19
|
|
|
class CodexNotificationWorker extends NotificationWorker |
|
20
|
|
|
{ |
|
21
|
|
|
const PAGENAME_NOTIFICATION_LOG = 'Utilisateur:CodexBot/Notifications'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* todo Refac that stupid idea :) |
|
25
|
|
|
* Delete article title in the log text file. |
|
26
|
|
|
* |
|
27
|
|
|
* @param $title |
|
28
|
|
|
*/ |
|
29
|
|
|
private function deleteEditedArticleFile(string $title): void |
|
30
|
|
|
{ |
|
31
|
|
|
$text = file_get_contents(self::ARTICLE_ANALYZED_FILENAME); |
|
32
|
|
|
$newText = str_replace($title."\n", '', $text); |
|
33
|
|
|
if (!empty($text) && $text !== $newText) { |
|
34
|
|
|
@file_put_contents(self::ARTICLE_ANALYZED_FILENAME, $newText); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Process external URL completion to wiki-template. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $article |
|
42
|
|
|
* @param string|null $username |
|
43
|
|
|
*/ |
|
44
|
|
|
private function processExternLinks(string $article, ?string $username = '') |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
try { |
|
47
|
|
|
$wiki = ServiceFactory::wikiApi(); |
|
48
|
|
|
$logger = new Logger(); |
|
49
|
|
|
//$logger->debug = true; |
|
50
|
|
|
$botConfig = new WikiBotConfig($logger); |
|
51
|
|
|
$botConfig->taskName = '🔔🌐 Amélioration de références : URL ⇒ '; |
|
52
|
|
|
new ExternRefWorker($botConfig, $wiki, new PageList([$article])); |
|
53
|
|
|
|
|
54
|
|
|
new GoogleBooksWorker($botConfig, $wiki, new PageList([$article])); |
|
55
|
|
|
sleep(10); |
|
56
|
|
|
} catch (\Throwable $e) { |
|
57
|
|
|
unset($e); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Process wikiSan for future {ouvrage} completion |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $article |
|
65
|
|
|
*/ |
|
66
|
|
|
private function processWikiscanForOuvrage(string $article): void |
|
67
|
|
|
{ |
|
68
|
|
|
try { |
|
69
|
|
|
$wiki = ServiceFactory::wikiApi(); |
|
70
|
|
|
$list = new PageList([$article]); |
|
71
|
|
|
new ScanWiki2DB($wiki, new DbAdapter(), new WikiBotConfig(), $list, 15); |
|
72
|
|
|
} catch (\Throwable $e) { |
|
73
|
|
|
echo $e->getMessage(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param $notif |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function processSpecialActions($notif) |
|
81
|
|
|
{ |
|
82
|
|
|
if (isset($notif['title']) && in_array($notif['title']['namespace'], ['', 'Discussion'])) { |
|
83
|
|
|
// PROCESS ARTICLES |
|
84
|
|
|
$article = $notif['title']['text']; |
|
85
|
|
|
|
|
86
|
|
|
// wikiScan for {ouvrage} completion |
|
87
|
|
|
$this->processWikiscanForOuvrage($article); |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
// URL => wiki-template completion |
|
91
|
|
|
$this->deleteEditedArticleFile($article); |
|
92
|
|
|
$this->processExternLinks($article); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: