Commit 9cbc4238 authored by Luke081515's avatar Luke081515

Update output stuff

parent 069ca70f
Pipeline #1823 failed with stages
in 1 minute and 45 seconds
......@@ -2,12 +2,11 @@
<?php
require './Cygnus/BotCore.php';
/** Corrector.php
* Searches for occurences and allows you to correct the manually
* Searches for occurences and allows you to correct them manually
* @Author Freddy2001, Luke081515
* @Version 0.1
* @Status Alpha
*/
class Corrector extends Core {
private $summary;
private $search;
......@@ -17,7 +16,7 @@ class Corrector extends Core {
private $accountname;
public function __construct($Account, $Job, $pUseHTTPS = true) {
if ($this->askOperator('Use a botflag? [y/N] ') === 'y') {
if ($this->ask("Use a botflag? [y/N] ", "required") === 'y') {
$this->initcurl($Account, $Job, $pUseHTTPS);
} else {
$this->initcurl($Account, $Job, $pUseHTTPS, "user");
......@@ -34,11 +33,11 @@ class Corrector extends Core {
* Defines the condition for search and replace
*/
private function defineConditions () {
if ($this->askOperator('Use a pattern? [y/N] ') === 'y') {
$this->pattern = $this->askOperator('What should be the pattern? ');
if ($this->ask("Use a pattern? [y/N] ", "required") === 'y') {
$this->pattern = $this->ask("What should be the pattern? ", "required");
}
$needle = $this->askOperator('What should be replaced? ');
$replace = $this->askOperator('What should be the replacement? ');
$needle = $this->ask("What should be replaced? ", "required");
$replace = $this->ask("What should be the replacement? ", "required");
$this->needle = $needle;
$this->replace = $replace;
}
......@@ -48,15 +47,15 @@ class Corrector extends Core {
*/
private function setSummary() {
if($this->summary == null) {
$answer = strtoupper($this->askOperator('Set summary to "Replace ' . $this->needle . ' with ' . $this->replace . '"? [Y], [N]'));
$answer = strtoupper($this->ask('Set summary to "Replace ' . $this->needle . ' with ' . $this->replace . '"? [Y], [N]', "required"));
if($this->validateAnswer($answer)) {
if($answer == 'Y') {
$this->summary = 'Replace ' . $this->needle . ' with ' . $this->replace;
$this->summary = "Replace " . $this->needle . " with " . $this->replace;
} else {
$newsummary = $this->askOperator('Which summary should I use instead? ');
$newsummary = $this->ask("Which summary should I use instead? ", "required");
$this->summary = $newsummary;
}
echo 'OK, summary is now: ' . $this->summary . "\n";
$this->echoMsg("OK, summary is now: " . $this->summary, "success");
}
}
}
......@@ -66,7 +65,7 @@ class Corrector extends Core {
* @return void
*/
private function searchPages () {
echo "\n" . 'Searching…' . "\n";
$this->echoMsg("Searching…" . "\n", "notice");
if (isset($this->pattern)) {
$suche = urlencode($this->pattern);
} else {
......@@ -87,19 +86,19 @@ class Corrector extends Core {
$Again = false;
}
}
echo 'Found ' . count($Seite) . ' Results.' . "\n";
$this->echoMsg("Found " . count($Seite) . " Results.", "notice");
$this->search = $Seite;
}
private function goAllPages() {
for($i = 0; $i < count($this->search); $i++) {
echo "\n\n\033[1mTitle:\033[0m " . $this->search[$i] . "\n";
$this->echoMsg("\n\033[1mTitle:\033[0m " . $this->search[$i], "none");
for($j = 0; $j < count(unserialize($this->getLoginName())); $j++) {
if(unserialize($this->getLoginName())[$j] == $this->accountname) {
$loginhost = unserialize($this->getLoginHost())[$j];
}
}
echo 'URL: http://' . $loginhost . '/wiki/' . urlencode($this->search[$i]) . "\n";
$this->echoMsg("URL: http://" . $loginhost . "/w/index.php?title=" . urlencode($this->search[$i]), "none");
$seite = $this->readPage($this->search[$i]);
$this->display($this->search[$i], $seite, $this->needle, $this->replace);
}
......@@ -130,30 +129,30 @@ class Corrector extends Core {
$newstr = str_replace($needle, $new, $htmlarr[$i]);
$newstr = str_replace($new, $green . $new . $end, $newstr);
echo 'Zeile ' . ($i + 1) . ":\n– " . $old . "\n+ " . $newstr . "\n\n";
$this->echoMsg('Zeile ' . ($i + 1) . ":\n– " . $old . "\n+ " . $newstr . "\n", "none");
}
}
$answer = strtoupper($this->askOperator('Replace all occurrences? [Y], [N] '));
$answer = strtoupper($this->ask("Replace all occurrences? [Y], [N] ", "required"));
if($this->validateAnswer($answer)) {
if($answer == 'Y') {
// Do replace
$newhtml = $this->replace($html, $needle, $new);
$this->editPage($seite, $newhtml, $this->summary);
$this->echoMsg("\n" . "Replaced.", "success");
break;
} else {
$answer = strtoupper($this->askOperator('Add a space? [Y], [N] '));
$answer = strtoupper($this->ask("Add a space? [Y], [N] ", "required"));
if($answer == 'Y') {
$new = $new . " ";
} else {
// Leave it as it is
echo "\n" . 'Not replaced. Skipping…' . "\n";
$this->echoMsg("\n" . "Not replaced. Skipping…", "warning");
break;
}
}
}
}
}
/** replace
* Replaces a string
* @param String $html – Full string
......@@ -164,7 +163,6 @@ class Corrector extends Core {
private function replace($html, $needle, $replace) {
return str_replace($needle, $replace, $html);
}
/** validateAnswer
* validates if the answer is Y or N
* @param String $answer – String of answer
......@@ -174,7 +172,7 @@ class Corrector extends Core {
if($answer == 'Y' || $answer == 'N') {
return true;
} else {
$this->validateAnswer(strtoupper($this->askOperator('Please answer [Y], [N]')));
$this->validateAnswer(strtoupper($this->ask('Please answer [Y], [N]', "required")));
}
}
}
......
Subproject commit 680548de92cefefae2cdda5870ac922040a1a4f6
Subproject commit 63bb38f632065a129311882073af93ed6ebbdcac
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment