Commit 84a6f4f5 authored by Luke081515's avatar Luke081515

Some new stuff

* Use https for the url
* Allow to continue old searches
* Performance tuning
parent 9cbc4238
Pipeline #1838 passed with stages
in 1 minute and 50 seconds
......@@ -13,10 +13,11 @@ class Corrector extends Core {
private $pattern;
private $replace;
private $needle;
private $cont;
private $accountname;
public function __construct($Account, $Job, $pUseHTTPS = true) {
if ($this->ask("Use a botflag? [y/N] ", "required") === 'y') {
if ($this->ask("Use a botflag? [y/N] ", "required") === 'y') {
$this->initcurl($Account, $Job, $pUseHTTPS);
} else {
$this->initcurl($Account, $Job, $pUseHTTPS, "user");
......@@ -28,23 +29,22 @@ class Corrector extends Core {
$this->setSummary();
$this->goAllPages();
}
/** defineConditions
* Defines the condition for search and replace
*/
private function defineConditions () {
if ($this->ask("Use a pattern? [y/N] ", "required") === 'y') {
if ($this->ask("Use a pattern? [y/N] ", "required") === 'y') {
$this->pattern = $this->ask("What should be the pattern? ", "required");
}
$needle = $this->ask("What should be replaced? ", "required");
$replace = $this->ask("What should be the replacement? ", "required");
$this->needle = $needle;
$this->replace = $replace;
$this->needle = $this->ask("What should be replaced? ", "required");
$this->replace = $this->ask("What should be the replacement? ", "required");
if ($this->ask("Continue a previous search request? [y/N] ", "required") === 'y') {
$this->cont = $this->ask("What was the last title you've checked? ", "required");
}
}
/** setSummary
* @return void
*/
* @return void
*/
private function setSummary() {
if($this->summary == null) {
$answer = strtoupper($this->ask('Set summary to "Replace ' . $this->needle . ' with ' . $this->replace . '"? [Y], [N]', "required"));
......@@ -86,47 +86,63 @@ class Corrector extends Core {
$Again = false;
}
}
$this->echoMsg("Found " . count($Seite) . " Results.", "notice");
$this->search = $Seite;
if (isset($this->cont)) {
$i = 0;
while (isset($Seite[$i]) && $Seite[$i] !== $this->cont) {
$i++;
}
if (!isset($Seite[$i])) {
$this->echoMsg("Found 0 Results.", "error");
die(1);
} else {
$a = 0;
$newSearch = array();
while(isset($Seite[$i])) {
$newSearch[$a] = $Seite[$i];
$a++;
$i++;
}
$this->echoMsg("Found " . count($newSearch) . " Results.", "notice");
$this->search = $newSearch;
}
} else {
$this->echoMsg("Found " . count($Seite) . " Results.", "notice");
$this->search = $Seite;
}
}
private function goAllPages() {
for($i = 0; $i < count($this->search); $i++) {
$count1 = count($this->search);
$count2 = count(unserialize($this->getLoginName()));
for($i = 0; $i < $count1; $i++) {
$this->echoMsg("\n\033[1mTitle:\033[0m " . $this->search[$i], "none");
for($j = 0; $j < count(unserialize($this->getLoginName())); $j++) {
for($j = 0; $j < $count2; $j++) {
if(unserialize($this->getLoginName())[$j] == $this->accountname) {
$loginhost = unserialize($this->getLoginHost())[$j];
}
}
$this->echoMsg("URL: http://" . $loginhost . "/w/index.php?title=" . urlencode($this->search[$i]), "none");
$this->echoMsg("URL: https://" . $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);
}
}
private function display ($seite, $html = '', $needle = '', $new = '') {
$red = "\033[0;31m";
$green = "\033[0;32m";
$end = "\033[0m";
$htmlarr = explode("\n", $html);
$count = count($htmlarr);
while (true) {
for($i = 0; $i < count($htmlarr); $i++) {
for($i = 0; $i < $count; $i++) {
$anzahl = substr_count($htmlarr[$i], $needle);
if($anzahl > 0) {
// cut off long lines
if(stripos($htmlarr[$i], $needle) > 70) {
$htmlarr[$i] = substr($htmlarr[$i], stripos($htmlarr[$i], $needle) - 50);
}
if(strripos($htmlarr[$i], $needle) + strlen($needle) + 70 < strlen($htmlarr[$i])) {
$htmlarr[$i] = substr($htmlarr[$i], 0, strripos($htmlarr[$i], $needle) + strlen($needle) + 50);
}
$old = str_replace($needle, $red . $needle . $end, $htmlarr[$i]);
$newstr = str_replace($needle, $new, $htmlarr[$i]);
$newstr = str_replace($new, $green . $new . $end, $newstr);
$this->echoMsg('Zeile ' . ($i + 1) . ":\n– " . $old . "\n+ " . $newstr . "\n", "none");
......
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