Commit 70605007 authored by ~rs's avatar ~rs

Update EditInEditor.php

parent aa05ab5f
Pipeline #1896 failed with stages
in 48 seconds
#!/usr/bin/php
#!/usr/bin/php
<?php
require './Core/BotCore.php';
//require './Diff/src/DiffOpFactory.php';
/** EditInEditor.php
* Opens a page in a user-defined editor and saves the page after closing the editor
* @Author KPFC
......@@ -8,44 +9,33 @@ require './Core/BotCore.php';
* @Status Alpha
*/
class EditInEditor extends Core {
public function __construct ($Account, $Job, $pUseHTTPS = true) {
public function __construct ($Account, $Job, $pUseHTTPS = true, $botflag, $pagename, $minor = false, $fast = false) {
$this->initcurl($Account, $Job, $pUseHTTPS); //login
//ask for editor to use
// $editor = $this->askOperator('Enter your favorit text editor:');
// if (!$editor) {
$editor = 'kate'; //change this as you like
// }
while (!$exit) {
$pagename = $this->askOperator('Enter the page to edit:');
$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");
$this->askOperator('Done?');
$pagecontent = file_get_contents($page_tmp);
//delete temporary file
unlink($page_tmp);
//save page
$minor = $this->askOperator('Minor? [y/N/a]:');
if (($minor === 'a') || ($minor === 'A')) {
echo "aborted edit …\n";
} else if (($minor === 'y') || ($minor === 'Y') || ($minor === 'yes') || ($minor === 'Yes')) {
$this->editPageMinor($pagename, $pagecontent, $this->askOperator('Edit Summary:'));
echo "saved minor edit …\n";
} else {
$this->editPage ($pagename, $pagecontent, $this->askOperator('Edit Summary:'));
echo "saved edit …\n";
$editor = 'code'; //change this as you like
$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");
$this->askOperator('Done?');
$oldcontent = $pagecontent;
$pagecontent = file_get_contents($page_tmp);
//delete temporary file
unlink($page_tmp);
//save page
$diff = new DiffOpFactory;
Please register or sign in to reply
//$diffOp = array('type' => 'change', 'newvalue' => $pagecontent, 'oldvalue' => $oldcontent);
$diffOp['type'] = 'change';
$diffOp['newvalue'] = $pagecontent;
$diffOp['oldvalue'] = $oldcontent;
if (!$fast) {
echo $diff->newFromArray($diffOp);
if ($this->askOperator('Save? [Y/n]')==='n') {
return 0;
}
$continue = $this->askOperator("Continue? [y/N]");
if (($continue === 'y') || ($continue === 'Y') || ($continue === 'yes') || ($continue === 'Yes')) {
$exit = false;
} else {
$exit = true;
}
}
$this->editPageD($pagename, $pagecontent, $Job, $botflag, $minor, 0, false);
}
}
$Bot = new EditInEditor ('KPFC@dewiki', 'Custom-Edit'); // Aufrufen der definierten Passwortdaten in Password.php
$Bot = new EditInEditor ('KPFC@dewiki', 'Custom-Edit', true, false, 'test', false, false); // Aufrufen der definierten Passwortdaten in Password.php
?>
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