edit_move.py 9.3 KB

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