User:Ohconfucius/script/MOSNUM dates: Difference between revisions

Content deleted Content added
Overview: disabling body dates
indeed, the parameter is "cs1-dates"
 
(45 intermediate revisions by 11 users not shown)
Line 1:
{{Editnotice
| id = userpageedn
| header = New Features as of 26 June 2025
| headerstyle = font-size: 150%;
| text = Hello! the user script [[User:Ohconfucius/script/MOSNUM_dates.js]] has been updated to add new features in further support of [[WP:MOSNUM]] in articles. Two new functions have been added: <code>DMY_cs1=ly</code> and <code>MDY_cs1=ly</code> where dates in the body of the text (and publication dates within citation templates, plus all "loose dates" inside references) are converted to DMY or MDY; access dates and archive dates align to ymd (1978-07-14); adds template parameter {{para|cs1-dates}} with a matching value "ly".
 
Users are reminded to respect the [[WP:RETAIN|existing format in place]] and abide by [[WP:CONSENSUS]] when using this script.
{{Message
| textstyle = font-size: 120%;
| image = File:New-Bouncywikilogo.gif
| imagesize = 90px
| style = border:DarkRed solid 2px; background:var(--background-color-neutral,white); color:var(--color-base,black);
}}{{Message
| bgcolor = lightblue
| border-color = royalblue
Line 7 ⟶ 17:
| message = bug report or suggestion
| link = Wikipedia:Date formattings/script/MOSNUM dates/bugs
| extra-style = extra styles, like border-radius, etc...
| width =
| margin = 10px
| padding = 20px
| text-align = left
}}
}}{{shortcut|WP:Mosnumscript|WP:MOSNUMscript}}
[[File:Screen Shot 2014-02-04 at 00.29.33.png|thumb|280px|Sidebar ___location of the script buttons after you have clicked on the 'Tools' triangle]]
 
{{shortcut|WP:Mosnumscript|WP:MOSNUMscript}}
==Overview==
[[File:Update screenshot for activating MOSNUM dates.png|thumb|280px|Sidebar ___location of the script buttons when you in 'Edit' mode]]
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").
 
== Overview ==
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 &ndash; but only in tables and reference sections.
<!-- '''''NOTE:''' Functions converting dates within citation templates has been withdrawn now that WM[[MediaWiki|MW]] 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:
# '''all datesDATES to dmy''' &ndash; dates in the body of the text as well as in the reference sections are converted to "14 July 1978" or similar.
# '''all datesDATES to mdy''' &ndash; as above. dates are converted to "July 14, 1978" or similar.
# '''DMY_cs1=ly''' &ndash; dates in the body of the text are converted to dmy ("14 July 1978" or similar); access dates and archive dates to ymd (1978-07-14); adds template parameter {{para|cs1-dates}} with a matching value "ly".
<!-- Commented out modes that have been removed
# '''MDY_cs1=ly''' &ndash; as above. prose and publication dates are aligned to mdy ("July 14, 1978" or similar); access dates and archive dates to ymd (1978-07-14); adds template parameter {{para|cs1-dates}} with a matching value "ly".
#'''body dates to dmy''' &ndash; <s>no yyyy-mm-dd dates ("1978-07-14") converted</s> function withdrawn (WM software engine renders date formats automatically)
In addition, there are the following modes to convert slash or contracted dates into the desired format:
#'''body dates to mdy''' &ndash; <s>no yyyy-mm-dd dates ("1978-07-14") converted</s> function withdrawn (WM software engine renders date formats automatically)
<!--
#'''ISO to dmy''' &ndash; only ''ISO-style'' dates within ref tags are converted
# '''ISOExpand toref mdydates''' &ndash; onlyExpand ''ISO-style''month datesnames within ref tags arethe convertedreferences -->section
# '''Expand all dates''' &ndash; Expand month names elsewhere within the article
In addition, there are the following six modes to convert slash or contracted dates into the desired format:
-->#'''US-slash dates''' &ndash; converts dates that use slash or decimal separators in formats commonly used in the US into '''mdy''' dates ''viz'': <code>mm/dd/yy</code>, <code>mm/dd/yyyy</code>, <code>mm.dd.yy</code> or <code>mm.dd.yyyy</code>
 
# '''UK-slash dates''' &ndash; converts dates that use slash or decimal separators in formats commonly used in the UK, Europe and elsewhere into '''dmy''' dates ''viz'': <code>dd/mm/yy</code>, <code>dd/mm/yyyy</code>, <code>dd.mm.yy</code> or <code>dd.mm.yyyy</code>
#'''Del year-in-X dates''' &ndash; unlinks the most common 'year-in-X' links
''* '''Note''': In these latter 2 cases, false positives are possible because the protection mechanism of the script is bypassed, meaning the regex will act on dates in instances other than where the {{para|date}} parameter is used''
#'''Expand ref dates''' &ndash; Expand month names within the references section
#'''Expand all dates''' &ndash; Expand month names elsewhere within the article
<!-- Commented out modes that have been removed
#'''Big endian ref dates''' &ndash; Converts dates into [[Big-endian]] (yyyy-mm-dd) dates within the {{para|date}}, {{para|accessdate}}, {{para|archivedate}} parameters – mainly in references section*
-->
''*Note: the script will act on dates in other templates where the {{para|date}} parameter is used''
 
== History ==
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. ButIn itApril was2012, gettingthe unwieldy,engine andunderwent wasa gettingmajor slowrework by {{User|1exec1}}, andwho harderbuilt it and harderincorporated a new regex_worker function that allows more effective treatment of date fragments; there is better protection of strings that ought not to maintainbe modified by the script. In May, the new improved version of the script went 'live'.
 
== Detailed functional overview ==
In April 2012, the engine underwent a major rework by {{User|1exec1}}, 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
** yyyy-mmm-dd dates within accessdate and archivedate are not acted upon, but inconsistent (out of place) dates – dd mmm yyyy or mmm dd, yyyy will be converted.
** removes ordinal suffixes and constructions such as '<span style="color:orange;">the</span> 5<span style="color:orange;">th of</span> September', 'December 25<span style="color:orange;">th</span>' or 'October <span style="color:orange;">of</span> 2003'
** adds commas where necessary (e.g. February 28, 2001)
** removes redundant commas (e.g. July<span style="color:orange;">,</span> 1997; 28 February<span style="color:orange;">,</span> 2001)
* It removes direct links to dates and most forms of piped date links
* It removes <s>year linking templates (such as {{tl|scy}}, {{tl|by}}), and</s> links to 'year-in X' where piped from years (such as <nowiki>[[1984 in literature|1984]]</nowiki>)
* 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 makes certain fixes that may be identified as [[:Category:CS1 errors: dates|CS1 dates errors]]
* cs1=ly buttons, of which there are two, insert the eponymous template parameters, and will convert underlying dates within {{para|accessdate}} and {{para|archivedate}} to ymd.
 
<!-- * ISO-style dates (yyyy-mm-dd) which are outside <nowiki><ref></ref></nowiki> tags are not acted upon by the script -->
 
==Overview==
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 '<font color=orange>the</font> 5<font color=orange>th of</font> September', 'December 25<font color=orange>th</font>' or 'October <font color=orange>of</font> 2003'
**adds commas where necessary (e.g. February 28 2001)
**removes redundant commas (e.g. July<font color=orange>,</font> 1997; 28 February<font color=orange>,</font> 2001)
*It removes direct links to dates, and most form of piped date links
*It removes year linking templates (such as {{tl|scy}}, {{tl|by}}), and links to 'year-in X' where piped from years (such as <nowiki>[[1984 in literature|1984]]</nowiki>)
*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.
*<s>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.</s> Now disabled. CS1 now manages the date rendering by [[Help:Citation_Style_1#Auto-formatting_citation_template_dates|auto-formatting citation template dates]] using parameters within the {{tl|use dmy dates}} and {{tl|use mdy dates}} templates, so this can be used to fine-tune the rendering.
<!-- *ISO-style dates (yyyy-mm-dd) which are outside <nowiki><ref></ref></nowiki> tags are not acted upon by the script
-->
The script adds or updates a non-displaying template {{tl|use mdy dates}} or {{tl|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 [[WP:AWB|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 – {{tl|cite news}} and {{tl|cite web}}; I try to stick to syntax in <nowiki>{{cite web}}</nowiki> where 'Retrieved' is capitalised and preceded by a full-stop.
 
Although the MediaWiki software interprets {{tl|use dmy dates}} or {{tl|use mdy dates}} templates, allowing dates and access dates within citation templates to be automatically formatted, errors there and elsewhere may still require correction. The script takes care of that.
The format and syntax of citations were modelled after the way reference sections are rendered when using the most common citation templates – {{tl|cite news}} and {{tl|cite web}}; I try to stick to syntax in <nowiki>{{cite web}}</nowiki> where 'Retrieved' is capitalised and preceded by a full-stop.
 
=== How it works ===
The script is configured so that dates are stored as an array. The given [[regex]] and substitution strings can contain [[Help:Magic words|magic word]]s 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. <code>|title=</code>). Occasionally, due to the proliferation of templates across en.wp, some may be the subject of unintended changes that have not been anticipated in the script regexes.
 
As also mentioned [[#Known_limitations|below]], the actions of the protection mechanism can be revealed in the event of the script stalling, and substitution markers may appear in the edit window. When this occurs, the user should abandon the action, reopen the edit window and reperform the edit.
 
=== Optional auto-formatting citation template dates ===
Script default is without parameter all dates are aligned to the prevailing style indicated – dmy or mdy.
 
Notwithstanding the available buttons, [[Help:Citation Style 1|Citation Style 1]] and [[Help:Citation Style 2|2]] (collectively cs1|2) templates can be configured to render dates ({{para|date}}, {{para|access-date}}, {{para|archive-date}}, etc) in the style specified by this template as permitted by [[WP:MOSDATES]].
{{#lst:Help:Citation Style 1|auto_date_format_table}}
 
An example is given at {{section link|Help:Citation Style 1#Auto-formatting citation template dates}}.
 
=== Credits ===
Line 79 ⟶ 97:
{{User:Ohconfucius/script/install}}
 
== Actions and test ==
'''Use of the [[Safari (web browser)|''Safari'']] or ''[[Firefox]]'' browsers is highly recommended'''. It only functions in desktop mode.
 
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 [[Internet Explorer 8|version 8]], there are [http://en.wikipedia.org/w/index.php?title=User_talk:Ohconfucius&oldid=518237638#Issue_with_.22ALL_dates_to_dmy.22_script22_ knownhave issuesbeen reported]. thatThese may or may not have been resolved.
 
The tool may also be used on mobile browsers. However, extensive testing has not been undertaken.
 
Once you are in edit mode, there are buttons in the toolbox in the left margin:
#'''DATES to dmy'''{{snd}}converts all dates to ''{{date|{{date}}|dmy}}'' dmy format
#'''DATES to mdy'''{{snd}}converts all dates to ''{{date|{{date}}|mdy}}'' mdy format
#'''US-slash dates''' &ndash; converts all applicable dates into ''{{date|{{date}}|mdy}}'' mdy format
#body dates to dmy (''yyyy-mm-dd dates within ref tags are avoided'')
#'''UK-slash dates''' &ndash; converts all applicable dates into ''{{date|{{date}}|dmy}}'' dmy format
#body dates to mdy
 
#Del year-in-X dates
;Notes
#Expand all dates (''month names within the article'')
{{Notelist}}
#Abbrev ref dates (''only month names within the references section'')
#Big endian ref dates (''access and archive dates, and other dates within the {{para|date}} parameter – references section and elsewhere'')
 
<span class="plainlinks">Users are equally reminded of the following provisions of [https://en.wikipedia.org/w/index.php?title=Wikipedia:Manual_of_Style/Dates_and_numbers&oldid=606447604#Consistency Wikipedia:Manual of Style (dates and numbers)]</span>:
<blockquote>
 
===== Format consistency =====
* 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 =====
{{shortcut|WP:STRONGNAT|WP:TIES}}
 
* 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 =====
{{shortcut|WP:RETAIN}}
 
* 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.
Line 117 ⟶ 138:
 
==== Test pages ====
* [[User:Full-date unlinking bot/Test environment]] - tests unlinking and dmy<&ndash;>mdy conversion
* [[User:Dl2000/testtemp7]] - slash dates
* [[User:Ohconfucius/MOSNUM script test]] – test page dealing with [[Help:CS1 errors|CS1 date errors]]
 
===Known limitations===
 
=== Known limitations ===
* '''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 "<fontspan colorstyle="color:orange;">the</fontspan> 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").
<!-- * '''"body dates" functions''': When these two functions are run, the script protects all within <nowiki><ref></ref></nowiki> tags, so that no dates within citations will be changed, '''even if they are incorrect''' (ie mdy in dmy articles and vice versa). As a consequence, there are corrections the full script makes dates such as missing commas (eg Sept 27 2013), extra commas (eg 27 Sept, 2013) or misspelt month names or missing capitalisation (eg 2 mars 2013), which will not happen with these functions. ''For the above reason, the function – which has been disabled once and restated due to a specific request – may be withdrawn permanently in due course.'' -->
* '''Stalling''': If you see characters such as the following in your diffs window, don't panic:
::<code>⍌190⍍</code>
Line 133 ⟶ 154:
==== Other Wiki scripts or gadgets ====
* '''wikEd''': The script is known to conflict with ''[[User:Cacycle/wikEd|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.
 
==== Browsers ====
* It has [https://en.wikipedia.org/w/index.php?title=User_talk:Ohconfucius&oldid=776359500#MOSNUM_script been reported] that Chrome extension "[[Privacy Badger]]" may somehow inhibit the script functioning.
 
== Disclaimers ==
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 [http://en.wikipedia.org/w/index.php?title=User_talk:Ohconfucius&oldid=518237638#Issue_with_.22ALL_dates_to_dmy.22_script 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]] or [[January 25]], 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 ==
* [[Wikipedia:User scripts]]
* [[Wikipedia:Date formattings]]