edit_move.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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) == 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. if do_edit_send_check(send) == 1:
  24. return re_error('/error/37')
  25. if do_edit_text_bottom_check_box_check(agree) == 1:
  26. return re_error('/error/29')
  27. curs.execute(db_change("select title from history where title = ?"), [move_title])
  28. if curs.fetchall():
  29. if flask.request.form.get('move_option', 'normal') == 'merge' and admin_check(None, 'merge documents') == 1:
  30. curs.execute(db_change("select data from data where title = ?"), [move_title])
  31. data = curs.fetchall()
  32. if data:
  33. curs.execute(db_change("delete from data where title = ?"), [move_title])
  34. curs.execute(db_change("delete from back where link = ?"), [move_title])
  35. curs.execute(db_change("select data from data where title = ?"), [name])
  36. data = curs.fetchall()
  37. if data:
  38. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  39. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  40. data_in = data[0][0]
  41. else:
  42. data_in = ''
  43. history_plus(
  44. name,
  45. data_in,
  46. time,
  47. ip,
  48. send,
  49. '0',
  50. t_check = 'merge <a>' + name + '</a> - <a>' + move_title + '</a> move',
  51. mode = 'move'
  52. )
  53. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  54. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  55. curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [move_title])
  56. data = curs.fetchall()
  57. num = data[0][0]
  58. curs.execute(db_change("select id from history where title = ? order by id + 0 asc"), [name])
  59. data = curs.fetchall()
  60. for move in data:
  61. curs.execute(db_change("update rc set title = ?, id = ? where title = ? and id = ?"), [
  62. move_title,
  63. str(int(num) + int(move[0])),
  64. name,
  65. move[0]
  66. ])
  67. curs.execute(db_change("update history set title = ?, id = ? where title = ? and id = ?"), [
  68. move_title,
  69. str(int(num) + int(move[0])),
  70. name,
  71. move[0]
  72. ])
  73. conn.commit()
  74. return redirect('/w/' + url_pas(move_title))
  75. elif flask.request.form.get('move_option', 'normal') == 'reverse':
  76. var_name = ''
  77. i = 0
  78. while 1:
  79. curs.execute(db_change("select title from history where title = ?"), ['test ' + str(i)])
  80. if not curs.fetchall():
  81. curs.execute(db_change("select data from data where title = ?"), [name])
  82. data = curs.fetchall()
  83. if data:
  84. curs.execute(db_change("update data set title = ? where title = ?"), ['test ' + str(i), name])
  85. curs.execute(db_change("update back set link = ? where link = ?"), ['test ' + str(i), name])
  86. curs.execute(db_change("update history set title = ? where title = ?"), ['test ' + str(i), name])
  87. curs.execute(db_change("update rc set title = ? where title = ?"), ['test ' + str(i), name])
  88. break
  89. else:
  90. i += 1
  91. for title_name in [[move_title, name], ['test ' + str(i), move_title]]:
  92. curs.execute(db_change("select data from data where title = ?"), [title_name[0]])
  93. data = curs.fetchall()
  94. if data:
  95. curs.execute(db_change("update data set title = ? where title = ?"), [title_name[1], title_name[0]])
  96. curs.execute(db_change("update back set link = ? where link = ?"), [title_name[1], title_name[0]])
  97. data_in = data[0][0]
  98. else:
  99. data_in = ''
  100. history_plus(
  101. title_name[0],
  102. data_in,
  103. time,
  104. ip,
  105. send,
  106. '0',
  107. t_check = '<a>' + (title_name[0] if title_name[0] != 'test ' + str(i) else name) + '</a> - <a>' + title_name[1] + '</a> move',
  108. mode = 'move'
  109. )
  110. curs.execute(db_change("update history set title = ? where title = ?"), [title_name[1], title_name[0]])
  111. curs.execute(db_change("update rc set title = ? where title = ?"), [title_name[1], title_name[0]])
  112. conn.commit()
  113. return redirect('/w/' + url_pas(move_title))
  114. else:
  115. return re_error('/error/19')
  116. else:
  117. curs.execute(db_change("select data from data where title = ?"), [name])
  118. data = curs.fetchall()
  119. if data:
  120. curs.execute(db_change("update data set title = ? where title = ?"), [move_title, name])
  121. curs.execute(db_change("update back set link = ? where link = ?"), [move_title, name])
  122. data_in = data[0][0]
  123. else:
  124. data_in = ''
  125. history_plus(
  126. name,
  127. data_in,
  128. time,
  129. ip,
  130. send,
  131. '0',
  132. t_check = '<a>' + name + '</a> - <a>' + move_title + '</a> move',
  133. mode = 'move'
  134. )
  135. curs.execute(db_change("update back set type = 'no' where title = ? and not type = 'cat' and not type = 'no'"), [name])
  136. curs.execute(db_change("delete from back where title = ? and not type = 'cat' and type = 'no'"), [move_title])
  137. curs.execute(db_change("update history set title = ? where title = ?"), [move_title, name])
  138. curs.execute(db_change("update rc set title = ? where title = ?"), [move_title, name])
  139. conn.commit()
  140. return redirect('/w/' + url_pas(move_title))
  141. else:
  142. return easy_minify(flask.render_template(skin_check(),
  143. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('move') + ')', 0])],
  144. data = '''
  145. <form method="post">
  146. ''' + ip_warning() + '''
  147. <input placeholder="''' + load_lang('document_name') + '" value="' + name + '''" name="title" type="text">
  148. <hr class="main_hr">
  149. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  150. <hr class="main_hr">
  151. <select name="move_option">
  152. <option value="normal"> ''' + load_lang('normal') + '''</option>
  153. <option value="reverse"> ''' + load_lang('replace_move') + '''</option>
  154. ''' + ('<option value="merge"> ' + load_lang('merge_move') + '</option>' if admin_check() == 1 else '') + '''
  155. </select>
  156. <hr class="main_hr">
  157. ''' + captcha_get() + ip_warning() + get_edit_text_bottom_check_box() + get_edit_text_bottom() + '''
  158. <button type="submit">''' + load_lang('move') + '''</button>
  159. </form>
  160. ''',
  161. menu = [['w/' + url_pas(name), load_lang('return')]]
  162. ))