summaryrefslogtreecommitdiff
path: root/game/wiki.rpy
blob: 2f8b2be6b7ab8f5175c2f32961e74f0febb8772c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#################################################################################
#     This file is part of Mana Launcher.
#     Copyright (C) 2023  Jesusalva <jesusalva@tmw2.org>
#
#     Distributed under the MIT license.
#################################################################################
init python:
    if mwclient is not None:
        wiki=mwclient.Site('wiki.themanaworld.org', path='/')
    else:
        wiki=None

    def wiki_get(game, page):
        if wiki is None:
            return ""
        page = wiki.pages['%s:%s' % (game, page)]
        if page.exists:
            return page.text(expandtemplates=False) # expandtemplates=True cache=False
        return ""

    def wiki_links(page):
        ls=[]
        for ln in list(page.links()):
            # ln.name takes the namespace in account
            # ln.base_name is ln.name but split by "/"
            # ln.page_title has no namespace and base_title is split by "/"
            # Red links are excluded by the if clause
            if ln.exists:
                ls.append([str(ln.page_title), str(ln.name)])
        return ls

    def wiki_sub(s, nl=" "):
        parsed=""
        if s.startswith('https://'):
            parsed+="{a=%s}%s{/a}" % (s, _("External Link"))
        elif s.startswith('[[') and s.startswith(']]'):
            # We don't have a code for this...
            parsed+=s
        elif s.startswith('{{') and s.startswith('}}'):
            return ""
        else:
            parsed+=s
        parsed+=nl
        return parsed

    def wiki_parse(raw):
        raw=raw.replace('<br>', '\n').replace('<br/>', '\n')
        fin=""
        part=""
        for s in raw.split('\n'):
            part+=wiki_sub(s, "\n")
        for s in part.split(' '):
            fin+=wiki_sub(s, " ")
        # TODO: Add a see-also section with the inner links
        return fin

    def load_wiki(server=99):
        global statusmsg
        print("Loading wiki for server %d" % server)
        # persistent.serverlist[server]["Help"]
        game="Classic"
        page="Walkthrough"

        #data=wiki_get(game, page)
        print("Wiki loaded, parsing")
        statusmsg = "Boo boo boo" #wiki_parse(data)
        print("Done!")
        renpy.restart_interaction()
        print("Forcefully restarted, returning now.")
        return None