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\CLI; |
||
11 | |||
12 | use App\Application\WikiBotConfig; |
||
13 | use App\Application\WikiPageAction; |
||
14 | use App\Infrastructure\CirrusSearch; |
||
15 | use App\Infrastructure\DiffAdapter; |
||
16 | use App\Infrastructure\Monitor\ConsoleLogger; |
||
17 | use App\Infrastructure\ServiceFactory; |
||
18 | use Codedungeon\PHPCliColors\Color; |
||
19 | use Mediawiki\DataModel\EditInfo; |
||
20 | |||
21 | include __DIR__ . '/../ZiziBot_Bootstrap.php'; |
||
22 | |||
23 | /** |
||
24 | * Stupid bot for replacement task (manual or auto) |
||
25 | */ |
||
26 | |||
27 | $wiki = ServiceFactory::getMediawikiFactory(); |
||
28 | $taskName = "🐵 style : début de vie → jeunesse"; // 🧹📗🐵 |
||
29 | $botFlag = false; |
||
30 | $minor = false; |
||
31 | $auto = false; |
||
32 | $bot = new WikiBotConfig($wiki, new ConsoleLogger()); |
||
33 | $diffAdapter = new diffAdapter(); |
||
34 | |||
35 | //// Get raw list of articles |
||
36 | //$filename = __DIR__.'/../resources/plume.txt'; |
||
37 | //$titles = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
||
38 | //$titles = $titles ?: []; |
||
39 | // ------ |
||
40 | |||
41 | $list = new CirrusSearch( |
||
42 | [ |
||
43 | 'srsearch' => '"début de vie"', |
||
44 | 'srnamespace' => '0', |
||
45 | 'srlimit' => '1000', |
||
46 | 'srqiprofile' => 'popular_inclinks_pv', |
||
47 | 'srsort' => CirrusSearch::SRSORT_RANDOM, |
||
48 | ] |
||
49 | ); |
||
50 | $titles = $list->getPageTitles(); |
||
51 | // ------ |
||
52 | |||
53 | echo count($titles) . " articles !\n"; |
||
54 | foreach ($titles as $title) { |
||
55 | sleep(1); |
||
56 | $bot->checkStopOnTalkpageOrException(); |
||
57 | |||
58 | $title = trim($title); |
||
59 | echo Color::BG_YELLOW . $title . Color::NORMAL . "\n"; |
||
60 | |||
61 | $pageAction = new WikiPageAction($wiki, $title); |
||
62 | if ($pageAction->getNs() !== 0) { |
||
63 | //throw new Exception("La page n'est pas dans Main (ns!==0)"); |
||
64 | echo "La page n'est pas dans Main (ns!==0)\n"; |
||
65 | continue; |
||
66 | } |
||
67 | $text = $pageAction->getText(); |
||
68 | $newText = $text; |
||
69 | |||
70 | // ------ |
||
71 | |||
72 | $replacements = [ |
||
73 | 'Début de vie' => 'Jeunesse', |
||
74 | 'début de vie' => 'jeunesse', |
||
75 | 'son jeunesse' => 'sa jeunesse', |
||
76 | 'un jeunesse' => 'une jeunesse', |
||
77 | 'le jeunesse' => 'la jeunesse', |
||
78 | 'en jeunesse' => 'pendant la jeunesse', |
||
79 | 'Jeunesse et de carrière' => 'Jeunesse et carrière', |
||
80 | 'ce jeunesse' => 'cette jeunesse', |
||
81 | 'Jeunesse et carrière' => 'Jeunesse et début de carrière', |
||
82 | ]; |
||
83 | foreach ($replacements as $old => $new) { |
||
84 | $newText = str_replace($old, $new, $newText); |
||
85 | } |
||
86 | |||
87 | // ------ |
||
88 | |||
89 | if ($newText === $text) { |
||
90 | echo "Skip identique\n"; |
||
91 | continue; |
||
92 | } |
||
93 | |||
94 | echo $diffAdapter->getDiff( |
||
95 | str_replace('. ', ".\n", $text), |
||
96 | str_replace('. ', ".\n", $newText), |
||
97 | ) . "\n"; |
||
98 | |||
99 | if (!$auto) { |
||
100 | $ask = readline("*** ÉDITION ? [y/n/auto]"); |
||
101 | if ('auto' === $ask) { |
||
102 | $auto = true; |
||
103 | } |
||
104 | if ('y' !== $ask && 'auto' !== $ask) { |
||
105 | continue; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $currentTaskName = $taskName; |
||
110 | if ($botFlag) { |
||
111 | $currentTaskName = 'Bot ' . $taskName; |
||
112 | } |
||
113 | $result = $pageAction->editPage($newText, new EditInfo($currentTaskName, $minor, $botFlag)); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
114 | dump($result); |
||
115 | sleep(2); |
||
116 | } |
||
117 | |||
118 |