recent_changes.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. one_admin = admin_check(1)
  12. six_admin = admin_check(6)
  13. ban = ''
  14. select = ''
  15. div = '''
  16. <hr class=\"main_hr\">
  17. <table id="main_table_set">
  18. <tbody>
  19. <tr>
  20. '''
  21. if name:
  22. num = int(number_check(flask.request.args.get('num', '1')))
  23. if num * 50 > 0:
  24. sql_num = num * 50 - 50
  25. else:
  26. sql_num = 0
  27. if tool == 'history':
  28. div += '''
  29. <td id="main_table_width">''' + load_lang('version') + '''</td>
  30. <td id="main_table_width">''' + load_lang('editor') + '''</td>
  31. <td id="main_table_width">''' + load_lang('time') + '''</td></tr>
  32. '''
  33. tool_select = flask.request.args.get('tool', None)
  34. if tool_select and tool_select == 'move':
  35. curs.execute(db_change('' + \
  36. 'select id, title, date, ip, send, leng from history ' + \
  37. 'where (send like ? or send like ?) and type = "" ' + \
  38. 'order by id + 0 desc ' + \
  39. "limit ?, 50" + \
  40. ''), ['%(<a>' + name +'</a>%', '%<a>' + name + '</a> move)', sql_num])
  41. else:
  42. curs.execute(db_change('' + \
  43. 'select id, title, date, ip, send, leng from history ' + \
  44. 'where title = ? and type = "" ' + \
  45. 'order by id + 0 desc ' + \
  46. "limit ?, 50" + \
  47. ''), [name, sql_num])
  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. </tr>
  54. '''
  55. div = '<a href="/topic_record/' + url_pas(name) + '">(' + load_lang('discussion') + ')</a><hr class=\"main_hr\">' + div
  56. curs.execute(db_change('' + \
  57. 'select id, title, date, ip, send, leng from history ' + \
  58. "where ip = ? and type = '' order by date desc limit ?, 50" + \
  59. ''), [name, sql_num])
  60. else:
  61. num = int(number_check(flask.request.args.get('num', '1')))
  62. if num * 50 > 0:
  63. sql_num = num * 50 - 50
  64. else:
  65. sql_num = 0
  66. div += '''
  67. <td id="main_table_width">''' + load_lang('document_name') + '''</td>
  68. <td id="main_table_width">''' + load_lang('editor') + '''</td>
  69. <td id="main_table_width">''' + load_lang('time') + '''</td>
  70. </tr>
  71. '''
  72. set_type = flask.request.args.get('set', 'normal')
  73. if set_type == 'normal':
  74. div = '<a href="?set=user">(' + load_lang('user_document') + ')</a> <a href="?set=req">(' + load_lang('edit_req') + ')</a>' + div
  75. if set_type == 'req':
  76. curs.execute(db_change('' + \
  77. 'select id, title, date, ip, send, leng from history ' + \
  78. "where type = 'req' " + \
  79. 'order by date desc ' + \
  80. 'limit ?, 50' + \
  81. ''), [sql_num])
  82. else:
  83. curs.execute(db_change('' + \
  84. 'select id, title, date, ip, send, leng from history ' + \
  85. "where " + ('' if set_type == 'user' else 'not ') + "title like 'user:%' and type = '' " + \
  86. 'order by date desc ' + \
  87. 'limit ?, 50' + \
  88. ''), [sql_num])
  89. data_list = curs.fetchall()
  90. for data in data_list:
  91. select += '<option value="' + data[0] + '">' + data[0] + '</option>'
  92. send = '<br>'
  93. if data[4]:
  94. if not re.search("^(?: *)$", data[4]):
  95. send = data[4]
  96. if re.search("\+", data[5]):
  97. leng = '<span style="color:green;">(' + data[5] + ')</span>'
  98. elif re.search("\-", data[5]):
  99. leng = '<span style="color:red;">(' + data[5] + ')</span>'
  100. else:
  101. leng = '<span style="color:gray;">(' + data[5] + ')</span>'
  102. ip = ip_pas(data[3])
  103. if tool == 'history':
  104. m_tool = '<a href="/history_tool/' + url_pas(data[1]) + '?num=' + data[0] + '&type=history">(' + load_lang('tool') + ')</a>'
  105. else:
  106. m_tool = '<a href="/history_tool/' + url_pas(data[1]) + '?num=' + data[0] + '">(' + load_lang('tool') + ')</a>'
  107. style = ['', '']
  108. date = data[2]
  109. curs.execute(db_change('''
  110. select title from history
  111. where title = ? and id = ? and hide = 'O'
  112. '''), [data[1], data[0]])
  113. hide = curs.fetchall()
  114. if six_admin == 1:
  115. if hide:
  116. style[0] = 'id="toron_color_grey"'
  117. style[1] = 'id="toron_color_grey"'
  118. if send == '<br>':
  119. send = '(' + load_lang('hide') + ')'
  120. else:
  121. send += ' (' + load_lang('hide') + ')'
  122. elif not hide:
  123. pass
  124. else:
  125. ip = ''
  126. ban = ''
  127. date = ''
  128. send = '(' + load_lang('hide') + ')'
  129. style[0] = 'style="display: none;"'
  130. style[1] = 'id="toron_color_grey"'
  131. if tool == 'history':
  132. title = '<a href="/w/' + url_pas(name) + '?num=' + data[0] + '">r' + data[0] + '</a> '
  133. else:
  134. if not name and set_type == 'req':
  135. title = '<a href="/edit_req/' + url_pas(data[1]) + '?r=' + data[0] + '">' + html.escape(data[1]) + ' (r' + data[0] + ')</a> '
  136. else:
  137. title = '<a href="/w/' + url_pas(data[1]) + '">' + html.escape(data[1]) + '</a> '
  138. title += '<a href="/history/' + url_pas(data[1]) + '">(r' + data[0] + ')</a> '
  139. div += '''
  140. <tr ''' + style[0] + '''>
  141. <td>''' + title + m_tool + ' ' + leng + '''</td>
  142. <td>''' + ip + ban + '''</td>
  143. <td>''' + date + '''</td>
  144. </tr>
  145. <tr ''' + style[1] + '''>
  146. <td colspan="3">''' + send_parser(send) + '''</td>
  147. </tr>
  148. '''
  149. div += '''
  150. </tbody>
  151. </table>
  152. '''
  153. sub = ''
  154. if name:
  155. if tool == 'history':
  156. if not tool_select:
  157. div = '''
  158. <a href="?tool=move">(''' + load_lang('move') + ''')</a>
  159. <hr class=\"main_hr\">
  160. ''' + div
  161. div = '''
  162. <form method="post">
  163. <select name="a">''' + select + '''</select> <select name="b">''' + select + '''</select>
  164. <button type="submit">''' + load_lang('compare') + '''</button>
  165. </form>
  166. <hr class=\"main_hr\">
  167. ''' + div
  168. title = name
  169. sub += ' (' + load_lang('history') + ')'
  170. menu = [['w/' + url_pas(name), load_lang('document')], ['raw/' + url_pas(name), load_lang('raw')]]
  171. div += next_fix('/history/' + url_pas(name) + '?num=', num, data_list)
  172. else:
  173. title = load_lang('edit_record')
  174. menu = [['other', load_lang('other')], ['user', load_lang('user')], ['count/' + url_pas(name), load_lang('count')]]
  175. div += next_fix('/record/' + url_pas(name) + '?num=', num, data_list)
  176. else:
  177. menu = 0
  178. title = load_lang('recent_change')
  179. div += next_fix('/recent_changes?num=', num, data_list)
  180. if set_type == 'user':
  181. sub = ' (' + load_lang('user') + ')'
  182. menu = [['recent_changes', load_lang('return')]]
  183. elif set_type == 'req':
  184. sub = ' (' + load_lang('edit_req') + ')'
  185. menu = [['recent_changes', load_lang('return')]]
  186. if sub == '':
  187. sub = 0
  188. return easy_minify(flask.render_template(skin_check(),
  189. imp = [title, wiki_set(), custom(), other2([sub, 0])],
  190. data = div,
  191. menu = menu
  192. ))