Jump to content

User:PerfektesChaos/js/lintHint

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by PerfektesChaos (talk | contribs) at 14:23, 7 August 2017 (+). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

JavaScript gadget – show LintErrors analysis (Parsoid messages) live.

Note: The features are rather new in summer 2017 and may be subject to discontinued support without any notice.

Automatic analysis of all visited pages will require some bandwith and hardware resources in background.

Purpose

Problems in wikitext detected by Parsoid and managed via Special:LintErrors for entire namespaces may be retrieved for a particular page view, and wikitext sequences may be checked interactively.

The Linter Extension is structured by error type only and may be filtered by namespace.

When visiting a particular page, this gadget can inform about all current error types immediately, and users interested in syntax improvement are encouraged to remedy right now.

Usage

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

Default behaviour

In wiki main space (e.g. Wikipedia articles) on regular view or during source text editing of a page a yellow button is offered in top right corner, that triggers an analysis.

If problems were detected a large yellow box is inserted in top region of the page.

The yellow box contains a table of errors.

  • If no error has been reported, a small green label is shown in the top right corner of content area in page view, or the button is refreshed on source text editing.
  • The large error table box might be minimized into a button in the top right corner, and could be expanded again.

If pages are not used for viewing nor editing, but e.g. history, info etc., no action is taken. Note that only wikitext pages may be subject to investigation.

There are detectable error types which are not yet in Linter categories. Choose later option to include them into table.

Control page

On a virtual page some version information is shown, if gadget is active.

Two interactive ways are offered for individual investigation:

  1. Input any wikitext sequence and check out.
  2. Enter a page name and get result of analysis, without a need to visit that page itself.

The result appears on the same page like on a regular page. Page names entered are reflected by clickable links and would be opened in a new window.

Configuration by JavaScript

Individual desire may be passed to the gadget at any time, best before loading.

The raw JavaScript code looks as follows:

// create a user defined object
var myLintHints = { };

// specify some object component
myLintHints.rooms = "-";

// communicate user defined object
mw.hook( "lintHint.config" ).fire( myLintHints );

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

Currently the following options are available:

Name Type Default Meaning
rooms Array
string
[ 0 ]
  • Array with namespace numbers, where analysis should be available.
  • "*" – all namespaces
  • "-" – no page analysis, but individual requests on control page.
oldid boolean false
  • Analyze previous revisions, too.
  • Otherwise only current page version will support analysis.
later boolean false Show also error types not yet in Linter categories.
launch boolean false Run analysis automatically in rooms rather than manual triggering by button.
lazy boolean false Suppress small label if no error detected.

Further options will be considered when lint system grows.

Multiple calls of mw.hook("lintHint.config") will not influence other components that were set before, if not explicitly changed.

LintErrors special page

Special:LintErrors categories will make tables sortable, until Mediawiki provides this feature.

Internationalization

Not required for gadget itself, but support on control page by a few lines.

Suggestions on foreign languages may be offered, as well as a translation of this page.

Codes

Source code
ResourceLoader
Namespaces
  • Every ≥0
  • Special: for control page and LintErrors improvements.
Cookies None
mw.libs lintHint
mw.hook
MediaWiki 1.30

A test page tells how to check for proper functionality.