Jump to content

User:Trappist the monk/HarvErrors

From Wikipedia, the free encyclopedia
HarvErrors.js
DescriptionFinds problems with {{sfn}}/{{harv}}-style footnotes
Author(s)User:Ucucha, User:Trappist the monk
Maintainer(s)User:Trappist the monk
UpdatedJune 21, 2024
    (4 months ago)
SourceUser:Trappist the monk/HarvErrors.js

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

[edit]

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 {{sfn|Smith|1981}} 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 {{sfn|Jones|2004}} 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 {{sfn|Anderson|2021}} 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.
Warning message
  1. 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 '{{sfn|Mqrtindale|1997}}' 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.

Resolving errors

[edit]

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

[edit]

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

[edit]

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:

ttm_harv_err – default color is DarkOrange #FF8C00
ttm_harv_warn – default color is some-sort-of brown #AC6600
ttm_harv_err_dup – default color is some-sort-of purple #C3F

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 Wikipedia:Common.css).

body .ttm_harv_err {color:green} – displays the message in green, instead of the dark orange default: ⟶
Harv error: link from "CITEREFSmith1981" doesn't point to any citation.
body .ttm_harv_err_dup {color:#AA00AA; border:thin solid gray; background-color:cornsilk} adds color, a gray border, and light shading, like this ⟶
Harv error: "CITEREFJones2004" has multiple targets (2x)
body .ttm_harv_warn {color:#793300; text-decoration:wavy wheat underline} – 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

[edit]

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:

.harv-error::before{content: "Mod:FN: "}Mod:FN: sfn error: no target: CITEREFNowhereman2024 ...

Known issues

[edit]
  • (none at present)

See also

[edit]