recent_change.py 10 KB

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