Back to SFN Script

Short Footnote Conversion Script Instructions

This page describes a JavaScript utility that converts source citations in Wikipedia articles from long footnotes and loosely-formatted short footnotes to Harvard-style short footnotes. For an example of modifications made by the script, see this edit to the article "What Goes On".

The script creates short footnotes that use the {{Sfn}} template. You can read my take on how to cite sources on Wikipedia, and an endorsement of the {{Sfn}} method, in my Wikipedia essay "Citation method comparison".

Limitations

  1. I have only tested this script using Firefox 2 and Firefox 3.
  2. The script may hang if you use it on an article that has errors in the wikitext. In particular, if there are unmatched braces ("{" and "}") in the text, one of the regular expressions will execute forever. After a delay, Firefox will ask if you want to cancel the execution of the script, and you should agree. Most Wikipedia articles do not have such errors, but some do.
  3. This script may not help you as much as it has helped me. I designed and implemented this script to automate the changes I was making by hand as part of improving citations in Wikipedia articles related to The Beatles. Certain conventions in those articles, such as the way short footnotes were formatted, may not be prevalent in Wikipedia articles devoted to other topics. Many of the citations I was converting I had entered and/or formatted myself over the past few years and so I was familiar with the patterns in the text. That familiarity introduces bias into this utility and may mean it is not useful in the articles you want to edit.

Usage Instructions

The basic procedure is to (1) copy the article text into the "Article Text Input" textbox and (2) click the "Convert" button. After the script writes the modified text to the "Article Text Output" textbox, (3) copy that text back to the Wikipedia edit page.

It's a good idea to review the citations before you attempt a conversion. Editing some of the citations prior to the conversion will reduce the manual work required after the conversion. (See the Pre-Conversion Edits section.)

Steps

  1. In Firefox, open a tab for the conversion utility and a tab for the article you want to edit.
  2. Edit the article; key Ctl-A to select all the text, then Ctl-C to copy all the text.
  3. Switch to the conversion utility tab and paste the text into the "Article Text Input" textbox.
  4. Click the "Convert" button.
  5. The script will write a series of log entries on the right-hand side of the page. The log entries describe the changes the script made to the article.
  6. Click somewhere in the "Article Text Output" textbox so the cursor moves to that area and key Ctl-A to select all the text, then Ctl-C to copy all the text.
  7. Switch to the article tab and paste the text into edit textbox, replacing all the existing text.
  8. Click the "Changes" button to see a comparison of the existing article to the version edited by the script.
  9. Click the "Preview" button to see a preview of the edited article.
  10. Make any corrections you feel are required based on the diff or the preview.
  11. Click the "Save page" button to save the changes.

Ambiguous Footnotes

Short footnotes typically include the author's surname and the year of publication. When a source has no author, the recommended solution is to use the name of the organization as a substitute for an author surname. If you use multiple documents from the same organization, and those documents were published the same year, that can lead to ambiguous footnotes.

In many cases, the short foonote won't be ambiguous because (A) the article references only one document from the organization in question or (B) the article references multiple documents but they were published in different years.

The Include ambiguity IDs checkbox helps process articles with potentially ambiguous footnotes. When the option is enabled (checked), and the script uses an organization name in a short footnote, it includes a unique ID to mark the short footnote as potentially ambiguous. When disabled (unchecked), the unique ID is not included.

The best way to use this feature is as follows:

  1. The first time you attempt to convert the article, make sure Include ambiguity IDs is enabled.
  2. The script includes an alphabetical list of the ambiguous footnotes at the end of the log. Review the list to see if there is a conflict.
  3. If there is no conflict, disable Include ambiguity IDs and press "Convert" again.
  4. If there is a conflict:
    1. Edit the current article text to avoid the issue, either by adding an alpha digit after the year for each of the conflicting citations, or
    2. Review the source and see if you can assign an author's name; see "Pre-Conversion Edits" below, or
    3. Manually edit the {{Sfn}} and {{SfnRef}} entries to make the footnotes unique.
    4. For (A) and (B), you should correct the issue and then re-run the conversion. For (C), edit the output of the conversion.

Pre-Conversion Edits

You should review the citations in the article before using the conversion script. It's often the case that a few easy manual edits prior to running the conversion will reduce or eliminate tedious edits after the conversion. In particular, and as described above, it's best to try and resolve ambiguous footnotes prior to running the script for real.

If you decide to make edits to the article that are unrelated to the footnote conversion, it's usually best to make those edits prior to running the script. If you make the manual changes first, you can run the script multiple times without losing those manual changes.

Here's a simple example of some pre-conversion edits I made prior to converting the article "Love You To":

Post-Conversion Edits

You should use the Wikipedia "Preview" and "Changes" functions after pasting the converted article text into the edit window to review the article closely after running the conversion script.