User:Ohconfucius/script/MOSNUM dates

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

Overview[edit]

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. Although the yyyy-mm-dd dates ("1978-07-14") used in Wikipedia are not actually fully ISO 8601-compliant, they are shorthanded in the sidebar button to "ISO" due to space constraints.

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.
  3. body dates to dmy – no ISO-style dates converted
  4. body dates to mdy – no ISO-style dates converted

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. US-slash dates – resolves US style slash-dates (e.g. 7/27/1961, 07/27/1961, 07/27/61, 7/27/61), or dates using the full stop or hyphens as separator (e.g. 7.27.1961, 7.27.1961, 7.27.61, 7.27.61, 7-27-1961, 7-27-1961, 7-27-61, 7-27-61), into mdy format
  3. UK-slash dates – resolves UK/European style slash-dates (e.g. 27/7/1961, 27/07/1961, 27/07/61, 27/7/61), or dates using the full stop or hyphens as separator (e.g. 27.7.1961, 27.07.1961, 27.07.61, 27.7.61, 27-7-1961, 27-07-1961, 27-07-61, 27-7-61), into dmy format
  4. Expand ref dates – Expand month names within the references section
  5. Expand all dates – Expand month names elsewhere within the article
  6. Abbrev ref dates – Abbreviate month names within the references section

History[edit]

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

Overview[edit]

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 easy future maintenance for anybody armed with 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=).

Credits[edit]

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. Assuming that you are now using vector... Open/create your vector.js page by clicking on this link.
    • 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 cache for modifications to this script.
  2. Copy the following command onto your vector.js, common.js or monobook.js page:
    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 "skin".js page.
  4. Bookmark the script page. This will be your cue to purge the cache on your browser for any updates to take effect.

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 Windoze. 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. Accessdate to YYYY-MM-DD (only access dates within the references section)
  9. US-slash dates
  10. UK-slash dates

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]
Shortcuts:
  • 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]
Shortcut:
  • 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]

  • 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.
  • 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 phrased reconfigured so that the date is no longer adjectival (e.g. "the beach landings on 6 June").
  • 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.
  • There has been report of conflict with WikEd that may prevent this script from making any changes to articles.

Disclaimers[edit]

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.

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]