User:Trappist the monk/HarvErrors

Short footnote templates like Sfn and harvnb are prone to problems with their automatically generated links. This script checks these links for validity and displays error messages when incorrect linkage is discovered. In addition, it displays warning messages when full citations that are set up to receive links from shortened footnotes do not have any pointing to them.

What it does
This script may produce any of three types of error messages, and one type of warning message. Here are some sample messages, explained:
 * Error messages
 * 1) Harv error: link from "CITEREFSmith1981" doesn't point to any citation. – You included short footnote  inline, but there is no matching full citation in the Bibliography or Works cited section in the Appendix. This message is dark orange by default.
 * 2) Harv error: "CITEREFJones2004" has multiple targets (2x). – You included short footnote  inline, but there are two full citations in the Bibliography or Works cited section in the Appendix that are both targeted by this short footnote. This may occur, for example, when Jones has two publications in 2004. Violet by default.
 * 3) Harv error: linked from "CITEREFAnderson2021". – This is a "wrong section" error; You included short footnote  inline, and there is a valid  full citation for it in the bottom matter, but it's in the wrong section, such as "Further reading". It should be in either "Bibliography", or "Works cited" (which must be a level two section heading). Dark orange by default.

 Harv warning: There is no link pointing to this citation. The anchor is named "CITEREFMqrtindale1997". – You included an item in the Bibliography or Works cited section, but there isn't a matching short footnote '' anywhere in the body with the same last-name and year. Maybe you forgot to include a short footnote inline, or maybe you included it, but the year or last names don't match—as in this example, where a typo in the full citation causes a match failure, resulting in the warning. Brownish by default.
 * Warning message

Resolving errors
Error messages #1 and 2 above are serious, because they indicate a lack of sourcing information or missing information that negatively impacts verifiability. Number 1 may be due to a missing full citation, such as when copying content from another article but neglecting to copy the full citation from the appendix; or it can result from a mismatch between short footnote and full citation due to a typo, or a source lacking a last name or year. For other condtions which may provoke this error, see Harv and Sfn template errors#Resolving errors.

Installation
To install this script, add:
 * mw.loader.load( '/w/index.php?title=User:Trappist_the_monk/HarvErrors.js&action=raw&ctype=text/javascript' ); // Backlink: User:Trappist the monk/HarvErrors.js

to Special:MyPage/common.js.

Simple testcases page at User:Trappist the monk/HarvErrors/testcases.

Style customization
There are three undefined css classes that can be used in your common CSS page or your specific skin's CSS page (common.css and skin.css respectively) for styling the error messages to personal taste. These are:
 * – default color is DarkOrange
 * – default color is some-sort-of brown
 * – default color is some-sort-of purple

You can customize the font color or other CSS style elements by adding css attributes to the body tag to your common.css file (see Common.css).


 * ➢  – displays the message in green, instead of the dark orange default: ⟶
 * Harv error: link from "CITEREFSmith1981" doesn't point to any citation.
 * ➢  adds color, a gray border, and light shading, like this ⟶
 * Harv error: "CITEREFJones2004" has multiple targets (2x)
 * ➢  – darker brown, and underlined ⟶
 * Harv warning: There is no link pointing to this citation. The anchor is named "CITEREFMoiré2004".

For more color choices, see HTML color names; for more styling possibilities, see CSS style.

Similar errors and warnings
Error or warning messages from other sources may appear similar to the ones generated by this script. You may notice the following error messages generated by Module:Footnotes:
 * sfn error: no target: CITEREFNowhereman2024 (help) – this is similar to error message #1 above. You may see just one, or both right next to each other, depending on your preferences, and script or css settings.
 * sfn error: multiple targets (2×): CITEREFDoubleton2005 (help) – this is similar to error message #2 above; and you might see either, or both of them.

If you wish to distinguish errors generated by the module from those generated by this script, you can apply css style to them using class harv-error in your common.css, similar to style customization above. This will tag errors from the module with a prefix:
 * ➢  ⟶ Mod:FN: sfn error: no target: CITEREFNowhereman2024 ...

Known issues

 * (none at present)