recent_changes.py 8.6 KB

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