edit_move.py 8.1 KB

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