Difference between revisions of "Template:Links to"

From blackwiki
Jump to navigation Jump to search
imported>Cpiral
(+ same page links)
imported>Jdaloner
m ("{{plainlink" --> "{{plain link")
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
<onlyinclude><!--
 
<onlyinclude><!--
  
We can't do EL's directly.  There's too many ways to match.
+
By relying foundationally on search parameter "linksto",
We report EL's as highly probable links,  
+
this version avoids namespace name variations in the wikitext,
or as the best bet "pattern to investigate".
+
and reduces the number of search links to two.
  
The URL-style links to sections are found along with wikilinks
+
This version does not concern itself with URL-style links to sections.
by the pattern, not by the actual linking effect.
+
A later version will re-introduce that functionality, but only
So we don't 1) use search parameter linksto to find just WL,
+
by way of a parameter that flags the need to produce up to twelve search links.
and then 2) use search patterns to find just EL. 
 
Instead, we mix them all, and use insource patterns only, not linksto.
 
  
Why? Because indexed searches make canonicalurl:namespace:pagename atomic.
+
That version will rely on up to twelve insource searches to do this 2 X 2 X 3:
With that term indexed, you can't find canonicalurl or namespace or pagename.
+
+ two kinds of *url: canonicalurl and fullurl
You can only find canonicalurl:namespace:pagename.
+
+ two kinds of atomic search terms: *url with and without space char
The same is true for fullurl, and for namespace:pagename.
+
+ up to three namespace names: WP and WT have two other aliases.
Compounding the matter:
+
Logical OR to combine the possibilities is not an option for
* Insource doesn't take OR.
+
search parameter insource.
* Canonicalurl and fullurl can have a space afterwords.
 
Regex could do it, but needs a filter, and as said, there's too matches.
 
That translates to too many search links.  Hense the combination.
 
  
Another combination used is "same page" and "sub page".
+
Output one of the two possible contexts for the search links.
This is done in one search link.  It does use regexp
 
to account for the alias "slink" for the template "search link",
 
but that's OK because it is easily filtered with a linksto.
 
(Linksto finds the wikilinks that template search link makes.)
 
  
We create several six links.
+
-->{{#if: {{{2|}}} <!-- Was a page name also given? -->
We use search parameter hastemplate to find "Section link", and report it.
 
That's one search link.  The other three are insource:"arguments" based:
 
1) namespace:pagename  (finds #Links as WL or EL1 or EL2 having space)
 
2) canonicalurl:namespace:pagename (finds EL1 without a space)
 
3) fullurl:namespace:pagename (finds EL2 without a space)
 
The colon : character creates an atomic term, no splitting it term.
 
(The /subpage and #section don't create atomic terms.)
 
The (2) and (3) are at-least-four-match sequences (when given section names are shown).
 
The (1) finds most pages, but is only at-least-three-match, so it gets regexp /#fragment/.
 
 
 
This would all be a lot easier if search parameter linksto did ELs.
 
Why?  Because by having to search the wikitext with insource instead
 
(and because regex is not a wiki-wide search option; it always requires a
 
filter)
 
we run into the namespace alias problem.
 
The wikitext will have all the aliases.
 
If the section linked to is in the Wikipedia or Wikipedia talk, or  namespace,
 
you have to run the template for each of the two other aliases WP and Project.
 
Same for
 
Finally, when searching for links to the fragment,
 
since linksto does not recognizes links using URL-style,
 
we can't use it as a filter.
 
 
 
Let's call "section name" (or "anchor" or "id" or "heading") just "fragment".
 
"{{{2}}} {{{1}}}" is "namespace:pagename fragment".
 
 
 
Trim is used in case both 1) user says 1= or 2=, plus 2) uses extra whitespace.
 
Trim is then used to ensure correct and/or pretty queries.
 
 
 
-->{{#if: {{{2|}}} <!-- if a page name is given in a second parameter, -->
 
 
|<!-- True, so don't output the pink box stuff.
 
|<!-- True, so don't output the pink box stuff.
 
Instead output a line starting with "fullpagename#Section: "
 
Instead output a line starting with "fullpagename#Section: "
Line 64: Line 25:
 
{{(!}} border="1" cellpadding="6" cellspacing="0" style="background:pink;width:61%"
 
{{(!}} border="1" cellpadding="6" cellspacing="0" style="background:pink;width:61%"
 
{{!}}<!-- this translates to a pipe | character, so's not to confuse #if's pipe chars -->  
 
{{!}}<!-- this translates to a pipe | character, so's not to confuse #if's pipe chars -->  
Search links to find all links to ''{{{1|section}}}'':<br/>
+
Search links to find links to ''{{{1|section}}}'':<br/>
 
}}<!-- end #if
 
}}<!-- end #if
  
Output the search links. #Links §Links EL1 EL2 SL.  Same processing for both #if versions of this template.
+
Output the search links (either context): #Links and §Links.  
  
First, the most populous search: wikilinks and the external style links
+
-->{{plain link<!--
that have a space after the colon -- "canonicalurl: " and "fullurl: ".
 
If more search links are tolerable, this combo batch is separable.
 
Just use linksto to ensure wikilinks, and then have separate searches
 
EL1 EL2 for spaced and unspaced versions of "canonicalurl:", and
 
EL3 EL4 for fullurl.
 
-->{{plainlink<!--
 
 
   -->|{{fullurl:Special:Search|search={{urlencode:<!--
 
   -->|{{fullurl:Special:Search|search={{urlencode:<!--
 
     -->{{ trim | {{{3|all}}} }}: <!--
 
     -->{{ trim | {{{3|all}}} }}: <!--
    Match "canonicalurl: fullpagename", "fullurl: fullpagename", and [[fullpagename]]
+
     -->linksto: "{{ trim | {{{2|{{FULLPAGENAME}}}}} }}" <!-- target the entire page
     -->insource: "{{trim | {{{2|{{FULLPAGENAME}}}}} {{{1}}} }}" <!-- trim any spaces on outer boundary of insource arg
+
    (trims any spaces on outer boundary of insource arg)
     Regexp the number # sign is actually there for the fragment in this batch of matching.
+
    Proof: both linksto and matches "#section". 
     -->insource:/"#<!-- Preprocess {{{1}}}
+
     Matching "#section" requires a regexp that permits metachars in the section name, and equates _ to space char.
    Change " to \", / to \/ and a space character to [ _]
+
    -->insource: "{{{2|{{FULLPAGENAME}}}}} {{{1}}}" <!-- target the desired term sequence
 +
     -->insource:/"<!-- target the redirect symbol and section name
 +
    Preprocess {{{1}}}, changing " to \", / to \/ and a space character to [ _]
 
     -->{{#invoke:String|replace
 
     -->{{#invoke:String|replace
 
       |source =  
 
       |source =  
Line 88: Line 45:
 
           |source =  
 
           |source =  
 
             {{#invoke:String|replace
 
             {{#invoke:String|replace
               |source = {{trim | {{{1}}} }}
+
               |source = {{trim | {{{2|{{FULLPAGENAME}}}}}#{{{1}}} }}
 
               |pattern = "
 
               |pattern = "
 
               |replace = "\""
 
               |replace = "\""
Line 100: Line 57:
 
     }}"/}}}} <!-- end of urlencode and fullurl  
 
     }}"/}}}} <!-- end of urlencode and fullurl  
 
   -->|name=#Links<!-- Make the label fullpagename#Section : WL . TL . EL
 
   -->|name=#Links<!-- Make the label fullpagename#Section : WL . TL . EL
-->}}<!-- end of plainlinks: #Links
+
-->}}<!-- end of plain links: #Links
  
Now for:          hastemplate:"section link"
+
Now for:          §Links
Section link is little used, so it's a good filter.  Linksto is highly used, so not.
+
-->{{middot}}{{plain link<!--
linksto actually regognizes hastemplate
 
-->{{middot}}{{plainlink<!--
 
 
   -->|{{fullurl:Special:Search|search={{urlencode:<!--
 
   -->|{{fullurl:Special:Search|search={{urlencode:<!--
    -->{{trim | {{{3|all}}} }}: <!-- (saw aesthetic space)
+
     -->{{ trim | {{{3|all}}} }}: <!--
    -->hastemplate: "section link" <!--
 
    -->insource: "section link {{{2|{{FULLPAGENAME}}}}} {{{1}}}"<!--
 
    -->}}}}<!-- end fullurl and url
 
  -->|name=&sect;Links<!--
 
-->}}<!-- end plainlinks §Links
 
 
 
Now for:          canonicalurl:fullpagename
 
-->{{middot}}{{plainlink<!--
 
  -->|{{fullurl:Special:Search|search={{urlencode:<!--
 
    -->{{trim | {{{3|all}}} }}: <!-- (saw aesthetic space)
 
    -->insource: "canonicalurl:{{ trim | {{{2|{{FULLPAGENAME}}}}} {{{1}}} }}" <!--
 
    -->}}}}<!-- end fullurl and url
 
  -->|name=EL1<!--
 
-->}}<!-- end plainlinks EL1
 
 
 
Now for:          fullurl:fullpagename
 
-->{{middot}}{{plainlink<!--
 
  -->|{{fullurl:Special:Search|search={{urlencode:<!--
 
     -->{{trim | {{{3|all}}} }}: <!-- (saw aesthetic space)
 
    -->insource: "fullurl:{{ trim | {{{2|{{FULLPAGENAME}}}}} {{{1}}} }}" <!--
 
    -->}}}}<!-- end fullurl and url
 
  -->|name=EL2<!--
 
-->}}<!-- end plainlinks EL2
 
  
Now for:          same page and subpage #Links
+
     -->linksto: "{{ trim | {{{2|{{FULLPAGENAME}}}}} }}" <!--  
-->{{middot}}{{plainlink<!--
+
     Proof: both linksto fullpagename, and matches the given section _inside a template Section link (alias "slink") call_ .
  -->|{{fullurl:Special:Search|search={{urlencode:<!--
+
    The [Ss](ection )?link finds "section link" or its alias "slink", and in a case insensitive fashion.
     -->linksto: "{{ trim | {{{2|{{FULLPAGENAME}}}}} }}" <!--
+
     The [^}]* construct searches inside the template call.
     -->insource:/"#<!-- Preprocess {{{1}}}
 
      Change " to \", / to \/ and a space character to [ _]
 
      -->{{#invoke:String|replace
 
        |source =
 
          {{#invoke:String|replace
 
            |source =
 
              {{#invoke:String|replace
 
                |source = {{trim | {{{1}}} }}
 
                |pattern = "
 
                |replace = "\""
 
              }}
 
            |pattern = /
 
            |replace = "\/"
 
          }}
 
        |pattern = %s
 
        |replace = "[ _]"  
 
        |plain = false
 
      }}"/ prefix:{{NAMESPACE}}:{{ROOTPAGENAME}}<!-- same as {{FULLPAGENAME}} when no subpages exist
 
    -->}}}}<!-- end of urlencode and fullurl
 
  -->|name=#SL<!--
 
-->}}<!-- end plainlinks
 
 
 
Now for:          same page and subpage §links
 
-->{{middot}}{{plainlink<!--
 
  -->|{{fullurl:Special:Search|search={{urlencode:<!--
 
     The [^}]* construct you'll see next allows us to search for the section name, but just inside the template call.
 
 
     This catches both {{section link || section name }} and {{section link| fullpagename | section name}}.
 
     This catches both {{section link || section name }} and {{section link| fullpagename | section name}}.
     Acceptably, it misses when other kinds of braces are inside: {{section link | {{FULLPAGENAME}} | section name}}.
+
    Alternatively, using ({{{2}}} *\| *)? could be used to ensure fewer false positives if {{slink}} ever gets high use.
    The [Ss](ection )?link finds "section link" alias "slink", and in a case insensitive fashion.
+
     Acceptably, it misses when other kinds of braces are inside: {{section link | {{markup}} | section name}}.
     -->insource:/\{\{ *[Ss](ection )?link *[^}]*"<!-- quotation mark starts escaping any metacharacters in section name
+
     -->insource:/\{\{ *[Ss](ection )?link *[^}]*"<!-- QUOTE the regexp " or / chars
 +
    quotation mark starts escaping any metacharacters in section name
 
       -->{{#invoke:String|replace
 
       -->{{#invoke:String|replace
 
         |source =  
 
         |source =  
Line 171: Line 78:
 
             |source =  
 
             |source =  
 
               {{#invoke:String|replace
 
               {{#invoke:String|replace
 +
                <!--|source = {{trim | ({{{2|{{FULLPAGENAME}}}}} *\{{!}} *)?{{{1}}} }}<!-- overkill? -->
 
                 |source = {{trim | {{{1}}} }}
 
                 |source = {{trim | {{{1}}} }}
 
                 |pattern = "
 
                 |pattern = "
Line 182: Line 90:
 
         |plain = false
 
         |plain = false
 
       }}"/ <!--
 
       }}"/ <!--
    -->prefix:{{NAMESPACE}}:{{ROOTPAGENAME}}<!-- same as {{FULLPAGENAME}} when no subpages exist
 
 
     -->}}}}<!-- end fullurl and url
 
     -->}}}}<!-- end fullurl and url
   -->|name=&sect;SL<!--
+
   -->|name=&sect;Links<!--
-->}}<!-- end plainlinks
+
-->}}<!-- end plain links
  
 
Output a newline
 
Output a newline

Latest revision as of 19:09, 18 April 2018

Search links to find links to section:
Template:Plain link · Template:Plain link

Template documentation[view] [edit] [history] [purge]

{{Links to}} lists all pages that link to a section, and shows a snippet from each page, with the link highlighted. It uses the linksto search parameter to find the pages, and from that a regexp search to find the section's incoming links. (Note that the input to {{links to}} is a section, while the input to the search parameter linksto is a fullpagename.)

Purpose

Use {{links to}} to help decide about changing or removing section headings, {{anchor}}s, or "span id=" (HTML) tags.

  • Manage anchors. Assess and delete excess anchors. Move and replace anchors.
  • Manage section headings. Delete section headings. Rename section headings.

This template lists all the wikilinks to a section that are found in the wikitext as:

  1. [[ fullpagename#section ]]
  2. {{ section link | section}}
  3. {{ slink|section}}

These are all the usual-style wikilinks, and the search links produced by this template are definitive concerning the sections of most pages.[1]

While editing a section, you decide to rename its heading. Or you want to restructure an article. But it might break a link. And you're not sure about adding {{anchors}}.

  • "What links here" does not report links by section name.
  • This template, {{links to}}, reports sections but does not report redirects.
  • "Show redirects only" does report redirects to sections names. (It's on the What links here page).

Using these three tools, the incoming wikilinks to a section can be known.[1]

Usage

Work from the edit page — going from it and back to it — while finding all links and redirects.[2] When entering a {{links to|section}} copy any section name exactly as it appears in the wikitext:

  • == inside the heading markup == {{links to|section heading}} or
  • {{anchor | inside the anchor parameter }} {{links to|anchor}} or
  • <span id="inside the double quotes">...</span> {{links to|span id}}

The spacing outside the name is not important, but the markup and spacing inside the name is important.[3] The most common mistake is wrong capitalization.

Should you change or removed a section name, then for each incoming wikilink or redirect it had, you must edit that page, even if it is a user page. Use an edit summary like "fixing changed section name".

Links

Links. Taken altogether, the search links generated by this template will list all wikilinks to a section name of a page name.

  • #Links · Finds #section used in wikilinks (and URL-style links).
  • §Links · Finds {{ Section link | fullpagename | section }}. (uncommon)

The results do not overlap and are guaranteed links to that section.

Redirects

Redirects. Use the "Tool" What links here. (Its on every page and every edit page.) Once there, immediately activate the "external tool" Show redirects only. If your section name is shown, your redirects are reported. Just find the wikilinks to them using What links here, and you're done. If your section is not shown in the report, no redirect at all links to your section.

These normally report zero results (or fewer than ten).

Basic

{{ links to | section }}

Links to creates a pink box with search links inside: one to find wikilinks, one to find templates ({{Section link}}).

  1. On an edit page enter a {{links to}}.
  2. Preview the edit. A pink box appears with search links inside.
  3. Visit each of them while learning how to proceed.[4]
  4. Go back to your edit page.
  5. Visit the redirects report.
  6. Go back to your edit page and proceed.

Advanced

{{ links to | section | fullpagename }}
{{ links to | section | fullpagename | namespace }}

Links to outputs a single line starting with the fullpagename, and followed by the search links. This style is fit for collaboration or storage for wikiprojects.

Just add the fullpagename of the page of interest in parameter two. (The {{FULLPAGENAME}}, before {{DISPLAYTITLE}} or the like may have applied.)[5]

To limit search results to a namespace instead of all namespaces, use parameter three. This is necessary for a highly linked-to page like the Manual of Style (over a million links to it). This is useful to try when a search takes around twenty seconds and returns with zero results. (Search silently fails, with no indication of an HTML timeout.)

Parameters

Template:More

Spacing does not matter around the input.

{{ links to | 1st | 2nd | 3rd }}

1stTemplate:Space Section. Case sensitive. Matches wikitext character-wise.

2ndTemplate:Space Fullpagename. Case sensitive. First letter capitalized.[5]

3rdTemplate:Space namespace. Defaults to all. Accepts aliases.

Examples

Inside an edit session of this section
What you type What you get Description
{{ links to | Examples }}

Search links to find links to Examples :
Template:Plain link · Template:Plain link

Find all links to this section.
{{ links to | Usage }}

Search links to find links to Usage :
Template:Plain link · Template:Plain link

Find all links to this page's Usage section.
What you type: What you get:
{{ links to | Linux | Operating system }} Operating system#Linux:  Template:Plain link · Template:Plain link
{{ links to | Registers | Javanese language }} Javanese language#Registers:  Template:Plain link · Template:Plain link
{{ links to | Different functions of "to be" | E-prime }} E-prime#Different functions of "to be":  Template:Plain link · Template:Plain link
{{ links to | Projects | Mediawiki | talk }} Mediawiki#Projects:  Template:Plain link · Template:Plain link
{{ links to | Projects | Mediawiki | user talk }} Mediawiki#Projects:  Template:Plain link · Template:Plain link

Reordering. If you used natural instead of most-requested order, you can number them.
What you type:
{{ links to | Wikipedia:Manual of Style | Section headings }}
{{ links to | WP | Wikipedia:Manual of Style | Section management }}

{{ links to | 2= Wikipedia:Manual of Style | 1=Section headings }}
{{ links to | 3= WP | 2= Wikipedia:Manual of Style | 1= Section management }}

What you get:
Wikipedia:Manual of Style#Section headings:  Template:Plain link · Template:Plain link
Wikipedia:Manual of Style#Block quotations:  Template:Plain link · Template:Plain link

See also

Template:Search templates

Notes and references

  1. 1.0 1.1 There may exist additional wikilinks (internal links) to a given section. These are not currently listed:
    1. Web links made with URL-style syntax.
    2. wikilinks or {{Section link}}'s placed on a page by a transclusion.
  2. It is safe to navigate away from an edit page, for example to test a wikilink in the preview. It is safe also to activate a search link, for the same reasons. (To open a new tab or window instead, press Ctrl or ⇧ Shift while following a link.)
  3. The actual query, seen on the search results page, for sections with space characters in them, replaces every space with a "[ _]". This mirrors the behavior of the wikilinks.
  4. To get an edit tag for each search result, add this to your custom javaScript:
    $( function() {
    	'use strict';
    	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) {
    		$( '.mw-search-result-heading a' ).each( function() {
    			$( this ).after( '<span class="searchedit">[<a href="' + $( this ).attr( 'href' ) + '?action=edit">edit</a>]</span>' );
    		} );
    	}
    } );
    

    Until it is an official user preference, the code may be susceptible to malcontents.

  5. 5.0 5.1 It's the canonical name, not the redirect. It's the title line exactly, but the title line should begin with a capital letter. If there are any questionable aspects to the title's appearance, go to that page and render {{FULLPAGENAME}} in a temporary preview.