view_xref.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from .tool.func import *
  2. def view_xref_2(conn, name, xref_type = '1'):
  3. curs = conn.cursor()
  4. if acl_check(name, 'render') == 1:
  5. return re_error('/ban')
  6. num = int(number_check(flask.request.args.get('num', '1')))
  7. sql_num = (num * 50 - 50) if num * 50 > 0 else 0
  8. if xref_type == '1':
  9. div = '<a href="/xref/this/' + url_pas(name) + '">(' + load_lang('link_in_this') + ')</a><hr class="main_hr">'
  10. data_sub = '(' + load_lang('backlink') + ')'
  11. else:
  12. div = '<a href="/xref/' + url_pas(name) + '">(' + load_lang('normal') + ')</a><hr class="main_hr">'
  13. data_sub = '(' + load_lang('link_in_this') + ')'
  14. div += '<ul class="inside_ul">'
  15. sql_insert = ['link', 'title'] if xref_type == '1' else ['title', 'link']
  16. curs.execute(db_change("" + \
  17. "select distinct " + sql_insert[0] + ", type from back " + \
  18. "where " + sql_insert[1] + " = ? and not type = 'no' and not type = 'nothing'" + \
  19. "order by type asc, title asc limit ?, 50" + \
  20. ""), [
  21. name,
  22. sql_num
  23. ])
  24. data_list = curs.fetchall()
  25. for data in data_list:
  26. div += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a>'
  27. if data[1]:
  28. div += ' (' + data[1] + ')'
  29. curs.execute(db_change("select title from back where title = ? and type = 'include'"), [data[0]])
  30. db_data = curs.fetchall()
  31. if db_data:
  32. div += ' <a id="inside" href="/xref/' + url_pas(data[0]) + '">(' + load_lang('backlink') + ')</a>'
  33. div += '</li>'
  34. div += '</ul>' + next_fix('/xref/' + url_pas(name) + '?change=' + xref_type + '&num=', num, data_list)
  35. return easy_minify(flask.render_template(skin_check(),
  36. imp = [name, wiki_set(), wiki_custom(), wiki_css([data_sub, 0])],
  37. data = div,
  38. menu = [['w/' + url_pas(name), load_lang('return')], ['backlink_reset/' + url_pas(name), load_lang('reset_backlink')]]
  39. ))