view_read.py 6.7 KB

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