On 02/07/2011 03:01 AM, Brion Vibber wrote:
On Sun, Feb 6, 2011 at 4:30 PM, David
Gerard<dgerard(a)gmail.com> wrote:
Here's an interesting question. Is there any
way for
Special:WhatLinksHere to distinguish between links from a template
rather than links from the actual article text? I presume at present
it all just goes into a links table generated on save, and can't be
distinguished ...
Long story short, there's no good way to distinguish them due to combination
of 1) it's hard to define the actual problem domain and 2) the links tables
as they are today are not rich enough to distinguish the various cases after
the fact.
The link tables aren't really a problem: while the existing fields are
indeed insufficient for storing this information, adding an extra field
pointing the template which generated the link shouldn't take much work.
As you note, the major difficulty is in getting the information in the
first place (and deciding just how it should be determined).
It's not very clear what "links from a
template" mean, exactly; there are
several possibilities:
* the literal text [[Foobar]] appears in template code that gets expanded
into the calling page, but does not appear in the calling page's source
* the literal text [[Foobar]] appears in a template parameter passed from
the calling page to the template, which then expands it into the calling
page's own context. It would not become a link unless the template were
there, but the entire link appears in the calling page's source (example:
anything linked in freetext parameters to a citation or infobox template)
* the template constructs a link with some parameter, say
[[{{{something}}}]] which creates a link [[Foobar]] that exists by itself in
neither the calling page nor the template, but whose target is provided by
the calling page (example: lots and lots of infoboxes and such)
* the template constructs a link with some parameter, say
[[Wikipedia:List_of_requests/{{{something}}}]] which creates a link that
exists by itself in neither the calling page nor the template, but whose
target is influenced in some way by the calling page (example: lots of
helper templates for discussion chunks)
* the template constructs a link with some other piece of information,
perhaps a parser function, that can't clearly be traced from the calling
page (though it might be related to the calling page, such as pulling its
page name.)
I'd think that the most practical definition would probably be that the
link should be considered as generated by the calling page in the second
case in your list (literal link in template parameters) and generated by
the template in all the others. That is, the link should be considered
as generated at the point where the parser first sees something that
begins with [[ and ends with ]].
In any case, the tricky corner cases really don't matter much. Just
handle the common cases (literal link on calling page, literal link in
template, literal link in template params) right, and do whatever is
most practical to implement for the rest. It might not be perfect, but
it'd still be better than what we have now (i.e. nothing).
More information would need to be saved from the
parser into the link
tables... it may, or may not, be possible in the present parser system to
distinguish some of these cases when actually finding links and expanding
things, and then find some way to record in the links tables what source(s)
the link came from.
I'm not particularly familiar with the parser, but I suspect that this
would require doing at least some parts of link parsing _during_ brace
expansion, rather than in a separate pass after it. Which is probably
not trivial, but probably not quite impossible either.
--
Ilmari Karonen