edit_move.py 8.3 KB

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