Last modified: 2011-04-14 15:12:56 UTC
Request for enhancement: A parser function that can extract part of a wikilink I imagine such a parser function would/could work something like this: {{#linkpart: [[foo|bar]] }} => bar //returns the link's presentation text {{#linkpart: [[foo|bar]]:R }} => foo //returns the "raw", i.e. the link's target {{#linkpart: [[foo]] }} => foo //presentation form and raw form are identical {{#linkpart: [[foo]]:R }} => foo //... so both return the same thing {{#linkpart: plaintext }} => plaintext // a non-link returns plain text Rationale: Such a function is necessary for parameter handling in templates (e.g. to deal with links when one isn't expected), and to be able to generate clean metadata. For example, invoking {{cite|title=[[foo|bar]] }} will be appear "fine" in an article, but the metadata (invisible to the editor) will end up with the wiki syntax too, as in: <span title="ctx_ver=Z39.88-2004&rft.btitle=[[foo|bar]]"> (the urlencoded version thereof)
To find out if it's a link or not - if you know that only existing pages are linked - you can use {{#ifexist:}}.
(In reply to comment #1) > To find out if it's a link or not - if you know that only > existing pages are linked - you can use {{#ifexist:}}. * This RFE has nothing directly to do with determining whether a parameter is a link or not. What this RFE does is request a particular kind of (wikisyntax-specific) string manipulation, i.e. to extract one part of what is inside a [[ ]]. See also {{#titleparts:}} * Its not meaningful for a template to simply determine if a parameter is a link. The template couldn't do anything about it. * {{#ifexist:}} cannot in fact be reliably (mis)used to determine if a parameter is a link. Case in point: 'bugzilla:16080' and 'm:Parser functions' will "not exist", nor will anything else that needs "parsing", like '2008-10-24' or for that matter anything '[[like this]]' (which would be "expected" use of the suggested {{#linkparts:}}) * Now that you mention it (and although not related to the rationale for this RFE), simply determining if a parameter is a link can (also) be determined using the suggested {{#linkpart}} syntax mentioned above, but even then, its not altogether trivial: {{#ifeq:{{#linkpart:{{{1|+}}}}}|{{{1|-}}}||Param #1 is a wikilink!}} would be the most basic form. And a more robust implementation would still fail if {{{1}}} has internal leading/trailing whitespace. I repeat: This RFE has nothing directly to do with determining whether a parameter is a link or not. Together with #ifeq it can /also/ be used to determine that, but that is not its basic function. The basic function is a particular kind of (wikisyntax-specific) string manipulation.