User:Ohconfucius/script/MOSNUM dates

From Wikipedia, the free encyclopedia
< User:Ohconfucius‎ | script  (Redirected from Wikipedia:MOSNUMscript)
Jump to navigation Jump to search
Sidebar location of the script buttons after you have clicked on the 'Tools' triangle


This script delinks all dates and date fragments, and converts them all to the same format, either dd mmm yyyy ("14 July 1978") or mmm dd, yyyy ("July 14, 1978").

MOSNUM allows one other format to be used in articles – but only in tables and reference sections.

NOTE: Functions converting dates within citation templates has been withdrawn now that WM software engine renders date formats automatically There are modes that allow the user to select whether to treat body dates only or body and reference sections:

  1. all dates to dmy – dates in the body of the text as well as in the reference sections are converted to "14 July 1978" or similar.
  2. all dates to mdy – as above. dates are converted to "July 14, 1978" or similar.

In addition, there are the following six modes to convert slash or contracted dates into the desired format:

  1. Del year-in-X dates – unlinks the most common 'year-in-X' links
  2. Expand ref dates – Expand month names within the references section
  3. Expand all dates – Expand month names elsewhere within the article

*Note: the script will act on dates in other templates where the |date= parameter is used


Lightmouse initially created a script to deal with a number of general formatting issues, and date alignment was one such function. I used it and often gave feedback and bug reports. Seeing the need to work on the diversity of date formats and date situations that are seen here on Wikipedia, I created an independent script targeted at dates with some help and advice from Lightmouse.

Over the years, this script has been built on and refined, but it was getting unwieldy, and was getting slow, and harder and harder to maintain.

In April 2012, the engine underwent a major rework by 1exec1 (talk · contribs), who built it and incorporated a new regex_worker function that allows more effective treatment of date fragments; there is better protection of strings that ought not to be modified by the script. In May, the new improved version of the script went 'live'.


The dates script is at User:Ohconfucius/script/MOSNUM dates.js.

  • It is aimed to make displayed dates fully compatible with Wikipedia:Manual of Style (dates and numbers) (WP:MOSNUM)
  • It ensures uniform presentation of dates within any given article. As such, it:
    • delinks all dates and date fragments, including day-month strings, days, months, decades, centuries,
    • converts all these date fragments to the same format, either dd mmm yyyy or mmm dd, yyyy, at the option of the user
    • removes ordinal suffixes and constructions such as 'the 5th of September', 'December 25th' or 'October of 2003'
    • adds commas where necessary (e.g. February 28 2001)
    • removes redundant commas (e.g. July, 1997; 28 February, 2001)
  • It removes direct links to dates, and most form of piped date links
  • It removes year linking templates (such as {{scy}}, {{by}}), and links to 'year-in X' where piped from years (such as [[1984 in literature|1984]])
  • It converts other often used (but not MOSNUM-compliant) date formats within the references section, such as dd-mm-yyyy or dd-mmm-yyyy to the chosen prevailing format used in the rest of the article.
  • It also allows users to choose to convert dates within only the body of the article, as is permitted for reference sections (where yyyy-mm-dd dates are common) to have different dates, or throughout the article.
  • ISO-style dates (yyyy-mm-dd) which are outside <ref></ref> tags are not acted upon by the script

The script adds or updates a non-displaying template {{use mdy dates}} or {{use dmy dates}} depending on the conversion used; this tagging allows for WM software engine to render date formats automatically in conformity with tagged format). It also facilitates future maintenance by bot by script AWB.

The script will achieve overall consistency of the format of the date, but will not alter the form (i.e. month spelt out in full or abbreviated to 3 or 4 letters. This task is assured by 'Expand ref dates', 'Expand all dates' and 'Abbrev ref dates' functions.

The format and syntax of citations were modelled after the way reference sections are rendered when using the most common citation templates – {{cite news}} and {{cite web}}; I try to stick to syntax in {{cite web}} where 'Retrieved' is capitalised and preceded by a full-stop.

How it works[edit]

The script is configured so that dates are stored as an array; the given regex and substitution strings can contain magic words that specify what date format the routine should accept and to what date format the routine should convert the date to.

There is a mechanism in place to protect a wide range of strings that ought to be immutable: such as images, categories, urls; text within blockquotes and double quotes; text within certain parameters (e.g. |title=).


I am solely responsible for this tool, which has been inspired by the dates scripts written by User:Lightmouse and User:Plastikspork, it incorporates many additional features, such as unlinking many unusually-piped date-links, conversion of date series and ranges, and delinking months of the year. Thanks also to User:1exec1 for the invaluable assistance in rewriting and simplifying the workings of the script in April 2012.

Feedback is appreciated at User Talk:Ohconfucius. Please report any false negatives as well as false positives you may detect.

Installing the script[edit]

  1. Open your common.js in edit mode (alternatively, go to your user page and append "common.js" to the end of the URL and open the page in edit mode).
    • If you prefer to load this only on a specific skin, such as monobook, open your monobook.js in edit mode.
    • If you make a straight copy of this script, instead of "importing" it, you may not benefit from the enhancements and bug-fixes that are made from time to time. In the latter case, you may choose to watchlist this page so you will know when to update your copy for modifications to this script.
  2. Copy the following code onto the JavaScript page you have chosen in the previous step:
    importScript('User:Ohconfucius/script/MOSNUM dates.js'); // [[User:Ohconfucius/script/MOSNUM dates.js]]
  3. Save the page and (re-)load it – refresh the cache by following the instructions at the top of your JavaScript page.
  4. Bookmark the script page. This will be your cue to purge the cache on your browser for any updates to take effect.

Disclaimer: Use at your own risk and make sure you check the edit changes before you save.

Actions and test[edit]

Use of the Safari or Firefox browsers is highly recommended.

The script is continually being run, and seems to work as intended on the latest Firefox and Chrome browsers on Mac and Windows. On Windows machines, browser-specific issues for IE, specifically version 8, are known.

Once you are in edit mode, there are buttons in the toolbox in the left margin:

  1. all dates to dmy
  2. all dates to mdy
  3. body dates to dmy (ISO-style dates within ref tags are avoided)
  4. body dates to mdy
  5. Del year-in-X dates
  6. Expand all dates (month names within the article)
  7. Abbrev ref dates (only month names within the references section)
  8. Big endian ref dates (access and archive dates, and other dates within the |date= parameter – references section and elsewhere)

Users are equally reminded of the following provisions of Wikipedia:Manual of Style (dates and numbers):

Format consistency[edit]
  • Dates in article body text should all use the same format: Julia ate a poisoned apple on 25 June 2005, and died on 28 June (not ... on June 28).
  • Publication dates in references should all use the same format. Any format from the "Acceptable date formats" table above may be used, unless the citation style being used requires a different format (however, all-numeric date formats other than yyyy-mm-dd must still be avoided).
  • Access and archive dates in references should all use the same format – either the format used for publication dates, or yyyy-mm-dd

(These consistency requirements apply to dates in general prose and reference citations, but not to dates in quotations or titles)

Strong national ties to a topic[edit]
  • Articles on topics with strong ties to a particular English-speaking country should generally use the more common date format for that nation. For the United States, this is month before day; for most others, it is day before month. Articles related to Canada may use either format consistently.
  • Sometimes the customary format differs from the usual national one: for example, articles on the modern US military use day before month, in accordance with military usage.
Retaining the existing format[edit]
  • If an article has evolved using predominantly one format, the whole article should conform to it, unless there are reasons for changing it based on strong national ties to the topic or consensus on article talk.
  • The date format chosen by the first major contributor in the early stages of an article should continue to be used, unless there is reason to change it based on strong national ties to the topic or consensus on article talk.
  • Where an article has shown no clear sign of which format is used, the first person to insert a date is equivalent to "the first major contributor".

Test pages[edit]

Known limitations[edit]

  • Proper nouns with dates: A number of proper nouns containing date fragments (such as 'March 14 Alliance', '6th of October City', 'June 1, 1974', '2000 AD') have been specifically protected from conversion or delinking. Only the displayed part of piped links are acted upon, whilst the underlying pipe will not be changed. For the purposes of this script, September 11 or September 11 attacks is treated: there are ample redirects in existence for any problems to be mitigated. Let me know if there are other proper names which ought to be protected.
  • Dates that are used as adjectives: Because the script routinely removes the leading "the" for dates, attention should be paid to where the date is used as an adjective, such as "the 6 June beach landings". The "the" should either be reinserted, or the phrase reconfigured so that the date is no longer adjectival (e.g. "the beach landings on 6 June").
  • Non-ISO-style date within citation: The 'body dates' functions will act on any non-ISO-style date within citation, so that if there is a dmy date within references (amongst dates such as 2009-01-11), the former will be acted on by the mdy function whilst the latter will be unaffected.

Known conflicts[edit]

Other Wiki scripts or gadgets[edit]

  • wikEd: The script is known to conflict with wikEd that prevents the MOSNUM dates script from making any changes to articles, or simply blocking the creation of a script button. The solution is to toggle the wikEd text area off while running MOSNUM dates. wikEd has an easy toggle button for that called: Use wikEd instead of classic text area. Simply press the toggle button so the button pops out (off), then run MOSNUM dates; when you are done running MOSNUM dates you can press the toggle button again so the toggle button pops in (on) and the wikEd text area will be live again. Once you get in the habit of toggling the wikEd text area on and off, running MOSNUM dates is no longer a conflict with wikEd. There is no need to disable/re-enable wikEd in your common.js file.



I use and make experimental changes to another version, and update this production version regularly to a suitably stable prior version of the test script. However, like all software, bugs are unavoidable. Use at your own risk, and make sure you check the edit changes before you save. The script is continually being run, and seems to work as intended on the latest Firefox and Chrome browsers. However, browser-specific issues have been reported for IE on Windows machines in the past (as at 1 January 2019, there are no recent reports of such compatibility issues).

By consensus, this script should not be used in articles about chronological periods, such as 2015, as date links here, considered desirable, would otherwise be automatically removed. Equally, I suspect that using the script on talk pages or on WP pages is likely to result in more angst than benefit to the project.

See also[edit]