AnserWikiBrowser.php 2.68 KB
Newer Older
~rs's avatar
~rs committed
1 2
#!/usr/bin/php
<?php
Luke081515's avatar
Luke081515 committed
3 4
require './Core/BotCore.php';
/** AnserWikiBrowser.php
~rs's avatar
~rs committed
5
* Opens a page in a user-defined editor and let’s you do things.
Luke081515's avatar
Luke081515 committed
6
* @Author KPFC
~rs's avatar
~rs committed
7 8
* @Version 0.1
* @Status Alpha
Luke081515's avatar
Luke081515 committed
9 10 11 12
*/
class AnserWikiBrowser extends Core {
	public function __construct ($Account, $Job, $pUseHTTPS = true) {
		$this->initcurl($Account, $Job, $pUseHTTPS); //login
~rs's avatar
~rs committed
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
		//ask for editor to use
		$editor = $this->askOperator('Enter your favorit text editor:');
		if (!$editor) {
			$editor = 'code'; //change this as you like
		}
		$exit = false;
		$pagename = $this->askOperator('Enter the page to view:');
		//create temporary file to edit
		$page_tmp = tempnam(__DIR__, 'AnserBrowser_');
		while (!$exit) {
			$pagecontent = $this->readPage($pagename);
			$action = "read";
			$head[0] = "/* HEAD\n * PAGE: $pagename\n * ACTION: $action\n**/\n";
			fwrite(fopen($page_tmp, 'a+'), $head[0] . $pagecontent);
			if ($editor !== 'vi') {
				popen($editor . ' ' . $page_tmp, "w");
			} else {
				echo "Please open $page_tmp with vi.";
			}
			echo "Replace \"ACTION: $action\" with the action you want to perform.\n";
			echo "Replace \"PAGE: $pagename\" with the page you want to perform the action on.\n";
			$action = $this->askOperator('Done?');
			//read what to do from new file content
			preg_match("~/\* HEAD\n \* PAGE: (.*)\n \* ACTION: (.*)\n\*\*/\n~", file_get_contents($page_tmp), $head);
			$pagecontent = substr(file_get_contents($page_tmp), strlen($head[0]));
			if ($action === "") {
				$action = $head[2];
			}
			//save page
			switch ($action) {
				case "edit":
				case "save":
				case "e":
					$this->editPage ($pagename, $pagecontent, $this->askOperator('Edit Summary:'));
					echo "saved edit …\n";
					break;
				case "read":
				case "r":
					break;
				case "history": //here has to be more
				case "h":
					break;
				case "move":
				case "m":
					$this->movePage ($pagename, $this->askOperator('New Pagename:'), $this->askOperator('Reason:'));
					break;
				case "purge":
				case "*":
					$this->purge ($pagename);
					break;
				case "watch":
				case "w":
					$this->watch ($pagename);
					break;
				case "delete":
				case "d":
					$this->deletePage ($pagename, $this->askOperator('Reason:'));
					break;
				case "protect":
				case "p":
					$this->protectPage ($pagename, $this->askOperator('Reason:'), $this->askOperator('Protections:'), $this->askOperator('Expiry:'), $this->askOperator('Cascade:'));
					break;
				case "quit":
				case "exit":
				case "q":
					$exit = true;
					break;
			}
			$pagename = $head[1];
		}
		//delete temporary file
		unlink($page_tmp);
	}
}
Luke081515's avatar
Luke081515 committed
87
$Bot = new AnserWikiBrowser('KPFC@test2wiki', 'Custom-Edit'); // Aufrufen der definierten Passwortdaten in Password.php
~rs's avatar
~rs committed
88
?>