edit_move.py 15 KB

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