edit_move.py 7.5 KB

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