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

Content deleted Content added
Typo fix.
indeed, the parameter is "cs1-dates"
 
(18 intermediate revisions by 6 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:ScreenUpdate Shotscreenshot 2014-02-04for atactivating 00.29.33MOSNUM dates.png|thumb|280px|Sidebar ___location of the script buttons afterwhen you havein clicked on the 'ToolsEdit' trianglemode]]
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".
#'''<s>Big endian ref dates</s>''' button now disabled. Users are invited to manually add {{para|cs1-dates}} parameter to {{tl|Use dmy dates}} or {{tl|Use mdy dates}} causing applicable dates to be rendered in ''{{date|{{date}}|iso}}'' YMD format
# '''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".
 
In addition, there are the following modes to convert slash or contracted dates into the desired format:
<!--
# '''Expand ref dates''' &ndash; Expand month names within the references section
# '''Expand all dates''' &ndash; Expand month names elsewhere within the article
-->#'''US-slash dates''' &ndash; converts dates that use slash or decimal separators in formats commonly used in the USAUS 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>
''* '''Note''': In these latter 2 cases, false positives are more likelypossible 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''
 
== History ==
Line 39 ⟶ 51:
Over the years, this script has been built on and refined. 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'.
 
== Detailed functional 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
** 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 '<fontspan colorstyle="color:orange;">the</fontspan> 5<fontspan colorstyle="color:orange;">th of</fontspan> September', 'December 25<fontspan colorstyle="color:orange;">th</fontspan>' or 'October <fontspan colorstyle="color:orange;">of</fontspan> 2003'
**adds commas where necessary (e.g. February 28 2001)
**removes redundantadds commas where necessary (e.g. July<font color=orange>,</font> 1997;February 28 February<font color=orange>,</font> 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 form of piped date links
* 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.
*<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]].
 
Line 68 ⟶ 82:
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, inall whichdates case date isare 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 automaticallycan be configured to render dates ({{para|date}}, {{para|access-date}}, {{para|archive-date}}, etc) in the style specified by this template. as Because it is allowedpermitted by [[WP:MOSDATES]], the cs1|2 templates can automatically format dates in a variety of styles. Editors may choose how cs1|2 templates render dates by the use of {{para|cs1-dates|&lt;{{var|keyword}}>}}.
{{#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}}.
 
Line 82 ⟶ 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]] [http://en.wikipedia.org/w/index.php?title=User_talk:Ohconfucius&oldid=518237638#Issue_with_.22ALL_dates_to_dmy.22_ have been reported]. These may or may not have been resolved.
 
The tool may also be used on mobile browsers. However, extensive testing has not been undertaken.
Line 101 ⟶ 116:
<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 121 ⟶ 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:
Line 138 ⟶ 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]]