Jump to content

User:PerfektesChaos/js/idResolver: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
+
update
 
Line 87: Line 87:
Every external link containing a presumable [[digital object identifier]] (DOI) code will offer multiple targets:
Every external link containing a presumable [[digital object identifier]] (DOI) code will offer multiple targets:
* original URL
* original URL
* <code>dx.doi.org</code> – the genuine resolver
* <code>doi.org</code> – the genuine resolver
* <code>dx.doi.org</code> – the older resolver
* <code>doai.io</code>
* <code>doai.io</code>
* <code>openaccessbutton.org</code>
* <code>openaccessbutton.org</code>

Latest revision as of 07:20, 30 June 2024

JavaScript gadget – offer multiple targets for certain links in page view.

Links governed by a kind of ID will access not only the original URL, but various resolvers and URL modifications. If desired all URL offer a colletion of archive entries.

Functionality

[edit]

On any page in selected namespaces the links will be analyzed whether they match a known format.

  • Link targets which are enabled by user option are showing a selection box now.
    • They will work as usual on double click.
    • A second single click on the text link closes the selection box again.
  • In some cases URL may be redirected to another page, based on current ID (shift mode).
  • Target pages are opened in new browser window or tab, if resulting from modified link target.
  • If resource type can be guessed from URL, some (e.g. PDF) will be marked by specific icon.
Internal links
The following type of ID is recognized and gets multi-targetting:
Future plans:
  • User pages and user talk pages (disclosing plain nick for c&p; offering common link set for user page, talk page, logs, statistics; IP tools for anonymous users; retrieving capability of some key values [group membership, registration, editcount, date of last edit, blocked])
  • Media files (offering direct link to commons, various tools)
  • Template links (offering various tools)
  • Categories (offering various tools)
  • Redirects (retrieving redirect target)
External links
The following types of ID are recognized and get multi-targetting:
  • DOI
  • ISSN
  • National library identifiers
    • German GND already supported (DNB)
    • LCCN envisioned
  • Any other external URL, offering links to web archives (www)
Future plans:
  • Handle (supertype of DOI)
  • Bible quotes (offering links to ancient sources and current user language resources)

Usage

[edit]

Insert these lines into personal common.js or similar (on any wiki):

mw.loader.load("https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/idResolver/r.js&action=raw&bcache=1&maxage=86400&ctype=text/javascript",
               "text/javascript");

Selective activation

[edit]

Namespaces

[edit]

By default, on normal view and preview links are analyzed in the following situations:

  • main namespace (encyclopedic articles on Wikipedia)
  • own user pages
  • project sandbox

More namespace numbers may be added by interactive costumization or in rooms Array.

Currently no relevant links are expected on special pages, but that will change when user page links enter the field.

Toolbox

[edit]

An appropriate page will be equipped. This may be suspended by interactive costumization or lazy property. On left column of desktop pages a toolbox link will be created.

Individual buttons

[edit]

Experts may block automatic equipment of pages, but provide their own facilities.

var resolverOpts = { };
resolverOpts.lock = true;
mw.hook( "idResolver.before" ).fire( resolverOpts );
mw.loader.load( /* ... */ );    // as shown above

function myResolverButton( action ) {
   // Create button and insert into collection ...
   $button.click( action );
}
mw.hook( "idResolver.fire" ).add( myResolverButton );

action is a function without parameters, that triggers expensive core loading and page equipment.

By setting the lock property other causes for equipment will be blocked.

If nothing to do myResolverButton wouldn’t be called ever; then no useless button.

[edit]

ISBN

[edit]

Links pointing on Special:Booksources (with current value) will offer multiple targets:

The entire link may be diverted to a single library catalog only; see shift configuration.

See below for details on personal configuration.

DOI

[edit]

Every external link containing a presumable digital object identifier (DOI) code will offer multiple targets:

  • original URL
  • doi.org – the genuine resolver
  • dx.doi.org – the older resolver
  • doai.io
  • openaccessbutton.org
  • sci-hub.io
  • scholar.google.de

The handler code is: doi – see handler configuration how to expand your personal index.

ISSN

[edit]

Every external link containing a possible International Standard Serial Number (ISSN) pattern will offer multiple targets:

  • original URL
  • WorldCat entry
  • JSTOR index
  • German national library catalog of periodicals (ZDB)
  • French national library catalog of periodicals

The handler code is: issn – see handler configuration how to expand your personal index.

DNB

[edit]

Some external links known to contain a GND identifier of German national library will offer multiple targets:

  • original URL
  • d-nb.info (if not the same)
  • deutsche-digitale-bibliothek.de

The handler code is: dnb – see handler configuration how to expand your personal index.

www

[edit]

All external links not matching the rules above may be turned into multi-target selection, if explicitly requested by interactive costumization or linking property. The following list will be offered:

  • original URL
  • web.archive.org
  • www.webcitation.org
  • archive.is

The handler code is: www – see handler configuration how to expand your personal index.

Resource type

[edit]

The following resource types are guessed from external link path:

ID icon ext start
pdf PDF [./=]
msexcel XLS \.
msword DOC \.

By JavaScript types property object components may be added or changed:

  • object component: ID
  • assigned to object with components:
    • ext – plain string with file extension (will be used upcased and downcased)
    • start – RegExp string prepending ext; defaults to \.
    • commons – URL path on Commons upload, part like x/xx/title.ext
  • or assigned to false – do not append such icon

Individual Configuration

[edit]

The initial environment and the behaviour can be equipped by each user individually.

Quick interactive costumization

[edit]

Some options can be set interactively on Special:Blankpage as soon as the script has been loaded.

When reloading a page the preferences declared here come into effect. This dynamic assignment overrides the static setting by application object.

Anonymous users can use this mode, too; options will be stored in browser profile rather than on wiki server.

Only simple yes/no stuff is meaningful here. Sophisticated configuration requires JavaScript objects.

Configuration by JavaScript

[edit]

Insert code similar to the following lines into common.js etc. before mw.loader.load:

var resolverOpts = { };       // use any name you like
resolverOpts.key1 = value1;   // example
// ... etc.
mw.hook( "idResolver.before" ).fire( resolverOpts );
mw.loader.load( /* ... */ );    // as shown above

Components and simple switches

[edit]
Key Default Bedeutung
launch false Run on all pages in all namespaces.
lazy false Run on explicit request only.
true – create link in portlet toolbox only
light false Skip individual visited link colours.
true – colour of all links equipped will permanently change when one of them was first visited
linking false Equip all externals.
true – all externals not covered by other scope will offer archived alternatives
lock false Block page equipping.
true – do nothing but toolbox link, if requested
false – equip page, if no toolbox link request
make 0 Divert equipped links into another tab/window.
0 – always the same (but not current) window.
1 – the same window for each task
2 – the same window for each domain
3 – always entirely new window
seen 00008B Colour hexcode for “visited” state of equipped links.
rooms null Array of namespace numbers.
Default: see namespaces
types null object for “file name extensions”
Default: see resource types
cfg null object for handler configuration
debug false Development.
false – run minimized code.
true – use human readable code.

Handler configuration

[edit]

The rules how to deal with certain IDs are called “handler”.

  • A single rule is an URL pattern that contains a # sign.
  • The ID in question will replace that first # which is not supposed to be necessary to call the page, and only the first one would be replaced anyway.
  • For www handlers the ID is the entire linked URL, otherwise a certain number etc.
  • Multiple rules may be provided. They are expected to form a list, stored as an Array.
  • If for any reason a single rule is repeated in the overall collection, no problem – double entries get filtered out.

The entire handler for a certain type of ID is one of the following:

  • the value false – ignore this ID type completely
  • an object with
    • a shift component
      • This is a string with an URL pattern.
      • All requests of this ID type will be diverted immediately to the resulting URL.
      • Any other component will be ignored.
    • a resolver component
      • This is an Array of URL pattern strings.
      • Those will be added to the built-in pattern strings for this ID.
      • For the isbn type it is an object with language code components; see below.

The cfg component of the application object resolverOpts (or any other name) is bearing the information how to add handlers. It is an object with handler ID as component.

var resolverOpts = { };
resolverOpts.cfg = { };
// Link tool with current GND
resolverOpts.cfg.dnb = { resolver: [ "https://tools.wmflabs.org/persondata/p/gnd/#" ] };
// divert all ISBN to KVK
resolverOpts.cfg.isbn = { shift: "http://www.ubka.uni-karlsruhe.de/kvk.html?SB=#" };
// don't do DOI
resolverOpts.cfg.doi = false;
// ... etc.
ISBN resolving
[edit]

The handler code is: isbn

Depending on the human language exposed by ISBN a specific set of library catalogs is chosen:

  • qqq – matching all languages.
  • en or fr or de etc. – filter particular catalogs

The handler for ISBN differs slightly from the others. It is an object which has language codes as components. Those are assigned to Arrays which contain URL patterns like the other handlers. In other words: the language codes act as resolver components.

resolverOpts.cfg.isbn =
    { qqq: [ "http://catalog.loc.gov/vwebv/search?searchCode=ISBL&searchType=1&searchArg=#" ],
      de:  [ "http://www.ubka.uni-karlsruhe.de/kvk.html?SB=#" ]
    };

Use also Library of Congress for all books, and add KVK to German libraries.

mw.libs

[edit]

The application is reflected on mw.libs.idResolver as well. The following code may be used as project default, but properties will be overruled by individual hook:

if ( typeof mw.libs.idResolver !== "object" ) {
   mw.libs.idResolver = { };
}
if ( typeof mw.libs.idResolver.opt !== "object" ) {
   mw.libs.idResolver.opt = { };
}
mw.libs.idResolver.opt.key1 = value1;   // example

The opt component of mw.libs.idResolver has similar contents as “resolverOpts” in hook calls.

Involved modules

[edit]

The code is divided into three modules. Only the head module is to be loaded by user into selected pages. The head module will decide on appropriate further steps and load required core module and script libraries when really needed. This keeps the head module as slim and fast as possible if nothing to do.

The following table shows which scripts are loaded:

head module wherever regarded as meaningful
/core major implementation
/prego interactive costumization
isbnLib ISBN utilities

Codes

[edit]
Source code

head module:

major implementation:

interactive costumization:

ResourceLoader
Namespaces
Cookies
  • (localStorage) idResolver Anonymous user preferences only.
mw.libs idResolver
mw.hook
  • idResolver.beforeconfiguration
  • idResolver.ready – after loading
  • idResolver.fire – provide start function
  • idResolver.changed – when links got new equipment
MediaWiki
  • 1.26 (mw.storage) options for anonymous users
  • 1.23 for registered users

There is a Test page.