2
0

recent_change.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. from .tool.func import *
  2. def recent_change_send_render(data):
  3. def send_render_href_replace(match):
  4. match = match.group(1)
  5. data_unescape = html.unescape(match)
  6. return '<a href="/w/' + url_pas(data_unescape) + '">' + match + '</a>'
  7. if data == '&lt;br&gt;' or data == '' or re.search(r'^ +$', data):
  8. data = '<br>'
  9. else:
  10. data = data.replace('javascript:', '')
  11. data = re.sub(r'&lt;a(?:(?:(?!&gt;).)*)&gt;((?:(?!&lt;\/a&gt;).)+)&lt;\/a&gt;', send_render_href_replace, data)
  12. return data
  13. def recent_change(name = '', tool = '', num = 1, set_type = 'normal'):
  14. with get_db_connect() as conn:
  15. curs = conn.cursor()
  16. ip = ip_check()
  17. all_admin = admin_check('all', None, ip)
  18. owner = admin_check(None, None, ip)
  19. option_list = [
  20. ['normal', load_lang('normal')],
  21. ['edit', load_lang('edit')],
  22. ['move', load_lang('move')],
  23. ['delete', load_lang('delete')],
  24. ['revert', load_lang('revert')],
  25. ['r1', load_lang('new_doc')]
  26. ]
  27. if flask.request.method == 'POST':
  28. return redirect('/diff/' + flask.request.form.get('b', '1') + '/' + flask.request.form.get('a', '1') + '/' + url_pas(name))
  29. else:
  30. ban = ''
  31. select = ''
  32. sub = ''
  33. admin = owner
  34. div = '''
  35. <table id="main_table_set">
  36. <tbody>
  37. <tr id="main_table_top_tr">
  38. '''
  39. sql_num = (num * 50 - 50) if num * 50 > 0 else 0
  40. if tool == 'history':
  41. div += '''
  42. <td id="main_table_width">''' + load_lang('version') + '''</td>
  43. <td id="main_table_width">''' + load_lang('editor') + '''</td>
  44. <td id="main_table_width">''' + load_lang('time') + '''</td>
  45. '''
  46. sub = '(' + load_lang('history') + ')'
  47. set_type = '' if set_type == 'edit' else set_type
  48. if set_type != 'normal':
  49. curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where title = ? and type = ? order by id + 0 desc limit ?, 50'), [name, set_type, sql_num])
  50. else:
  51. curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where title = ? order by id + 0 desc limit ?, 50'), [name, sql_num])
  52. data_list = curs.fetchall()
  53. elif tool == 'record':
  54. div += '''
  55. <td id="main_table_width">''' + load_lang('document_name') + '''</td>
  56. <td id="main_table_width">''' + load_lang('editor') + '''</td>
  57. <td id="main_table_width">''' + load_lang('time') + '''</td>
  58. '''
  59. sub = '(' + load_lang('edit_record') + ')'
  60. set_type = '' if set_type == 'edit' else set_type
  61. if set_type != 'normal':
  62. curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where ip = ? and type = ? order by date desc limit ?, 50'), [name, set_type, sql_num])
  63. else:
  64. curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where ip = ? order by date desc limit ?, 50'), [name, sql_num])
  65. data_list = curs.fetchall()
  66. else:
  67. div += '''
  68. <td id="main_table_width">''' + load_lang('document_name') + '''</td>
  69. <td id="main_table_width">''' + load_lang('editor') + '''</td>
  70. <td id="main_table_width">''' + load_lang('time') + '''</td>
  71. '''
  72. sub = ''
  73. set_type = '' if set_type == 'edit' else set_type
  74. data_list = []
  75. if num == 1 or all_admin != 1:
  76. curs.execute(db_change('select title, id from rc where type = ? order by date desc limit 50'), [set_type])
  77. for for_a in curs.fetchall():
  78. curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where title = ? and id = ?'), for_a)
  79. data_list += curs.fetchall()
  80. else:
  81. if set_type != 'normal':
  82. curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where type = ? order by date desc limit ?, 50'), [sql_num])
  83. else:
  84. curs.execute(db_change('select id, title, date, ip, send, leng, hide from history order by date desc limit ?, 50'), [sql_num])
  85. data_list = curs.fetchall()
  86. div += '</tr>'
  87. all_ip = ip_pas([i[3] for i in data_list])
  88. for data in data_list:
  89. select += '<option value="' + data[0] + '">' + data[0] + '</option>'
  90. send = data[4]
  91. if re.search(r"\+", data[5]):
  92. leng = '<span style="color:green;">(' + data[5] + ')</span>'
  93. elif re.search(r"\-", data[5]):
  94. leng = '<span style="color:red;">(' + data[5] + ')</span>'
  95. else:
  96. leng = '<span style="color:gray;">(' + data[5] + ')</span>'
  97. ip = all_ip[data[3]]
  98. m_tool = '<a href="/history_tool/' + data[0] + '/' + url_pas(data[1]) + '">(' + load_lang('tool') + ')</a>'
  99. style = ['', '']
  100. date = data[2]
  101. if data[6] == 'O':
  102. if admin == 1:
  103. style[0] = 'class="opennamu_history_blind"'
  104. style[1] = 'class="opennamu_history_blind"'
  105. else:
  106. ip = ''
  107. ban = ''
  108. date = ''
  109. send = ''
  110. style[0] = 'style="display: none;"'
  111. style[1] = 'class="opennamu_history_blind"'
  112. if tool == 'history':
  113. title = '<a href="/w_rev/' + data[0] + '/' + url_pas(name) + '">r' + data[0] + '</a> '
  114. else:
  115. title = '<a href="/w/' + url_pas(data[1]) + '">' + html.escape(data[1]) + '</a> '
  116. if int(data[0]) < 2:
  117. title += '<a href="/history/' + url_pas(data[1]) + '">(r' + data[0] + ')</a> '
  118. else:
  119. title += '<a href="/diff/' + str(int(data[0]) - 1) + '/' + data[0] + '/' + url_pas(data[1]) + '">(r' + data[0] + ')</a> '
  120. div += '''
  121. <tr ''' + style[0] + '''>
  122. <td>''' + title + m_tool + ' ' + leng + '''</td>
  123. <td>''' + ip + ban + '''</td>
  124. <td>''' + date + '''</td>
  125. </tr>
  126. <tr ''' + style[1] + '''>
  127. <td colspan="3">''' + recent_change_send_render(html.escape(send)) + '''</td>
  128. </tr>
  129. '''
  130. div += '''
  131. </tbody>
  132. </table>
  133. '''
  134. if tool == 'history':
  135. div = '' + \
  136. ' '.join(['<a href="/history_page/1/' + for_a[0] + '/' + url_pas(name) + '">(' + for_a[1] + ')</a> ' for for_a in option_list]) + \
  137. '<hr class="main_hr">' + div + \
  138. ''
  139. menu = [['w/' + url_pas(name), load_lang('return')]]
  140. if set_type == 'normal':
  141. div = '''
  142. <form method="post">
  143. <select name="a">''' + select + '''</select> <select name="b">''' + select + '''</select>
  144. <button type="submit">''' + load_lang('compare') + '''</button>
  145. </form>
  146. <hr class="main_hr">
  147. ''' + div
  148. if admin == 1:
  149. menu += [
  150. ['history_add/' + url_pas(name), load_lang('history_add')],
  151. ['history_reset/' + url_pas(name), load_lang('history_reset')]
  152. ]
  153. title = name
  154. div += get_next_page_bottom('/history_page/{}/' + set_type + '/' + url_pas(name), num, data_list)
  155. elif tool == 'record':
  156. div = '' + \
  157. ' '.join(['<a href="/record/1/' + for_a[0] + '/' + url_pas(name) + '">(' + for_a[1] + ')</a> ' for for_a in option_list]) + \
  158. '<hr class="main_hr">' + div + \
  159. ''
  160. title = name
  161. menu = [
  162. ['other', load_lang('other')],
  163. ['user', load_lang('user')]
  164. ]
  165. if admin == 1:
  166. menu += [['record/reset/' + url_pas(name), load_lang('record_reset')]]
  167. div += get_next_page_bottom('/record/{}/' + url_pas(name), num, data_list)
  168. else:
  169. div = '' + \
  170. ' '.join(['<a href="/recent_change/1/' + for_a[0] + '">(' + for_a[1] + ')</a> ' for for_a in option_list]) + \
  171. '<a href="/recent_change/1/user">(' + load_lang('user_document') + ')</a> ' + \
  172. '<hr class="main_hr">' + div + \
  173. ''
  174. menu = [['other', load_lang('return')]]
  175. title = load_lang('recent_change')
  176. if all_admin == 1:
  177. div += get_next_page_bottom('/recent_change/{}/' + set_type, num, data_list)
  178. if sub == '':
  179. sub = 0
  180. return easy_minify(flask.render_template(skin_check(),
  181. imp = [title, wiki_set(), wiki_custom(), wiki_css([sub, 0])],
  182. data = div,
  183. menu = menu
  184. ))