URVAddNew.php 3.89 KB
Newer Older
Luke081515's avatar
Luke081515 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#!/usr/bin/php
<?php
require './Cygnus/BotCore.php';
/** URVAddNew.php
* Checks cat for unadded entries
* @Author Luke081515
* @Version 0.1
* @Status Alpha
*/
class URVAddNew extends Core {
	protected $DB;
	public function __construct($Account, $Job, $pUseHTTPS = true) {
		$this->initcurl($Account, $Job, $pUseHTTPS);
		if ($this->readPage("Benutzer:Luke081515Bot/AutoQS-URV") === "true") {
			$this->compare();
			$this->compare2();
		}
	}
	public function compare () {
		$resCat = unserialize($this->getCurrentCatMembers("Kategorie:Wikipedia:Urheberschaft ungeklärt"));
		$resPage = serialize($this->getLinks("Wikipedia:Löschkandidaten/Urheberrechtsverletzungen"));
		for ($i = 0; isset($resCat[$i]); $i++) {
			if(strpos($resPage, $resCat[$i]) === false) {
				$content = "";
				$content = $this->readSection("Wikipedia:Löschkandidaten/Urheberrechtsverletzungen", 1);
				$content = $content . "\n# [[" . $resCat[$i] . "]]: Automatisch nachgetragen. Hilfreiche Tools: ([https://tools.wmflabs.org/copyvios/?lang=de&project=wikipedia&title=" . urlencode($resCat[$i])
						. "&action=search&use_engine=1&use_links=1&turnitin=1 Aktuelle Version]). --[[Benutzer:Luke081515Bot/URV/Add|Luke081515Bot]] ~~~~~";
				$this->editSection("Wikipedia:Löschkandidaten/Urheberrechtsverletzungen", $content, "Bot: Update aus Kategorie ([[Benutzer:Luke081515Bot/URV/Add|URV/Add]])", 1);
			}
		}
	}
	public function compare2 () {
		$resCat = unserialize($this->getCurrentCatMembers("Kategorie:Wikipedia:URV"));
		$resPage = serialize($this->getLinks("Wikipedia:Löschkandidaten/Urheberrechtsverletzungen"));
		for ($i = 0; isset($resCat[$i]); $i++) {
			if(strpos($resPage, $resCat[$i]) === false) {
				$content = "";
				if(substr($resCat[$i], -3) === '.js' || $resCat[$i] === "Vorlage:URV" || $resCat[$i] === "Vorlage:URV/Doku") {
				} else {
					$content = $this->readPage("Wikipedia:Löschkandidaten/Urheberrechtsverletzungen");
					$content = $content . "\n# [[" . $resCat[$i] . "]]: Automatisch nachgetragen. Hilfreiche Tools: ([https://tools.wmflabs.org/copyvios/?lang=de&project=wikipedia&title=" . urlencode($resCat[$i])
							. "&action=search&use_engine=1&use_links=1&turnitin=1 Aktuelle Version]). --[[Benutzer:Luke081515Bot/URV/Add|Luke081515Bot]] ~~~~~";
					$this->editPage("Wikipedia:Löschkandidaten/Urheberrechtsverletzungen", $content, "Bot: Update aus Kategorie ([[Benutzer:Luke081515Bot/URV/Add|URV/Add]])");
				}
			}
		}
	}
	/** getLinks
	* returns all links that are located at a page, maximum 5000
	* @author Luke081515
	* @param $page - page that gets analyzed
	* @return array with page titles
	*/
	public function getLinks($title) {
		$request = "action=query&prop=links&format=json&assert=bot&maxlag=5&pllimit=max&pldir=ascending&rawcontinue=&indexpageids=1&titles=" . urlencode($title);
		$result = json_decode($this->httpRequest($request, $this->job, "GET"), true);
		$pageID = $result["query"]["pageids"][0];
		$count = 0;
		while (isset($result["query"]["pages"][$pageID]["links"][$count]["title"])) {
			$links[] = $result["query"]["pages"][$pageID]["links"][$count]["title"];
			$count++;
		}
		if (isset($links[0])) {
			return $links;
		}
		return false;
	}
	public function getCurrentCatMembers($kat) {
		try {
			$result = $this->httpRequest("action=query&format=json&generator=categorymembers&indexpageids=1&gcmtitle=" . urlencode($kat) .
				"&prop=info&gcmlimit=max&rawcontinue=&redirects", $this->job, "GET");
		} catch (Exception $e) {
			throw $e;
		}
		$i = 0;
		$result = json_decode($result, true);
		while (isset($result["query"]["pageids"][$i])) {
			$pages[$i] = $result["query"]["pageids"][$i];
			$i++;
		}
		$i = 0;
		$c = 0;
		if (isset($pages[$i])) {
			while (isset($pages[$i])) {
				$page[$c] = $result["query"]["pages"][$pages[$i]]["title"];
				$c++;
				$i++;
			}
		}
		if (!isset($page[0])) {
			return false;
		} else {
			return serialize($page);
		}
	}
}
$Bot = new URVAddNew ('Luke081515Bot@dewiki', 'URVAddNew');
?>