Commit ca025b68 authored by ~rs's avatar ~rs

Update EditInEditor.php; make oo

parent af19efed
Pipeline #1926 failed with stages
in 49 seconds
#!/usr/bin/php
p
<?php
require './Core/BotCore.php';
# commented out: show diff before saving
......@@ -10,32 +10,53 @@ require './Core/BotCore.php';
* @Status Alpha
*/
class EditInEditor extends Core {
public function __construct ($Account, $Job, $pUseHTTPS = true, $botflag, $pagename, $minor = false, $fast = false) {
$this->initcurl($Account, $Job, $pUseHTTPS, "user"); //login
$editor = 'code'; //change this as you like
$pagecontent = $this->readPage($pagename);
public function __construct ($Account = null, $Job = null, $pUseHTTPS = true, $botflag = true) {
$this->$Account = $Account;
$this->$Job = $Job;
$this->$pUseHTTPS = $pUseHTTPS;
$this->$botflag = $botflag;
}
public function login($Account = $this->$Account, $Job = $this->$Job, $pUseHTTPS = $this->$pUseHTTPS, $botflag = $this->$botflag) {
if ($botflag) {
$this->initcurl($Account, $Job, $pUseHTTPS, "bot");
} else {
$this->initcurl($Account, $Job, $pUseHTTPS, "user"); //login
}
// variables further used from save()
$this->$Account = $Account;
$this->$Job = $Job;
$this->$botflag = $botflag;
}
//set the editor you want to use with the command used to run it
public function setEditor($editor) {
$this->$editor = $editor;
}
public function edit($pagename) {
$this->$pagename = $pagename;
$this->$pagecontent = $this->readPage($pagename);
//create temporary file to edit
$page_tmp = tempnam(__DIR__, '.tmp_EiE_');
fwrite(fopen($page_tmp, 'a+'), $pagecontent);
popen($editor . ' ' . $page_tmp, "w");
fwrite(fopen($page_tmp, 'a+'), $this->$pagecontent);
popen($this->$editor . ' ' . $page_tmp, "w");
$this->askOperator('Done?');
$oldcontent = $pagecontent;
$pagecontent = file_get_contents($page_tmp);
# $oldcontent = $pagecontent;
$this->$pagecontent = file_get_contents($page_tmp);
//delete temporary file
unlink($page_tmp);
//save page
# $differ = new \Diff\Differ\MapDiffer();
# $diff = $differ->doDiff(str_split($oldcontent), str_split($pagecontent));
if (!$fast) {
# print_r( $diff );
if ($this->askOperator('Save? [Y/n]' === 'n')) {
$not = true;
}
}
if (!$not) {
$this->editPageD($pagename, $pagecontent, $Job, $botflag, $minor, 0, false);
}
}
/* does not work this way
public function showDiff() {
$differ = new \Diff\Differ\MapDiffer();
$diff = $differ->doDiff(str_split($oldcontent), str_split($pagecontent));
echo $diff;
}
*/
public function save(bool $minor) {
$this->editPageD($this->$pagename, $this->$pagecontent, $this->$Job, $this->$botflag, $minor, 0, false);
}
}
$Bot = new EditInEditor ('KPFC@dewiki', 'Custom-Edit', true, false, 'test', false, false); // Aufrufen der definierten Passwortdaten in Password.php
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment