Commit d6f67212 authored by Luke081515's avatar Luke081515

Dateien aus Hauptmodul ausgelagert

* Aus dem BKLLC-Ordner des Luke081515Bots kopiert
Ref T492

Tags: #BKLLC
parents
This diff is collapsed.
#!/usr/bin/php
<?php
include '../Core/BotCore.php';
include '../Core/DBCore.php';
/** ManageCategoryTable.php
* Erfasst fuer die Seiten die Kategorien
* Erlaubt eine Abfrage aller Seiten der Kategorie die gleichzeitig von einer BKL verlinkt werden
* Required: DB-Anbindung
* @Author Luke081515
* @Version 0.1
* @Status Alpha
*/
class BKLLC extends Core {
protected $DB;
public function BKLLC ($Account, $Job, $pUseHTTPS = true) {
global $argv;
$pwd = $argv[1];
$this->setSite ('de.wikipedia.org');
$this->setUsername ('Luke081515Bot');
$this->setPassword ($pwd);
$this->initcurlArgs ('ManageCategoryTable', true);
$this->login ();
$this->connectToDatabase ();
$this->fillBKLTable ();
}
/** connectToDatabase
* Verbindet sich nach den Daten aus der Passwort-Datei mit der Datenbank
*/
protected function connectToDatabase () {
$this->DB = new DBCore ('root@localhost', 'BKLLC');
}
}
$Bot = new BKLLC ('Luke081515Bot@dewiki', 'bkllc');
?>
\ No newline at end of file
#!/usr/bin/php
<?php
include '../Core/BotCore.php';
include '../Core/DBCore.php';
/** ManageLinkTable.php
* Aktualisiert
** Erfasste Seiten
** Links auf diese Seiten
* Required: DB-Anbindung
* @Author Luke081515
* @Version 0.2
* @Status Alpha
*/
class BKLLC extends Core {
protected $DB;
public function BKLLC ($Account, $Job, $pUseHTTPS = true) {
global $argv;
$pwd = $argv[1];
$this->setSite ('de.wikipedia.org');
$this->setUsername ('Luke081515Bot');
$this->setPassword ($pwd);
$this->initcurlArgs ('ManageLinkTable', true);
$this->login ();
$this->connectToDatabase ();
$this->manangeDatabases ();
}
/** connectToDatabase
* Verbindet sich nach den Daten aus der Passwort-Datei mit der Datenbank
*/
protected function connectToDatabase () {
$this->DB = new DBCore ('root@localhost', 'BKLLC');
}
/** manageDatabases
* Sucht nach neuen Links auf BKLs, schaut, ob bereits in den DBs vorhanden, falls nicht, werden die DBs aktualisiert
*/
protected function manangeDatabases () {
$sql = 'SELECT DisID FROM Disambig;';
$result = $this->DB->query ($sql);
$a=0;
while ($row = $result->fetch_assoc()){
$BKLs [$a] = $row['DisID'];
$a++;
}
$Total = $a;
$result->free();
$a=0;
while (isset ($BKLs [$a]) === true) {
$Page [$a] = $this->getPageLinks ($BKLs [$a]);
$a++;
}
$b=0;
for ($a = 0; $a < $Total; $a++) {
$b=0;
while (isset ($Page [$a] [$b]) === true) {
if ($Page [$a] [$b] !== false) {
$sql = 'SELECT PageID FROM Page WHERE PageID = ' . $Page [$a] [$b] . ';';
$result = $this->DB->query ($sql);
if ($result === 0) {
$sql = 'INSERT INTO Page SET PageID = ' . $Page [$a] [$b] . ', TotalLinks = 0;';
$this->DB->modify ($sql);
}
}
$b++;
}
}
for ($a = 0; $a < $Total; $a++) {
$b=0;
while (isset ($Page [$a] [$b]) === true) {
if ($Page [$a] [$b] !== false) {
$sql = 'SELECT Disambig_DisID, Page_PageID FROM PageLinkDisambig WHERE Page_PageID = ' . $Page [$a] [$b] . ' AND Disambig_DisID = ' . $BKLs [$a] . ';';
$result = $this->DB->query ($sql);
if ($result === 0) {
$sql = 'INSERT INTO PageLinkDisambig SET Page_PageID = ' . $Page [$a] [$b] . ', Disambig_DisID = ' . $BKLs [$a] . ', LinksToDisambig = true, Inserted = true;';
$this->DB->modify ($sql);
$sql = 'SELECT TotalLinks FROM Page WHERE PageID = ' . $Page [$a] [$b] . ';';
$result = $this->DB->query ($sql);
$row = $result->fetch_assoc();
$Tl = $row['TotalLinks'];
$Tl++;
$sql = 'UPDATE Page SET TotalLinks = ' . $Tl . ' WHERE PageID = ' . $Page [$a] [$b] . ';';
$this->DB->modify ($sql);
$sql = 'SELECT TotalLinks FROM Disambig WHERE DisID = ' . $BKLs [$a] . ';';
$result = $this->DB->query ($sql);
$row = $result->fetch_assoc();
$Tl = $row['TotalLinks'];
$Tl++;
$sql = 'UPDATE Disambig SET TotalLinks = ' . $Tl . ' WHERE DisID = ' . $BKLs [$a] . ';';
$this->DB->modify ($sql);
} else {
$sql = 'UPDATE PageLinkDisambig SET Inserted = true WHERE Page_PageID = ' . $Page [$a] [$b] . ' AND Disambig_DisID = ' . $BKLs [$a] . ';';
$this->DB->modify ($sql);
}
}
$b++;
}
}
$sql = 'DELETE FROM PageLinkDisambig WHERE Inserted = false AND LinksToDisambig = true;';
$this->DB->modify ($sql);
$sql = 'UPDATE PageLinkDisambig SET Inserted = false WHERE LinksToDisambig = true;';
$this->DB->modify ($sql);
## Statistik ##
echo ("--- STATISTIK ---");
$sql = 'SELECT * FROM PageLinkDisambig WHERE LinksToDisambig = true;';
$result = $this->DB->query ($sql);
$a=0;
while ($row = $result->fetch_assoc())
$a++;
echo ("PageLinkDisambig: Total " . $a . " rows. (Where LinksToDisambig is true)");
echo ("--- STATISTIK ENDE ---");
}
protected function getPageLinks ($PageID) {
$Again = true;
while ($Again === true) {
if (isset ($Continue) === true)
$data = "action=query&format=php&maxlag=5&prop=linkshere&rawcontinue=1&pageids=" . urlencode($PageID) . "&lhprop=pageid&lhnamespace=0&lhshow=!redirect&lhlimit=5000&lhcontinue=" . urlencode($Continue);
else
$data = "action=query&format=php&maxlag=5&prop=linkshere&rawcontinue=1&pageids=" . urlencode($PageID) . "&lhprop=pageid&lhnamespace=0&lhshow=!redirect&lhlimit=5000&lhcontinue=";
try {
$result = $this->httpRequest($data, $this->job, 'GET');
} catch (Exception $e) {
throw $e;
}
$answer = unserialize($result);
$a=0;
if (isset ($answer ["query-continue"]["linkshere"]["lhcontinue"]) === true) {
$Continue = $answer ["query-continue"]["linkshere"]["lhcontinue"];
$Again = true;
}
else
$Again = false;
if (isset ($answer["query"]['pages'][$PageID]['linkshere'][$a]['pageid']) === true) {
while (isset ($answer["query"]['pages'][$PageID]['linkshere'][$a]['pageid']) === true) {
$Site [$a] = $answer["query"]['pages'][$PageID]['linkshere'][$a]['pageid'];
$a++;
}
} else
return false;
}
$a=0;
$b=0;
while (isset ($Site [$a]) === true) {
if ($this->isBKL ($Site [$a]) === false) {
if ($this->checkLink ($Site [$a]) === true) {
$Result [$b] = $Site [$a];
$b++;
}
}
$a++;
}
if (isset ($Result [0]) === false)
return false;
return ($Result);
}
/** isBKL
* @Param PageID - ID der zu checkenden Seiten
* @returns bool - true: Seite ist eine BKL, false: ist keine BKL
* Erfordert aktuelle BKL-Database
*/
protected function isBKL ($PageID) {
$sql = 'SELECT DisID FROM Disambig WHERE DisID = ' . $PageID . ';';
$result = $this->DB->query ($sql);
if ($result === 0)
return false;
return true;
}
/** checkLink
* checkt, ob ein Link auf eine BKL bewusst gesetzt wurde
* @Param: String: PageID
* @Returns: true - normaler Link; false - bewusst gesetzt
*/
protected function checkLink ($PageID) {
$Content = $this->readPageID ($PageID);
if (strstr ($Content, "{{Dieser Artikel") !== false)
return false;
if (strstr ($Content, "{{Vorlage:Begriffskl") !== false)
return false;
return true;
}
}
$Bot = new BKLLC ('Luke081515Bot@dewiki', 'bkllc');
?>
\ No newline at end of file
#!/usr/bin/php
<?php
include '../Core/BotCore.php';
include '../Core/DBCore.php';
/** UpdateBKLTable.php
* Sucht die Kategorien von Seiten, die auf eine BKL verlinken
* Required: DB-Anbindung
* @Author Luke081515
* @Version 0.1
* @Status Alpha
*/
class BKLLC extends Core {
protected $DB;
public function BKLLC ($Account, $Job, $pUseHTTPS = true) {
global $argv;
$pwd = $argv[1];
$this->setSite ('de.wikipedia.org');
$this->setUsername ('Luke081515Bot');
$this->setPassword ($pwd);
$this->initcurlArgs ('SetCatForPages', true);
$this->login ();
$this->connectToDatabase ();
}
/** connectToDatabase
* Verbindet sich nach den Daten aus der Passwort-Datei mit der Datenbank
*/
protected function connectToDatabase () {
$this->DB = new DBCore ('root@localhost', 'BKLLC');
}
/** fillBKLTable
* In die Tabelle der BKLs werden BKLs geschrieben
*/
protected function SetPageCats () {
$sql = 'SELECT PageID FROM Page;';
$result = $this->DB->query ($sql);
$a = 0;
while ($row = $result->fetch_assoc()){
$AlreadySet [$a] = $row['DisID']; // Ruft alle bestehende Infos ab
$a++;
}
$result->free();
$a=0;
while (isset ($AlreadySet [$a])) {
$sql = 'DELETE FROM PageInCat WHERE Page_PageID = ' . $AlreadySet [$a];
$this->DB->modify ($sql);
$Cats = $this->GetPageCats ($AlreadySet [$a]);
$b=0;
while (isset ($Cats [$b])) {
if ($Cats [$b] !== false) {
$sql = 'SELECT CatID FROM Category WHERE CatID = ' . $Cats [$b] . ';';
$result = $this->DB->query ($sql);
if ($result === 0) {
$sql = 'INSERT INTO Category SET CatID = ' . $Cats [$b] . ';';
$this->DB->modify ($sql);
}
}
$sql = 'INSERT INTO PageInCat SET Page_PageID = ' . $AlreadySet [$a] . ', Category_CatID = ' . $Cats [$b] . ';';
$this->DB->modify ($sql);
$b++;
}
$a++;
}
}
private function GetPageCats ($Site) {
try {
$result = $this->httpRequest('action=query&prop=categories&format=php&cllimit=5000&cldir=ascending&rawcontinue=&ids=' . urlencode($Site), $this->job, 'GET');
} catch (Exception $e) {
throw $e;
}
$Result = explode ("\"", $result);
$a=19;
$b=0;
while (isset ($Result [$a]) === true) {
$Kats [$b] = $Result [$a];
$a = $a + 6;
$b++;
}
$b=1;
return $Kats;
}
}
$Bot = new BKLLC ('Luke081515Bot@dewiki', 'bkllc');
?>
\ No newline at end of file
#!/usr/bin/php
<?php
include '../Core/BotCore.php';
include '../Core/DBCore.php';
/** UpdateBKLTable.php
* Sucht nach BKLLS, fügt sie in die Datenbank ein
* Required: DB-Anbindung
* @Author Luke081515
* @Version 0.4
* @Status Alpha
*/
class BKLLC extends Core {
protected $DB;
public function BKLLC ($Account, $Job, $pUseHTTPS = true) {
global $argv;
$pwd = $argv[1];
$this->setSite ('de.wikipedia.org');
$this->setUsername ('Luke081515Bot');
$this->setPassword ($pwd);
$this->initcurlArgs ('UpdateBKLTable', true);
$this->login ();
$this->connectToDatabase ();
$this->UpdateBKLTable ();
}
/** connectToDatabase
* Verbindet sich nach den Daten aus der Passwort-Datei mit der Datenbank
*/
protected function connectToDatabase () {
$this->DB = new DBCore ('root@localhost', 'BKLLC');
}
/** fillBKLTable
* In die Tabelle der BKLs werden BKLs geschrieben
*/
protected function UpdateBKLTable () {
$sql = 'SELECT DisID FROM Disambig;';
$result = $this->DB->query ($sql);
$a = 0;
while ($row = $result->fetch_assoc()){
$AlreadySet [$a] = $row['DisID']; // Ruft alle bestehende Infos ab
$a++;
}
$result->free();
$ListIDs = unserialize ($this->getCatMembers ("Kategorie:Begriffskl&auml;rung"));
$a=0;
while (isset ($ListIDs [$a]))
$a++;
if ($a < 200000)
return false; // Fehler in der Abfrage
$a=0;
while (isset ($ListIDs [$a])) {
$sql = 'SELECT DisID FROM Disambig WHERE DisID = ' . $ListIDs [$a] . ';';
$result = $this->DB->query ($sql);
if ($result === 0) {
$sql = 'INSERT INTO Disambig SET DisID = ' . $ListIDs [$a] . ', TotalLinks = 0;';
$this->DB->modify ($sql);
}
$a++;
}
$a=0;
$sql = 'SELECT DisID FROM Disambig;';
$result = $this->DB->query ($sql);
$a = 0;
while ($row = $result->fetch_assoc()){
$AlreadySet [$a] = $row['DisID']; // Ruft alle bestehende Infos ab
$a++;
}
$result->free();
while (isset ($AlreadySet [$a]) === true) {
$b=0;
$hit = false;
while (isset ($ListIDs [$b]) === true && $hit === false) {
if ($ListIDs [$b] === $AlreadySet [$a])
$hit = true;
$b++;
}
if ($hit === false) {
$sql = 'DELETE FROM Disambig WHERE DisID = ' . $AlreadySet [$a] . ';';
$this->DB->modify ($sql);
}
$a++;
}
## Statstik ##
echo ("--- STATISTIK ---");
$sql = 'SELECT * FROM Disambig;';
$result = $this->DB->query ($sql);
$a=0;
while ($row = $result->fetch_assoc())
$a++;
echo ("Disamig: Total " . $a . " rows.");
$sql = 'SELECT * FROM Page;';
$result = $this->DB->query ($sql);
$a=0;
while ($row = $result->fetch_assoc())
$a++;
echo ("Page: Total " . $a . " rows.");
echo ("--- STATISTIK ENDE ---");
}
protected function getCatMembers ($Kat) {
$a=0;
$b=0;
$c=0;
try {
$result = $this->httpRequest('action=query&list=categorymembers&format=php&cmtitle=' . urlencode($Kat) . '&cmprop=ids&cmtype=page&cmlimit=5000&cmsort=sortkey&cmdir=ascending&rawcontinue=', $this->job, 'GET');
} catch (Exception $e) {
throw $e;
}
$answer = unserialize($result);
$Cont = false;
if (isset ($answer ["query-continue"]["categorymembers"]["cmcontinue"]) === true) {
$Continue = $answer ["query-continue"]["categorymembers"]["cmcontinue"];
$Cont = true;
}
while ($Cont === true) {
$a=0;
if (isset ($answer["query"]['categorymembers'][$a]['pageid']) === true) {
while (isset ($answer["query"]['categorymembers'][$a]['pageid']) === true) {
$Site [$c] = $answer["query"]['categorymembers'][$a]['pageid'];
$c++;
$a++;
}
} else {}
try {
$result = $this->httpRequest('action=query&list=categorymembers&format=php&cmcontinue=' . $Continue
. '&cmtitle=' . urlencode($Kat)
. '&cmprop=ids&cmtype=page&cmlimit=5000&cmsort=sortkey&cmdir=ascending&rawcontinue=', $this->job, 'GET');
} catch (Exception $e) {
throw $e;
}
$answer = unserialize($result);
if (isset ($answer ["query-continue"]["categorymembers"]["cmcontinue"]) === true) {
$Continue = $answer ["query-continue"]["categorymembers"]["cmcontinue"];
$Cont = true;
} else
$Cont = false;
}
$a=0;
if (isset ($answer["query"]['categorymembers'][$a]['pageid']) === true) {
while (isset ($answer["query"]['categorymembers'][$a]['pageid']) === true) {
$Site [$c] = $answer["query"]['categorymembers'][$a]['pageid'];
$c++;
$a++;
}
} else {}
$b++;
if (isset ($Site [0]) === false)
return false;
else
return (serialize ($Site));
}
}
$Bot = new BKLLC ('Luke081515Bot@dewiki', 'bkllc');
?>
\ 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