edit_move.py 14 KB

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