edit_move.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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(conn, name, 'document_move') == 1:
  6. return re_error(conn, '/ban')
  7. if do_title_length_check(conn, name) == 1:
  8. return re_error(conn, '/error/38')
  9. if flask.request.method == 'POST':
  10. move_title = flask.request.form.get('title', 'test')
  11. if acl_check(conn, move_title) == 1:
  12. return re_error(conn, '/ban')
  13. if captcha_post(conn, flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  14. return re_error(conn, '/error/13')
  15. else:
  16. captcha_post(conn, '', 0)
  17. if do_edit_slow_check(conn) == 1:
  18. return re_error(conn, '/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. has_error = 0
  24. move_option = flask.request.form.get('move_option', 'none')
  25. move_option_topic = flask.request.form.get('move_topic_option', 'none')
  26. document_set_option = flask.request.form.get('document_set_option', 'none')
  27. if do_edit_send_check(conn, send) == 1:
  28. return re_error(conn, '/error/37')
  29. if do_edit_text_bottom_check_box_check(conn, agree) == 1:
  30. return re_error(conn, '/error/29')
  31. # 역링크 관련 패치 해야할 듯
  32. # 문서 이동 파트 S
  33. curs.execute(db_change("select title from history where title = ?"), [move_title])
  34. if curs.fetchall():
  35. if move_option == 'merge' and admin_check(conn, None, 'merge documents (' + name + ') (' + move_title + ')') == 1:
  36. curs.execute(db_change("select data from data where title = ?"), [move_title])
  37. data = curs.fetchall()
  38. if data:
  39. curs.execute(db_change("delete from data where title = ?"), [move_title])
  40. curs.execute(db_change("delete from back where link = ?"), [move_title])
  41. curs.execute(db_change("select data from data where title = ?"), [name])
  42. data = curs.fetchall()
  43. data_in = data[0][0] if data else ''
  44. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  45. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  46. # 역링크 S
  47. # 문서 합치기이므로 기존 문서 쪽은 no 역링크 생성, 이동하는 곳에는 no 역링크 제거
  48. curs.execute(db_change("select distinct link from back where title = ?"), [name])
  49. backlink = [[for_a[0], name, 'no', ''] for for_a in curs.fetchall()]
  50. curs.executemany(db_change("insert into back (link, title, type, data) values (?, ?, ?, ?)"), backlink)
  51. curs.execute(db_change("delete from back where title = ? and type = 'no'"), [move_title])
  52. # 역링크 E
  53. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [move_title])
  54. num = curs.fetchall()[0][0]
  55. curs.execute(db_change("select id from history where title = ? order by id + 0 asc"), [name])
  56. data = curs.fetchall()
  57. for move in data:
  58. curs.execute(db_change("update rc set title = ?, id = ? where title = ? and id = ?"), [move_title, str(int(num) + int(move[0])), name, move[0]])
  59. curs.execute(db_change("update history set title = ?, id = ? where title = ? and id = ?"), [move_title, str(int(num) + int(move[0])), name, move[0]])
  60. history_plus(conn,
  61. move_title,
  62. data_in,
  63. time,
  64. ip,
  65. send,
  66. '0',
  67. t_check = '<a>' + name + '</a> ↔ <a>' + move_title + '</a>',
  68. mode = 'move'
  69. )
  70. elif move_option == 'reverse':
  71. # 전체적인 구조 변경 필요
  72. # 중간 문서 거치지 않고 불러와서 바로 변경하도록
  73. # 문서 이동 말고 나머지도 그렇게 변경 필요함
  74. i = 0
  75. var_name = ''
  76. while var_name == '':
  77. temp_title = 'test ' + load_random_key() + ' ' + str(i)
  78. curs.execute(db_change("select title from history where title = ? limit 1"), [temp_title])
  79. if not curs.fetchall():
  80. var_name = temp_title
  81. else:
  82. i += 1
  83. for title_name in [[name, var_name], [move_title, name], [var_name, move_title]]:
  84. curs.execute(db_change("update data set title = ? where title = ?"), [title_name[1], title_name[0]])
  85. curs.execute(db_change("update back set link = ? where link = ?"), [title_name[1], title_name[0]])
  86. curs.execute(db_change("update history set title = ? where title = ?"), [title_name[1], title_name[0]])
  87. curs.execute(db_change("update rc set title = ? where title = ?"), [title_name[1], title_name[0]])
  88. for title_name in [[name, move_title], [move_title, name]]:
  89. curs.execute(db_change("select data from data where title = ?"), [name])
  90. data = curs.fetchall()
  91. data_in = data[0][0] if data else ''
  92. history_plus(conn,
  93. title_name[0],
  94. data_in,
  95. time,
  96. ip,
  97. send,
  98. '0',
  99. t_check = '<a>' + title_name[0] + '</a> ⇋ <a>' + title_name[1] + '</a>',
  100. mode = 'move'
  101. )
  102. elif move_option != 'none':
  103. has_error = 1
  104. elif move_option != 'none':
  105. curs.execute(db_change("select data from data where title = ?"), [name])
  106. data = curs.fetchall()
  107. data_in = data[0][0] if data else ''
  108. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  109. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  110. # 역링크 S
  111. # 문서 합치기 쪽 역링크와 동일하게
  112. curs.execute(db_change("select distinct link from back where title = ?"), [name])
  113. backlink = [[for_a[0], name, 'no', ''] for for_a in curs.fetchall()]
  114. curs.executemany(db_change("insert into back (link, title, type, data) values (?, ?, ?, ?)"), backlink)
  115. curs.execute(db_change("delete from back where title = ? and type = 'no'"), [move_title])
  116. # 역링크 E
  117. # 역사와 최근 변경 이동 S
  118. curs.execute(db_change("update history set title = ? where title = ?"), [move_title, name])
  119. curs.execute(db_change("update rc set title = ? where title = ?"), [move_title, name])
  120. # 역사와 최근 변경 이동 E
  121. history_plus(conn,
  122. move_title,
  123. data_in,
  124. time,
  125. ip,
  126. send,
  127. '0',
  128. t_check = '<a>' + name + '</a> → <a>' + move_title + '</a>',
  129. mode = 'move'
  130. )
  131. # 문서 이동 파트 E
  132. # 토론 이동 파트 S
  133. curs.execute(db_change("select title from rd where title = ?"), [move_title])
  134. if curs.fetchall():
  135. if move_option_topic == 'merge' and admin_check(conn, None, 'merge document\'s topics (' + name + ') (' + move_title + ')') == 1:
  136. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  137. elif move_option_topic == 'reverse':
  138. i = 0
  139. var_name = ''
  140. while var_name == '':
  141. temp_title = 'test ' + load_random_key() + ' ' + str(i)
  142. curs.execute(db_change("select title from rd where title = ? limit 1"), [temp_title])
  143. if not curs.fetchall():
  144. var_name = temp_title
  145. else:
  146. i += 1
  147. for title_name in [[name, var_name], [move_title, name], [var_name, move_title]]:
  148. curs.execute(db_change("update rd set title = ? where title = ?"), [title_name[1], title_name[0]])
  149. else:
  150. has_error = 1
  151. elif move_option_topic != 'none':
  152. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  153. # 토론 이동 파트 E
  154. # data_set 이동 파트 S
  155. if document_set_option == 'reverse':
  156. i = 0
  157. var_name = ''
  158. while var_name == '':
  159. temp_title = 'test ' + load_random_key() + ' ' + str(i)
  160. curs.execute(db_change("select title from history where title = ? limit 1"), [temp_title])
  161. if not curs.fetchall():
  162. var_name = temp_title
  163. else:
  164. i += 1
  165. for title_name in [[name, var_name], [move_title, name], [var_name, move_title]]:
  166. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [title_name[1], title_name[0]])
  167. elif document_set_option == 'normal':
  168. curs.execute(db_change("delete from data_set where doc_name = ?"), [move_title])
  169. curs.execute(db_change("delete from acl where title = ?"), [move_title])
  170. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [move_title, name])
  171. curs.execute(db_change("update acl set title = ? where title = ?"), [move_title, name])
  172. # data_set 이동 파트 E
  173. if has_error == 0:
  174. return redirect(conn, '/w/' + url_pas(move_title))
  175. else:
  176. return re_error(conn, '/error/19')
  177. else:
  178. owner_auth = admin_check(conn)
  179. return easy_minify(conn, flask.render_template(skin_check(conn),
  180. imp = [name, wiki_set(conn), wiki_custom(conn), wiki_css(['(' + get_lang(conn, 'move') + ')', 0])],
  181. data = '''
  182. <form method="post">
  183. <span>''' + get_lang(conn, 'document_name') + '''</span>
  184. <hr class="main_hr">
  185. <input value="''' + name + '''" name="title" type="text">
  186. <hr class="main_hr">
  187. <input placeholder="''' + get_lang(conn, 'why') + '''" name="send" type="text">
  188. <hr class="main_hr">
  189. <h2>''' + get_lang(conn, 'document') + '''</h2>
  190. <select name="move_option">
  191. <option value="normal"> ''' + get_lang(conn, 'normal') + '''</option>
  192. <option value="none"> ''' + get_lang(conn, 'dont_move') + '''</option>
  193. <option value="reverse"> ''' + get_lang(conn, 'replace_move') + '''</option>
  194. ''' + ('<option value="merge"> ' + get_lang(conn, 'merge_move') + '</option>' if owner_auth == 1 else '') + '''
  195. </select>
  196. <hr class="main_hr">
  197. <!-- <input type="checkbox" name="move_redirect_make"> ''' + get_lang(conn, 'move_redirect_make') + '''
  198. <hr class="main_hr"> -->
  199. <h2>''' + get_lang(conn, 'discussion') + '''</h2>
  200. <select name="move_topic_option">
  201. <option value="none"> ''' + get_lang(conn, 'dont_move') + '''</option>
  202. <option value="normal"> ''' + get_lang(conn, 'normal') + '''</option>
  203. <option value="reverse"> ''' + get_lang(conn, 'replace_move') + '''</option>
  204. ''' + ('<option value="merge"> ' + get_lang(conn, 'merge_move') + '</option>' if owner_auth == 1 else '') + '''
  205. </select>
  206. <hr class="main_hr">
  207. ''' + ((
  208. '''<h2>''' + get_lang(conn, 'document_set') + '''</h2>
  209. <select name="document_set_option">
  210. <option value="none"> ''' + get_lang(conn, 'dont_move') + '''</option>
  211. <option value="normal"> ''' + get_lang(conn, 'normal') + '''</option>
  212. <option value="reverse"> ''' + get_lang(conn, 'replace_move') + '''</option>
  213. </select>
  214. <hr class="main_hr">
  215. '''
  216. ) if owner_auth == 1 else '') + '''
  217. ''' + captcha_get(conn) + ip_warning(conn) + get_edit_text_bottom_check_box(conn) + get_edit_text_bottom(conn) + '''
  218. <button type="submit">''' + get_lang(conn, 'move') + '''</button>
  219. </form>
  220. ''',
  221. menu = [['w/' + url_pas(name), get_lang(conn, 'return')]]
  222. ))