Debug.php 21.3 KB
Newer Older
Luke081515's avatar
Luke081515 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php
require_once __DIR__ . '/BotCore.php';
/** Debug.php
* This is a script for Cygnus which allows to execute single functions interactivly
* @Author Luke081515 <luke081515@tools.wmflabs.org>
* @Version 0.1
* @Status Alpha
*/
class Debug extends Core {
	public function __construct() {
		$this->setSite($this->askRequired('Enter the domain to use:'));
		$this->setUsername($this->askRequired('Enter the username to use:'));
		$this->setPassword($this->askRequired('Enter the password to use:'));
Luke081515's avatar
Luke081515 committed
14 15 16 17 18 19 20
		$assert = $this->askRequired('Enter the value for assert:');
		$debug = $this->askRequired('Use verbose debug mode? [y/N]');
		if (strtolower($debug) !== 'n') {
			$debug = true;
		} else {
			$debug = false;
		}
Luke081515's avatar
Luke081515 committed
21
		$this->initcurlArgs('Debug', true, $assert, false, $debug);
Luke081515's avatar
Luke081515 committed
22
		$this->login();
Luke081515's avatar
Luke081515 committed
23 24 25 26
		do {
			$this->debug($this->askRequired("Name of the function you want to debug:"));
			$answer = $this->askRequired("Do you want to debug another function? [y/N]");
		} while (strtolower($answer) !== 'n');
Luke081515's avatar
Luke081515 committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	}
	/** debug
	* This is the debug engine, here you need to define all methods the script can use
	*/
	private function debug($MethodName) {
		switch ($MethodName) {
			// Reading functions
			case 'readPage':
				$required = array("title");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of readPage...');
				$starttime = microtime (true);
				try {
					$ret = $this->readPage($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
42
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
43 44
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
45
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
46 47 48 49 50 51 52 53 54 55
				}
				break;
			case 'readPageID':
				$required = array("pageID");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of readPageID...');
				$starttime = microtime (true);
				try {
					$ret = $this->readPageID($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
56
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
57 58
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
59
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
60 61 62 63 64 65 66 67 68 69
				}
				break;
			case 'readPageJs':
				$required = array("title");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of readPageJs...');
				$starttime = microtime (true);
				try {
					$ret = $this->readPageJs($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
70
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
71 72
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
73
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
74 75 76 77 78 79 80 81 82 83
				}
				break;
			case 'readPageCss':
				$required = array("title");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of readPageCss...');
				$starttime = microtime (true);
				try {
					$ret = $this->readPageCss($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
84
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
85 86
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
87
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
88 89 90 91 92 93 94 95 96 97
				}
				break;
			case 'readSection':
				$required = array("title", "section");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of readSection...');
				$starttime = microtime (true);
				try {
					$ret = $this->readSection($Param[0], $Param[1]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
98
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
99 100
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
101
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
102 103 104
				}
				break;
			case 'getTableOfContents':
105
				$required = array("title");
Luke081515's avatar
Luke081515 committed
106 107 108 109 110 111
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of getTableOfContents...');
				$starttime = microtime (true);
				try {
					$ret = $this->getTableOfContents($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
112
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
113 114
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
115
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
116 117 118 119 120 121 122 123 124 125 126 127 128
				}
				break;
			// editPage functions
			case 'editPage':
				$required = array("title", "content", "summary");
				$optional = array("noCreate", "overrideNobots");
				$optvalues = array(1, false);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of editPage...');
				$starttime = microtime (true);
				try {
					$ret = $this->editPage($Param[0], $Param[1], $Param[2], intval($Param[3]), boolval($Param[4]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
129
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
130 131
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
132
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
133 134 135 136 137 138 139 140 141 142 143 144
				}
				break;
			case 'editPageMinor':
				$required = array("title", "content", "summary");
				$optional = array("noCreate", "overrideNobots");
				$optvalues = array(1, false);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of editPageMinor...');
				$starttime = microtime (true);
				try {
					$ret = $this->editPageMinor($Param[0], $Param[1], $Param[2], intval($Param[3]), boolval($Param[4]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
145
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
146 147
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
148
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
149 150 151 152 153 154 155 156 157 158 159 160
				}
				break;
			case 'editPageD':
				$required = array("title", "content", "summary", "botflag", "minorflag");
				$optional = array("noCreate", "overrideNobots");
				$optvalues = array(1, false);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of editPageD...');
				$starttime = microtime (true);
				try {
					$ret = $this->editPageD($Param[0], $Param[1], $Param[2], $Param[3], $Param[4], intval($Param[5]), boolval($Param[6]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
161
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
162 163
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
164
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
165 166 167 168 169 170 171 172 173 174 175 176
				}
				break;
			case 'editSection':
				$required = array("title", "content", "summary", "sectionnumber");
				$optional = array("noCreate", "overrideNobots");
				$optvalues = array(1, false);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of editSection...');
				$starttime = microtime (true);
				try {
					$ret = $this->editSection($Param[0], $Param[1], $Param[2], $Param[3], intval($Param[4]), boolval($Param[5]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
177
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
178 179
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
180
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
181 182 183 184 185 186 187 188 189 190 191 192
				}
				break;
			case 'editSectionMinor':
				$required = array("title", "content", "summary", "sectionnumber");
				$optional = array("noCreate", "overrideNobots");
				$optvalues = array(1, false);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of editSectionMinor...');
				$starttime = microtime (true);
				try {
					$ret = $this->editSectionMinor($Param[0], $Param[1], $Param[2], $Param[3], intval($Param[4]), boolval($Param[5]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
193
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
194 195
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
196
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
197 198 199 200 201 202 203 204 205 206 207 208
				}
				break;
			case 'editSectionD':
				$required = array("title", "content", "summary", "sectionnumber", "botflag", "minorflag");
				$optional = array("noCreate", "overrideNobots");
				$optvalues = array(1, false);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of editSectionD...');
				$starttime = microtime (true);
				try {
					$ret = $this->editSectionD($Param[0], $Param[1], $Param[2], $Param[3], $Param[4], $Param[5], intval($Param[6]), boolval($Param[7]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
209
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
210 211
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
212
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
213 214 215
				}
				break;
			case 'movePage':
216
				$required = array("oldTitle", "newTitle", "reason");
Luke081515's avatar
Luke081515 committed
217 218 219 220 221 222 223 224
				$optional = array("bot", "movetalk", "noredirect");
				$optvalues = array(0, 1, 1);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of movePage...');
				$starttime = microtime (true);
				try {
					$ret = $this->movePage($Param[0], $Param[1], $Param[2], intval($Param[3]), intval($Param[4]), intval($Param[5]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
225
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
226 227
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
228
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
229 230
				}
				break;
Luke081515's avatar
Luke081515 committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
			case 'watch':
				$required = array("title");
				$optional = array("unwatch");
				$optvalues = array(0);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of watch...');
				$starttime = microtime (true);
				try {
					$ret = $this->watch($Param[0], intval($Param[2]));
					$endtime = microtime (true);
					$this->processFunction($ret, $endtime);
				} catch (Exception $e) {
					$endtime = microtime (true);
					$this->processError($e, $endtime);
				}
				break;
Luke081515's avatar
Luke081515 committed
247 248 249 250 251 252 253 254
			case 'review':
				$required = array("revid", "comment", "reason");
				$optional = array("unapprove");
				$optvalues = array(0);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of review...');
				$starttime = microtime (true);
				try {
Luke081515's avatar
Luke081515 committed
255
					$ret = $this->review($Param[0], $Param[1], $Param[2], intval($Param[3]));
Luke081515's avatar
Luke081515 committed
256
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
257
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
258 259
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
260
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
261 262
				}
				break;
Luke081515's avatar
Luke081515 committed
263
			// User information functions
264 265 266 267 268 269 270 271
			case 'checkUserExistence':
				$required = array("username");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of checkUserExistence...');
				$starttime = microtime(true);
				try {
					$ret = $this->checkUserExistence($Param[0]);
					$endtime = microtime(true);
Luke081515's avatar
Luke081515 committed
272
					$this->processFunction($ret, $starttime, $endtime);
273
				} catch (Exception $e) {
Luke081515's avatar
Luke081515 committed
274 275
					$endtime = microtime (true);
					$this->processError($e, $starttime, $endtime);
276 277
				}
				break;
Luke081515's avatar
Luke081515 committed
278 279 280 281 282 283 284 285
			case 'getUserEditcount':
				$required = array("username");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of getUserEditcount...');
				$starttime = microtime(true);
				try {
					$ret = $this->getUserEditcount($Param[0]);
					$endtime = microtime(true);
Luke081515's avatar
Luke081515 committed
286
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
287
				} catch (Exception $e) {
Luke081515's avatar
Luke081515 committed
288 289
					$endtime = microtime (true);
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
290 291
				}
				break;
Luke081515's avatar
Luke081515 committed
292 293 294 295 296 297 298 299
			case 'checkUserBlock':
				$required = array("username");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of checkUserBlock...');
				$starttime = microtime(true);
				try {
					$ret = $this->checkUserBlock($Param[0]);
					$endtime = microtime(true);
Luke081515's avatar
Luke081515 committed
300
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
301
				} catch (Exception $e) {
Luke081515's avatar
Luke081515 committed
302 303
					$endtime = microtime (true);
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
304 305
				}
				break;
Luke081515's avatar
Luke081515 committed
306 307 308 309 310 311 312 313
			case 'checkUserMail':
				$required = array("username");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of checkUserMail...');
				$starttime = microtime(true);
				try {
					$ret = $this->checkUserMail($Param[0]);
					$endtime = microtime(true);
Luke081515's avatar
Luke081515 committed
314
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
315
				} catch (Exception $e) {
Luke081515's avatar
Luke081515 committed
316 317
					$endtime = microtime (true);
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
318 319
				}
				break;
Luke081515's avatar
Luke081515 committed
320 321 322 323 324 325 326 327 328 329 330
			// Query functions
			case 'getCatMembers':
				$required = array("kat");
				$optional = array("onlySubCats", "excludeWls");
				$optvalues = array(false, false);
				$Param = $this->getParams($required, $optional, $optvalues);
				$this->echoNotice('Starting the function call of getCatMembers...');
				$starttime = microtime (true);
				try {
					$ret = $this->getCatMembers($Param[0], boolval($Param[1]), boolval($Param[2]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
331
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
332 333
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
334
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
335 336 337
				}
				break;
			case 'getPageCats':
338
				$required = array("title");
Luke081515's avatar
Luke081515 committed
339 340 341 342 343 344
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of getPageCats...');
				$starttime = microtime (true);
				try {
					$ret = $this->getPageCats($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
345
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
346 347
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
348
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
349 350
				}
				break;
351
			case 'getAllEmbeddings':
Luke081515's avatar
Luke081515 committed
352 353
				$required = array("templ");
				$Param = $this->getParams($required);
354
				$this->echoNotice('Starting the function call of getAllEmbeddings...');
Luke081515's avatar
Luke081515 committed
355 356
				$starttime = microtime (true);
				try {
357
					$ret = $this->getAllEmbeddings($Param[0]);
Luke081515's avatar
Luke081515 committed
358
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
359
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
360 361
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
362
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
363 364 365 366 367 368 369 370 371 372
				}
				break;
			case 'getAllPages':
				$required = array("namespace");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of getAllPages...');
				$starttime = microtime (true);
				try {
					$ret = $this->getAllPages($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
373
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
374 375
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
376
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
377 378 379
				}
				break;
			case 'getPageID':
380
				$required = array("title");
Luke081515's avatar
Luke081515 committed
381 382 383 384 385 386
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of getPageID...');
				$starttime = microtime (true);
				try {
					$ret = $this->getPageID($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
387
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
388 389
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
390
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
391 392 393
				}
				break;
			case 'getLinks':
394
				$required = array("title");
Luke081515's avatar
Luke081515 committed
395 396 397 398 399 400
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of getLinks...');
				$starttime = microtime (true);
				try {
					$ret = $this->getLinks($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
401
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
402 403
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
404
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
405 406 407 408 409 410 411 412 413 414
				}
				break;
			case 'getSectionTitle':
				$required = array("title", "section");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of getSectionTitle...');
				$starttime = microtime (true);
				try {
					$ret = $this->getSectionTitle($Param[0]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
415
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
416 417
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
418
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
419 420 421 422
				}
				break;
			// Admin functions
			case 'deletePage':
423
				$required = array("title", "reason");
Luke081515's avatar
Luke081515 committed
424 425 426 427 428 429
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of deletePage...');
				$starttime = microtime (true);
				try {
					$ret = $this->deletePage($Param[0], $Param[1]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
430
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
431 432
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
433
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
434 435 436 437 438 439 440 441 442 443 444 445 446
				}
				break;
			case 'blockUser':
				$required = array("user", "reason", "expiry");
				$optional = array("anononly", "nocreate", "autoblock", "noemail", "hidename", "allowusertalk", "reblock");
				$optvalues = array(1, 1, 1, 0, 0, 1, 0);
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of blockUser...');
				$starttime = microtime (true);
				try {
					$ret = $this->blockUser($Param[0], $Param[1], $Param[2], intval($Param[3]), intval($Param[4]),
						intval($Param[5]), intval($Param[6]), intval($Param[7]), intval($Param[8]), intval($Param[9]));
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
447
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
448 449
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
450
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
451 452 453 454 455 456 457 458 459 460
				}
				break;
			case 'unblockUser':
				$required = array("user", "reason");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of unblockUser...');
				$starttime = microtime (true);
				try {
					$ret = $this->unblockUser($Param[0], $Param[1]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
461
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
462 463
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
464
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
465 466 467
				}
				break;
			case 'protectPage':
468
				$required = array("title", "reason", "protections", "expiry", "cascade");
Luke081515's avatar
Luke081515 committed
469 470 471 472 473 474
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of protectPage...');
				$starttime = microtime (true);
				try {
					$ret = $this->protectPage($Param[0], $Param[1], $Param[2], $Param[3], $Param[4]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
475
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
476 477
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
478
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
479 480 481 482 483 484 485 486 487 488
				}
				break;
			case 'stabilize':
				$required = array("title", "expiry", "reason", "default", "autoreview", "review");
				$Param = $this->getParams($required);
				$this->echoNotice('Starting the function call of stabilize...');
				$starttime = microtime (true);
				try {
					$ret = $this->stabilize($Param[0], $Param[1], $Param[2], $Param[3], $Param[4]);
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
489
					$this->processFunction($ret, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
490 491
				} catch (Exception $e) {
					$endtime = microtime (true);
Luke081515's avatar
Luke081515 committed
492
					$this->processError($e, $starttime, $endtime);
Luke081515's avatar
Luke081515 committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
				}
				break;
			default:
				throw new Exception("This function does not exist, or is not configured.");
		}
	}
	/** getParams
	* This method gets the params from the user
	* There are two lists, one with params, one with optional params
	*/
	private function getParams($ParamList, $ParamOptList = null, $ParamOptDefault = null) {
		$a = 0;
		while (isset($ParamList[$a])) {
			$Param[$a] = $this->askRequired('Enter the value for the param ' . $ParamList[$a] . ' to use:');
			$a++;
		}
		$b = 0;
		while (isset($ParamOptList[$b])) {
			$res = $this->askOptional('Enter the value for the optional param ' . $ParamOptList[$b] . ' (Leave blank to use default):');
			if ($res === "")
				$Param[$a] = $ParamOptDefault[$b];
			$a++;
			$b++;
		}
		return $Param;
	}
	/** echoCritical
	* Writes out a critical message
	* Use this only for critical messages
	* Prints out the message in red
	*/
	private function echoCritical($msg) {
525
		echo "\n\033[01;31m" . $msg . "\033[0m";
Luke081515's avatar
Luke081515 committed
526 527 528 529 530 531
	}
	/** echoSuccessful
	* Use this only when a task was successful
	* Prints out the message in green
	*/
	private function echoSuccessful($msg) {
532
		echo "\n\033[01;32m" . $msg . "\033[0m";
Luke081515's avatar
Luke081515 committed
533 534 535 536 537 538 539
	}
	/** echoWarning
	* Writes out a warning
	* Use this only for non-critical warnings
	* Prints the message out in yellow
	*/
	private function echoWarning($msg) {
540
		echo "\n\033[01;33m" . $msg . "\033[0m";
Luke081515's avatar
Luke081515 committed
541 542 543 544 545 546 547
	}
	/** echoNotice
	* Writes out a notice
	* Use this only for notices, no output, no warnings/errors
	* Prints the message out in blue
	*/
	private function echoNotice($msg) {
548
		echo "\n\033[01;34m" . $msg . "\033[0m";
Luke081515's avatar
Luke081515 committed
549 550 551 552 553 554 555
	}
	/** echoOutput
	* Writes out the output of a function
	* Use this only for function output
	* Prints the message out in purple
	*/
	private function echoOutput($msg) {
556
		echo "\n\033[01;35m" . $msg . "\033[0m";
Luke081515's avatar
Luke081515 committed
557 558 559 560 561 562 563
	}
	/** askRequired
	* Asks for something
	* Use this only if the answer is required
	* Prints the answer in yellow
	*/
	private function askRequired($msg) {
564
		return $this->askOperator("\n\033[01;33m" . $msg . "\033[0m");
Luke081515's avatar
Luke081515 committed
565 566 567 568 569 570 571
	}
	/** askOptional
	* Asks for something
	* Use this only if the answer is optional (additional param for example)
	* Prints the answer in cyan
	*/
	private function askOptional($msg) {
572
		return $this->askOperator("\n\033[01;36m" . $msg . "\033[0m");
Luke081515's avatar
Luke081515 committed
573 574 575 576
	}
	/** processFunction
	* Internal, used for successful calls
	*/
Luke081515's avatar
Luke081515 committed
577
	private function processFunction($ret, $starttime, $endtime) {
Luke081515's avatar
Luke081515 committed
578 579 580 581 582 583 584 585 586 587
		$total = $endtime - $starttime;
		$this->echoSuccessful('Function call succeeded');
		$this->echoNotice('Performance: ' . $total . ' seconds');
		$answer = $this->askRequired('Display the result now? [y/N]');
		if (strtolower($answer) !== 'n')
			$this->echoOutput($ret);
	}
	/** processError
	* Internal, used for errors
	*/
Luke081515's avatar
Luke081515 committed
588
	private function processError ($err, $starttime, $endtime) {
Luke081515's avatar
Luke081515 committed
589 590 591 592 593 594 595 596 597
		$total = $endtime - $starttime;
		$this->echoCritical('Function call failed after ' . $total . ' seconds');
		$answer = $this->askRequired('Display the error now? [y/N]');
		if (strtolower($answer) !== 'n')
			$this->echoWarning($err);
	}
}
$Bot = new Debug();
?>