Skip to content

Commit

Permalink
Tweaks to image copy/paste
Browse files Browse the repository at this point in the history
  • Loading branch information
turnermm committed Nov 29, 2018
1 parent 92ac98c commit a1e28c4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion action/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
*/

class action_plugin_ckgedit_save extends DokuWiki_Action_Plugin {

var $helper = false;
function register(Doku_Event_Handler $controller) {

$controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'ckgedit_save_preprocess');
}

function ckgedit_save_preprocess(Doku_Event $event){
global $ACT,$INPUT;
$this->helper = $this->loadhelper('ckgedit');
if (!isset($_REQUEST['ckgedit']) || ! is_array($ACT) || !(isset($ACT['save']) || isset($ACT['preview']))) return;
if (isset($_REQUEST["fontdel"]) ) {
msg($this->getLang("fontdel"),1);
Expand Down Expand Up @@ -186,6 +187,9 @@ function ckgedit_save_preprocess(Doku_Event $event){
$TEXT = preg_replace_callback(
'#\[\[(.*?)\]\]#ms',
function($matches){
if($this->helper->has_plugin('button') && strpos($matches[0], '[[{') === 0) {
return $matches[0];
}
if(preg_match('/(doku|this)\s*>/',$matches[0])) return $matches[0]; // exclude dokuwiki's wiki links
global $ID, $conf;
$qs = "";
Expand Down
6 changes: 3 additions & 3 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ function FCKeditor_OnComplete( editorInstance )
var len = e.data.dataValue.length;
var len = e.data.dataValue.length - 'data:image/png;base64,'.length;
var size = formatBytes(len,1);
var broken_msg = "$ckg_brokenimg " + size
if(e.data.dataValue.match(/data:image\/\w+;base64/) && len > 1000000) {
var broken_msg = ckg_RawImgMsg();
broken_msg += " " + size;
if(e.data.dataValue.match(/data:image\/\w+;base64/) && len > 2500000) {
alert(broken_msg);
e.data.dataValue = '<img src ='+ broken_image + '/>';
}
Expand Down
5 changes: 4 additions & 1 deletion lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@
$lang['off'] ='off';
$lang['js']['on'] ='on';
$lang['js']['off'] ='off';
$lang['broken_image'] = 'Use the imagePaste plugin with the Dokuwiki Mediamanager. Raw data of Ctrl-v images cannot exceed 1M. This image is: ';
$lang['broken_image'] = "Use the imagePaste plugin with the Dokuwiki Mediamanager or try the MS Word Paste Tool. Raw data of Ctrl-v images over 2.5M can hang. This image is: " ;
$lang['js']['broken_image_1'] = "Use the imagePaste plugin with the Dokuwiki Mediamanager or try the MS Word Paste Tool.";
$lang['js']['broken_image_2'] = "Ctrl-v images with raw data over 2.5M can hang. This image is: " ;


2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base ckgedit
author Myron Turner
email [email protected]
date 2018-11-24
date 2018-11-28
name ckgedit
desc WYSIWYG plugin for Dokuwiki
url https://www.dokuwiki.org/plugin:ckgedit
Expand Down
6 changes: 5 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var HTMLParser_Elements = new Array();
skip = true;
match = match.replace(/msword/,"");
}
if(p2.length > 1000000 && !skip ) {
if(p2.length > 2500000 && !skip ) {
jQuery('#dw__editform').append('<input type="hidden" id="broken_image" name="broken_image" value="' + p2.length +'" />');
return '{{' + broken_image + '}}';
}
Expand Down Expand Up @@ -268,6 +268,7 @@ function dwedit_draft_delete() {
document.cookie = 'ckgEdht=' + h +';expires="";path=' +JSINFO['doku_base'];
}

/* enable disable image paste */
function ckgd_setImgPaste(which) {
var state = JSINFO['ckgEdPaste'] ? JSINFO['ckgEdPaste'] : "";
if(state == 'on') {
Expand All @@ -279,6 +280,9 @@ function dwedit_draft_delete() {
alert(LANG.plugins.ckgedit.ckg_paste_restart + ' ' + LANG.plugins.ckgedit[which]);
}

function ckg_RawImgMsg() {
return LANG.plugins.ckgedit.broken_image_1 + "\n" + LANG.plugins.ckgedit.broken_image_2 ;
}
function GetE(e) {
return document.getElementById(e);
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/parse_wiki.js.unc
Original file line number Diff line number Diff line change
Expand Up @@ -1894,13 +1894,14 @@ results = results.replace(/(\s*={2,})(.*?)(\[\[|\{\{)(.*?)(\]\]|\}\})(.*?)\1/gm,
if(!useComplexTables) { results = results.replace(/~~COMPLEX_TABLES~~/gm,""); }
results=results.replace(/_CKG_ASTERISK_/gm,'*');
results = results.replace(/_ESC_BKSLASH_/g,'\\');
results=results.replace(/divalNLine/gm,"\n");
if(id == 'test') {
if(HTMLParser_test_result(results)) {
alert(results);
}
return;
}
results=results.replace(/divalNLine/gm,"\n")

var dwform = GetE('dw__editform');
dwform.elements.fck_wikitext.value = results;

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
master_18-Nov_24-05_23
master_18-Nov_28-19_27

0 comments on commit a1e28c4

Please sign in to comment.