edit_move.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. # 역링크 관련 패치 해야할 듯
  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(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. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  47. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  48. curs.execute(db_change('select data from other where name = "count_all_title"'))
  49. curs.execute(db_change("update other set data = ? where name = 'count_all_title'"), [str(int(curs.fetchall()[0][0]) - 1)])
  50. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [move_title])
  51. num = curs.fetchall()[0][0]
  52. curs.execute(db_change("select id from history where title = ? order by id + 0 asc"), [name])
  53. data = curs.fetchall()
  54. for move in data:
  55. curs.execute(db_change("update rc set title = ?, id = ? where title = ? and id = ?"), [move_title, str(int(num) + int(move[0])), name, move[0]])
  56. curs.execute(db_change("update history set title = ?, id = ? where title = ? and id = ?"), [move_title, str(int(num) + int(move[0])), name, move[0]])
  57. history_plus(move_title, data_in, time, ip, send, '0',
  58. t_check = 'merge <a>' + name + '</a> - <a>' + move_title + '</a> move',
  59. mode = 'move'
  60. )
  61. elif move_option == 'reverse':
  62. i = 0
  63. var_name = ''
  64. while var_name == '':
  65. temp_title = 'test ' + load_random_key() + ' ' + str(i)
  66. curs.execute(db_change("select title from history where title = ? limit 1"), [temp_title])
  67. if not curs.fetchall():
  68. var_name = temp_title
  69. else:
  70. i += 1
  71. for title_name in [[name, var_name], [move_title, name], [var_name, move_title]]:
  72. curs.execute(db_change("update data set title = ? where title = ?"), [title_name[1], title_name[0]])
  73. curs.execute(db_change("update back set link = ? where link = ?"), [title_name[1], title_name[0]])
  74. curs.execute(db_change("update history set title = ? where title = ?"), [title_name[1], title_name[0]])
  75. curs.execute(db_change("update rc set title = ? where title = ?"), [title_name[1], title_name[0]])
  76. for title_name in [[name, move_title], [move_title, name]]:
  77. curs.execute(db_change("select data from data where title = ?"), [name])
  78. data = curs.fetchall()
  79. data_in = data[0][0] if data else ''
  80. history_plus(title_name[0], data_in, time, ip, send, '0',
  81. t_check = '<a>' + title_name[0] + '</a> - <a>' + title_name[1] + '</a> move',
  82. mode = 'move'
  83. )
  84. elif move_option != 'none':
  85. has_error = 1
  86. elif move_option != 'none':
  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. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  91. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  92. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  93. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  94. curs.execute(db_change("update history set title = ? where title = ?"), [move_title, name])
  95. curs.execute(db_change("update rc set title = ? where title = ?"), [move_title, name])
  96. history_plus(move_title, data_in, time, ip, send, '0',
  97. t_check = '<a>' + name + '</a> - <a>' + move_title + '</a> move',
  98. mode = 'move'
  99. )
  100. # 문서 이동 파트 E
  101. # 토론 이동 파트 S
  102. curs.execute(db_change("select title from rd where title = ?"), [move_title])
  103. if curs.fetchall():
  104. if move_option_topic == 'merge' and admin_check(None, 'merge document\'s topics (' + name + ') (' + move_title + ')') == 1:
  105. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  106. elif move_option_topic == 'reverse':
  107. i = 0
  108. var_name = ''
  109. while var_name == '':
  110. temp_title = 'test ' + load_random_key() + ' ' + str(i)
  111. curs.execute(db_change("select title from rd where title = ? limit 1"), [temp_title])
  112. if not curs.fetchall():
  113. var_name = temp_title
  114. else:
  115. i += 1
  116. for title_name in [[name, var_name], [move_title, name], [var_name, move_title]]:
  117. curs.execute(db_change("update rd set title = ? where title = ?"), [title_name[1], title_name[0]])
  118. else:
  119. has_error = 1
  120. elif move_option_topic != 'none':
  121. curs.execute(db_change("update rd set title = ? where title = ?"), [move_title, name])
  122. # 토론 이동 파트 E
  123. # data_set 이동 파트 S
  124. if document_set_option == 'reverse':
  125. i = 0
  126. var_name = ''
  127. while var_name == '':
  128. temp_title = 'test ' + load_random_key() + ' ' + str(i)
  129. curs.execute(db_change("select title from history where title = ? limit 1"), [temp_title])
  130. if not curs.fetchall():
  131. var_name = temp_title
  132. else:
  133. i += 1
  134. for title_name in [[name, var_name], [move_title, name], [var_name, move_title]]:
  135. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [title_name[1], title_name[0]])
  136. elif document_set_option == 'normal':
  137. curs.execute(db_change("delete from data_set where doc_name = ?"), [move_title])
  138. curs.execute(db_change("delete from acl where title = ?"), [move_title])
  139. curs.execute(db_change("update data_set set doc_name = ? where doc_name = ?"), [move_title, name])
  140. curs.execute(db_change("update acl set title = ? where title = ?"), [move_title, name])
  141. # data_set 이동 파트 E
  142. conn.commit()
  143. if has_error == 0:
  144. return redirect('/w/' + url_pas(move_title))
  145. else:
  146. return re_error('/error/19')
  147. else:
  148. owner_auth = admin_check()
  149. return easy_minify(flask.render_template(skin_check(),
  150. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('move') + ')', 0])],
  151. data = '''
  152. <form method="post">
  153. <span>''' + load_lang('document_name') + '''</span>
  154. <hr class="main_hr">
  155. <input value="''' + name + '''" name="title" type="text">
  156. <hr class="main_hr">
  157. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  158. <hr class="main_hr">
  159. <h2>''' + load_lang('document') + '''</h2>
  160. <select name="move_option">
  161. <option value="none"> ''' + load_lang('dont_move') + '''</option>
  162. <option value="normal"> ''' + load_lang('normal') + '''</option>
  163. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  164. ''' + ('<option value="merge"> ' + load_lang('merge_move') + '</option>' if owner_auth == 1 else '') + '''
  165. </select>
  166. <hr class="main_hr">
  167. <!-- <input type="checkbox" name="move_redirect_make"> ''' + load_lang('move_redirect_make') + '''
  168. <hr class="main_hr"> -->
  169. <h2>''' + load_lang('discussion') + '''</h2>
  170. <select name="move_topic_option">
  171. <option value="none"> ''' + load_lang('dont_move') + '''</option>
  172. <option value="normal"> ''' + load_lang('normal') + '''</option>
  173. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  174. ''' + ('<option value="merge"> ' + load_lang('merge_move') + '</option>' if owner_auth == 1 else '') + '''
  175. </select>
  176. <hr class="main_hr">
  177. ''' + ((
  178. '''<h2>''' + load_lang('document_set') + '''</h2>
  179. <select name="document_set_option">
  180. <option value="none"> ''' + load_lang('dont_move') + '''</option>
  181. <option value="normal"> ''' + load_lang('normal') + '''</option>
  182. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  183. </select>
  184. <hr class="main_hr">
  185. '''
  186. ) if owner_auth == 1 else '') + '''
  187. ''' + captcha_get() + ip_warning() + get_edit_text_bottom_check_box() + get_edit_text_bottom() + '''
  188. <button type="submit">''' + load_lang('move') + '''</button>
  189. </form>
  190. ''',
  191. menu = [['w/' + url_pas(name), load_lang('return')]]
  192. ))