User:PerfektesChaos/js/pageLinkHelper

From Wikipedia, the free encyclopedia

JavaScript gadget – several little helpers for links related to pages:

  • diff – put a wiki formatted link source on diff pages for c&p
  • permalink – put a wiki formatted link source on some pages for c&p
  • purge – add a link to purge the current page into portlet
  • redirect – insert an entry in browsing history if redirected here

Usage[edit]

  • If your project has registered this as a gadget, just activate on your Preferences page.
  • Otherwise include the following lines into your common.js, global.js etc.:
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/pageLinkHelper/r.js&action=raw&bcache=1&maxage=604800&ctype=text/javascript",
                "text/javascript" );

Difflink source code[edit]

If you visit a diff page, comparing two revisions of a page, you get a link code for copy&paste in the upper right corner of the content, looking like this:

[[Special:Diff/-]]

Such Special:Diff/- is much shorter than an URL and works also in edit summary or as reason for some action, where URL is not evaluated.

The generated element has two selectors:

  • .pageLinkHelper
  • #pageLinkHelperDifflink

Permalink source code[edit]

If you visit an older revision of a page, you get two link codes for copy&paste in the upper right corner of the content, looking like this:

[[Special:PermanentLink/-]]
[[Special:Redirect/page/44620682]]

Such links are much shorter than an URL and work also in edit summary or as reason for some action, where URL is not evaluated.

The first permalink yields the current revision, the second one points always to the same page, even if had been moved meanwhile. There is an URL available within the copy pattern that contains also the informative parameter title= which memorizes the page name.

On some pages there is a link on “Permanent link” available within the toolbox, usually in left sidebar. The functionality of this standard link is modified to insert the link source codes as mentioned.

The generated element has two selectors:

  • .pageLinkHelper
  • #pageLinkHelperPermalink

Purge server cache[edit]

Add a link into your portlet to purge the current page on the server.

On “Vector” skin, this will be appended to the menu below the ▼ fly-out on top of the page. No further action is required.

On any other skin or if you want another place for the link you need to specify where to add that link by a statement like this:

mw.libs.pageLinkHelper = { purge: "p-tb" };

It should appear on your common.js, global.js or skin dependant JS best before an mw.loader.load() call as described in “Usage” section.

The assigned code specifies where to place the link:

  • "p-cactions" – end of content actions (usually horizontal menu at top of page) – default
  • "p-tb" – end of toolbox (usually in left sidebar) – see example
  • "p-navigation" – end of navigation box (usually in left sidebar)
  • "ca-history" – any particular portlet element after which you want to insert the purge link

The generated link has one if these selectors, depending on context:

  • #ca-purge (default)
  • #n-purge
  • #t-purge

Purging for experts: forcerecursivelinkupdate[edit]

This feature causes more updating than simple page purging, but might be confusing. Therefore it is disabled by default. Experts will know when to use this and which consequences to be expected.

By

mw.libs.pageLinkHelper = { forcerecursivelinkupdate: true };

(Vector) or the same selectors as mentioned in the section on purging a link can be inserted into a portlet-container, which starts a link update via API.

Depending on chosen container the generated link has a selector like:

  • #ca-purgeLinkUpdRec #n-purgeLinkUpdRec #t-purgeLinkUpdRec

Redirects in browser history[edit]

If you reach a page following a redirect link, you get a small note in the upper left corner of the content, including a link to the redirect page. However, if you continue to work, especially if you edited that page, this tiny note and link will vanish. If you need to open the redirect page later, there is no simple way to reach that particular redirect again.

This gadget inserts an entry in browsing history when a redirect has been processed. The rendered page is still the target page, but one step before in history you get the redirection URL displayed in address bar. After clicking that one you can view and edit the redirect.

Required Browser[edit]

This feature depends on the browser and requires a recent version: Chromium 5, Firefox 4, Gecko 2, IE 10, Opera 11.50, Safari 5.0.

Address bar until 2014[edit]

Until summer 2014 address bar did not show the URL of the current page but of the redirect page, if forwarded by a redirect link.

If this behaviour shall be simulated, the following statement may be used:

mw.libs.pageLinkHelper  =  {  redirect: { legacy: true }  };

It should appear on your common.js, global.js or skin dependant JS best before an mw.loader.load() call as described in “Usage” section.

History, contributions, watchlist[edit]

Every entry begins with some links on diffpage and particular revisions. These URL are converted into links to special pages, which may be transformed into internal links much easier.

qqx – make system messages visible[edit]

This feature is needed more for project maintenance rather than by regular users. Therefore it is disabled by default. It makes the identifiers of system messages in page visible.

By

mw.libs.pageLinkHelper = { slangQQX: true };

(Vector) or the same selectors as mentioned in the section on purging a link can be inserted into a portlet-container, which opens the same page again but under uselang=qqc circumstances.

Depending on chosen container the generated link has a selector like:

  • #ca-langQQX #n-langQQX #t-langQQX

Multiple user options[edit]

If more than one option is to be provided, the statements above would erase each other. A slightly different notation is needed, e.g. as follows:

if ( typeof mw.libs.pageLinkHelper !== "object" ) {
   mw.libs.pageLinkHelper = { };
}
mw.libs.pageLinkHelper.purge = "p-tb";
mw.libs.pageLinkHelper.redirect = { legacy: true };

It should appear on your common.js, global.js or skin dependant JS best before an mw.loader.load() call as described in “Usage” section.

Other languages[edit]

This gadget is prepared for multilingual support.

  • If you like a version in your own language, please forward translations to me:
    • This documentation page.
    • The Config mapping on top of source code.
    • Further ISO 639 language codes your translation might support.

Intermediately, programmers can override any Config component by providing a respective component at:

mw.libs.pageLinkHelper.config = { /* ... */ };

Codes[edit]

Source code
ResourceLoader
Namespaces
  • -1   *   Contributions Watchlist (Gadgets) and Diff if ever occurring
  • Any content namespace.
mw.libs pageLinkHelper