Topic on Project:Support desk

Jump to navigation Jump to search

Detecting whether a remote page exists while formatting a wiki page

5
Vicarage (talkcontribs)

I am trying to tie a 20000 page wiki with a separate file repository with 5000 directories. Its rather random whether a wiki page has a matching repository page. Ideally I want to present a wiki link only if the target page exists, so users don't click on the link and get a 404. I would hope to write a template


{{repo}}

and for the template to check the validity of the remote link, and either display "Files here" if they were available, or blank if not. I'd rather not go down the pywikibot route of modifying pages as the files site changes.


I like the iframe extension, and if I could wrap that in a check, I could display the files page inside the wiki page neatly.

Bawolff (talkcontribs)

Its possible to write an extension to detect if an external link exists (aka is not a 404), but I don't think any such extension exists as of yet.

Jonathan3 (talkcontribs)

I've written something similar for my wiki - it redirects all external links to a special page, which uses cURL to check the link and displays options accordingly (or goes automatically to the external page). You could do something similar without the special page. I could look up which MediaWiki hook I used if that would help.

Vicarage (talkcontribs)

That would be really useful, as I code up that.

Bawolff (talkcontribs)

the main two approaches would probably be: create a parser function similar to {{#ifexist so you can program a template to do what you want (see manual:Parser functions)

Otherwise, use a link hook to change the output/formatting of the link (e.g. you could make it plain black text if its 404, so still clickable but doesnt look it) using a link related hook like manual:hooks/LinkerMakeExternalLink

Reply to "Detecting whether a remote page exists while formatting a wiki page"