|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of dispositif/wikibot application |
|
5
|
|
|
* 2019 © Philippe M. <[email protected]> |
|
6
|
|
|
* For the full copyright and MIT license information, please view the LICENSE file. |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace App\Application\Examples; |
|
11
|
|
|
|
|
12
|
|
|
use App\Application\Color; |
|
13
|
|
|
use App\Application\RefBotWorker; |
|
14
|
|
|
use App\Application\RefWebTransformer; |
|
15
|
|
|
use App\Application\WikiBotConfig; |
|
16
|
|
|
use App\Infrastructure\CirrusSearch; |
|
17
|
|
|
use App\Infrastructure\ServiceFactory; |
|
18
|
|
|
use Throwable; |
|
19
|
|
|
|
|
20
|
|
|
include __DIR__.'/../ZiziBot_Bootstrap.php'; |
|
21
|
|
|
// VOIR EN BAS |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* TODO move PROCESS FROM BOTTOM |
|
25
|
|
|
* Class Ref2ArticleWorker |
|
26
|
|
|
* |
|
27
|
|
|
* @package App\Application\Examples |
|
28
|
|
|
*/ |
|
29
|
|
|
class RefWebWorker extends RefBotWorker |
|
30
|
|
|
{ |
|
31
|
|
|
const TASK_NAME = "Amélioration références : URL ⇒ {modèle}"; // 😎 |
|
32
|
|
|
const TASK_BOT_FLAG = false; |
|
33
|
|
|
const SLEEP_AFTER_EDITION = 30; |
|
34
|
|
|
|
|
35
|
|
|
protected $botFlag = false; |
|
36
|
|
|
protected $modeAuto = false; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var RefWebTransformer |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $transformer; |
|
41
|
|
|
|
|
42
|
|
|
public function processRefContent($refContent): string |
|
43
|
|
|
{ |
|
44
|
|
|
try { |
|
45
|
|
|
$result = $this->transformer->process($refContent); |
|
46
|
|
|
} catch (Throwable $e) { |
|
47
|
|
|
echo "** Problème détecté\n"; |
|
48
|
|
|
|
|
49
|
|
|
// TODO : parse $e->message pour traitement, taskName, botflag... |
|
50
|
|
|
return $refContent; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if ($result === $refContent) { |
|
54
|
|
|
return $refContent; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// Gestion semi-auto |
|
58
|
|
|
if (!$this->transformer->skipUnauthorised) { |
|
59
|
|
|
echo Color::BG_LIGHT_RED."--".Color::NORMAL." ".$refContent."\n"; |
|
60
|
|
|
echo Color::BG_LIGHT_GREEN."++".Color::NORMAL." $result \n\n"; |
|
61
|
|
|
$ask = readline(Color::LIGHT_MAGENTA."*** Conserver cette modif ? [y/n]".Color::NORMAL); |
|
62
|
|
|
if ($ask !== 'y') { |
|
63
|
|
|
return $refContent; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $result; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* RefWebWorker constructor. |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function setUpInConstructor(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$transformer = new RefWebTransformer($this->log); |
|
76
|
|
|
$transformer->skipUnauthorised = false; |
|
77
|
|
|
|
|
78
|
|
|
$this->transformer = $transformer; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$wiki = ServiceFactory::wikiApi(); |
|
84
|
|
|
$botConfig = new WikiBotConfig(); |
|
85
|
|
|
|
|
86
|
|
|
// &srqiprofile=popular_inclinks_pv&srsort=last_edit_desc |
|
87
|
|
|
$list = new CirrusSearch( |
|
88
|
|
|
'https://fr.wikipedia.org/w/api.php?action=query&list=search' |
|
89
|
|
|
// .'&srsearch=%22https%3A%2F%2Fjournals.openedition.org%22+insource%3A%2F%5C%3Cref%5C%3Ehttps%5C%3A%5C%2F%5C%2Fjournals%5C.openedition%5C.org%5B%5E%5C%3E%5D%2B%5C%3C%5C%2Fref%3E%2F' |
|
90
|
|
|
.'&srsearch=%22https%3A%2F%2F%22+insource%3A%2F%5C%3Cref%5C%3Ehttps%5C%3A%5C%2F%5C%2F%5B%5E%5C%3E%5D%2B%5C%3C%5C%2Fref%3E%2F' |
|
91
|
|
|
.'&formatversion=2&format=json&srnamespace=0&srlimit=100&srqiprofile=popular_inclinks_pv&srsort=random' |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
//$list = new PageList(['Pierre Zind', 'Économie du Soudan du Sud']); |
|
96
|
|
|
|
|
97
|
|
|
new RefWebWorker($botConfig, $wiki, $list); |
|
98
|
|
|
|