recent_change.py 11 KB

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