Commit 4c843f21 authored by Freddy's avatar Freddy Committed by Luke081515

fix

parent c05b5a38
#!/usr/bin/php
<?php
require '../BKLLC/Cygnus/BotCore.php';
require './Cygnus/BotCore.php';
/** Corrector.php
* Searches for occurences and allows you to correct the manually
* @Author Luke081515
* @Author Freddy2001, Luke081515
* @Version 0.1
* @Status Alpha
*/
class Corrector extends Core {
private $summary;
private $search;
......@@ -22,12 +23,8 @@ class Corrector extends Core {
$this->searchPages();
$this->setSummary();
$this->goAllPages();
/*
$this->display();*/
}
/** defineConditions
* Defines the condition for search and replace
*/
......@@ -43,21 +40,22 @@ 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->askOperator('Set summary to "Replace ' . $this->needle . ' with ' . $this->replace . '"? [Y], [N]'));
if($this->validateAnswer($answer)) {
if($answer == 'Y') {
$this->summary = 'Replace ' . $this->needle . ' with ' . $this->replace;
} else {
$newsummary = $this->askOperator('What Summary should I use instead?');
$newsummary = $this->askOperator('Which summary should I use instead?');
$this->summary = $newsummary;
}
echo 'OK, Summary is now: ' . $this->summary . "\n";
echo 'OK, summary is now: ' . $this->summary . "\n";
}
}
}
/** search
*
* Search
* @return void
*/
private function searchPages () {
echo "\n" . 'Searching…' . "\n";
......@@ -79,7 +77,6 @@ class Corrector extends Core {
}
}
echo 'Found ' . count($Seite) . ' Results.' . "\n";
//print_r($Seite);
$this->search = $Seite;
}
......@@ -93,24 +90,21 @@ class Corrector extends Core {
}
echo 'URL: http://' . $loginhost . '/wiki/' . urlencode($this->search[$i]) . "\n";
$seite = $this->readPage($this->search[$i]);
$this->display($seite, $this->needle, $this->replace);
$this->display($this->search[$i], $seite, $this->needle, $this->replace);
}
}
private function display ($html = '', $needle = '', $new = '') {
$htmlarr = explode("\n", $html);
private function display ($seite, $html = '', $needle = '', $new = '') {
$red = "\033[0;31m";
$green = "\033[0;32m";
$end = "\033[0m";
$htmlarr = explode("\n", $html);
for($i = 0; $i < count($htmlarr); $i++) {
$anzahl = substr_count($htmlarr[$i], $needle);
//echo $anzahl;
if($anzahl > 0) {
// cut off long lines
if(stripos($htmlarr[$i], $needle) > 70) {
......@@ -126,19 +120,18 @@ 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";
}
}
$answer = strtoupper($this->askOperator('Replace all occurrences? [Y], [N] '));
if($this->validateAnswer($answer)) {
if($answer == 'Y') {
$newhtml = $this->replace($html, $needle, $new);
// ToDo: Add Save Page
// Do replace
$newhtml = $this->replace($html, $needle, $new);
$this->editPage($seite, $newhtml, $this->summary);
} else {
echo "\n" . 'Not replaced. Skipping…' . "\n";
// Leave it as it is
echo "\n" . 'Not replaced. Skipping…' . "\n";
}
}
}
......@@ -167,5 +160,5 @@ class Corrector extends Core {
}
}
}
new Corrector ('BKLLC@dewiki', 'Corrector');
new Corrector ('Luke081515@dewiki', 'Corrector');
?>
\ No newline at end of file
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