edit_move.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. from .tool.func import *
  2. def edit_move(name):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if acl_check(name) == 1:
  6. return re_error('/ban')
  7. if do_title_length_check(name) == 1:
  8. return re_error('/error/38')
  9. if flask.request.method == 'POST':
  10. move_title = flask.request.form.get('title', 'test')
  11. if acl_check(move_title) == 1:
  12. return re_error('/ban')
  13. if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  14. return re_error('/error/13')
  15. else:
  16. captcha_post('', 0)
  17. if do_edit_slow_check() == 1:
  18. return re_error('/error/24')
  19. send = flask.request.form.get('send', '')
  20. agree = flask.request.form.get('copyright_agreement', '')
  21. time = get_time()
  22. ip = ip_check()
  23. move_option = flask.request.form.get('move_option', 'normal')
  24. if do_edit_send_check(send) == 1:
  25. return re_error('/error/37')
  26. if do_edit_text_bottom_check_box_check(agree) == 1:
  27. return re_error('/error/29')
  28. # 문서 이동 파트 S
  29. if (
  30. move_option == 'merge' and
  31. admin_check(None, 'merge documents (' + name + ') (' + move_title + ')') == 1
  32. ):
  33. curs.execute(db_change("select data from data where title = ?"), [move_title])
  34. data = curs.fetchall()
  35. if data:
  36. curs.execute(db_change("delete from data where title = ?"), [move_title])
  37. curs.execute(db_change("delete from back where link = ?"), [move_title])
  38. curs.execute(db_change("select data from data where title = ?"), [name])
  39. data = curs.fetchall()
  40. if data:
  41. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  42. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  43. data_in = data[0][0]
  44. else:
  45. data_in = ''
  46. history_plus(
  47. name,
  48. data_in,
  49. time,
  50. ip,
  51. send,
  52. '0',
  53. t_check = 'merge <a>' + name + '</a> - <a>' + move_title + '</a> move',
  54. mode = 'move'
  55. )
  56. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  57. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  58. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [move_title])
  59. data = curs.fetchall()
  60. num = data[0][0]
  61. curs.execute(db_change("select id from history where title = ? order by id + 0 asc"), [name])
  62. data = curs.fetchall()
  63. for move in data:
  64. curs.execute(db_change("update rc set title = ?, id = ? where title = ? and id = ?"), [
  65. move_title,
  66. str(int(num) + int(move[0])),
  67. name,
  68. move[0]
  69. ])
  70. curs.execute(db_change("update history set title = ?, id = ? where title = ? and id = ?"), [
  71. move_title,
  72. str(int(num) + int(move[0])),
  73. name,
  74. move[0]
  75. ])
  76. elif move_option == 'reverse':
  77. var_name = ''
  78. i = 0
  79. while 1:
  80. curs.execute(db_change("select title from history where title = ?"), ['test ' + str(i)])
  81. if not curs.fetchall():
  82. var_name = 'test ' + str(i)
  83. break
  84. else:
  85. i += 1
  86. curs.execute(db_change("select data from data where title = ?"), [name])
  87. data = curs.fetchall()
  88. if data:
  89. curs.execute(db_change("update data set title = ? where title = ?"), [var_name, name])
  90. curs.execute(db_change("update back set link = ? where link = ?"), [var_name, name])
  91. curs.execute(db_change("update history set title = ? where title = ?"), [var_name, name])
  92. curs.execute(db_change("update rc set title = ? where title = ?"), [var_name, name])
  93. for title_name in [[move_title, name], [var_name, move_title]]:
  94. curs.execute(db_change("select data from data where title = ?"), [title_name[0]])
  95. data = curs.fetchall()
  96. if data:
  97. curs.execute(db_change("update data set title = ? where title = ?"), [title_name[1], title_name[0]])
  98. curs.execute(db_change("update back set link = ? where link = ?"), [title_name[1], title_name[0]])
  99. data_in = data[0][0]
  100. else:
  101. data_in = ''
  102. history_plus(
  103. title_name[0],
  104. data_in,
  105. time,
  106. ip,
  107. send,
  108. '0',
  109. t_check = '<a>' + (title_name[0] if title_name[0] != var_name else name) + '</a> - <a>' + title_name[1] + '</a> move',
  110. mode = 'move'
  111. )
  112. curs.execute(db_change("update history set title = ? where title = ?"), [title_name[1], title_name[0]])
  113. curs.execute(db_change("update rc set title = ? where title = ?"), [title_name[1], title_name[0]])
  114. else:
  115. curs.execute(db_change("select title from history where title = ?"), [move_title])
  116. if curs.fetchall():
  117. return re_error('/error/19')
  118. curs.execute(db_change("select data from data where title = ?"), [name])
  119. data = curs.fetchall()
  120. if data:
  121. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  122. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  123. data_in = data[0][0]
  124. else:
  125. data_in = ''
  126. history_plus(
  127. name,
  128. data_in,
  129. time,
  130. ip,
  131. send,
  132. '0',
  133. t_check = '<a>' + name + '</a> - <a>' + move_title + '</a> move',
  134. mode = 'move'
  135. )
  136. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  137. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  138. curs.execute(db_change("update history set title = ? where title = ?"), [move_title, name])
  139. curs.execute(db_change("update rc set title = ? where title = ?"), [move_title, name])
  140. # 문서 이동 파트 E
  141. # 토론 이동 파트 S
  142. '''
  143. move_option_topic = flask.request.form.get('move_topic_option', 'none')
  144. if (
  145. move_option_topic == 'merge' and
  146. admin_check(None, 'merge document\'s topics (' + name + ') (' + move_title + ')') == 1
  147. ):
  148. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  149. elif move_option_topic == 'reverse':
  150. elif move_option_topic == 'normal':
  151. '''
  152. # 토론 이동 파트 E 제작중
  153. conn.commit()
  154. return redirect('/w/' + url_pas(move_title))
  155. else:
  156. # 설정 값 제작 필요
  157. return easy_minify(flask.render_template(skin_check(),
  158. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('move') + ')', 0])],
  159. data = '''
  160. <form method="post">
  161. <span>''' + load_lang('document_name') + '''</span>
  162. <hr class="main_hr">
  163. <input value="''' + name + '''" name="title" type="text">
  164. <hr class="main_hr">
  165. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  166. <hr class="main_hr">
  167. <h2>''' + load_lang('document') + '''</h2>
  168. <select name="move_option">
  169. <option value="normal"> ''' + load_lang('normal') + '''</option>
  170. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  171. ''' + ('<option value="merge"> ' + load_lang('merge_move') + '</option>' if admin_check() == 1 else '') + '''
  172. </select>
  173. <hr class="main_hr">
  174. <h2>''' + load_lang('discussion') + ''' (''' + load_lang('not_working') + ''')</h2>
  175. <select name="move_topic_option">
  176. <option value="none"> ''' + load_lang('dont_move') + '''</option>
  177. <option value="normal"> ''' + load_lang('normal') + '''</option>
  178. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  179. ''' + ('<option value="merge"> ' + load_lang('merge_move') + '</option>' if admin_check() == 1 else '') + '''
  180. </select>
  181. <hr class="main_hr">
  182. ''' + captcha_get() + ip_warning() + get_edit_text_bottom_check_box() + get_edit_text_bottom() + '''
  183. <button type="submit">''' + load_lang('move') + '''</button>
  184. </form>
  185. ''',
  186. menu = [['w/' + url_pas(name), load_lang('return')]]
  187. ))