view_diff_data.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. curs.execute(db_change("select data from history where id = ? and title = ?"), [second, name])
  14. second_raw_data = curs.fetchall()
  15. if first_raw_data and second_raw_data:
  16. first_raw_data = first_raw_data[0][0].replace('\r', '')
  17. second_raw_data = second_raw_data[0][0].replace('\r', '')
  18. if first_raw_data == second_raw_data:
  19. result = ''
  20. else:
  21. i = 1
  22. change_count = 0
  23. diff_data = diff_match_patch().diff_prettyHtml(
  24. diff_match_patch().diff_main(first_raw_data, second_raw_data)
  25. )
  26. end_data = ''
  27. diff_data = diff_data.replace('&para;<br>', '\n')
  28. diff_data = diff_data.replace('<span>', '')
  29. diff_data = diff_data.replace('</span>', '')
  30. re_data = re.findall(r'(?:(?:(?:(?!\n).)*)(?:\n)|(?:(?:(?!\n).)+)$)', diff_data)
  31. for re_in_data in re_data:
  32. change_find_start = len(re.findall(r'<(?:del|ins) ', re_in_data))
  33. change_find_end = len(re.findall(r'<\/(?:del|ins)>', re_in_data))
  34. change_count += (change_find_start - change_find_end)
  35. if change_count != 0 or change_find_start != 0 or change_find_end != 0:
  36. end_data += str(i) + ' : ' + re_in_data
  37. i += 1
  38. result = '<pre>' + end_data + '</pre>'
  39. return easy_minify(flask.render_template(skin_check(),
  40. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('compare') + ')', 0])],
  41. data = result,
  42. menu = [['history/' + url_pas(name), load_lang('return')]]
  43. ))
  44. else:
  45. return redirect('/history/' + url_pas(name))