recent_change.py 11 KB

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