recent_changes.py 8.5 KB

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