User:PerfektesChaos/js/lintHint

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

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.:

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.

On Special:ExpandTemplates the facility is always offered.

Error table
If any, the table looks as follows:
 * The first column tells the Linter category.
 * The + column contains additional information, if provided.
 * The ⇓ column appears only if there is any source text area in page. Each ↓ links to a selected region where this error occurred.

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

Limitations
LintHint does not expand transclusions that start with slash. For example, if on page Portal:Myportal the wikitext includes, this really means  , but lintHint does not make this conversion. To force lintHint to analyze such transcluded pages, insert the full page name ( in this example) before the slash in transclusion calls that start with slash. You can do this in an edit session to discover the identity and location of lint errors, possibly in other templates, fix the lint errors there, and not save the edit session where you inserted the full page names.

LintHint sometimes shows two or more errors in the same location on the page when there is only one problem to fix. To work around this limitation, fix as many problems as you can find, then run LintHint again. Repeat the process until LintHint shows no more errors.

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

Two interactive ways are offered for individual investigation: 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.
 * 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. Might be followed by a revision ID (“oldid”).

Quick interactive customization
Some options can be set interactively on  as soon as the script has been loaded. On pages where the analysis report box appears, a button is offered in the top right corner, which opens such User:Gadgets in a new browser tab or window. The same goes for the control page.
 * Select options as desired.
 * Finally use the submit button + that launches a server update if clicked.

When reloading a text page the preferences declared here come into effect.

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

This initial assignment may be overridden later on page by programmatic JavaScript. However, it is not recommended to mix both practises during initialization since a race condition would decide upon the final effect.

Configuration by JavaScript
Individual desire may be passed to the gadget at any time, best before loading if interactive costumization is not used.

The raw JavaScript code looks as follows:

Currently the following options are available:

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 (see T151282).

As with all pages, currently there is no table sorting on mobile.

Links to text pages might be chosen to start either common  or parsermigration explicitly.

Wikisource
On wikisource projects the two namespaces Page: and Index: get specific support: The remaining form fields are rather tiny. If a problem is hiding tenacious from your eyes you may drop it into control page wikitext input.
 * For both the total page contents may be analyzed via control page page name input.
 * On Page: source code editing the current main text (“body”) can be checked directly.

New categories
At a quite early stage of execution the gadget needs to know which error types may occur, since the explaining system messages are to be retrieved.
 * If a new category appears the first time, there is no explanation present in time.
 * The gadget memorizes the lack of description in the browser environment.
 * Beginning with next page view the new error category will be added to the already known types.
 * A while later a gadget maintainer should add the new category to the built-in list.
 * When the gadget has been updated the item will be removed from browser environment.
 * Unknown error types may be mentioned immediately by  configuration option.

Compatibility
The following tools are recognized and supported:
 * CodeMirror
 * wikEd

Version 3 as of May 2018
Some major changes:
 * A page can be analyzed by name only on server side.
 * Recently the API gave access to a quick way to get an analysis report by page name only.
 * Only name and perhaps revision ID are transferred to server, and only the result is returned from server.
 * In 2017 only source texts could be analyzed. That required to retrieve the page source text from server first, then sending back to server for expansion of templates, and then sending the expanded text a third time to the server, now for linter analysis. That caused a lot of network traffic and was not recommended for automatic procedures.
 * Since April 2018 MediaWiki links on special page are starting ParserMigration tool always.
 * The links can be requested to run common  or parsermigration explicitly.
 * Quick interactive costumization available now.
 * CodeMirror and wikEd supported now.

Internationalization
Not really 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
A test page tells how to check for proper functionality.

de:User:PerfektesChaos/js/lintHint