User:Inductiveload/popups reloaded

This script is a re-imagined version of Navigation Popups.

It is alpha-grade: expect bugs, use with care In particular, the API for config and adding hook can and probably will change.

There are a few WS-centric tools included, and eventually it will be possible to add your own.



Installation
The basic script can be installed by adding the following to your Common.js page:



Features

 * Quickly preview and access information about pages
 * View raw Wikitext of pages
 * Perform some streamlined actions
 * Handles links to any wiki in the WMF (Wikipedia, Commons, Wikidata, etc)
 * WS-specific features:
 * Page image previews
 * Direct links to the files for indexes

Configuration
Configuration is via the  hook:

Basic config
Simple configuration options are provided, and are set directly on the cfg object passed to your hook handler:


 * the time you have to hover to get a popup
 * the list of skins to not have popups in
 * show a users contribution list on their username instead of their user page
 * how many log items to show:
 * the value used if a more specific one is not set (default: 25)
 * how many linkLimit items to show:
 * the value used if a more specific one is not set (default: 25)
 * namespaces to show shortcut links for in some actions:
 * the value used if a more specific one is not set
 * , : List of entries to show in the default RC/watchlists views. The default is  . You can add.
 * : pre-set block shortcuts
 * : pre-set deletion shortcuts

Custom hooks
The core feature of Popups Reloaded is a simple, but powerful, action framework. These are handled though a set of "hooks". There are three kinds of hook:


 * Recogniser hooks: look at a given HTML element (probably a link) and decide what kind of link it is (e.g. a link to a wiki article, a third-party link, etc.)
 * Action hooks: for a given element, generate a list of further actions (e.g. edit, history, etc). These are shown at the top of the popup. Multiple action hooks can fire on one link.
 * Content hooks: for a given element, generate some kind of preview content (for example, render a wiki page). Only one content hook can be fired on a single link.

Hooks are checked against a link by "scores". If you want to add a hook, you have to make sure, for content and recogniser hooks, that you outscore any other hook for the links you want, and for action hooks, you should set the score so the order is correct.

Recogniser hooks
These have the following structure:

The  function runs first, and decides how well this recogniser matches the given element. Returns a value (or a Promise that resolves a value) to be considered for a match, or  to declare the link doesn't match at all. The highest scoring hook will be be used.

The  object is provided so that the hook can pre-compute or cache values for this element, to be used by action or content hooks/

The  function of the highest-scored recogniser will be run and resolves with an object:
 * a type string which will be passed to the action and content hooks
 * a "canonical" URL for the link (e.g. perhaps a URL fragment can be stripped, or useless query params stripped to make it easier to match with action or content hooks).
 * a human-readable display text.

Built-in recogniser:


 * A generic URL, score 0
 * : the link's original href
 * : the link's original text
 * : the link's original text

The "link" recognizer adds some values to the cache as :
 * the href of the link (might not be a complete URL)
 * the complete URL if there is one
 * get the given param, if available
 * does the link contain all the params listed?


 * A URL to a known wiki, score 100
 * : the link is to a normal wiki page
 * : the link is to a "hash" link that ends
 * : the link is to plain wikitext
 * : the link's original href
 * : the link's original text
 * : the link's original text

The "wiki" recogniser adds useful things to the cache which can be used by action and content hooks to decide if they apply:


 * the complete title
 * the title without any namespace prefix
 * the base name (i.e. everything before the first  if there is one, else the entire title)
 * the namespace, e.g.
 * the section of a link (i.e. after )
 * true if the link is to this wiki
 * the user associated with a given link (e.g. a link to ), or undefined

Action hooks
The  is a human-readable name to assist in debugging, as it can tell you which hook is running on which link.

The  function is similar except that instead of the best scored function, all non-null scoring hooks will be used, in order of the score. The  object can be consulted for pre-computed values.

is a string or array of strings declaring the recogniser types this action hook is compatible with. The hook's score function will only be run for matching types.

The  function returns (or resolves) a list of action lists. Each action list will be a line of options. These options can also be lists, then they look like.

Every action item has a format like this:


 * : the text of the link for the action
 * : the href for the action
 * : optional, set to  to suppress further popups on this action
 * : optional, extra classes to set on the action link (can be used by hooks on the action link)

Content hooks
The  is a human-readable name to assist in debugging, as it can tell you which hook is running on which link.

is as for an action hook: only matching recogniser types will be inspected by

The  function is as for a recogniser hook: the best-scored content hook will be used.

The  function is run on the best-scored content hook. is the originating element,  is as provided by the recogniser. Returns or resolves with content for the popup. This will be inserted into the body of the popup.

The  function can add things to the cache for use by the   function to avoid re-computation. For example, set  in   and you can read it back in

Privacy
Requests to WMF wikis (e.g. Wikisource, Commons and Wikidata) are, as always, covered by the WMF Privacy Policy.

If you hover over external links, the tool may attempt a request to those links.

Links

 * Phab Workboard (file bugs here)
 * ../popups reloaded.js/
 * ../popups reloaded.css/