User:PerfektesChaos/js/lintHint

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

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

New functionalities in May 2018 – please see below

Purpose[edit]

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[edit]

  • 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[edit]

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[edit]

If any, the table looks as follows:

lint +
category title DIV
  • 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 later option to include them into table.

Limitations[edit]

LintHint does not expand transclusions that start with slash. For example, if on page Portal:Myportal the wikitext includes {{/Box-header}}, this really means {{Portal:Myportal/Box-header}}, but lintHint does not make this conversion. To force lintHint to analyze such transcluded pages, insert the full page name (Portal:Myportal 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.

Control page[edit]

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. Might be followed by a revision ID (“oldid”).

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.

Quick interactive customization[edit]

Some options can be set interactively on Special:Blankpage as soon as the script has been loaded. On pages where the analysis report box appears, a button Nuvola apps kcmsystem.svg 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[edit]

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:

// 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. Needed only when encountered the first time, then memorized and not longer unknown.
launch boolean false Run analysis automatically in rooms rather than manual triggering by button.
layer boolean MediaWiki default Convert source edit links on LintErrors special page into ParserMigration edit.
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[edit]

Special:LintErrors categories will make tables sortable, until Mediawiki provides this feature (see phab:T151282).

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

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

Wikisource[edit]

On wikisource projects the two namespaces Page: and Index: get specific support:

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

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.

New categories[edit]

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 later configuration option.

Compatibility[edit]

The following tools are recognized and supported:

Version 3 as of May 2018[edit]

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 action=edit or parsermigration explicitly.
  • Quick interactive costumization available now.
  • CodeMirror and wikEd supported now.

Internationalization[edit]

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[edit]

Source code
ResourceLoader
Namespaces
Cookies localStorage
mw.libs lintHint
mw.hook
MediaWiki 1.30

A test page tells how to check for proper functionality.