edit_move.py 8.2 KB

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