edit_move.py 8.9 KB

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