edit_move.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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('/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. 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(send) == 1:
  28. return re_error('/error/37')
  29. if do_edit_text_bottom_check_box_check(agree) == 1:
  30. return re_error('/error/29')
  31. # 문서 이동 파트 S
  32. curs.execute(db_change("select title from history where title = ?"), [move_title])
  33. if curs.fetchall():
  34. if (
  35. move_option == 'merge' and
  36. admin_check(None, 'merge documents (' + name + ') (' + move_title + ')') == 1
  37. ):
  38. curs.execute(db_change("select data from data where title = ?"), [move_title])
  39. data = curs.fetchall()
  40. if data:
  41. curs.execute(db_change("delete from data where title = ?"), [move_title])
  42. curs.execute(db_change("delete from back where link = ?"), [move_title])
  43. curs.execute(db_change("select data from data where title = ?"), [name])
  44. data = curs.fetchall()
  45. if data:
  46. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  47. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  48. data_in = data[0][0]
  49. else:
  50. data_in = ''
  51. history_plus(
  52. name,
  53. data_in,
  54. time,
  55. ip,
  56. send,
  57. '0',
  58. t_check = 'merge <a>' + name + '</a> - <a>' + move_title + '</a> move',
  59. mode = 'move'
  60. )
  61. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  62. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  63. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [move_title])
  64. data = curs.fetchall()
  65. num = data[0][0]
  66. curs.execute(db_change("select id from history where title = ? order by id + 0 asc"), [name])
  67. data = curs.fetchall()
  68. for move in data:
  69. curs.execute(db_change("update rc set title = ?, id = ? where title = ? and id = ?"), [
  70. move_title,
  71. str(int(num) + int(move[0])),
  72. name,
  73. move[0]
  74. ])
  75. curs.execute(db_change("update history set title = ?, id = ? where title = ? and id = ?"), [
  76. move_title,
  77. str(int(num) + int(move[0])),
  78. name,
  79. move[0]
  80. ])
  81. elif move_option == 'reverse':
  82. i = 0
  83. var_name = ''
  84. while var_name == '':
  85. curs.execute(db_change("select title from history where title = ?"), ['test ' + str(i)])
  86. if not curs.fetchall():
  87. var_name = 'test ' + str(i)
  88. else:
  89. i += 1
  90. curs.execute(db_change("select data from data where title = ?"), [name])
  91. data = curs.fetchall()
  92. if data:
  93. curs.execute(db_change("update data set title = ? where title = ?"), [var_name, name])
  94. curs.execute(db_change("update back set link = ? where link = ?"), [var_name, name])
  95. curs.execute(db_change("update history set title = ? where title = ?"), [var_name, name])
  96. curs.execute(db_change("update rc set title = ? where title = ?"), [var_name, name])
  97. for title_name in [[move_title, name], [var_name, move_title]]:
  98. curs.execute(db_change("select data from data where title = ?"), [title_name[0]])
  99. data = curs.fetchall()
  100. if data:
  101. curs.execute(db_change("update data set title = ? where title = ?"), [title_name[1], title_name[0]])
  102. curs.execute(db_change("update back set link = ? where link = ?"), [title_name[1], title_name[0]])
  103. data_in = data[0][0]
  104. else:
  105. data_in = ''
  106. history_plus(
  107. title_name[0],
  108. data_in,
  109. time,
  110. ip,
  111. send,
  112. '0',
  113. t_check = '<a>' + (title_name[0] if title_name[0] != var_name else name) + '</a> - <a>' + title_name[1] + '</a> move',
  114. mode = 'move'
  115. )
  116. curs.execute(db_change("update history set title = ? where title = ?"), [title_name[1], title_name[0]])
  117. curs.execute(db_change("update rc set title = ? where title = ?"), [title_name[1], title_name[0]])
  118. elif move_option != 'none':
  119. has_error = 1
  120. elif move_option != 'none':
  121. curs.execute(db_change("select data from data where title = ?"), [name])
  122. data = curs.fetchall()
  123. if data:
  124. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  125. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  126. data_in = data[0][0]
  127. else:
  128. data_in = ''
  129. history_plus(
  130. name,
  131. data_in,
  132. time,
  133. ip,
  134. send,
  135. '0',
  136. t_check = '<a>' + name + '</a> - <a>' + move_title + '</a> move',
  137. mode = 'move'
  138. )
  139. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  140. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  141. curs.execute(db_change("update history set title = ? where title = ?"), [move_title, name])
  142. curs.execute(db_change("update rc set title = ? where title = ?"), [move_title, name])
  143. # 문서 이동 파트 E
  144. # 토론 이동 파트 S
  145. if (
  146. move_option_topic == 'merge' and
  147. admin_check(None, 'merge document\'s topics (' + name + ') (' + move_title + ')') == 1
  148. ):
  149. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  150. elif move_option_topic == 'reverse':
  151. i = 0
  152. var_name = ''
  153. while var_name == '':
  154. curs.execute(db_change("select title from rd where title = ?"), ['test ' + str(i)])
  155. if not curs.fetchall():
  156. var_name = 'test ' + str(i)
  157. else:
  158. i += 1
  159. curs.execute(db_change("update rd set title = ? where title = ?"), [var_name, move_title])
  160. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  161. curs.execute(db_change("update rd set title = ? where title = ?"), [name, var_name])
  162. elif move_option_topic == 'normal':
  163. curs.execute(db_change("select title from rd where title = ?"), [move_title])
  164. if curs.fetchall():
  165. has_error = 1
  166. else:
  167. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  168. # 토론 이동 파트 E
  169. # data_set 이동 파트 S
  170. if document_set_option == 'reverse':
  171. i = 0
  172. var_name = ''
  173. while var_name == '':
  174. curs.execute(db_change("select title from rd where title = ?"), ['test ' + str(i)])
  175. if not curs.fetchall():
  176. var_name = 'test ' + str(i)
  177. else:
  178. i += 1
  179. # create_data['data_set'] = ['doc_name', 'doc_rev', 'set_name', 'set_data']
  180. # create_data['acl'] = ['title', 'data', 'type']
  181. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [var_name, move_title])
  182. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [move_title, name])
  183. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [name, var_name])
  184. curs.execute(db_change("update acl set title = ? where title = ?"), [var_name, move_title])
  185. curs.execute(db_change("update acl set title = ? where title = ?"), [move_title, name])
  186. curs.execute(db_change("update acl set title = ? where title = ?"), [name, var_name])
  187. elif document_set_option == 'normal':
  188. curs.execute(db_change("delete from data_set where doc_name = ?"), [move_title])
  189. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [move_title, name])
  190. curs.execute(db_change("delete from acl where title = ?"), [move_title])
  191. curs.execute(db_change("update acl set title = ? where title = ?"), [move_title, name])
  192. if document_set_option != 'reverse':
  193. curs.execute(db_change("select data from data where title = ?"), [name])
  194. db_data = curs.fetchall()
  195. if db_data:
  196. render_set(
  197. doc_name = name,
  198. doc_data = db_data[0][0],
  199. data_type = 'backlink'
  200. )
  201. curs.execute(db_change("select data from data where title = ?"), [move_title])
  202. db_data = curs.fetchall()
  203. if db_data:
  204. render_set(
  205. doc_name = move_title,
  206. doc_data = db_data[0][0],
  207. data_type = 'backlink'
  208. )
  209. # data_set 이동 파트 E
  210. conn.commit()
  211. if has_error == 0:
  212. return redirect('/w/' + url_pas(move_title))
  213. else:
  214. return re_error('/error/19')
  215. else:
  216. owner_auth = admin_check()
  217. return easy_minify(flask.render_template(skin_check(),
  218. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('move') + ')', 0])],
  219. data = '''
  220. <form method="post">
  221. <span>''' + load_lang('document_name') + '''</span>
  222. <hr class="main_hr">
  223. <input value="''' + name + '''" name="title" type="text">
  224. <hr class="main_hr">
  225. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  226. <hr class="main_hr">
  227. <h2>''' + load_lang('document') + '''</h2>
  228. <select name="move_option">
  229. <option value="none"> ''' + load_lang('dont_move') + '''</option>
  230. <option value="normal"> ''' + load_lang('normal') + '''</option>
  231. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  232. ''' + ('<option value="merge"> ' + load_lang('merge_move') + '</option>' if owner_auth == 1 else '') + '''
  233. </select>
  234. <hr class="main_hr">
  235. <!-- <input type="checkbox" name="move_redirect_make"> ''' + load_lang('move_redirect_make') + '''
  236. <hr class="main_hr"> -->
  237. <h2>''' + load_lang('discussion') + '''</h2>
  238. <select name="move_topic_option">
  239. <option value="none"> ''' + load_lang('dont_move') + '''</option>
  240. <option value="normal"> ''' + load_lang('normal') + '''</option>
  241. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  242. ''' + ('<option value="merge"> ' + load_lang('merge_move') + '</option>' if owner_auth == 1 else '') + '''
  243. </select>
  244. <hr class="main_hr">
  245. ''' + ((
  246. '''<h2>''' + load_lang('document_set') + '''</h2>
  247. <select name="document_set_option">
  248. <option value="none"> ''' + load_lang('dont_move') + '''</option>
  249. <option value="normal"> ''' + load_lang('normal') + '''</option>
  250. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  251. </select>
  252. <hr class="main_hr">
  253. '''
  254. ) if owner_auth == 1 else '') + '''
  255. ''' + captcha_get() + ip_warning() + get_edit_text_bottom_check_box() + get_edit_text_bottom() + '''
  256. <button type="submit">''' + load_lang('move') + '''</button>
  257. </form>
  258. ''',
  259. menu = [['w/' + url_pas(name), load_lang('return')]]
  260. ))