2
0

view_diff_data.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from .tool.func import *
  2. def view_diff_data_2(conn, name):
  3. curs = conn.cursor()
  4. if acl_check(name, 'render') == 1:
  5. return re_error('/ban')
  6. first = number_check(flask.request.args.get('first', '1'))
  7. second = number_check(flask.request.args.get('second', '1'))
  8. curs.execute(db_change("select title from history where title = ? and (id = ? or id = ?) and hide = 'O'"), [name, first, second])
  9. if curs.fetchall() and admin_check(6) != 1:
  10. return re_error('/error/3')
  11. curs.execute(db_change("select data from history where id = ? and title = ?"), [first, name])
  12. first_raw_data = curs.fetchall()
  13. if first_raw_data:
  14. first_raw_data = first_raw_data[0][0].replace('\r', '')
  15. curs.execute(db_change("select data from history where id = ? and title = ?"), [second, name])
  16. second_raw_data = curs.fetchall()
  17. if second_raw_data:
  18. second_raw_data = second_raw_data[0][0].replace('\r', '')
  19. if first == second:
  20. result = ''
  21. elif first_raw_data == second_raw_data:
  22. result = ''
  23. else:
  24. i = 1
  25. include_ins = 0
  26. diff_data = diff_match_patch().diff_prettyHtml(diff_match_patch().diff_main(first_raw_data, second_raw_data))
  27. end_data = ''
  28. re_data = re.findall(r'(?:(?:(?:(?!&para;<br>).)*)(?:&para;<br>)|(?:(?:(?!&para;<br>).)+)$)', diff_data)
  29. for re_in_data in re_data:
  30. re_in_data = re.sub(r'&para;<br>$', '', re_in_data)
  31. if re.search(r'<ins (((?!<\/ins>).)+)<\/ins>', re_in_data):
  32. end_data += str(i) + ' : ' + re_in_data + '\n'
  33. include_ins = 0
  34. elif re.search(r'(<ins |<del )', re_in_data) and re.search(r'(<\/ins>|<\/del>)', re_in_data):
  35. end_data += str(i) + ' : ' + re_in_data + '\n'
  36. include_ins = 1
  37. elif re.search(r'(<\/ins>|<\/del>)', re_in_data):
  38. end_data += str(i) + ' : ' + re_in_data + '\n'
  39. include_ins = 0
  40. elif re.search(r'(<ins |<del )', re_in_data) or include_ins == 1:
  41. end_data += str(i) + ' : ' + re_in_data + '\n'
  42. include_ins = 1
  43. else:
  44. include_ins = 0
  45. i += 1
  46. result = '<pre>' + end_data + '</pre>'
  47. return easy_minify(flask.render_template(skin_check(),
  48. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('compare') + ')', 0])],
  49. data = result,
  50. menu = [['history/' + url_pas(name), load_lang('return')]]
  51. ))
  52. return redirect('/history/' + url_pas(name))