2
0

view_diff_data.py 2.5 KB

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