Queue.php 37.8 KB
Newer Older
1
#!/usr/bin/php
Luke081515's avatar
Luke081515 committed
2
<?php
Luke081515's avatar
Luke081515 committed
3
require './Cygnus/BotCore.php';
Luke081515's avatar
Luke081515 committed
4 5 6 7 8
/** Queue.php
* Stellt Tasks in der Warteschlange bereit
* @Author Luke081515
* Dokumentation siehe Submodule
*/
Luke081515's avatar
Luke081515 committed
9
class QueueBot extends Core {
Luke081515's avatar
Luke081515 committed
10
	protected $account;
Luke081515's avatar
Luke081515 committed
11 12
	protected $inwork;
	protected $auftraege;
Luke081515's avatar
Luke081515 committed
13 14
	public function __construct($Account, $Job, $pUseHTTPS = true) {
		$this->initcurl($Account, $Job, $pUseHTTPS);
Luke081515's avatar
Luke081515 committed
15
		$this->writeToFile ("/home/luke/botecho", "[Queue] - Result - Starting Script");
Luke081515's avatar
Luke081515 committed
16 17
		while (true) {
			$this->mainEngine();
18
			sleep (5);
Luke081515's avatar
Luke081515 committed
19
		}
Luke081515's avatar
Luke081515 committed
20
	}
Luke081515's avatar
Luke081515 committed
21 22 23
	/** mainEngine
	* Ueberprueft die Warteschlange, triggert Submodule
	*/
Luke081515's avatar
Luke081515 committed
24
	public function mainEngine () {
Luke081515's avatar
Luke081515 committed
25
		$inwork = false;
Luke081515's avatar
Luke081515 committed
26
		if ($this->readPage("Benutzer:Luke081515/Bot.js") === "true") {
Luke081515's avatar
Luke081515 committed
27
			$AllTasks = $this->readPage("Benutzer:Luke081515Bot/Warteschlange/Auftraege");
Luke081515's avatar
Luke081515 committed
28
			$Tasks = explode ("}}", $AllTasks);
Luke081515's avatar
Luke081515 committed
29
			$i = 0;
Luke081515's avatar
Luke081515 committed
30
			while (isset($Tasks[$i]) === true) {
Luke081515's avatar
Luke081515 committed
31 32 33
				$i++;
			}
			$i--;
Luke081515's avatar
Luke081515 committed
34
			for ($j = 0; $j < $i; $j++) {
Luke081515's avatar
Luke081515 committed
35
				$Tasks[$j] = explode ("|", $Tasks[$j]);
Luke081515's avatar
Luke081515 committed
36 37 38 39 40 41
				$Task[$j] = substr ($Tasks[$j][1], 5);
				$User[$j] = substr ($Tasks[$j][2], 5);
				$StartLemma[$j] = substr ($Tasks[$j][3], 11);
				$TargetLemma[$j] = substr ($Tasks[$j][4], 12);
				$Summary[$j] = substr ($Tasks[$j][5], 8);
				$Status[$j] = substr ($Tasks[$j][6], 7);
Luke081515's avatar
Luke081515 committed
42
				if (isset ($Tasks[$j][7]) === true) {
43
					$Zeitstempel[$j] = substr ($Tasks[$j][7], 12);
Luke081515's avatar
Luke081515 committed
44
				} else {
45
					$Zeitstempel[$j] = "";
Luke081515's avatar
Luke081515 committed
46
				}
Luke081515's avatar
Luke081515 committed
47
			}
Luke081515's avatar
Luke081515 committed
48 49 50
			if ($inwork === false) {
				for ($j = 0; $j < $i; $j++) {
					if ($Status[$j] === "s") {
Luke081515's avatar
Luke081515 committed
51
						$TaskNumber = $j;
Luke081515's avatar
Luke081515 committed
52
						$j = $i;
Luke081515's avatar
Luke081515 committed
53
						$NumberOfTasks = $i;
Luke081515's avatar
Luke081515 committed
54
						$inwork = true;
Luke081515's avatar
Luke081515 committed
55
						$ToWriteDown = "";
Luke081515's avatar
Luke081515 committed
56
						$this->writeToFile ("/home/luke/botecho", "[Queue] - WORKING - Started working on an entry");
Luke081515's avatar
Luke081515 committed
57
					}
Luke081515's avatar
Luke081515 committed
58
					if ($inwork === true) {
Luke081515's avatar
Luke081515 committed
59
						if ($this->ControlIgnoreList ($User[$TaskNumber]) === true) {
Luke081515's avatar
Luke081515 committed
60
							$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "u", "Bot: Auftrag abgelehnt, Benutzer steht auf der Ignorierliste", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
61
							$this->writeToFile ("/home/luke/botecho", "[QUEUE] - RESULT - User ignored");
Luke081515's avatar
Luke081515 committed
62
							$this->NotificateOnTalkPage ($User[$TaskNumber], 4, "");
Luke081515's avatar
Luke081515 committed
63
						} else {
Luke081515's avatar
Luke081515 committed
64
							$CheckUser = $this->CheckUser ($User[$TaskNumber]);
Luke081515's avatar
Luke081515 committed
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
						}
						/** Job "Suppressredirect"
						* Verschiebt eine Seite ohne Weiterleitung
						* @Version 2.0
						* @Author Luke081515
						* @Status stable
						*/
						if ($Task[$TaskNumber] === "sr") {
							$Was = 0;
							$Possible1 = substr ($StartLemma[$TaskNumber], 0, 9);
							$Possible2 = substr ($StartLemma[$TaskNumber], 0, 11);
							$Possible3 = substr ($StartLemma[$TaskNumber], 0, 5);
							$Possible4 = strtolower ($Possible1);
							$Possible5 = strtolower ($Possible2);
							$Possible6 = strtolower ($Possible3);
							if ($Possible4 === "benutzer:")
								$Was = 1;
							if ($Possible5 === "benutzerin:")
								$Was = 2;
							if ($Possible6 === "user:")
								$Was = 3;
							if ($Was != 0) {
								$NextBorder = "/";
								$EndResult = "";
								if ($Was === 1)
									$EndResult = substr ($StartLemma[$TaskNumber], 9);
								if ($Was === 2)
									$EndResult = substr ($StartLemma[$TaskNumber], 11);
								if ($Was === 3)
									$EndResult = substr ($StartLemma[$TaskNumber], 5);
								$ToCheck = explode ($NextBorder, $EndResult);
								if ($CheckUser === 0) {
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "p", "Bot: Auftrag abgelehnt, die Startseite im BNR entsprach nicht dem Antragstellenden Benutzer", $Zeitstempel);
									echo ("\n" . time () . "--" . "Auftrag abgelehnt");
Luke081515's avatar
Luke081515 committed
99
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
100
									$this->NotificateOnTalkPage ($User[$TaskNumber], 5, "");
Luke081515's avatar
Luke081515 committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
								} else if ($CheckUser === 2) {
									$this->writeToFile ("/home/luke/botecho", "[Queue] - WORKING - Moving page");
									$answer = $this->MovePage ($StartLemma[$TaskNumber], $TargetLemma[$TaskNumber], "Bot: Verschiebung im Auftrag von [[User:" . $User[$TaskNumber] . "|" . $User[$TaskNumber] ."]]: " . $Summary[$TaskNumber]);
									if (strstr ($answer, "error") === false) {
										$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Page moved");
										$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "e", "Bot: Auftrag bearbeitet", $Zeitstempel);
										$this->NotificateOnTalkPage ($User[$TaskNumber], 1, $TargetLemma[$TaskNumber]);
										$this->WriteLogError ("", "", 5, $StartLemma[$TaskNumber], $TargetLemma[$TaskNumber], $Summary[$TaskNumber]);
										$this->doService( $TargetLemma[$TaskNumber] );
									} else {
										$this->writeToFile ("/home/luke/botecho", "[Queue] - ERROR - Page move failed");
										$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "f", "Bot: Fehler bei der Verschiebung", $Zeitstempel);
										$this->NotificateOnTalkPage ($User[$TaskNumber], 2, "");
									}
									$inwork = false;
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request resolved");
Luke081515's avatar
Luke081515 committed
117 118
								} else if ($ToCheck[0] != $User[$TaskNumber]) {
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "p", "Bot: Auftrag abgelehnt, die Startseite im BNR entsprach nicht dem Antragstellenden Benutzer", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
119
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
120 121 122
									$this->NotificateOnTalkPage ($User[$TaskNumber], 5, "");
								} else if (strstr ($StartLemma[$TaskNumber], "/") === false) {
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "n", "Bot: Auftrag abgelehnt, die zu verschiebende Seite ist keine Unterseite", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
123
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
124 125 126
									$this->NotificateOnTalkPage ($User[$TaskNumber], 3, "");
								} else if (strstr ($TargetLemma[$TaskNumber], ":") === false) {
									if ($this->MovePageProtection ($EndResult) === true) {
Luke081515's avatar
Luke081515 committed
127
										$this->writeToFile ("/home/luke/botecho", "[Queue] - WORKING - Moving page");
Luke081515's avatar
Luke081515 committed
128
										$answer = $this->MovePage ($StartLemma[$TaskNumber], $TargetLemma[$TaskNumber], "Bot: Verschiebung im Auftrag von [[User:" . $User[$TaskNumber] . "|" . $User[$TaskNumber] ."]]: " . $Summary[$TaskNumber]);
Luke081515's avatar
Luke081515 committed
129
										if (strstr ($answer, "error") === false) {
Luke081515's avatar
Luke081515 committed
130
											$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Page moved");
Luke081515's avatar
Luke081515 committed
131 132 133 134
											$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "e", "Bot: Auftrag bearbeitet", $Zeitstempel);
											$this->NotificateOnTalkPage ($User[$TaskNumber], 1, $TargetLemma[$TaskNumber]);
											$this->WriteLogError ("", "", 5, $StartLemma[$TaskNumber], $TargetLemma[$TaskNumber], $Summary[$TaskNumber]);
											$this->doService( $TargetLemma[$TaskNumber] );
Luke081515's avatar
Luke081515 committed
135
										} else {
Luke081515's avatar
Luke081515 committed
136
											$this->writeToFile ("/home/luke/botecho", "[Queue] - ERROR - Page move failed");
Luke081515's avatar
Luke081515 committed
137
											$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "f", "Bot: Fehler bei der Verschiebung", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
138
											$this->NotificateOnTalkPage ($User[$TaskNumber], 2, "");
Luke081515's avatar
Luke081515 committed
139
										}
Luke081515's avatar
Luke081515 committed
140
										$inwork = false;
Luke081515's avatar
Luke081515 committed
141
										$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request resolved");
Luke081515's avatar
Luke081515 committed
142 143 144
									} else {
										$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "f", "Bot: Auftrag abgelehnt, die dazugehörige Diskussionsseite ist vollgeschützt", $Zeitstempel);
										$this->NotificateOnTalkPage ($User[$TaskNumber], 2, "");
Luke081515's avatar
Luke081515 committed
145
										$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
146
									}
Luke081515's avatar
Luke081515 committed
147
								} else {
Luke081515's avatar
Luke081515 committed
148
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "n", "Bot: Auftrag abgelehnt, die Zielseite ist nicht im ANR", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
149
									$this->NotificateOnTalkPage ($User[$TaskNumber], 3, "");
Luke081515's avatar
Luke081515 committed
150
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
151
								}
Luke081515's avatar
Luke081515 committed
152 153 154
							} else {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "n", "Bot: Auftrag abgelehnt, der Startnamensraum war invalid", $Zeitstempel);
								$this->NotificateOnTalkPage ($User[$TaskNumber], 3, "");
Luke081515's avatar
Luke081515 committed
155
								$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
156
							}
Luke081515's avatar
Luke081515 committed
157
						}
Luke081515's avatar
Luke081515 committed
158

Luke081515's avatar
Luke081515 committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
						/** Job "Massmessage"
						* Verteilt eine Massennachricht
						* @Version 1.0
						* @Author Luke081515
						* @Status stable
						*/
						else if ($Task[$TaskNumber] === "mm") {
							$User[$TaskNumber] = str_replace ("_", " ", $User[$TaskNumber]);
							if ($CheckUser === 2) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "a", "Bot: Bearbeite Auftrag", $Zeitstempel);
								$Replaced = str_replace ("_", " ", $StartLemma[$TaskNumber]);
								$Possible1 = substr ($Replaced, 0, 9);
								$Possible2 = substr ($Replaced, 0, 11);
								$Possible3 = substr ($Replaced, 0, 5);
								$Possible7 = substr ($Replaced, 0, 10);
								$Possible9 = substr ($Replaced, 0, 7);
Luke081515's avatar
Luke081515 committed
175 176 177
								$Possible4 = strtolower ($Possible1);
								$Possible5 = strtolower ($Possible2);
								$Possible6 = strtolower ($Possible3);
Luke081515's avatar
Luke081515 committed
178 179
								$Possible8 = strtolower ($Possible7);
								$Possible10 = strtolower ($Possible9);
Luke081515's avatar
Luke081515 committed
180
								if ($Possible4 === "benutzer:")
Luke081515's avatar
Luke081515 committed
181
									$Was = 1;
Luke081515's avatar
Luke081515 committed
182
								if ($Possible5 === "benutzerin:")
Luke081515's avatar
Luke081515 committed
183
									$Was = 2;
Luke081515's avatar
Luke081515 committed
184
								if ($Possible6 === "user:")
Luke081515's avatar
Luke081515 committed
185
									$Was = 3;
Luke081515's avatar
Luke081515 committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
								if ($Possible8 === "wikipedia:")
									$Was = 4;
								if ($Possible10 === "portal:")
									$Was = 5;
								if ($Was === 1) {
									$EndResult = substr ($Replaced, 9);
									$data = "action=query&prop=links&format=xml&pllimit=5000&pldir=ascending&plnamespace=3&rawcontinue=&titles=Benutzer:" . urlencode($EndResult);
								} else if ($Was === 2) {
									$EndResult = substr ($Replaced, 11);
									$data = "action=query&prop=links&format=xml&pllimit=5000&pldir=ascending&plnamespace=3&rawcontinue=&titles=Benutzer:" . urlencode($EndResult);
								} else if ($Was === 3) {
									$EndResult = substr ($SReplaced, 5);
									$data = "action=query&prop=links&format=xml&pllimit=5000&pldir=ascending&plnamespace=3&rawcontinue=&titles=Benutzer:" . urlencode($EndResult);
								} else if ($Was === 4) {
									$EndResult = substr ($Replaced, 10);
									$data = "action=query&prop=links&format=xml&pllimit=5000&pldir=ascending&plnamespace=3&rawcontinue=&titles=Wikipedia:" . urlencode($EndResult);
								} else if ($Was === 5) {
									$EndResult = substr ($Replaced, 7);
									$data = "action=query&prop=links&format=xml&pllimit=5000&pldir=ascending&plnamespace=3&rawcontinue=&titles=Portal:" . urlencode($EndResult);
								}
								try {
									$website = $this->httpRequest($data, $this->job, 'GET');
								} catch (Exception $e) {
									throw $e;
								}
								$Answer = explode ("\"", $website);
								$b = 13;
								$q = 0;
								while (isset($Answer [$b]) === true) {
									$Result [$q] = $Answer [$b];
									$b = $b + 4;
									$q++;
								}
								$q = 0;
								$f = 0;
								$g = 0;
								while (isset($Result [$q]) === true) {
Luke081515's avatar
Luke081515 committed
223
									$this->writeToFile ("/home/luke/botecho", "[Queue] - WORKING - Message gets delivered to " . $Result[$q]);
Luke081515's avatar
Luke081515 committed
224 225 226 227
									$answer = $this->editPage ($Result [$q], $this->readPage($Result [$q]) . "\n{{subst:" . $TargetLemma[$TaskNumber] . "}}", "Bot: Nachricht von [[User:" . $User[$TaskNumber] . "|" . $User[$TaskNumber] ."]]: " . $Summary[$TaskNumber]);
									if (strstr ($answer, "error") !== false) {
										$Error [$f] = $Result [$q];
										$f++;
Luke081515's avatar
Luke081515 committed
228
									} else {
Luke081515's avatar
Luke081515 committed
229 230
										$Success [$g] = $Result [$q];
										$g++;
Luke081515's avatar
Luke081515 committed
231
									}
Luke081515's avatar
Luke081515 committed
232 233
									$q++;
									sleep (4);
Luke081515's avatar
Luke081515 committed
234
								}
Luke081515's avatar
Luke081515 committed
235 236 237 238 239 240 241
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "e", "Bot: Auftrag bearbeitet", $Zeitstempel);
								$this->NotificateOnTalkPage ($User[$TaskNumber], 6, "");
								if (isset ($Error [0]) === false)
									$Error = "";
								$this->WriteLogError ($Success, $Error, 6, $StartLemma [$TaskNumber], $TargetLemma [$TaskNumber], $Summary [$TaskNumber]);
							} else if ($CheckUser === 1) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "d", "Bot: Warte auf Best&auml;tigung des Betreibers", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
242
								$this->writeToFile ("/home/luke/botecho", "[Queue] - WORKING - Request on hold");
Luke081515's avatar
Luke081515 committed
243 244
							} else if ($CheckUser === 0) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "p", "Bot: Auftrag abgelehnt, du hast einen falschen Namen angegeben", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
245
								$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
246
								$this->NotificateOnTalkPage ($User[$TaskNumber], 5, "");
Luke081515's avatar
Luke081515 committed
247
							}
Luke081515's avatar
Luke081515 committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
						}
						/** Job "CategorySearcher"
						* Erstellt eine Tabelle mit allen Seiten einer Kategorie und deren Kategorien
						* @Version 1.0
						* @Author Luke081515
						* @Status stable
						*/
						else if ($Task[$TaskNumber] === "cs") {
							$Was = 0;
							$Possible1 = substr ($StartLemma[$TaskNumber], 0, 9);
							$Possible2 = substr ($StartLemma[$TaskNumber], 0, 11);
							$Possible3 = substr ($StartLemma[$TaskNumber], 0, 5);
							$Possible4 = strtolower ($Possible1);
							$Possible5 = strtolower ($Possible2);
							$Possible6 = strtolower ($Possible3);
							if ($Possible4 === "benutzer:")
								$Was = 1;
							if ($Possible5 === "benutzerin:")
								$Was = 2;
							if ($Possible6 === "user:")
								$Was = 3;
							if ($Was != 0) {
								$NextBorder = "/";
								$EndResult = "";
								if ($Was === 1)
									$EndResult = substr ($StartLemma[$TaskNumber], 9);
								if ($Was === 2)
									$EndResult = substr ($StartLemma[$TaskNumber], 11);
								if ($Was === 3)
									$EndResult = substr ($StartLemma[$TaskNumber], 5);
								$ToCheck = explode ($NextBorder, $EndResult);
								if ($CheckUser === 0) {
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "p", "Bot: Auftrag abgelehnt, die Seite im BNR entsprach nicht dem Antragstellenden Benutzer", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
281
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
282
									$this->NotificateOnTalkPage ($User[$TaskNumber], 5, "");
Luke081515's avatar
Luke081515 committed
283 284
								} else if ($ToCheck[0] != $User[$TaskNumber]) {
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "p", "Bot: Auftrag abgelehnt, die Seite im BNR entsprach nicht dem Antragstellenden Benutzer", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
285
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
286 287 288
									$this->NotificateOnTalkPage ($User[$TaskNumber], 5, "");
								} else if (strstr ($StartLemma[$TaskNumber], "/") === false) {
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "n", "Bot: Auftrag abgelehnt, die zu Seite ist keine Unterseite", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
289
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
290 291
									$this->NotificateOnTalkPage ($User[$TaskNumber], 3, "");
								} else if (strstr ($TargetLemma[$TaskNumber], "Kategorie") !== false) {
Luke081515's avatar
Luke081515 committed
292
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "a", "Bot: Bearbeite Auftrag", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
293 294 295
									$SitesS = $this->getCatMembers ($TargetLemma[$TaskNumber]);
									$Sites = unserialize ($SitesS);
									$Write = "{| class=\"wikitable sortable\"\n! Titel !! class=\"unsortable\"| Kategorie(n)\n|-";
Luke081515's avatar
Luke081515 committed
296
									$a = 0;
Luke081515's avatar
Luke081515 committed
297 298 299 300 301 302 303 304 305 306 307
									if ($Summary[$TaskNumber] > 5000)
											$Summary[$TaskNumber] = 5000;
									while (isset ($Sites [$a]) === true && $a < $Summary[$TaskNumber]) {
										$b = 0;
										$CatList = $this->GetPageCats ($Sites [$a]);
										$Cats = explode ($Border, $CatList);
										$Write = $Write . "\n|[[" . $Sites [$a] . "]]";
										$Write = $Write . "\n|";
										while (isset ($Cats [$b]) == true)
										{
											$Write = $Write . "\n* [[:" . $Cats [$b] . "]]";
Luke081515's avatar
Luke081515 committed
308 309
											$b++;
										}
Luke081515's avatar
Luke081515 committed
310
										$Write = $Write . "\n|-";
Luke081515's avatar
Luke081515 committed
311 312
										$a++;
									}
Luke081515's avatar
Luke081515 committed
313 314 315 316 317 318 319
									$Listed = $a;
									while (isset ($Sites [$a]) === true)
										$a++;
									$All = $a;
									$Write = $Write . "\n|}";
									$Write = $Write . "\n\nErstellt durch ~~~ um ~~~~~\n\n{{ping|" . $User [$TaskNumber] . "}} Auftrag bearbeitet. ~~~~";
									$this->editPage($StartLemma[$TaskNumber], $Write, "Bot: Erstelle Liste auf Anfrage des Benutzers");
Luke081515's avatar
Luke081515 committed
320
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "e", "Bot: Auftrag bearbeitet", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
321 322 323 324
									$this->WriteLogError ($All, $Listed, 7, $StartLemma [$TaskNumber], $TargetLemma [$TaskNumber], $Summary [$TaskNumber]);
								} else {
									$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "n", "Bot: Auftrag abgelehnt, die angebene Seite ist keine Kategorie", $Zeitstempel);
									$this->NotificateOnTalkPage ($User[$TaskNumber], 3, "");
Luke081515's avatar
Luke081515 committed
325
									$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
326
								}
Luke081515's avatar
Luke081515 committed
327 328
							} else {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "n", "Bot: Fehler", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
329
								$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
330 331 332 333 334 335 336 337 338 339 340 341 342
							}
						}
						/** Job "TemplateOperator:Umbennen"
						* Benennt alle Einbindungen einer Vorlage um
						* @Version 0.8
						* @Author Luke081515
						* @Status Alpha
						*/
						else if ($Task[$TaskNumber] === "tr") {
							if ($CheckUser === 2) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "a", "Bot: Bearbeite Auftrag", $Zeitstempel);
								$EmbeddingsS = $this->getAllEmbedings ($StartLemma[$TaskNumber]);
								$Embeddings = unserialize ($EmbeddingsS);
Luke081515's avatar
Luke081515 committed
343
								$a = 0;
Luke081515's avatar
Luke081515 committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
								$b = 0;
								$c = 0;
								while (isset ($Embeddings [$a]) === true) {
									$Content = $this->readPage ($Embeddings [$a]);
									$NameI = substr ($StartLemma [$TaskNumber], 8);
									$NameII = substr ($TargetLemma [$TaskNumber], 8);
									$Content = str_replace ("{{" . $NameI . "}}", "{{" . $NameII . "}}" , $Content);
									$Content = str_replace ("{{" . $NameI, "{{" . $NameII, $Content);
									$answer = $this->editPage ($Embeddings [$a], $Content, "Bot: Umbenennung einer Vorlage aufgrund [[" . $Summary [$TaskNumber] . "|dieser Diskussion]]");
									if (strstr ($answer, "error") === false) {
										$Succesful [$b] = $Embeddings [$a];
										$b++;
									} else {
										$Error [$c] = $Embeddings [$a];
										$c++;
									}
360 361
									$a++;
								}
Luke081515's avatar
Luke081515 committed
362 363 364 365 366 367 368
								if (isset ($Error [0]) === true)
									$this->WriteLogError ($Succesful, $Error, 1, $StartLemma[$TaskNumber], $TargetLemma[$TaskNumber], $Summary [$TaskNumber]);
								else
									$this->WriteLogError ($Succesful, "", 1, $StartLemma[$TaskNumber], $TargetLemma[$TaskNumber], $Summary [$TaskNumber]);
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "e", "Bot: Auftrag bearbeitet", $Zeitstempel);
							} else if ($CheckUser === 1) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "d", "Bot: Warte auf Best&auml;tigung des Betreibers", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
369
								$this->writeToFile ("/home/luke/botecho", "[Queue] - WORKING - Request on hold");
Luke081515's avatar
Luke081515 committed
370 371
							} else if ($CheckUser === 0) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "p", "Bot: Auftrag abgelehnt, du hast einen falschen Namen angegeben", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
372
								$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386
								$this->NotificateOnTalkPage ($User[$TaskNumber], 5, "");
							}
						}
						/** Job "TemplateOperator:Substituieren"
						* Substituiert alle Einbindungen einer Vorlage
						* @Version 0.8
						* @Author Luke081515
						* @Status Alpha
						*/
						else if ($Task[$TaskNumber] === "ts") {
							if ($CheckUser === 2) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "a", "Bot: Bearbeite Auftrag", $Zeitstempel);
								$EmbeddingsS = $this->getAllEmbedings ($StartLemma[$TaskNumber]);
								$Embeddings = unserialize ($EmbeddingsS);
Luke081515's avatar
Luke081515 committed
387
								$a = 0;
Luke081515's avatar
Luke081515 committed
388 389 390 391 392 393 394 395 396 397
								$b = 0;
								$c = 0;
								while (isset ($Embeddings [$a]) === true) {
									$Content = $this->readPage ($Embeddings [$a]);
									$Name = substr ($StartLemma [$TaskNumber], 8);
									$Content = str_replace ("{{" . $Name . "}}", "{{ers:" . $Name . "}}" , $Content);
									$Content = str_replace ("{{" . $Name, "{{ers:" . $Name, $Content);
									$answer = $this->editPage ($Embeddings [$a], $Content, "Bot: Substituierung einer Vorlage aufgrund [[" . $Summary [$TaskNumber] . "|dieser Diskussion]]");
									if (strstr ($answer, "error") === false) {
										$Succesful [$b] = $Embeddings [$a];
398
										$b++;
Luke081515's avatar
Luke081515 committed
399 400 401
									} else {
										$Error [$c] = $Embeddings [$a];
										$c++;
402 403 404
									}
									$a++;
								}
Luke081515's avatar
Luke081515 committed
405 406 407 408
								$this->WriteLogError ($Succesful, $Error, 3, $StartLemma[$TaskNumber], "", $Summary [$TaskNumber]);
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "e", "Bot: Auftrag bearbeitet", $Zeitstempel);
							} else if ($CheckUser === 1) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "d", "Bot: Warte auf Best&auml;tigung des Betreibers", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
409
								$this->writeToFile ("/home/luke/botecho", "[Queue] - WORKING - Request on hold");
Luke081515's avatar
Luke081515 committed
410 411
							} else if ($CheckUser === 0) {
								$this->ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, "p", "Bot: Auftrag abgelehnt, du hast einen falschen Namen angegeben", $Zeitstempel);
Luke081515's avatar
Luke081515 committed
412
								$this->writeToFile ("/home/luke/botecho", "[Queue] - RESULT - Request denied");
Luke081515's avatar
Luke081515 committed
413
								$this->NotificateOnTalkPage ($User[$TaskNumber], 5, "");
414
							}
Luke081515's avatar
Luke081515 committed
415
						}
Luke081515's avatar
Luke081515 committed
416
						/** Job "CatOverview"
Luke081515's avatar
Luke081515 committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
						* Erstellt einen Uebersicht ueber einen Teil des Kategoriebaumes
						* @Version 0.3
						* @Author Luke081515
						* @Status Alpha
						* Gebe eine Kategorie an (Oberkat)
						* Gebe eine Kat an, deren Seiten gelistet werden
						* Lese alle Seiten aus der zweiten Kat aus
						* Sortiere die Seiten nach Kategorien der Unterkategorien der Oberkategorie
						*/
						else if ($Task[$TaskNumber] === "co") {
							$Kats = unserialize ($this->getCatMembers ($StartLemma [$TaskNumber], true));
							$a = 0;
							while (isset ($Kat [$a]) === true) {
								$PageList = $this->getPages ($Kats [$a]);
								$a++;
							}
							$a = 0;
							while (isset ($Kat [$a]) === true) {
								$ResultPages = $this->PageInCat ($TargetLemma [$TaskNumber], $PageList);
								$a++;
							}
							$a = 0;
							$output = ("== Liste der Seiten der Kategorie" . $TargetLemma [$TaskNumber] . "in der Kategorie" . $StartLemma [$TaskNumber] . " ==");
							while (isset ($Kat [$a]) === true) {
								$output = $output . "\n * [[:" . $Kat [$a] . "]]";
								$b = 0;
								while (isset ($ResultPages [$b]) === true) {
									$output = $output . "\n ** [[:" . $ResultPages [$b] . "]]";
									$b++;
								}
								$a++;
								$output = $output . "\n\nErstellt durch ~~~ um ~~~~~\n\n\n{{ping|" . $User [$TaskNumber] . "}} Liste erstellt. Viele Gr&uuml;ße, ~~~~";
							}
							$this->editPage ($Summary [$TaskNumber], $output, "Bot: Erstelle Liste auf Anfrage", 0);
Luke081515's avatar
Luke081515 committed
451 452 453 454
						}
					}
				}
			}
Luke081515's avatar
Luke081515 committed
455
		} else {
Luke081515's avatar
Luke081515 committed
456
			$this->writeToFile ("/home/luke/botecho", "[Queue] - ERROR - Bot blocked");
Luke081515's avatar
Luke081515 committed
457 458
		}
	}
459 460 461 462 463
	/** PageInCat
	* @Param: Eine Kategorie, eine Seitenliste
	* Aus der Kategorie werden alle Unterkategorien ausgelesen
	* Die Kategorien der Seiten in der Seiteliste der ausgelesen
	* Seiten aus der Seiteliste die in der Oberkategorie oder in ihren Subkategorien sind kommen ins Array
Luke081515's avatar
Luke081515 committed
464
	* Das Array wird zurueckgegeben
465 466
	*/
	protected function PageInCat ($Kat, $Pages) {
Luke081515's avatar
Luke081515 committed
467 468
		$a = 0;
		$d = 0;
469 470 471
		$Subcats = $this->getCatMembers ($Kat, true);
		while (isset ($Pages [$a]) === true) {
			$found = false;
Luke081515's avatar
Luke081515 committed
472
			$b = 0;
473 474
			$PageKats = $this->getPageCats($Pages [$a]);
			while (isset ($PageKats [$b]) === true && $found === false) {
Luke081515's avatar
Luke081515 committed
475
				$c = 0;
476 477 478 479 480 481 482 483 484 485 486 487 488 489
				while (isset ($Subcats [$c]) === true && $found === false) {
					if ($PageKats [$b] === $Subcats [$c]) {
						$Result [$d] = $Pages [$a];
						$d++;
						$found = true;
					}
					$c++;
				}
				$b++;
			}
			$a++;
		}
		return $Result;
	}
Luke081515's avatar
Luke081515 committed
490 491 492
	/** ChangeStatus
	* Aenderung des Status eines Tasks in der Warteschlange
	*/
493 494
	protected function ChangeStatus ($NumberOfTasks, $TaskNumber, $Task, $User, $StartLemma, $TargetLemma, $Summary, $Status, $NewStatus, $Reason, $Zeitstempel) {
		$ToWriteDown = "";
Luke081515's avatar
Luke081515 committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
		if ($NewStatus === 'e') {
			$ToWriteDown = $ToWriteDown
				. "{{Benutzer:Luke081515Bot/Warteschlange/Job|TASK="
				. $Task[$TaskNumber] . "|USER="
				. $User[$TaskNumber] . "|StartLemma="
				. $StartLemma[$TaskNumber] . "|TargetLemma="
				. $TargetLemma[$TaskNumber] . "|Summary="
				. $Summary[$TaskNumber] . "|STATUS="
				. $NewStatus . "|Zeitstempel=~~~~~}}";
		} else {
			$ToWriteDown = $ToWriteDown
				. "{{Benutzer:Luke081515Bot/Warteschlange/Job|TASK="
				. $Task[$TaskNumber] . "|USER="
				. $User[$TaskNumber] . "|StartLemma="
				. $StartLemma[$TaskNumber] . "|TargetLemma="
				. $TargetLemma[$TaskNumber] . "|Summary="
				. $Summary[$TaskNumber] . "|STATUS="
				. $NewStatus . "|Zeitstempel=}}";
		}
Luke081515's avatar
Luke081515 committed
514
		for ($a = 0; $a < $NumberOfTasks; $a++) {
Luke081515's avatar
Luke081515 committed
515
			if ($a !== $TaskNumber) {
Luke081515's avatar
Luke081515 committed
516
				$ToWriteDown = $ToWriteDown . "\n{{Benutzer:Luke081515Bot/Warteschlange/Job|TASK=" . $Task[$a] . "|USER=" . $User[$a] . "|StartLemma=" . $StartLemma[$a] . "|TargetLemma=" . $TargetLemma[$a] . "|Summary=" . $Summary[$a] . "|STATUS=" . $Status[$a] . "|Zeitstempel=" . $Zeitstempel[$a] ."}}";
517 518
			}
		}
Luke081515's avatar
Luke081515 committed
519
		$this->editPage("Benutzer:Luke081515Bot/Warteschlange/Auftraege", $ToWriteDown, $Reason);
520
	}
Luke081515's avatar
Luke081515 committed
521
	/** getPages
522 523 524 525 526 527
	* liest alle einkategorisierten Seiten einer Kat aus
	* @autor: Luke081515
	* @version: 1.0
	*/
	protected function getPages ($Kat) {
		$data = "action=query&list=categorymembers&format=php&cmtitle=" . urlencode($Kat) . "&cmprop=title&cmtype=page&cmlimit=5000&cmsort=sortkey&cmdir=ascending&rawcontinue=";
Luke081515's avatar
Luke081515 committed
528 529 530 531 532
		try {
			$website = $this->httpRequest($data, $this->job, 'GET');
		} catch (Exception $e) {
			throw $e;
		}
Luke081515's avatar
Luke081515 committed
533
		$a = 9;
Luke081515's avatar
Luke081515 committed
534
		$Answer = explode ("\"", $website);
Luke081515's avatar
Luke081515 committed
535
		while (isset ($Answer [$a]) === true) {
536 537 538 539 540
			$Exception = false;
			$x = $a + 1;
			while (strstr ($Answer [$x], ";}") === false) {
				if ($Exception === false)
					$New = $Answer [$a] . "\"" . $Answer [$x];
Luke081515's avatar
Luke081515 committed
541
				else
542 543 544
					$New = $New . "\"" . $Answer [$x];
				$Exception = true;
				$a++;
Luke081515's avatar
Luke081515 committed
545 546
				$x = $a + 1;
			}
547 548 549 550 551 552
			if ($Exception === true)
				$Page [$c] = $New;
			else
				$Page [$c] = $Answer [$a];
			$a = $a + 6;
			$c++;
Luke081515's avatar
Luke081515 committed
553
		}
554
		$b++;
Luke081515's avatar
Luke081515 committed
555 556
		$b = 0;
		$d = 0;
Luke081515's avatar
Luke081515 committed
557
		while (isset ($Page [$b]) === true) {
Luke081515's avatar
Luke081515 committed
558
			$c = 0;
Luke081515's avatar
Luke081515 committed
559
			$Found = false;
Luke081515's avatar
Luke081515 committed
560
			while (isset ($PageResults [$c]) === true) {
Luke081515's avatar
Luke081515 committed
561 562 563 564
				if ($Page [$b] === $PageResults [$c])
					$Found = true;
				$c++;
			}
Luke081515's avatar
Luke081515 committed
565
			if ($Found === false) {
Luke081515's avatar
Luke081515 committed
566 567 568
				$PageResults [$d] = $Page [$b];
				$d++;
			}
Luke081515's avatar
Luke081515 committed
569 570
			$b++;
		}
571
		return serialize ($PageResults);
Luke081515's avatar
Luke081515 committed
572
	}
Luke081515's avatar
Luke081515 committed
573
	protected function ControlIgnoreList ($TargetUser) {
Luke081515's avatar
Luke081515 committed
574
		$AllIgnoredUsers = $this->readPage("Benutzer:Luke081515Bot/ignore.js");
Luke081515's avatar
Luke081515 committed
575
		$Border = "|";
Luke081515's avatar
Luke081515 committed
576 577 578 579
		$IgnoredUsers = explode ($Border, $AllIgnoredUsers);
		$q = 0;
		while (isset($IgnoredUsers[$q]) === true)
			$q++;
Luke081515's avatar
Luke081515 committed
580
		for ($x = 0; $x < $q; $x++) {
Luke081515's avatar
Luke081515 committed
581 582 583 584 585
			if ($TargetUser === $IgnoredUsers[$x])
				return true;
		}
		return false;
	}
Luke081515's avatar
Luke081515 committed
586
	protected function MovePageProtection ($Page) {
Luke081515's avatar
Luke081515 committed
587
		$title = "Benutzer Diskussion:" . $Page;
588
		$data = "action=query&format=php&prop=info&titles=" . urlencode($title);
Luke081515's avatar
Luke081515 committed
589 590 591 592 593
		try {
			$website = $this->httpRequest($data, $this->job, 'GET');
		} catch (Exception $e) {
			throw $e;
		}
Luke081515's avatar
Luke081515 committed
594
		$answer = unserialize($website);
595
		$data = "action=query&prop=info&format=php&inprop=protection&titles=" . urlencode($title);
Luke081515's avatar
Luke081515 committed
596 597 598 599 600
		try {
			$website = $this->httpRequest($data, $this->job, 'GET');
		} catch (Exception $e) {
			throw $e;
		}
Luke081515's avatar
Luke081515 committed
601 602
		$answer = unserialize($website);
		// do nothing with the answer... ;)
Luke081515's avatar
Luke081515 committed
603
		echo ("\n". $website);
Luke081515's avatar
Luke081515 committed
604 605
		if (strstr ($website, "sysop") === false)
			return true;
Luke081515's avatar
Luke081515 committed
606
		return false;
Luke081515's avatar
Luke081515 committed
607
	}
Luke081515's avatar
Luke081515 committed
608
	public function CheckUser ($CheckUser) {
Luke081515's avatar
Luke081515 committed
609
		$title = "Benutzer:Luke081515Bot/Warteschlange/Auftraege";
610
		$data = "action=query&format=php&prop=info&titles=" . urlencode($title);
Luke081515's avatar
Luke081515 committed
611 612 613 614 615
		try {
			$website = $this->httpRequest($data, $this->job, 'GET');
		} catch (Exception $e) {
			throw $e;
		}
Luke081515's avatar
Luke081515 committed
616 617
		$answer = unserialize($website);
		$data = "action=query&prop=revisions&format=php&rvprop=user&titles=Benutzer%3ALuke081515Bot%2FWarteschlange%2FAuftraege";
Luke081515's avatar
Luke081515 committed
618 619 620 621 622
		try {
			$website = $this->httpRequest($data, $this->job, 'GET');
		} catch (Exception $e) {
			throw $e;
		}
Luke081515's avatar
Luke081515 committed
623
		$answer = unserialize($website);
Luke081515's avatar
Luke081515 committed
624
		$position = strpos ($website , "user");
Luke081515's avatar
Luke081515 committed
625
		$Result = substr ($website, $position);
Luke081515's avatar
Luke081515 committed
626
		echo ("\n". $website);
Luke081515's avatar
Luke081515 committed
627
		echo ("\n". $Result);
Luke081515's avatar
Luke081515 committed
628
		if (strstr ($Result, "Luke081515\"") !== false) {
Luke081515's avatar
Luke081515 committed
629
			return 2;
Luke081515's avatar
Luke081515 committed
630
		} else if (strstr ($Result, $CheckUser) !== false) {
Luke081515's avatar
Luke081515 committed
631
			return 1;
Luke081515's avatar
Luke081515 committed
632
		} else  {
633
			return 1;
Luke081515's avatar
Luke081515 committed
634 635
		}
	}
Luke081515's avatar
Luke081515 committed
636
	public function GetPageCats ($Site) {
Luke081515's avatar
Luke081515 committed
637 638
		echo ("\n Lese: " . $Site);
		$data = "action=query&prop=categories&format=php&cllimit=500&cldir=ascending&rawcontinue=&titles=" . urlencode($Site);
Luke081515's avatar
Luke081515 committed
639 640 641 642 643
		try {
			$website = $this->httpRequest($data, $this->job, 'GET');
		} catch (Exception $e) {
			throw $e;
		}
Luke081515's avatar
Luke081515 committed
644
		$Result = explode ("\"", $website);
Luke081515's avatar
Luke081515 committed
645 646
		$a = 19;
		$b = 0;
Luke081515's avatar
Luke081515 committed
647
		while (isset ($Result [$a]) === true) {
Luke081515's avatar
Luke081515 committed
648
			$Kats [$b] = $Result [$a];
Luke081515's avatar
Luke081515 committed
649
			$a = $a + 6;
Luke081515's avatar
Luke081515 committed
650 651
			$b++;
		}
Luke081515's avatar
Luke081515 committed
652
		$b = 1;
Luke081515's avatar
Luke081515 committed
653
		$Ret = $Kats [0];
Luke081515's avatar
Luke081515 committed
654
		while (isset ($Kats [$b]) === true) {
Luke081515's avatar
Luke081515 committed
655 656 657 658 659 660
			$Ret = $Ret . "|" . $Kats [$b];
			$b++;
		}
		echo ("\n" . $Ret);
		return $Ret;
	}
Luke081515's avatar
Luke081515 committed
661 662
	protected function ControlRobinsonList ($TargetUser) {
		$AllRobinsonUsers = $this->readPage("Benutzer:Luke081515Bot/Opt-Out");
Luke081515's avatar
Luke081515 committed
663
		$Border = "|";
Luke081515's avatar
Luke081515 committed
664
		$RobinsonUsers = explode ($Border, $AllRobinsonUsers);
Luke081515's avatar
Luke081515 committed
665 666 667
		$q = 0;
		while (isset($RobinsonUsers[$q]) === true)
			$q++;
Luke081515's avatar
Luke081515 committed
668
		for ($x = 0; $x < $q; $x++) {
Luke081515's avatar
Luke081515 committed
669 670 671 672 673
			if ($TargetUser === $RobinsonUsers[$x])
				return true;
		}
		return false;
	}
Luke081515's avatar
Luke081515 committed
674 675
	protected function ControlOnlyErrorList ($TargetUser) {
		$AllOnlyErrorUsers = $this->readPage("Benutzer:Luke081515Bot/Only-Error");
Luke081515's avatar
Luke081515 committed
676 677 678 679 680
		$Border = "|";
		$OnlyErrorUsers = explode ($Border, $AllOnlyErrorUsers);
		$q = 0;
		while (isset($OnlyErrorUsers[$q]) === true)
			$q++;
Luke081515's avatar
Luke081515 committed
681
		for ($x = 0; $x < $q; $x++) {
Luke081515's avatar
Luke081515 committed
682 683 684 685 686
			if ($TargetUser === $OnlyErrorUsers[$x])
				return true;
		}
		return false;
	}
Luke081515's avatar
Luke081515 committed
687
	protected function NotificateOnTalkPage ($User, $MessageNumber, $Sitename) {
Luke081515's avatar
Luke081515 committed
688
		if ($MessageNumber === 5)
689
			$this->editPage("Benutzer Diskussion:Luke081515", "\n" . $this->readPage("Benutzer Diskussion:Luke081515"), "Bot: Benachrichtigung");
Luke081515's avatar
Luke081515 committed
690 691 692
		else if ($this->ControlRobinsonList ($User) === true) {
			sleep(0);
		} else if ($this->ControlOnlyErrorList ($User) === true) {
Luke081515's avatar
Luke081515 committed
693 694 695 696 697 698
			if ($MessageNumber === 2)
				$Message = "\n{{subst:Benutzer:Luke081515Bot/Nachricht/Fehlerhaft}}";
			if ($MessageNumber === 3)
				$Message = "\n{{subst:Benutzer:Luke081515Bot/Nachricht/Abgelehnt}}";
			if ($MessageNumber === 4)
				$Message =	"\n{{subst:Benutzer:Luke081515Bot/Nachricht/Verweigert}}";
Luke081515's avatar
Luke081515 committed
699
		} else {
Luke081515's avatar
Luke081515 committed
700
			if ($MessageNumber === 1)
701
				$Message = "\n{{subst:Benutzer:Luke081515Bot/Nachricht/Erledigt|" . $Sitename . "}}";
Luke081515's avatar
Luke081515 committed
702
			if ($MessageNumber === 2)
Luke081515's avatar
Luke081515 committed
703
				$Message = "\n{{subst:Benutzer:Luke081515Bot/Nachricht/Fehlerhaft}}";
Luke081515's avatar
Luke081515 committed
704
			if ($MessageNumber === 3)
Luke081515's avatar
Luke081515 committed
705
				$Message = "\n{{subst:Benutzer:Luke081515Bot/Nachricht/Abgelehnt}}";
Luke081515's avatar
Luke081515 committed
706
			if ($MessageNumber === 4)
Luke081515's avatar
Luke081515 committed
707
				$Message =	"\n{{subst:Benutzer:Luke081515Bot/Nachricht/Verweigert}}";
708 709
			if ($MessageNumber === 6)
				$Message =	"\n{{subst:Benutzer:Luke081515Bot/Nachricht/Verteilt}}";
710
			$this->editPage("Benutzer Diskussion:" . $User, $this->readPage("Benutzer Diskussion:" . $User) . $Message, "Bot:Benachrichtigung aufgrund eines beendeten Auftrages");
Luke081515's avatar
Luke081515 committed
711 712
		}
	}
Luke081515's avatar
Luke081515 committed
713
	public function getAllEmbedings ($Templ) {
Luke081515's avatar
Luke081515 committed
714
		$b = 0;
Luke081515's avatar
Luke081515 committed
715 716 717
		$data = "action=query&list=embeddedin&format=php&eititle=" . urlencode($Templ) . "&einamespace=0&eidir=ascending&eilimit=5000&rawcontinue=";
		echo ("\n" . $data);
		sleep (5);
Luke081515's avatar
Luke081515 committed
718 719 720 721 722
		try {
			$website = $this->httpRequest($data, $this->job, 'GET');
		} catch (Exception $e) {
			throw $e;
		}
Luke081515's avatar
Luke081515 committed
723 724 725
		echo ("\n" . $website);
		unset ($Answer);
		$Answer = explode ("\"", $website);
Luke081515's avatar
Luke081515 committed
726
		while (strstr ($website, "eicontinue") !== false) {
Luke081515's avatar
Luke081515 committed
727
			$a = 19;
Luke081515's avatar
Luke081515 committed
728
			$Continue = $Answer [7];
Luke081515's avatar
Luke081515 committed
729
			while (isset ($Answer [$a]) === true) {
730 731
				$x = $a + 1;
				$Exception = false;
Luke081515's avatar
Luke081515 committed
732
				while (strstr ($Answer [$x], ";}") === false) {
733 734 735 736 737 738 739 740 741 742 743 744
					if ($Exception === false)
						$New = $Answer [$a] . "\"" . $Answer [$x];
					else
						$New = $New . "\"" . $Answer [$x];
					$Exception = true;
					$a++;
					$x = $a + 1;
				}
				if ($Exception === true)
					$Result [$b] = $New;
				else
					$Result [$b] = $Answer [$a];
Luke081515's avatar
Luke081515 committed
745
				$a = $a + 8;
746
				$b++;
Luke081515's avatar
Luke081515 committed
747
			}
Luke081515's avatar
Luke081515 committed
748 749
			unset ($Answer);
			$data = "action=query&list=embeddedin&format=php&eititle=" . urlencode($Templ [$z]) . "&einamespace=0&eicontinue=" . urlencode($Continue) .  "&eidir=ascending&eifilterredir=nonredirects&eilimit=5000&rawcontinue=";
Luke081515's avatar
Luke081515 committed
750 751 752 753 754
			try {
				$website = $this->httpRequest($data, $this->job, 'GET');
			} catch (Exception $e) {
				throw $e;
			}
Luke081515's avatar
Luke081515 committed
755 756
			$Answer = explode ("\"", $website);
		}
Luke081515's avatar
Luke081515 committed
757
		$a = 11;
Luke081515's avatar
Luke081515 committed
758
		while (isset ($Answer [$a]) === true) {
Luke081515's avatar
Luke081515 committed
759 760
			$x = $a + 1;
			$Exception = false;
Luke081515's avatar
Luke081515 committed
761
			while (strstr ($Answer [$x], ";}") === false) {
Luke081515's avatar
Luke081515 committed
762 763 764 765 766 767 768
				if ($Exception === false)
					$New = $Answer [$a] . "\"" . $Answer [$x];
				else
					$New = $New . "\"" . $Answer [$x];
				$Exception = true;
				$a++;
				$x = $a + 1;
769
			}
Luke081515's avatar
Luke081515 committed
770 771 772 773
			if ($Exception === true)
				$Result [$b] = $New;
			else
				$Result [$b] = $Answer [$a];
Luke081515's avatar
Luke081515 committed
774
			$a = $a + 8;
Luke081515's avatar
Luke081515 committed
775
			$b++;
776 777 778 779
		}
		$Ret = serialize ($Result);
		return $Ret;
	}
Luke081515's avatar
Luke081515 committed
780
	public function WriteLogError ($LS, $Fehler, $Function, $One, $Two, $Three) {
Luke081515's avatar
Luke081515 committed
781
		$ToWrite = $this->readPage ("User:Luke081515Bot/Log");
Luke081515's avatar
Luke081515 committed
782
		if ($Function === 1)
Luke081515's avatar
Luke081515 committed
783
			$Functiontext = "Log zur Umbenennung der [[" . $One . "]] in [[" . $Two . "]]";
Luke081515's avatar
Luke081515 committed
784
		else if ($Function === 2)
785
			$Functiontext = "Log zur Entfernung der [[" . $One . "]]";
Luke081515's avatar
Luke081515 committed
786
		else if ($Function === 3)
Luke081515's avatar
Luke081515 committed
787
			$Functiontext = "Log zur Substituierung der [[" . $One . "]]";
Luke081515's avatar
Luke081515 committed
788 789
		else if ($Function === 4)
			$Functiontext = "";
Luke081515's avatar
Luke081515 committed
790
		else if ($Function === 5)
Luke081515's avatar
Luke081515 committed
791
			$Functiontext = "Log zur Verschiebung der Seite [[" . $One . "]] nach [[" . $Two . "]]";
Luke081515's avatar
Luke081515 committed
792 793 794 795
		else if ($Function === 6)
			$Functiontext = "Log zur Verteilung der Nachricht [[" . $Two . "]] an [[" . $One . "]]";
		else if ($Function === 7)
			$Functiontext = "Log zur Erstellung der Kategorieübersicht der [[:" . $Two . "]] auf der Seite [[" . $One . "]]";
Luke081515's avatar
Luke081515 committed
796 797 798
		else {
			echo "Strange things happen here.";
		}
Luke081515's avatar
Luke081515 committed
799
		if ($Function < 5) {
Luke081515's avatar
Luke081515 committed
800
			$ToWrite = $ToWrite . "\n\n== " . $Functiontext ."  ==\nGrund war [[" . $Three . "|diese Diskussion]]. Die Aktion wurde zu der folgenden Zeit abgeschlossen: ~~~~~\n";
Luke081515's avatar
Luke081515 committed
801
			$a = 0;
Luke081515's avatar
Luke081515 committed
802 803
			if (isset ($LS [$a]) === true)
				$ToWrite = $ToWrite . "\n;Folgende Vorlageeinbindungen wurden erfolgreich bearbeitet:\n";
Luke081515's avatar
Luke081515 committed
804
			while (isset ($LS [$a]) === true) {
Luke081515's avatar
Luke081515 committed
805 806 807
				$ToWrite = $ToWrite . "\n* [[" . $LS [$a] . "]]";
				$a++;
			}
Luke081515's avatar
Luke081515 committed
808
			$a = 0;
Luke081515's avatar
Luke081515 committed
809 810
			if (isset ($Fehler [$a]) === true)
				$ToWrite = $ToWrite . ";Bei den folgenden Seiten gab es Fehler:\n";
Luke081515's avatar
Luke081515 committed
811
			while (isset ($Fehler [$a]) === true) {
Luke081515's avatar
Luke081515 committed
812 813 814
				$ToWrite = $ToWrite . "\n* [[" . $Fehler [$a] . "]]";
				$a++;
			}
Luke081515's avatar
Luke081515 committed
815 816
		} else {
			if ($Function === 5) {
Luke081515's avatar
Luke081515 committed
817 818 819
				$ToWrite = $ToWrite . "\n\n== " . $Functiontext ."  ==\n* Alter Titel: [[" . $One . "]]";
				$ToWrite = $ToWrite . "\n* Neuer Titel: [[" . $Two . "]]";
				$ToWrite = $ToWrite . "\n* Begründung: " . $Three;
Luke081515's avatar
Luke081515 committed
820
				$ToWrite = $ToWrite . "\n* Status: Erfolgreich verschoben";
Luke081515's avatar
Luke081515 committed
821
			} else if ($Function === 6) {
Luke081515's avatar
Luke081515 committed
822 823 824
				$ToWrite = $ToWrite . "\n\n== " . $Functiontext ."  ==\n* Verteilerliste: [[" . $One . "]]";
				$ToWrite = $ToWrite . "\n* Zu verteilende Nachricht: [[" . $Two . "]]";
				$ToWrite = $ToWrite . "\n* Begründung: " . $Three;
Luke081515's avatar
Luke081515 committed
825
				if (isset ($LS [0]) === true) {
Luke081515's avatar
Luke081515 committed
826
					$ToWrite = $ToWrite . "\n;Auf die folgenden Seiten wurde die Nachricht zugestellt:";
Luke081515's avatar
Luke081515 committed
827
					$a = 0;
Luke081515's avatar
Luke081515 committed
828
					while (isset ($LS [$a]) === true) {
Luke081515's avatar
Luke081515 committed
829 830 831
						$ToWrite = $ToWrite . "\n* [[:" . $LS [$a] . "]]";
						$a++;
					}
Luke081515's avatar
Luke081515 committed
832
				}
Luke081515's avatar
Luke081515 committed
833
				if (isset ($Fehler [0]) === true) {
Luke081515's avatar
Luke081515 committed
834
					$ToWrite = $ToWrite . "\n;Auf folgenden Seiten konnte keine Nachricht zugestellt werden:";
Luke081515's avatar
Luke081515 committed
835
					$a = 0;
Luke081515's avatar
Luke081515 committed
836
					while (isset ($Fehler [$a]) === true) {
Luke081515's avatar
Luke081515 committed
837 838 839 840
						$ToWrite = $ToWrite . "\n* [[:" . $Fehler [$a] . "]]";
						$a++;
					}
				}
Luke081515's avatar
Luke081515 committed
841
			} else if ($Function === 7) {
842 843
				$ToWrite = $ToWrite . "\n\n== " . $Functiontext ."  ==\n* Analysierte Kategorie: [[:" . $Two . "]]";
				$ToWrite = $ToWrite . "\n* Zielseite: [[" . $One . "]]";
Luke081515's avatar
Luke081515 committed
844 845 846
				$ToWrite = $ToWrite . "\n* Gewähltes Limit: " . $Three;
				$ToWrite = $ToWrite . "\n* Anzahl gefundene Einträge: " . $LS;
				$ToWrite = $ToWrite . "\n* Gelistete Einträge: " . $Fehler; //auch wenn hier der Name der Variable nicht passt
Luke081515's avatar
Luke081515 committed
847 848 849
			} else {
				echo "Strange things happen here.";
			}
Luke081515's avatar
Luke081515 committed
850 851
		}
		$ToWrite = $ToWrite . "\n\n--~~~~";
852
		$this->editPage("User:Luke081515Bot/Log", $ToWrite, "Bot: Schreibe Log &uuml;ber den letzten Auftrag");
Luke081515's avatar
Luke081515 committed
853
	}
Luke081515's avatar
Luke081515 committed
854
	private function doService ($Page) {
855 856 857
		$Content = $this->readPage($Page);
		$Content = str_replace("[[:Kategorie:", "[[Kategorie:", $Content);
		$Content = str_replace("[[:Category:", "[[Kategorie:", $Content);
858
		$this->editPage($Page, $Content, "Bot:Aktiviere Kategorien nach Verschiebung");
859
	}
Luke081515's avatar
Luke081515 committed
860
}
Luke081515's avatar
Luke081515 committed
861
$Bot = new QueueBot ('Luke081515Bot@dewiki', 'Queue');
Luke081515's avatar
Luke081515 committed
862
?>