made markdown/showdown image processing codepot wiki-aware

This commit is contained in:
hyung-hwan 2016-01-17 14:06:33 +00:00
parent 16d4213c53
commit 45d2d50ba6
5 changed files with 126 additions and 86 deletions

View File

@ -470,9 +470,6 @@ class Wiki extends Controller
function attachment0 ($projectid = '', $target = '')
{
//$target => projectid:wikiname:attachment
//$target => projectid:#I1:file
$login = $this->login->getUser ();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
@ -489,6 +486,8 @@ class Wiki extends Controller
$part = explode (':', $target);
if (count($part) == 3)
{
//$target => projectid:wikiname:attachment
//$target => projectid:#I1:file
if ($part[0] == '') $part[0] = $projectid;
if ($part[1][0] == '#' && $part[1][1] == 'I')
{
@ -500,6 +499,20 @@ class Wiki extends Controller
$this->_handle_wiki_attachment ($login, $part[0], $part[1], $part[2]);
}
}
else if (count($part) == 2)
{
//$target => wikiname:attachment
//$target => #I1:file
if ($part[0][0] == '#' && $part[0][1] == 'I')
{
$issueid = substr ($part[0],2);
$this->_handle_issue_file ($login, $projectid, $issueid, $part[1]);
}
else
{
$this->_handle_wiki_attachment ($login, $projectid, $part[0], $part[1]);
}
}
}
function attachment ($projectid = '', $wikiname = '', $filename = '')
@ -538,6 +551,25 @@ class Wiki extends Controller
}
if ($part[2] != '') $filename = $part[2];
}
else if (count($part) == 2)
{
//$target => wikiname:attachment
//$target => #I1:file
if ($part[0] != '')
{
if ($part[0][0] == '#' && $part[0][1] == 'I')
{
$issueid = substr ($part[0],2);
$wikiname = '';
}
else
{
$wikiname = $part[0];
$issueid = '';
}
}
if ($part[1] != '') $filename = $part[1];
}
if ($wikiname != '')
$this->_handle_wiki_attachment ($login, $projectid, $wikiname, $filename);

View File

@ -32,6 +32,10 @@ $file_count = count($wiki->attachments);
<script type="text/javascript">
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
var previewing_text = false;
function show_alert (outputMsg, titleMsg)
{
$('#wiki_edit_alert').html(outputMsg).dialog({
@ -48,8 +52,33 @@ function show_alert (outputMsg, titleMsg)
});
}
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
var previewing_text = false;
buttons: {
"OK": function () {
// do nothing, don't event close the dialog.
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function resize_text_editor()
{
@ -76,7 +105,6 @@ function resize_text_editor()
}
}
function preview_text (input_text)
{
if (previewing_text)
@ -107,7 +135,7 @@ function preview_text (input_text)
input_text,
"wiki_edit_text_preview",
"<?php print site_url()?>/wiki/show/<?php print $project->id?>/",
"<?php print site_url()?>/wiki/attachment0/<?php print $project->id?>/",
"<?php print site_url()?>/wiki/attachment/<?php print $project->id?>/" + codepot_string_to_hex(wiki_original_name) + "/",
true // raw
);
}
@ -117,7 +145,7 @@ function preview_text (input_text)
input_text,
"wiki_edit_text_preview",
"<?php print site_url()?>/wiki/show/<?php print $project->id?>/",
"<?php print site_url()?>/wiki/attachment0/<?php print $project->id?>/",
"<?php print site_url()?>/wiki/attachment/<?php print $project->id?>/" + codepot_string_to_hex(wiki_original_name) + "/",
true // raw
);
}
@ -204,7 +232,6 @@ function kill_file (no)
resize_text_editor ();
}
function update_original_file_name_array ()
{
$('#wiki_edit_add_file_list').empty();
@ -259,37 +286,6 @@ function update_original_file_name_array ()
var wiki_text_editor = null;
var work_in_progress = false;
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
buttons: {
"OK": function () {
// do nothing
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function save_wiki (wiki_new_name, wiki_new_text)
{

View File

@ -37,6 +37,8 @@ $file_count = count($wiki->attachments);
?>
<script type="text/javascript">
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
function show_alert (outputMsg, titleMsg)
{
@ -54,6 +56,34 @@ function show_alert (outputMsg, titleMsg)
});
}
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
buttons: {
"OK": function () {
// do nothing, don't event close the dialog.
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function resize_editor()
{
var editor = $("#wiki_edit_text_editor");
@ -208,36 +238,6 @@ function update_original_file_name_array ()
var wiki_text_editor = null;
var work_in_progress = false;
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
buttons: {
"OK": function () {
// do nothing
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function save_wiki (wiki_new_name, wiki_new_text)
{

View File

@ -416,16 +416,15 @@ var Url = {
var img = document.createElement('img');
if (r[1].match(rx.uriPrefix))
{
img.src = r[1];
}
else
{
var tmp = r[1].replace(/~(.)/g, '$1');
tmp = Url.encode (tmp);
img.src = options && options.imgFormat?
formatLink (tmp, options.imgFormat): tmp;
}
{
img.src = r[1];
}
else
{
var tmp = r[1].replace(/~(.)/g, '$1');
tmp = Url.encode (tmp);
img.src = options && options.imgFormat? formatLink (tmp, options.imgFormat): tmp;
}
img.alt = r[2] === undefined
? (options && options.defaultImageText ? options.defaultImageText : '')
@ -450,15 +449,15 @@ var Url = {
build: function(node, r, options) {
var link = document.createElement('a');
var tmp = r[1].replace(/~(.)/g, '$1');
tmp = Url.encode (tmp);
var tmp = r[1].replace(/~(.)/g, '$1');
tmp = Url.encode (tmp);
/*link.href = options && options.linkFormat
? formatLink(r[1].replace(/~(.)/g, '$1'), options.linkFormat)
: r[1].replace(/~(.)/g, '$1');*/
link.href = options && options.linkFormat?
formatLink (tmp, options.linkFormat): tmp;
formatLink (tmp, options.linkFormat): tmp;
this.apply(link, r[2], options);

View File

@ -1125,8 +1125,6 @@ showdown.subParser('anchors', function (text, options, globals) {
}
}
url = showdown.helper.escapeCharacters(url, '*_', false);
// codepot
var front2 = url.substr(0, 2);
var front3 = url.substr(0, 3);
@ -1140,6 +1138,8 @@ showdown.subParser('anchors', function (text, options, globals) {
url = options.codepotLinkBase + codepot_string_to_hex(url);
}
// end codepot
url = showdown.helper.escapeCharacters(url, '*_', false);
var result = '<a href="' + url + '"';
if (title !== '' && title !== null) {
@ -1908,7 +1908,20 @@ showdown.subParser('images', function (text, options, globals) {
}
altText = altText.replace(/"/g, '&quot;');
altText = showdown.helper.escapeCharacters(altText, '*_', false);
altText = showdown.helper.escapeCharacters(altText, '*_', false);
// codepot
if (url.match (/^[a-zA-Z]+:\/\//))
{
// begins with XXX://
// do nothing special
}
else
{
url = options.codepotImageBase + codepot_string_to_hex(url);
}
// end codepot
url = showdown.helper.escapeCharacters(url, '*_', false);
var result = '<img src="' + url + '" alt="' + altText + '"';
@ -2548,7 +2561,7 @@ function showdown_render_wiki_with_input_text (input_text, outputid, linkbase, i
tasklists: true,
codepotLinkBase: linkbase,
codepotImgBase: imgbase
codepotImageBase: imgbase
});
function decodeEntities(str)