1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-09 20:05:12 +00:00

Fix Wiki downloads (Update all pages)

Better detect deleted/new pages and prevent the problem discussed here: https://qb64phoenix.com/forum/showthread.php?tid=1521
This commit is contained in:
Roland Heyder 2023-03-19 12:33:24 +01:00
parent c52d3bcd28
commit 7038e2527d

View file

@ -62,38 +62,51 @@ FUNCTION Wiki$ (PageName$) 'Read cached wiki page (download, if not yet cached)
a$ = "" 'dummy pages (for error display) a$ = "" 'dummy pages (for error display)
ELSE ELSE
a$ = wikiDLPage$(url$, 15) a$ = wikiDLPage$(url$, 15)
IF INSTR(a$, "Login required") > 0 THEN a$ = s1$ + s2$ 'continue as empty page
END IF END IF
'Find wikitext in the downloaded page 'Find wikitext in the downloaded page
s1 = INSTR(a$, s1$) s1 = INSTR(a$, s1$)
IF s1 > 0 THEN a$ = MID$(a$, s1 + LEN(s1$)): s2 = INSTR(a$, s2$): ELSE s2 = 0 IF s1 > 0 THEN a$ = MID$(a$, s1 + LEN(s1$)): s2 = INSTR(a$, s2$): ELSE s2 = 0
IF s2 > 0 THEN a$ = LEFT$(a$, s2 - 1) IF s2 > 0 THEN a$ = LEFT$(a$, s2 - 1)
IF s1 > 0 AND s2 > 0 AND a$ <> "" THEN IF s1 > 0 AND s2 > 0 THEN
'If wikitext was found, then substitute stuff & save it IF a$ <> "" THEN
'--- first HTML specific entities 'If wikitext was found, then substitute stuff & save it
WHILE INSTR(a$, "&amp;") > 0 ' '&amp; must be first and looped until all '--- first HTML specific entities
a$ = StrReplace$(a$, "&amp;", "&") 'multi-escapes are resolved (eg. &amp;lt; &amp;amp;lt; etc.) WHILE INSTR(a$, "&amp;") > 0 ' '&amp; must be first and looped until all
WEND a$ = StrReplace$(a$, "&amp;", "&") 'multi-escapes are resolved (eg. &amp;lt; &amp;amp;lt; etc.)
a$ = StrReplace$(a$, "&lt;", "<") WEND
a$ = StrReplace$(a$, "&gt;", ">") a$ = StrReplace$(a$, "&lt;", "<")
a$ = StrReplace$(a$, "&quot;", CHR$(34)) a$ = StrReplace$(a$, "&gt;", ">")
'--- wiki redirects & crlf a$ = StrReplace$(a$, "&quot;", CHR$(34))
a$ = StrReplace$(a$, "#REDIRECT", "See page") '--- wiki redirects & crlf
a$ = StrReplace$(a$, CHR$(13) + CHR$(10), CHR$(10)) a$ = StrReplace$(a$, "#REDIRECT", "See page")
WHILE LEFT$(a$, 1) = CHR$(10): a$ = MID$(a$, 2): WEND a$ = StrReplace$(a$, CHR$(13) + CHR$(10), CHR$(10))
IF LEN(a$) > 0 AND RIGHT$(a$, 1) <> CHR$(10) THEN a$ = a$ + CHR$(10) WHILE LEFT$(a$, 1) = CHR$(10): a$ = MID$(a$, 2): WEND
'--- put a download date/time entry IF LEN(a$) > 0 AND RIGHT$(a$, 1) <> CHR$(10) THEN a$ = a$ + CHR$(10)
a$ = "{{QBDLDATE:" + DATE$ + "}}" + CHR$(10) + "{{QBDLTIME:" + TIME$ + "}}" + CHR$(10) + a$ '--- put a download date/time entry
'--- now save it a$ = "{{QBDLDATE:" + DATE$ + "}}" + CHR$(10) + "{{QBDLTIME:" + TIME$ + "}}" + CHR$(10) + a$
fh = FREEFILE '--- now save it
OPEN outputFile$ FOR OUTPUT AS #fh fh = FREEFILE
PRINT #fh, a$; OPEN outputFile$ FOR OUTPUT AS #fh
CLOSE #fh PRINT #fh, a$;
CLOSE #fh
ELSE
'if page returns empty, then it's either
IF _FILEEXISTS(outputFile$) THEN
KILL outputFile$ 'an old no longer existing/needed page
ELSE
'or a new not yet created page
a$ = CHR$(10) + "{{PageInternalError}}" + CHR$(10) +_
"* The requested page is not yet available in the Wiki." + CHR$(10) +_
"** If this is a new keyword, which was recently added to the language, then " +_
"please allow some time for the developers to add it and recheck later." + CHR$(10)
END IF
END IF
ELSE ELSE
'Error message, if empty or corrupted (force re-download on next access) 'download failure, page corrupted, no text delimiters found
a$ = CHR$(10) + "{{PageInternalError}}" + CHR$(10) +_ a$ = CHR$(10) + "{{PageInternalError}}" + CHR$(10) +_
"* Either the requested page is not yet available in the Wiki," + CHR$(10) +_ "* For some unknown reason the download of the requested page failed." + CHR$(10) +_
"* or the download from Wiki failed and corrupted the page data." + CHR$(10) +_
"** You may try ''Update Current Page'' from the ''Help'' menu." + CHR$(10) +_ "** You may try ''Update Current Page'' from the ''Help'' menu." + CHR$(10) +_
";Note:This may also just be a temporary server issue. If the problem persists " +_ ";Note:This may also just be a temporary server issue. If the problem persists " +_
"after waiting some time, then please feel free to leave us a message." + CHR$(10) "after waiting some time, then please feel free to leave us a message." + CHR$(10)
@ -488,7 +501,7 @@ SUB WikiParse (a$) 'Wiki page interpret
END IF END IF
END IF END IF
'However, the internal link logic must run always, as it also handles 'However, the internal link logic must run always, as it also handles
'the template {{Cb| and {{Cl| links used in text/code blocks 'the template {{Cb|, {{Cl| and {{Cm| links used in text/code blocks
IF link = 1 THEN IF link = 1 THEN
IF c$(2) = "]]" OR c$(2) = "}}" THEN IF c$(2) = "]]" OR c$(2) = "}}" THEN
i = i + 1 i = i + 1
@ -557,7 +570,7 @@ SUB WikiParse (a$) 'Wiki page interpret
'Wiki templates are handled always, as these are the basic building blocks of all 'Wiki templates are handled always, as these are the basic building blocks of all
'the wiki pages, but look for special conditions inside (Help_LockParse checks) 'the wiki pages, but look for special conditions inside (Help_LockParse checks)
IF c$(5) = "{{Cb|" OR c$(5) = "{{Cl|" THEN 'just nice wrapped links IF c$(5) = "{{Cb|" OR c$(5) = "{{Cl|" OR c$(5) = "{{Cm|" THEN 'just nice wrapped links
i = i + 4 i = i + 4
link = 1: link$ = "": lcol$ = "" link = 1: link$ = "": lcol$ = ""
Help_LinkTxt = 1: col = Help_Col Help_LinkTxt = 1: col = Help_Col