bsw@2: slot.put_into("title", _"Diff") bsw@2: bsw@2: local old_draft_id = param.get("old_draft_id", atom.integer) bsw@2: local new_draft_id = param.get("new_draft_id", atom.integer) bsw@2: bsw@10: if not old_draft_id or not new_draft_id then bsw@10: slot.put( _"Please choose two versions of the draft to compare") bsw@10: return bsw@10: end bsw@10: bsw@10: if old_draft_id == new_draft_id then bsw@10: slot.put( _"Please choose two different versions of the draft to compare") bsw@10: return bsw@10: end bsw@10: bsw@2: if old_draft_id > new_draft_id then bsw@2: local tmp = old_draft_id bsw@2: old_draft_id = new_draft_id bsw@2: new_draft_id = tmp bsw@2: end bsw@2: bsw@2: local old_draft = Draft:by_id(old_draft_id) bsw@2: local new_draft = Draft:by_id(new_draft_id) bsw@2: bsw@2: local key = multirand.string(26, "123456789bcdfghjklmnpqrstvwxyz"); bsw@2: bsw@2: local old_draft_filename = encode.file_path(request.get_app_basepath(), 'tmp', "diff-" .. key .. "-old.tmp") bsw@2: local new_draft_filename = encode.file_path(request.get_app_basepath(), 'tmp', "diff-" .. key .. "-new.tmp") bsw@2: bsw@2: local old_draft_file = assert(io.open(old_draft_filename, "w")) bsw@2: old_draft_file:write(old_draft.content) bsw@2: old_draft_file:write("\n") bsw@2: old_draft_file:close() bsw@2: bsw@2: local new_draft_file = assert(io.open(new_draft_filename, "w")) bsw@2: new_draft_file:write(new_draft.content) bsw@2: new_draft_file:write("\n") bsw@2: new_draft_file:close() bsw@2: bsw@2: local output, err, status = os.pfilter(nil, "sh", "-c", "diff -U 100000 '" .. old_draft_filename .. "' '" .. new_draft_filename .. "' | grep -v ^--- | grep -v ^+++ | grep -v ^@") bsw@2: bsw@2: os.remove(old_draft_filename) bsw@2: os.remove(new_draft_filename) bsw@2: bsw@2: if not status then bsw@2: ui.field.text{ value = _"The drafts do not differ" } bsw@2: else bsw@2: slot.put('
' .. _"Old draft revision" .. ' | ' .. _"New draft revision" .. ' |
---|---|
", encode.html_newlines(encode.html(text)), " | ", encode.html_newlines(encode.html(text)), " |
', encode.html_newlines(encode.html(text)), " | |
', encode.html_newlines(encode.html(removed_text)), ' | ', encode.html_newlines(encode.html(text)), " |
', encode.html_newlines(encode.html(text)), " |