Page MenuHomePhabricator

RFE: ParserFunction to extract one or the other part of a wikilink
Closed, DeclinedPublic

Description

Author: cyp

Description:
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)


Version: unspecified
Severity: enhancement

Details

Reference
bz16080

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 10:18 PM
bzimport added a project: ParserFunctions.
bzimport set Reference to bz16080.
bzimport added a subscriber: Unknown Object (MLST).

To find out if it's a link or not - if you know that only existing pages are linked - you can use {{#ifexist:}}.

cyp wrote:

(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:}}.

  • Its not meaningful for a template to simply determine if a parameter is a link. The template couldn't do anything about it.
  • 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.

Danny_B removed a subscriber: wikibugs-l-list.

Achievable with Scribunto nowadays, besides the mentioned example ({{cite|title=[[foo|bar]] }}) is bad by design (it should rather allow two params, sth. like {{cite|target=foo|title=bar}}).