recent_change.py 11 KB

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