User:PerfektesChaos/js/idResolver

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
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 ( 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:
 * ISBN by Special:Booksources
 * 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
Insert these lines into personal common.js or similar (on any wiki):

Namespaces
By default, on normal view and preview links are analyzed in the following situations: More namespace numbers may be added by interactive costumization or in  Array.
 * main namespace (encyclopedic articles on Wikipedia)
 * own user pages
 * project sandbox

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

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

Individual buttons
Experts may block automatic equipment of pages, but provide their own facilities. is a function without parameters, that triggers expensive core loading and page equipment.

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

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

ISBN
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  configuration.
 * original Special:Booksources page
 * WorldCat entry
 * Libraries depending on language of ISBN
 * User defined assignments from language code to certain specific catalogs

See below for details on personal configuration.

DOI
Every external link containing a presumable digital object identifier (DOI) code will offer multiple targets: The handler code is:  – see handler configuration how to expand your personal index.
 * original URL
 * – the genuine resolver
 * – the older resolver

ISSN
Every external link containing a possible International Standard Serial Number (ISSN) pattern will offer multiple targets: The handler code is:  – see handler configuration how to expand your personal index.
 * original URL
 * WorldCat entry
 * JSTOR index
 * German national library catalog of periodicals (ZDB)
 * French national library catalog of periodicals

DNB
Some external links known to contain a GND identifier of German national library will offer multiple targets: The handler code is:  – see handler configuration how to expand your personal index.
 * original URL
 * (if not the same)

www
All external links not matching the rules above may be turned into multi-target selection, if explicitly requested by interactive costumization or   property. The following list will be offered: The handler code is:  – see handler configuration how to expand your personal index.
 * original URL

Resource type
The following resource types are guessed from external link path: By JavaScript  property object components may be added or changed:
 * object component: ID
 * assigned to object with components:
 * – plain string with file extension (will be used upcased and downcased)
 * – RegExp string prepending ; defaults to
 * – URL path on Commons upload, part like x/xx/title.ext
 * or assigned to  – do not append such icon

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

Quick interactive costumization
Some options can be set interactively on  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
Insert code similar to the following lines into common.js etc. before mw.loader.load:

Handler configuration
The rules how to deal with certain IDs are called “handler”. The entire handler for a certain type of ID is one of the following:
 * 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  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 value  – ignore this ID type completely
 * an object with
 * a  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  component
 * This is an Array of URL pattern strings.
 * Those will be added to the built-in pattern strings for this ID.
 * For the  type it is an object with language code components; see below.

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

ISBN resolving
The handler code is:

Depending on the human language exposed by ISBN a specific set of library catalogs is chosen: 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  components. Use also Library of Congress for all books, and add KVK to German libraries.
 * – matching all languages.
 * or  or   etc. – filter particular catalogs

mw.libs
The application is reflected on  as well. The following code may be used as project default, but properties will be overruled by individual hook: The  component of   has similar contents as “resolverOpts” in hook calls.

Involved modules
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:

Codes
There is a /Test/ page.

de:User:PerfektesChaos/js/idResolver