view_read.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. from .tool.func import *
  2. def view_read_2(conn, name):
  3. curs = conn.cursor()
  4. sub = ''
  5. div = ''
  6. ip = ip_check()
  7. name_doc_pass = flask.request.args.get('from', '')
  8. uppage = re.sub(r"/([^/]+)$", '', name)
  9. num = flask.request.args.get('num', None)
  10. num = int(number_check(num)) if num else None
  11. curs.execute(db_change("select sub from rd where title = ? and not stop = 'O' order by date desc"), [name])
  12. topic = 1 if curs.fetchall() else 0
  13. curs.execute(db_change("select title from data where title like ?"), [name + '/%'])
  14. down = 1 if curs.fetchall() else 0
  15. if re.search(r'^category:', name):
  16. curs.execute(db_change("select link from back where title = ? and type = 'cat' order by link asc"), [name])
  17. back = curs.fetchall()
  18. if back:
  19. u_div = ''
  20. for data in back:
  21. if div == '':
  22. div = '<br><h2 id="cate_normal">' + load_lang('category_title') + '</h2><ul class="inside_ul">'
  23. if re.search(r'^category:', data[0]):
  24. u_div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  25. else:
  26. curs.execute(db_change("select title from back where title = ? and type = 'include'"), [data[0]])
  27. db_data = curs.fetchall()
  28. if db_data:
  29. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> <a id="inside" href="/xref/' + url_pas(data[0]) + '">(' + load_lang('backlink') + ')</a></li>'
  30. else:
  31. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
  32. if div != '':
  33. div += '</ul>'
  34. if u_div != '':
  35. div += '<br><h2 id="cate_under">' + load_lang('under_category') + '</h2><ul class="inside_ul">' + u_div + '</ul>'
  36. if num:
  37. curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, str(num)])
  38. if curs.fetchall() and admin_check(6) != 1:
  39. return redirect('/history/' + url_pas(name))
  40. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, str(num)])
  41. else:
  42. curs.execute(db_change("select data from data where title = ?"), [name])
  43. data = curs.fetchall()
  44. end_data = render_set(
  45. doc_name = name,
  46. doc_data = data[0][0] if data else None
  47. )
  48. if end_data == 'HTTP Request 401.3':
  49. response_data = 401
  50. curs.execute(db_change('select data from other where name = "error_401"'))
  51. sql_d = curs.fetchall()
  52. if sql_d and sql_d[0][0] != '':
  53. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  54. else:
  55. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('authority_error') + '</li></ul>'
  56. elif end_data == 'HTTP Request 404':
  57. response_data = 404
  58. curs.execute(db_change('select data from other where name = "error_404"'))
  59. sql_d = curs.fetchall()
  60. if sql_d and sql_d[0][0] != '':
  61. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + sql_d[0][0] + '</li></ul>'
  62. else:
  63. end_data = '<h2>' + load_lang('error') + '</h2><ul class="inside_ul"><li>' + load_lang('decument_404_error') + '</li></ul>'
  64. curs.execute(db_change('' + \
  65. 'select ip, date, leng, send, id from history ' + \
  66. 'where title = ? and hide != "O" order by id + 0 desc limit 3' + \
  67. ''), [name])
  68. sql_d = curs.fetchall()
  69. if sql_d:
  70. end_data += '<h2>' + load_lang('history') + '</h2><ul class="inside_ul">'
  71. for i in sql_d:
  72. if re.search(r"\+", i[2]):
  73. leng = '<span style="color:green;">(' + i[2] + ')</span>'
  74. elif re.search(r"\-", i[2]):
  75. leng = '<span style="color:red;">(' + i[2] + ')</span>'
  76. else:
  77. leng = '<span style="color:gray;">(' + i[2] + ')</span>'
  78. end_data += '<li>' + i[1] + ' | r' + i[4] + ' | ' + ip_pas(i[0]) + ' | ' + leng + (' | ' + i[3] if i[3] != '' else '') + '</li>'
  79. end_data += '<li><a href="/history/' + url_pas(name) + '">(...)</a></li></ul>'
  80. else:
  81. response_data = 200
  82. if num:
  83. menu = [['history/' + url_pas(name), load_lang('history')]]
  84. sub = ' (r' + str(num) + ')'
  85. acl = 0
  86. r_date = 0
  87. else:
  88. curs.execute(db_change("select title from acl where title = ?"), [name])
  89. acl = 1 if curs.fetchall() else 0
  90. menu_acl = 1 if acl_check(name) == 1 else 0
  91. if response_data == 404:
  92. menu = [['edit/' + url_pas(name), load_lang('create'), menu_acl]]
  93. else:
  94. menu = [['edit/' + url_pas(name), load_lang('edit'), menu_acl]]
  95. menu += [
  96. ['topic/' + url_pas(name), load_lang('discussion'), topic],
  97. ['history/' + url_pas(name), load_lang('history')],
  98. ['xref/' + url_pas(name), load_lang('backlink')],
  99. ['acl/' + url_pas(name), load_lang('acl'), acl],
  100. ]
  101. if name_doc_pass != '':
  102. menu += [['w/' + url_pas(name), load_lang('pass')]]
  103. end_data = '''
  104. <div id="redirect">
  105. <a href="/w/''' + url_pas(name_doc_pass) + '?from=' + url_pas(name) + '">' + name_doc_pass + '</a> ⇨ <b>' + name + '''</b>
  106. </div>
  107. <br>
  108. ''' + end_data
  109. if uppage != 0:
  110. menu += [['w/' + url_pas(uppage), load_lang('upper')]]
  111. if down:
  112. menu += [['down/' + url_pas(name), load_lang('sub')]]
  113. curs.execute(db_change("select date from history where title = ? order by date desc limit 1"), [name])
  114. r_date = curs.fetchall()
  115. r_date = r_date[0][0] if r_date else 0
  116. div = end_data + div
  117. match = re.search(r"^user:([^/]*)", name)
  118. if match:
  119. user_name = html.escape(match.group(1))
  120. div = '''
  121. <div id="get_user_info"></div>
  122. <script>load_user_info("''' + user_name + '''");</script>
  123. ''' + div
  124. curs.execute(db_change("select data from other where name = 'body'"))
  125. body = curs.fetchall()
  126. div = (body[0][0] + div) if body else div
  127. curs.execute(db_change("select data from other where name = 'bottom_body'"))
  128. body = curs.fetchall()
  129. div += body[0][0] if body else ''
  130. if ip_or_user(ip) == 0:
  131. curs.execute(db_change("select title from scan where user = ? and title = ?"), [ip, name])
  132. watch_list = 2 if curs.fetchall() else 1
  133. else:
  134. watch_list = 0
  135. return easy_minify(flask.render_template(skin_check(),
  136. imp = [name, wiki_set(), wiki_custom(), wiki_css([sub, r_date, watch_list])],
  137. data = div,
  138. menu = menu
  139. )), response_data