ব্যবহারকারী:রবি/common.js: সংশোধিত সংস্করণের মধ্যে পার্থক্য
অবয়ব
অসম্পাদনা সারাংশ নেই |
|||
| ১,৬৭৩ নং লাইন: | ১,৬৭৩ নং লাইন: | ||
}); | }); | ||
} | } | ||
//my common.js | //my common.js | ||
| ২,৪১৬ নং লাইন: | ২,৩০৩ নং লাইন: | ||
); | ); | ||
}); | }); | ||
/*********************************************************************************** | |||
* CatMan: The category manager for MediaWiki wikis that is simple, lightweight, * | |||
* and modern. Nya nya. * | |||
* * | |||
* This script is largely a work in progress and may sometimes not work properly. * | |||
* Please see the English Wikipedia for known problems that are currently being * | |||
* fixed. * | |||
*********************************************************************************** | |||
* IMPORTANT (particularly for those who are viewing a copy of the script): * | |||
* THIS FILE IS AVAILABLE ON GITHUB AT https://github.com/Awesome-Aasim/CatMan * | |||
* ALL PULL REQUESTS AND CHANGES MUST BE MADE THERE, OTHERWISE THEY WILL BE LOST * | |||
* IF THE FILE AT THE REPOSITORY IS CHANGED OR REBUILT. * | |||
*********************************************************************************** | |||
* LICENSING INFORMATION: Licensed under the MIT license * | |||
* MIT License * | |||
* Copyright (c) 2021 Aasim Syed * | |||
* Permission is hereby granted, free of charge, to any person obtaining a copy * | |||
* of this software and associated documentation files (the "Software"), to deal * | |||
* in the Software without restriction, including without limitation the rights * | |||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * | |||
* copies of the Software, and to permit persons to whom the Software is * | |||
* furnished to do so, subject to the following conditions: * | |||
* The above copyright notice and this permission notice shall be included in all * | |||
* copies or substantial portions of the Software. * | |||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * | |||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * | |||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * | |||
* SOFTWARE. * | |||
***********************************************************************************/ | |||
//<nowiki> | |||
if (!Catman && mw.config.get("wgNamespaceNumber") >= 0 && mw.config.get("wgIsProbablyEditable") && mw.config.get("wgArticleId") > 0 && mw.config.get("wgNamespaceNumber") != 10) { | |||
var Catman = {}; | |||
mw.loader.using(["oojs-ui-core", "oojs-ui-windows", "oojs-ui-widgets", "oojs-ui.styles.icons-moderation", "oojs-ui.styles.icons-interactions", "oojs-ui.styles.icons-editing-core"], function () { | |||
Catman.start = function () { | |||
// Create a factory. | |||
Catman.factory = new OO.Factory(); | |||
Catman.getEditableCategories = function (text, categoryname = "Category") { | |||
categoryname = categoryname[0].toUpperCase() + categoryname.slice(start = 1); | |||
var temp = text.split("[["); | |||
var res = [] | |||
for (var i in temp) { | |||
if (temp[i].startsWith(categoryname + ":")) { | |||
var temp2 = temp[i].split("]]")[0].slice(start = categoryname.length + 1); | |||
res.push(temp2[0].toUpperCase() + temp2.substring(1)); | |||
} | |||
} | |||
/* | |||
var catlist = mw.config.get("wgCategories"); | |||
var rtn = []; | |||
for (var i in res) { | |||
for (var j in catlist) { | |||
if (catlist[j] == res[i]) { | |||
rtn.push(res[i]); | |||
} | |||
} | |||
} | |||
*/ | |||
return res; | |||
} | |||
function CatManDialog(config) { | |||
CatManDialog.super.call(this, config); | |||
} | |||
OO.inheritClass(CatManDialog, OO.ui.ProcessDialog); | |||
CatManDialog.static.name = 'catmandialog'; | |||
CatManDialog.static.title = 'Category Manager'; | |||
CatManDialog.static.actions = [ | |||
{ | |||
flags: ['primary', 'progressive'], | |||
icon: 'check', | |||
title: 'Save changes', | |||
action: 'next', | |||
disabled: false | |||
}, | |||
{ | |||
flags: 'safe', | |||
icon: 'close', | |||
title: 'Cancel', | |||
action: 'back', | |||
disabled: false | |||
} | |||
] | |||
CatManDialog.prototype.getActionProcess = function (action) { | |||
var categoriestoadd, categoriestoremove, summary, presummary, wikitext; | |||
switch (action) { | |||
case 'next': | |||
return new OO.ui.Process(function () { | |||
try { | |||
categoriestoadd = []; | |||
$(".catman-addcategory").each(function () { | |||
categoriestoadd.push($(this).find(".catman-categoryname").text()); | |||
}); | |||
categoriestoremove = []; | |||
$(".catman-remove").each(function () { | |||
categoriestoremove.push($(this).find(".catman-categoryname").text()); | |||
}); | |||
summary = Catman.esinput.getValue(); | |||
presummary = "Run [[w:en:User:Awesome Aasim/CatMan|CatMan]]" + (summary ? " (reason: " + summary + ")" : "") + ": "; | |||
if (categoriestoadd.length == 0 && categoriestoremove.length == 0) { | |||
throw new OO.ui.Error("No categories to add or remove.", { warning: true, recoverable: true }); | |||
} | |||
return $.get(mw.config.get("wgScriptPath") + "/api.php", { | |||
action: "parse", | |||
format: "json", | |||
page: mw.config.get("wgPageName"), | |||
prop: "wikitext" | |||
}).then(function (result, status) { | |||
if (status != 'success') { | |||
throw new OO.ui.Error("Connection failed. Please check your Internet and try again.", {recoverable: true}); | |||
} | |||
wikitext = result.parse.wikitext["*"]; | |||
debugger; | |||
for (var i in categoriestoremove) { | |||
for (var j in Catman.catprefixes) { | |||
if (wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0 || wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0) { | |||
presummary += "-cat [[Category:" + categoriestoremove[i].split("|")[0] + "|" + categoriestoremove[i].split("|")[0] + "]]" | |||
} | |||
if (i != categoriestoremove.length - 1) { | |||
presummary += ", " | |||
} | |||
while (wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0) { | |||
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]\n", ""); | |||
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]", ""); | |||
} | |||
while (wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0) { | |||
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]\n", ""); | |||
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]", ""); | |||
} | |||
} | |||
} | |||
if (categoriestoadd.length > 0 && categoriestoremove.length > 0) { | |||
presummary += "; " | |||
} | |||
for (var i in categoriestoadd) { | |||
if (wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0 && wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0) { | |||
presummary += "+cat [[Category:" + categoriestoadd[i].split("|")[0] + "|" + categoriestoadd[i].split("|")[0] + "]]"; | |||
} | |||
if (i != categoriestoadd.length - 1) { | |||
presummary += ", "; | |||
} | |||
while (wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0 && wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0) { | |||
wikitext += "\n[[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "]]"; | |||
break; | |||
} | |||
} | |||
return $.get(mw.config.get("wgScriptPath") + "/api.php", { | |||
action: "query", | |||
format: "json", | |||
meta: "tokens", | |||
type: "csrf" | |||
}).then(function (result, status) { | |||
if (status != 'success') { | |||
throw new OO.ui.Error("Connection failed. Please check your Internet and try again.", {recoverable: true}); | |||
} | |||
if (result.error) { | |||
throw new OO.ui.Error(result.error.info, { recoverable: true }); | |||
} else { | |||
return $.post(mw.config.get("wgScriptPath") + "/api.php", { | |||
action: "edit", | |||
format: "json", | |||
title: mw.config.get("wgPageName"), | |||
token: result.query.tokens.csrftoken, | |||
text: wikitext, | |||
summary: presummary | |||
}).then(function (result, status) { | |||
if (status != 'success') { | |||
throw new OO.ui.Error("Connection failed. Please check your Internet and try again.", {recoverable: true}); | |||
} | |||
if (result.error) { | |||
throw new OO.ui.Error(result.error.info, { recoverable: true }); | |||
} else { | |||
Catman.windowManager.closeWindow('catmandialog'); | |||
Catman.windowManager.$element.remove(); | |||
mw.notify("Categories successfully edited. Reloading..."); | |||
location.reload(); | |||
} | |||
}); | |||
} | |||
}); | |||
}); | |||
} catch (error) { | |||
return error; | |||
} | |||
}, this); | |||
case 'back': return new OO.ui.Process(function () { | |||
Catman.windowManager.closeWindow('catmandialog'); | |||
Catman.windowManager.$element.remove(); | |||
}, this); | |||
} | |||
// Fallback to parent handler | |||
return CatManDialog.super.prototype.getActionProcess.call(this, action); | |||
}; | |||
function CategoriesLayout(name, config) { | |||
CategoriesLayout.super.call(this, name, config); | |||
this.$element.append('<span id="catman-categories"></span>'); | |||
} | |||
OO.inheritClass(CategoriesLayout, OO.ui.TabPanelLayout); | |||
CategoriesLayout.prototype.setupTabItem = function () { | |||
this.tabItem.setLabel('Categories'); | |||
} | |||
function SummaryLayout(name, config) { | |||
SummaryLayout.super.call(this, name, config); | |||
this.$element.append('<span id="catman-summary"></span>'); | |||
} | |||
OO.inheritClass(SummaryLayout, OO.ui.TabPanelLayout); | |||
SummaryLayout.prototype.setupTabItem = function () { | |||
this.tabItem.setLabel('Edit summary'); | |||
} | |||
CategoriesLayout.prototype.getBodyHeight = function () { | |||
return "full"; | |||
} | |||
SummaryLayout.prototype.getBodyHeight = function () { | |||
return "full"; | |||
} | |||
CatManDialog.prototype.getBodyHeight = function () { | |||
return "full"; | |||
} | |||
CatManDialog.prototype.initialize = function () { | |||
CatManDialog.super.prototype.initialize.call(this); | |||
this.content = new OO.ui.PanelLayout({ padded: false, expanded: false, $overlay: this.$overlay }); | |||
var catinput = new OO.ui.ComboBoxInputWidget({ expanded: false, padded: true, placeholder: "Enter category name", options: [], $overlay: this.$overlay }); | |||
var catinputsubmit = new OO.ui.ButtonWidget({ flags: ["primary", "progressive"], icon: "add", title: 'Add category', $overlay: this.$overlay }) | |||
var esinput = new OO.ui.TextInputWidget({ placeholder: "Edit summary", $overlay: this.$overlay }); | |||
var catpage = new CategoriesLayout('categories', { expanded: false, $overlay: this.$overlay }); | |||
var sumpage = new SummaryLayout('summary', { expanded: false, $overlay: this.$overlay }); | |||
var index = new OO.ui.IndexLayout({ expanded: true, $overlay: this.$overlay }); | |||
index.addTabPanels([catpage, sumpage]); | |||
this.content.$element.append('<span id="catman-loading"><p></p></span><span id="catman"></span>'); | |||
this.$body.append(this.content.$element); | |||
var progressBar = new OO.ui.ProgressBarWidget( { | |||
progress: false, | |||
padded: true, | |||
$overlay: this.$overlay | |||
}); | |||
$("#catman-loading").find("p").html(progressBar.$element); | |||
$("#catman").hide(); | |||
$("#catman").html(index.$element); | |||
var catinputset = new OO.ui.FieldsetLayout({$overlay: this.$overlay}); | |||
catinputset.addItems([ | |||
new OO.ui.ActionFieldLayout(catinput, catinputsubmit, {$overlay: this.$overlay}) | |||
]); | |||
$("#catman-categories").append(catinputset.$element); | |||
$("#catman-summary").append(esinput.$element); | |||
var categorylist = mw.config.get("wgCategories"); | |||
Catman.catinput = catinput; | |||
Catman.catinputsubmit = catinputsubmit; | |||
Catman.esinput = esinput; | |||
Catman.catpage = catpage; | |||
Catman.sumpage = sumpage; | |||
Catman.index = index; | |||
Catman.catinputset = catinputset; | |||
Catman.$overlay = this.$overlay; | |||
$.get(mw.config.get("wgScriptPath") + "/api.php", { | |||
action: "parse", | |||
format: "json", | |||
page: mw.config.get("wgPageName"), | |||
prop: "wikitext" | |||
}).then(function (result, status) { | |||
if (status != "success") { | |||
Catman.windowManager.closeWindow('catmandialog'); | |||
Catman.windowManager.$element.remove(); | |||
OO.ui.alert('Failed to load CatMan.'); | |||
} | |||
//find all category links on the page | |||
var text = result.parse.wikitext["*"]; | |||
var catprefixes = []; | |||
for (var i in mw.config.get("wgNamespaceIds")) { | |||
if (mw.config.get("wgNamespaceIds")[i] == 14) { | |||
catprefixes.push(i); | |||
} | |||
} | |||
Catman.catprefixes = catprefixes; | |||
var editablelist = []; | |||
for (var i of catprefixes) { | |||
editablelist = Catman.getEditableCategories(text, i); | |||
} | |||
Catman.list = editablelist; | |||
var uneditablelist = []; | |||
for (var i in categorylist) { | |||
var editablecategory = false; | |||
for (var j in editablelist) { | |||
if (categorylist[i] == editablelist[j].split("|")[0]) { | |||
editablecategory = true; | |||
break; | |||
} | |||
} | |||
if (!editablecategory) { | |||
uneditablelist.push(categorylist[i]); | |||
} | |||
} | |||
$("#catman-categories").append("<style>\n.catman-remove {\ntext-decoration:line-through;\n}</style>") | |||
$("#catman-categories").append("<table style=\"width:100%\"><caption><b>Categories you can edit</b></caption><tbody id=\"catman-table\"></tbody></table>"); | |||
for (var i of editablelist) { | |||
var $el = $("<tr class=\"catman-category catman-currentcategory\"><td class=\"catman-categoryname\"><a href=\"" + mw.config.get("wgArticlePath").replace("$1", "Category:" + i.split("|")[0]) + "\">" + i.split("|")[0] + "</a>" + (i.split("|").length > 1 ? "<span title=\"This is a category sort key, used to sort category entries when viewing the page in the category.\" style=\"text-decoration-line:underline;text-decoration-style:dotted;\">|" + i.split("|")[1] + "</span>" : "") + "</td><td class=\"catman-categoryremove\"></td></tr>") | |||
$("#catman-table").append($el); | |||
var removeCat = new OO.ui.ButtonWidget({ | |||
icon: 'trash', | |||
title: 'Remove category', | |||
flags: 'destructive', | |||
$overlay: Catman.$overlay, | |||
classes: ['catman-categoryremovebutton'] | |||
}); | |||
$el.find(".catman-categoryremove").append(removeCat.$element); | |||
removeCat.$element.click(function (e) { | |||
e.preventDefault(); | |||
$(this).parent().parent().addClass("catman-remove"); | |||
$(this).parent().parent().find(".catman-undobutton").show(); | |||
$(this).hide(); | |||
}); | |||
var undoCat = new OO.ui.ButtonWidget({ | |||
icon: 'undo', | |||
title: 'Undo remove', | |||
$overlay: Catman.$overlay, | |||
classes: ['catman-undobutton'] | |||
}); | |||
$el.find(".catman-categoryremove").append(undoCat.$element); | |||
undoCat.$element.click(function (e) { | |||
e.preventDefault(); | |||
$(this).parent().parent().removeClass("catman-remove"); | |||
$(this).parent().parent().find(".catman-categoryremovebutton").show(); | |||
$(this).hide(); | |||
}); | |||
undoCat.$element.hide(); | |||
} | |||
if (uneditablelist.length > 0) { | |||
$("#catman-categories").append("<table style=\"width:100%\"><caption><b>Categories you cannot edit</b> (<span title=\"These categories cannot be edited with CatMan because they are automatically added with templates or magic words. To remove these categories, remove the templates or magic words that populate these categories.\" style=\"text-decoration-line:underline;text-decoration-style:dotted;\">?</span>)</caption><tbody id=\"catman-uneditable\"></tbody></table>"); | |||
for (var i of uneditablelist) { | |||
var $el = $("<tr><td class=\"catman-categoryname\"><a href=\"" + mw.config.get("wgArticlePath").replace("$1", "Category:" + i.split("|")[0]) + "\">" + i + "</a></td></tr>") | |||
$("#catman-uneditable").append($el); | |||
} | |||
} | |||
Catman.addCat = function (e) { | |||
e.preventDefault(); | |||
if (catinput.getValue().length > 0) { | |||
var $el = $("<tr class=\"catman-category catman-addcategory\"><td class=\"catman-categoryname\"><a href=\"" + mw.config.get("wgArticlePath").replace("$1", "Category:" + catinput.getValue().split("|")[0]) + "\">" + catinput.getValue().split("|")[0] + "</a>" + (catinput.getValue().split("|").length > 1 ? "<span title=\"This is a category sort key, used to sort category entries when viewing the page in the category.\" style=\"text-decoration-line:underline;text-decoration-style:dotted;\">|" + catinput.getValue().split("|")[1] + "</span>" : "") + "</td><td class=\"catman-categoryremove\"></td></tr>") | |||
$("#catman-table").append($el); | |||
var removeCat = new OO.ui.ButtonWidget({ | |||
icon: 'trash', | |||
title: 'Remove category', | |||
flags: 'destructive', | |||
$overlay: Catman.$overlay | |||
}); | |||
$el.find(".catman-categoryremove").append(removeCat.$element); | |||
removeCat.$element.click(function (e) { | |||
e.preventDefault(); | |||
$(this).parent().parent().remove(); | |||
}); | |||
catinput.setValue(""); | |||
} | |||
$(".catman-categoryname").each(function() { | |||
var that = this; | |||
$.get(mw.config.get("wgScriptPath") + "/api.php", { | |||
action: "parse", | |||
format: "json", | |||
page: "Category:" + $(this).text().split("|")[0] | |||
}).done(function(result) { | |||
if (result.error) { | |||
if (result.error.code == "missingtitle") { | |||
$(that).find("a").addClass("new"); | |||
} | |||
} | |||
}); | |||
}); | |||
} | |||
catinput.$element.keypress(function(e) { | |||
if (e.which == 13) { | |||
Catman.addCat(e); | |||
} else { | |||
var key = e.which || e.keyCode; | |||
if (key == 91 || key == 93 || (catinput.getValue() == "" && key == 32) || (catinput.getValue().search("\\|") >= 0 && key == 124) || (catinput.getValue() == "" && key == 124) || key == 35 || key == 123 || key == 125 || key == 60 || key == 62) { // stop the input of forbidden wikitext characters (except for pipe which is used for category sorting) | |||
e.preventDefault(); | |||
} | |||
} | |||
}); | |||
window.setInterval(function(e) { | |||
//populate the combobox | |||
var searchterm = catinput.getValue(); | |||
var splitsearch = searchterm.split("|"); | |||
$.get(mw.config.get("wgScriptPath") + "/api.php", { | |||
"action": "query", | |||
"format": "json", | |||
"list": "search", | |||
"utf8": 1, | |||
"srsearch": splitsearch[0], | |||
"srnamespace": "14" | |||
}).then(function(result, status) { | |||
if (status == "success") { | |||
if (result.error) { | |||
catinput.setOptions([]); | |||
} else { | |||
var options = [], searchresults = result.query.search; | |||
var restofsearchterm = ""; | |||
for (var i in splitsearch) { | |||
if (i != 0) { | |||
restofsearchterm += splitsearch[i]; | |||
} | |||
if (i != splitsearch.length - 1) { | |||
restofsearchterm += "|"; | |||
} | |||
} | |||
for (var i in searchresults) { | |||
options.push({data: searchresults[i].title.split(":")[1] + restofsearchterm, label: searchresults[i].title.split(":")[1]}); | |||
} | |||
if (options.length == 0) { | |||
options.push({data: searchterm, label: "No results found."}) | |||
} | |||
catinput.setOptions(options); | |||
} | |||
} | |||
}) | |||
}, 1000); | |||
catinputsubmit.$element.click(Catman.addCat); | |||
$(".catman-categoryname").each(function() { | |||
var that = this; | |||
$.get(mw.config.get("wgScriptPath") + "/api.php", { | |||
action: "parse", | |||
format: "json", | |||
page: "Category:" + $(this).text() | |||
}).done(function(result) { | |||
if (result.error) { | |||
if (result.error.code == "missingtitle") { | |||
$(that).find("a").addClass("new"); | |||
} | |||
} | |||
}); | |||
}); | |||
$("#catman").show(); | |||
$("#catman-loading").hide(); | |||
}); | |||
}; | |||
// Register the window constructor with the factory. | |||
Catman.factory.register(CatManDialog); | |||
// Create a window manager. Specify the name of the factory with the ‘factory’ config. | |||
Catman.windowManager = new OO.ui.WindowManager({ | |||
factory: Catman.factory | |||
}); | |||
$(document.body).append(Catman.windowManager.$element); | |||
Catman.windowManager.openWindow('catmandialog', { size: "full" }); | |||
}; | |||
if (mw.config.get("skin") == "minerva") { | |||
mw.util.addPortletLink('p-tb', 'javascript:Catman.start()', 'Start CatMan', 'pt-catman'); | |||
} else { | |||
mw.util.addPortletLink('p-cactions', 'javascript:Catman.start()', 'Start CatMan', 'pt-catman'); | |||
} | |||
}); | |||
} | |||
//</nowiki> | |||
০৬:৫৯, ২৫ এপ্রিল ২০২২ তারিখে সংশোধিত সংস্করণ
// This script aligns dates into one of two formats allowed by [[WP:MOSNUM]].
// PLEASE READ THE DOCUMENTATION at [[User:Ohconfucius/script/MOSNUM dates]] (click on the link above) before using.
// Feedback and constructive criticism are welcome
/**
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
* @see https://meta.wikimedia.org/wiki/TemplateScript
*/
// <pre>
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
$.ajax(
'//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js',
{dataType: 'script', cache: true}
).done(function () {
$.when(
mw.loader.using(['mediawiki.util']),
$.ajax('//en.wikipedia.org/w/index.php?title=User:Ohconfucius/script/MOSNUM_utils.js&action=raw&ctype=text/javascript',
{dataType: 'script', cache: true}),
$.ready
).done(function () {
var add = function() {
return mw.util.addPortletLink.apply(mw.util, arguments);
};
$(add('p-tb', '#', 'DATES to dmy', 'dmy-unitfixer', 'Align all dates to dmy', '', '')).click(ohc_all_to_dmy_driver);
$(add('p-tb', '#', 'DATES to mdy', 'mdy-unitfixer', 'Align all dates to mdy', '', '')).click(ohc_all_to_mdy_driver);
// $(add('p-tb', '#', 'Expand ref dates', 't-expandref', 'Expand month names within refs', '', '')).click(ohc_expand_ref_dates_driver);
// $(add('p-tb', '#', 'Expand all dates', 't-expandall', 'Expand month names throughout', '', '')).click(ohc_expand_all_dates_driver);
$( add('p-tb', '#', 'US-slash dates', 't-US', 'US-slash', '', '') ).click(ohc_US_slash_dates_driver);
$( add('p-tb', '#', 'UK-slash dates', 't-UK', 'UK-slash', '', '') ).click(ohc_UK_slash_dates_driver);
});
});
}
function ohc_fix_unambiguous_dates()
{
// resolvable ambiguous date formats
// UK style
ohc_regex(/([^-\w/:\.])@DD\.@MM\.@YYYY(?=[^-–/\w&])/gi, "$1@Day @Month @YYYY", function(d) {
if (d.d == d.m) return true;
if (d.d > 12) return true;
return false;
});
ohc_regex(/([^-\w/:\.])@DD\/@MM\/@YYYY(?=[^-–/\w&])/gi, "$1@Day @Month @YYYY", function(d) {
if (d.d == d.m) return true;
if (d.d > 12) return true;
return false;
});
// US style
ohc_regex(/([^-\w/:\.])@MM\.@DD\.@YYYY(?=[^-–/\w&])/gi, "$1@Month @Day, @YYYY", function(d) {
if (d.d > 12) return true;
return false;
});
ohc_regex(/([^-\w/:\.])@MM\/@DD\/@YYYY(?=[^-–/\w&])/gi, "$1@Month @Day, @YYYY", function(d) {
if (d.d > 12) return true;
return false;
});
}
function ohc_US_slash_dates_to_mdy()
{
//ranges
ohc_regex(/([^-\d/:\.])@MM\/@DD\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\/@DD\/@YYNN(?=[^-–/\w&])/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2");
ohc_regex(/([^-\d/:\.])@MM\.@DD\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\.@DD\.@YYNN(?=[^-–/\w&])/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2");
ohc_regex(/(\| ?)@MM\/@DD\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\/@DD\/@YYNN(?=\s*\|)/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2");
ohc_regex(/(\| ?)@MM\.@DD\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\.@DD\.@YYNN(?=\s*\|)/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon @Day2, @Year2");
// resolvable ambiguous date formats
ohc_regex(/([^-\d/:\.])@MM\/@DD\/@YYNN(?=[^-–/\w&])/gi, '$1@Month @Day, @YYYY');
ohc_regex(/([^-\d/:\.])@MM\.@DD\.@YYNN(?=[^-–/\w&])/gi, '$1@Month @Day, @YYYY');
ohc_regex(/([^-\d/:\.])@MM[-–]@DD[-–]@YYNN(?=[^-–/\w&])/gi, '$1@Month @Day, @YYYY');
ohc_regex(/(\| ?)@MM\/@DD\/@YYNN(?=\s*\|)/gi, '$1@Month @Day, @YYYY');
ohc_regex(/(\| ?)@MM\.@DD\.@YYNN(?=\s*\|)/gi, '$1@Month @Day, @YYYY');
// ohc_regex(/(\| ?)@MM[-–]@DD[-–]@YYNN(?=\s*\|)/gi, '$1@Month @Day, @YYYY');
}
function ohc_UK_slash_dates_to_dmy()
{
//ranges
ohc_regex(/([^-\d/:\.])@DD\/@MM\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\/@MM\/@YYNN(?=[^-–/\w&])/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");
ohc_regex(/([^-\d/:\.])@DD\.@MM\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\.@MM\.@YYNN(?=[^-–/\w&])/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");
ohc_regex(/(\| ?)@DD\/@MM\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\/@MM\/@YYNN(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");
ohc_regex(/(\| ?)@DD\.@MM\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\.@MM\.@YYNN(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");
// resolvable ambiguous date formats
ohc_regex(/([^-\d/:\.])@DD\/@MM\/@YYNN(?=[^-–/\w&])/gi, '$1@Day @Month @YYYY');
ohc_regex(/([^-\d/:\.])@DD\.@MM\.@YYNN(?=[^-–/\w&])/gi, '$1@Day @Month @YYYY');
ohc_regex(/([^-\d/:\.])@DD[-–]@MM[-–]@YYNN(?=[^-–/\w&])/gi, '$1@Day @Month @YYYY');
ohc_regex(/(\| ?)@DD\/@MM\/@YYNN(?=\s*\|)/gi, '$1@Day @Month @YYYY');
ohc_regex(/(\| ?)@DD\.@MM\.@YYNN(?=\s*\|)/gi, '$1@Day @Month @YYYY');
// ohc_regex(/(\| ?)@DD[-–]@MM[-–]@YYNN(?=\s*\|)/gi, '$1@Day @Month @YYYY');
}
function ohc_remove_leading_zeroes()
{
ohc_regex(/(\D[^\w\/])@Month\s@ZD@th?,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @LYear");
ohc_regex(/(\D[^\w\/])@Month\s@ZD@th?(?=\W\D)/gi, "$1@LMonth @Day");
ohc_regex(/(\D[^\w\/])@ZD@th?\s@Month\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @LYear");
ohc_regex(/(\D[^\w\/])@ZD@th?\s@Month(?=\W\D)/gi, "$1@Day @LMonth");
}
function ohc_delink_dates()
{
//add missing space between wikilinks
regex(/(\]\])(\[\[)/gi, '$1 $2'); //remove (?!file:) to ensure a space between all links
// rem redundant quote marks and parentheses
regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\'\'\'([^|}\[\]]*)\'\'\'(?=\s*[|}])/gi, "$1$2");
regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\'\'([^|}\[\]]*)\'\'(?=\s*[|}])/gi, "$1$2");
regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\"([^|}\[\]]*)\"(?=\s*[|}])/gi, "$1$2");
regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\(([^|}\[\]]*)\)(?=\s*[|}])/gi, "$1$2");
//delink unpiped dates
//delink full dates
ohc_regex(/\[\[@Day[\s_](?:of[\s_])?@Month(?:\]\]\s?\[\[\| )@YYYY\]\]/gi, "@Day @LMonth @YYYY");
ohc_regex(/\[\[@Month (?:the\s)?@Day(?:\]\],? \[\[|, )@YYYY\]\]/gi, "@LMonth @Day, @YYYY");
//delink yyyy-mm-dd dates
ohc_regex(/\[\[@YYYY(?:\]\]-\[\[|-)@MM-@DD\]\]/gi, "@YYYY-@MM-@DD");
ohc_regex(/@YYYY-\[\[@MM-@DD\]\]/gi, "@YYYY-@MM-@DD");
//underscore and nbsp in linked dates
ohc_regex(/\[\[@DD@th?(?:\s|_| )@Month\]\]/gi, "@Day @LMonth");
ohc_regex(/\[\[@Month(?:\s|_| )@DD@th?\]\]@th?/gi, "@LMonth @Day"); //consolidated regex with flexible removal of ordinal simple date
ohc_regex(/\[\[@Day @Month\]\]/gi, "@Day @LMonth");
ohc_regex(/\[\[@Month @YYYY\]\]/gi, "@LMonth @YYYY");
ohc_regex(/\[\[@YYYY\]\]/gi, "@YYYY");
//remove leading zero and links from linked date
ohc_regex(/\[\[@Month(?:[ _]| )@ZD@th\]\]/gi, "@LMonth @Day");
ohc_regex(/\[\[@ZD@th(?:[ _]| )@Month\]\]/gi, "@Day @LMonth");
// remove nowrap template from dm and md dates
ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@DD(?:[ _]| )@Month)( @yyyy|)\}\}/gi, '$1@DD @LMonth$2');
ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@Month(?:[ _]| )@DD)( @yyyy|)\}\}/gi, '$1@LMonth @DD$2');
//delink single dm or 'dth the m'
ohc_regex(/(?:the\s)?\[\[@Day@th?[\s_](?:of[\s_])?@Month\]\]/gi, "@Day @LMonth");
//delink single md or 'm the dth'
ohc_regex(/\[\[@Month[\s_](?:the[\s_])?@Day@th?\]\](?=\W)/gi, "@LMonth @Day");
//month+day piped
ohc_regex(/\[\[(?:@dd@th?[\s_](?:of[\s_])?@month|@month[\s_]@dd@th?)\|((?:@month |)@day)@th?\]\]/gi, "$1");
ohc_regex(/\[\[(?:@dd@th?[\s_](?:of[\s_])?@month|@month[\s_]@dd@th?)\|@Day@th?[\s_](@month|)\]\]/gi, "@Day $1");
// ohc_regex(/\[\[@month @dd(?:#[^|]+|)\|([^|\]]+)@th?\]\]/gi, "$1");
// ohc_regex(/\[\[@dd @month(?:#[^|]+|)\|([^|\]]+)@th?\]\]/gi, "$1");
ohc_regex(/\[\[@month @yyyy(?:#[^|]+|)\|([^|\]]+)\]\]/gi, "$1");
//month+day+year pseudo-ISO dates
ohc_regex(/\[\[@Month @DD\|\d\d-\d\d\]\]-(?:\[\[)?(?:@yyyy[^|]*\|)?@YYYY(?:\]\])/gi, "@Day @LMonth @YYYY");
ohc_regex(/\[\[@DD\s@Month\|\d\d-\d\d\]\]-(?:\[\[)?(?:@yyyy[^|]*\|)?@YYYY(?:\]\])/gi, "@Day @LMonth @YYYY");
//'[[month day|xxXxx]]Xyyyy ' to 'month day, year'
ohc_regex(/\[\[@Month\s@Day\|@dd.@dd\]\].@YYYY/gi, "@LMonth @Day, @YYYY");
//'[[day month|xxXxx]]Xyyyy' to 'day month year'
ohc_regex(/\[\[@Day\s@Month\|@dd.@dd\]\].@YYYY/gi, "@Day @LMonth @YYYY");
// century
regex(/\[\[((?:first|second|third|(?:four|fif|six|seven|eigh|nin|ten|eleven|twelf|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twentie)th|twenty[\s\-]first[\s\-])centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE))?)\]\]/gi, '$1');
regex(/\[\[(?:first|second|third|(?:four|fif|six|seven|eigh|nin|ten|eleven|twelf|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twentie)th|twenty[\s\-]first)[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE))?\|([^\]]{1,30})\]\]/gi, '$1');
regex(/\[\[(\d{1,2}(?:st|[nr]d|th))[\s\-_](centur(?:y|ies))(\s(?:AD|BC|CE|BCE)|)\]\]/gi, '$1 $2$3');
ohc_regex(/\[\[\d{1,2}@th[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE)|)\|([^\]]{1,30})\]\]/gi, '$1');
// months
ohc_regex(/\[\[@Month\]\]/gi, "@LMonth");
ohc_regex(/\[\[@FullMonth\|([^\]]{1,30})\]\]/gi, "$1");
// decades and years
regex(/(\d{1,3}0)[‘`´’′]?s/g, '$1s');
regex(/\[\[(\d{1,3}0)\'?s\]\]/g, '$1s');
regex(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g, '$1');
regex(/\[\[(\d{1,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '$1$2 $3');
regex(/\[\[(\d{1,4}[\s_]?)(AD|BC|CE|BCE)\]\]/gi, '$1$2');
regex(/\[\[(AD|BC|CE|BCE)([\s_]?)(\d{1,4})\]\]/gi, '$1$2$3');
ohc_regex(/([-–])\[\[\s?@yyyy\s?\|\s?(\d{2,4})\s?\]\]/gi, '$1$2'); //piped year
regex(/\[\[([12]\d{3}|[1-9]\d{0,2})\]\]/gi, '$1');
regex(/\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]/gi, '$1');
regex(/\[\[\d{1,3}0\'?s?\s\(decade\)\|([^\]]{1,30})\]\]/gi, '$1');
//month+year
//Identify surprise or 'Easter egg' diversions linking month+years to year articles. Turn them into month+year links to be dealt with below
ohc_regex(/\[\[@yyyy in[^|\]]+\|@Day @Month @YYYY\]\]/gi, "@Day @LMonth @YYYY");
ohc_regex(/\[\[@yyyy in[^|\]]+\|@Month @Day,? @YYYY\]\]/gi, "@LMonth @Day, @YYYY");
ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month\s|)(@yyyy)\]\]/gi, "$1$2");
ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month|@yyyy)\]\]/gi, "$1");
ohc_regex(/\[\[(@month\s@yyyy)\]\]/gi, "$1");
ohc_regex(/\[\[@month\s@yyyy\|([^\]]{1,30})\]\]/gi, "$1");
ohc_regex(/\[\[(?:List of |)Bollywood films of @yyyy\|@YYYY\]\](?= [^\[]{2}^B)/gi, "@YYYY");
ohc_regex(/(\[\[@yyyy[^|\]]+\|@yyyy)(\]\])( season)/gi, "$1$3$2");
//removed piped years when in full date (excepting disambiguated parentheses - updated 24/2/2012)
// ohc_regex(/\[\[[^|\]\(\)]{1,32}\|@YYYY\]\]/gi, '@Year'); // 23/6/2021 – disabled delinking "other" year-in articles
//Identify surprise or 'Easter egg' diversions linking months to year or "year in" articles.
ohc_regex(/\[\[\d{1,4}#[^|\]]+\|@Month\]\]/gi, "@LMonth");
ohc_regex(/\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, '@Year');
// month and day piped
ohc_regex(/\[\[@month[\s_]@day\|@MM-@DD\]\]/gi, "@MM-@DD");
ohc_regex(/\[\[@month[\s_]@day\|([^\]]{1,30})\]\]/gi, "$1");
ohc_regex(/\[\[@day(?:\s|_|@th )(?:of[\s_]|)?@month\|([^\]]{1,30})\]\]/gi, "$1");
//years piped
regex(/\[\[\d{1,4}\|([^\]]{1,30})\]\]/gi, '$1');
}
function ohc_fix_common_errors()
{
ohc_regex(/(\d)<sup>@th<\/sup>/gi, '$1th');
// remove dashbot comment from dates
regex(/<!-- ?DASHBot ?-->/gi, '');
ohc_regex(/(\|\s*(?:date|year)\s*=)\s*c(?:irca|a\.)?\s?((?:@day |)@month @year)(?=[\s\n]*[<|}])/gi, '$1c. $2'); //add space
//common cs1 errors
regex(/(\|\s*(?:date|year)\s*=)\s*(1[7-9]\d|20[0-1])\?(?=[\s\n]*[<|}])/gi, '$1c. $20');
regex(/(\|\s*(?:date|year)\s*=\s*(1[7-9])\d{2})[-–](\d{2})(?=[\s\n]*[<|}])/gi, '$1–$2$3');
// regex(/(\|\s*(?:date|year)\s*=\s*(20)[0-1]\d)[-–]([0-2]\d)(?=[\s\n]*[<|}])/gi, '$1–$2$3');
regex(/(\|\s*(?:date|year)\s*=\s*)@YYYY\s*[-–/]\s*@YYYY(?=[\s\n]*[<|}])/gi, '$1@YYYY1–@YYYY2'); //common cs1 error
regex(/(\|\s*(?:date)\s*=)\s*s(pring|ummer),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '$1S$2 $3'); //common cs1 error
regex(/(\|\s*(?:date)\s*=)\s*a(utumn),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '$1A$2 $3'); //common cs1 error
regex(/(\|\s*(?:date)\s*=)\s*f(all),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '$1F$2 $3'); //common cs1 error
regex(/(\|\s*(?:date)\s*=)\s*w(inter),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '$1W$2 $3'); //common cs1 error
ohc_regex(/(\|\s*access-?date\s*=)\s*(@month @year)(?=[\s\n]*[<|}])/gi, '$11 $2'); //common cs1 error
// ohc_regex(/(\|\s*date\s*=\s*)@year\?(?=[\s\n]*[<|}])/gi, '$1@Year'); //common cs1 error
// ohc_regex(/(\|\s*(?:date|year)\s*=)\s*@year\?(?=[\s\n]*[<|}])/gi, '$1c. @Year'); //common cs1 error
// ohc_regex(/(\|\s*(?:date|year)\s*=)\s*(@month @year)\?(?=[\s\n]*[<|}])/gi, '$1c. $2'); //common cs1 error
ohc_regex(/(\|\s*access-?date\s*=)\s*@month @day, (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi, '$1'); //rem access date before Wikipedia (জানুয়ারি 2001)
ohc_regex(/(\|\s*access-?date\s*=)\s*@day @month.? (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi, '$1'); //rem access date before Wikipedia (জানুয়ারি 2001)
ohc_regex(/(\|\s*access-?date\s*=)\s*31( (?:এপ্রিল|জুন|সেপ্টেম্বর|নভেম্বর) @year)(?=[\s\n]*[<|}])/gi, '$130$2'); //rem nonsense access date (short months)
ohc_regex(/(\|\s*access-?date\s*=)\s*29( ফেব্রুয়ারি (?:200[1235679]|201[1345789]))(?=[\s\n]*[<|}])/gi, '$128$2'); //rem nonsense access date 29 ফেব্রুয়ারি (non-leap year)
ohc_regex(/(\|\s*access-?date\s*=)\s*(?:3[01])( ফেব্রুয়ারি @yyyy)(?=[\s\n]*[<|}])/gi, '$128$2'); //rem nonsense access dates ফেব্রুয়ারি
regex(/(\|\s*access-?date\s*=)\s*(\d{4})(?=[\s\n]*[<|}])/gi, ''); //common cs1 error
//month+day+year pseudo-ISO dates
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*@dd)-@Mon-@YYYY/gi, "$1 @FullMonth @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@YYYY-@DD-@Mon/gi, "$1 @DD @FullMonth @YYYY");
regex(/(\|\s*(?:date|year)\s*=)\s*(?:(?:date |)unknown|(?:not? |non-|un)date[ds])(?=[\s\n]*[<|}])/gi, '$1n.d.'); //common cs1 error
regex(/(\|\s*(?:date|year)\s*=)\s*n\.?d(?=[\s\n]*[<|}])/gi, '$1n.d.'); //common cs1 error
regex(/(\|\s*)year(\s*=\s*)(?=n\.?d\.)(?=[\s\n]*[<|}])/gi, '$1date$2'); //common cs1 error
// remove parasitic metadata - days of the week/descriptives
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:[^|}\d]*|)@Day\s+@Month\s+@YYYY((?:[a-z]\b|)\s?)[^|<}]*(?=[\s\n]*[<|}])/gi, "$1@Day @Month @YYYY$2"); //rem negate "<", "hyphens" "dashes" 26/6/2020
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)[^|}]*@Month\s+@Day,\s+@YYYY((?:[a-z]\b|)\s?)[^|<}]*(?=[\s\n]*[<|}])/gi, "$1@Month @Day, @YYYY$2"); //rem negate "<", "hyphens" "dashes" 26/6/2020
// ohc_regex(/(\|\s*date\s*=\s*)(?:[^|}–<]*\D|)@Day\s+@Month\s+@YYYY ?– ?@Day\s+@Month\s+@YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Day1 @Mon1 @Year1 – @Day2 @Mon2 @Year2");
// ohc_regex(/(\|\s*date\s*=\s*)[^|}–<]*@Month\s+@Day,\s+@YYYY ?– ?@Month @Day, @YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Mon1 @Day1, @Year1 – @@Mon2 Day2, @Year2");
// regex(/(\|\s*author\s*=\s*)(?:posted|published)(?: by\b| on\b|)[\s:](?=\w)/gi, "$1");
// regex(/(\|\s*(?:date|archive-?date|access-?date|author|year)\s*=\s*)(?:accessed|retrieved|entered|posted|published|(?:last |)updated?|©)(?: by\b| on\b|)[\s:]*(?=\w)/gi, "$1");
regex(/(\|\s*(?:author|first|last)\s*=\s*)(?:by\b|on\b)[\s:]*(?=\w)/gi, "$1");
regex(/(\|\s*(?:date|archive-?date|access-?date|author|first|last)\s*=\s*)(?:(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day,?)\s/gi, "$1");
regex(/(\|\s*(?:date|archive-?date|access-?date|author|first|last)\s*=\s*)(?:Mon|Tues?|Wed|Thur?|Fri|Sat)[\.,]?\s/gi, "$1"); //<!-- rem "Sun" - false positives -->
// remove deprecated parameters (|day= and |month)
ohc_regex(/(\|\s*)day(?:\s*=\s*)@DD ?\| ?month(?:\s*=\s*)@Month ?\| ?year(?:\s*=\s*)@YYYY(?=[|}\s])/gi, '$1date=@Day @Month @Year');
ohc_regex(/(\|\s*)year(?:\s*=\s*)@YYYY ?\| ?month(?:\s*=\s*)@Month ?\| ?day(?:\s*=\s*)@DD(?=[|}\s])/gi, '$1date=@Month @Day, @Year');
// typos
ohc_regex(/(date *= *)@Day @Month ?@th/gi, '$1@Day @Month');
ohc_regex(/(date *= *)@Day @Month\w(?= \d{3,4})/gi, '$1@Day @Month');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )(জানুয়ারি|Febr)[\w ]?[aur]{3,4}\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1$2uary');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )J[anu]{3,5}r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1জানুয়ারি');
ohc_regex(/(date *= *(?:[12]?\d) )Febua?r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1ফেব্রুয়ারি');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )M\w{2,3}ch(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1মার্চ');
ohc_regex(/(date *= *(?:[12]?\d|30) )A[bpv\[]\w{2,3}l\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1এপ্রিল');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )Ma[tui](?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1মে');
ohc_regex(/(date *= *(?:[12]?\d|30) )J\wn\w(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1জুন');
ohc_regex(/(date *= *(?:[12]?\d|30) )J\w{1,2}e(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1জুন');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )জুলাই\w{1,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1জুলাই');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )A[oug]{2,3}\w{1,4}t(?:\w|us)?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1আগষ্ট');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )(সেপ্টেম্বর|নভেম্বর|ডিসেম্বর)\w{2,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1$2ember');
ohc_regex(/(date *= *(?:[12]?\d|30) )S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1সেপ্টেম্বর');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )O\w{0,2}t\w{1,3}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1অক্টোবর');
ohc_regex(/(date *= *(?:[12]?\d|30) )[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1নভেম্বর');
ohc_regex(/(date *= *(?:[12]?\d|30|31) )D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1ডিসেম্বর');
ohc_regex(/(date *= *)@Month\w(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1@Month'); //rem stray digit at the end of year string
ohc_regex(/(date *= *)(জানুয়ারি|Febr)[\w ]?[aur]{3,4}\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1$2uary');
ohc_regex(/(date *= *)J[anu]{3,5}r\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1জানুয়ারি');
ohc_regex(/(date *= *)Febua?r\w{0,2}(?=(?: (?:[12]?\d),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1ফেব্রুয়ারি');
ohc_regex(/(date *= *)M\w{2,3}ch(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1মার্চ');
ohc_regex(/(date *= *)A[bpv\[]\w{2,3}l\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1এপ্রিল');
ohc_regex(/(date *= *)Ma[tui](?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1মে');
ohc_regex(/(date *= *)J\wn\w(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1জুন');
ohc_regex(/(date *= *)J\w{1,2}e(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1জুন');
ohc_regex(/(date *= *)জুলাই\w{1,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1জুলাই');
ohc_regex(/(date *= *)A[oug]{2,3}\w{1,4}t(?:\w|us)?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1আগষ্ট');
ohc_regex(/(date *= *)(সেপ্টেম্বর|নভেম্বর|ডিসেম্বর)\w{2,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1$2ember');
ohc_regex(/(date *= *)S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1সেপ্টেম্বর');
ohc_regex(/(date *= *)O\w{0,2}t\w{1,3}[er]{2,3}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1অক্টোবর');
ohc_regex(/(date *= *)[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1নভেম্বর');
ohc_regex(/(date *= *)D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1ডিসেম্বর');
//insert comma to separate date from army unit
ohc_regex(/@FullMonth ((?:the |)\d\d*@th (?:Air(?:borne|)|Arm(?:ou?red|y)|Artillery|Battalion|Brigade|Co(?:mpan|)y|Division|Fleet|Group|Infantry|Land|Panzer|Regiment|Squadron|Sqn)\b)/g, "@Month, $1");
// remove parasitic metadata - time
ohc_regex(/(\|\s*\w*date\s*=\s*@yyyy-@mm-@dd)\s?(?:T[0-2]\d:[0-5]\d:[0-5]\d(?:\s*| |)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|Z))(?=\s*[|}])/g, "$1");
ohc_regex(/(\|\s*\w*date\s*=\s*@month @day,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*| )(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1");
ohc_regex(/(\|\s*\w*date\s*=\s*@day @month,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*| )(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1");
ohc_regex(/(\|\s*\w*date\s*=\s*\w[\w\s]+@month @day,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*| )(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1");
ohc_regex(/(\|\s*\w*date\s*=\s*\w[\w\s]+@day @month,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*| )(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1");
ohc_regex(/(\|\s*\w*date\s*=[^:|}]*)\s?(?:T?[0-2]\d:[0-5]\d:[0-5]\d(?:\s*| |)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|Z))/g, "$1");
// add back spaces or comma or remove other single artefact after date string
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:on |)@Day\s{,2}@Month\s{,2}@YYYY[^a-z{}]?(?=\s*[|}\n])/gi, "$1@Day @Month @YYYY$2");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:on |)@Month\s{,2}@Day,?\s{,2}@YYYY[^a-z{}]?(?=\s*[|}\n])/gi, "$1@Month @Day, @YYYY$2");
//long-hand palliative for observed failure to insert spaces
ohc_regex(/(\|\s*(?:archive|access|air)-?date\s*=\s*)(?:on |)([0-2]?\d|30|31)\s*(জানুয়ারি|ফেব্রুয়ারি|মার্চ|এপ্রিল|মে|জুন|জুলাই|আগষ্ট|সেপ্টেম্বর|অক্টোবর|নভেম্বর|ডিসেম্বর)\s*((?:19\d|20[0-1])\d\s?)[^|{}\s<>]*(?=\s*[|}])/gi, "$1$2 $3 $4");
// ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)(?:on |)@Day\s*@Month\s*@YYYY([a-z]\s?|\s?)\w*[^|{}<>]*(?=[|}])/gi, "$1@Day @Month @YYYY$2");
// ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)(?:on |)@Month\s*@Day,\s*@YYYY([a-z]\s?|\s?)\w*[^|{}<>]*(?=[|}])/gi, "$1@Month @Day, @YYYY$2");
//remove extraneous bracket //from Batty
ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:archive-?|access-?|publication-?)?date\s*=\s*)([\w\s-]+)\](?=\s*[\|}<])/gi, '{{$1$2$3$4');
//fix bda template redirect
// regex(/\{\{bda\|([^}]+)\}\}/gi, '{{birth date and age|$1}}');
// regex(/\{\{dda\|([^}]+)\}\}/gi, '{{death date and age|$1}}');
//zap redundant {{date}}, {{accessdate}} {{retrieved}}, {{monthname}} and {{#dateformat}}
// regex(/({{(?:end|start)[-–]date)\|df=y(?:es|)/gi, "$1"); //rem deprecated parameter - disabled: doesn't work here, so ejected to the formatting script
ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:[^\}]*)}}/gi, "@Day @Month @YYYY");
regex(/{{#formatdate:([^}]+)}}/gi, "$1");
regex(/\{\{#dateformat:([^}\|]+)(?:\|dmy|\|mdy)?\}\}/gi, '$1');
// ohc_regex(/(date[ ]*=[ ]*)\{\{(?:Start|End) ?date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\|@DD(?:\|df=y(?:es|)|)\}\}/gi, '$1@Month @DD, @YYYY'); //stripping start/end template notes inside "|date=" parameter (line 72)
ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:\|(?:[dmy]{3}|iso)|)}}/gi, "@Day @Month @YYYY");
ohc_regex(/\{\{date\|@YYYY-@MM-@DD\}\}/gi, "@Day @Month @YYYY");
ohc_regex(/\{\{date\|(@DD[\-\s]@Mon|@Mon[\-\s]@DD)\}\}/gi, "@Day @Month");
regex(/\{\{date\|([^}\|]+)(?:\|l?(?:[dmy]{3}|iso|none|link))?\}\}/gi, '$1');
ohc_regex(/[ ]*\{\{accessdate\|@YYYY-@MM-@DD[ ]*\}\}/gi, " Retrieved @YYYY-@MM-@DD");
ohc_regex(/[ ]*\{\{retrieved[ ]*\|[ ]accessdate=([\-\w, ]*)\}\}/gi, " Retrieved $1");
// ohc_regex(/(date[ ]*=[ ]*|\w{2,}[ ]*)\{\{(?:start|end).date[^|}]*(?:\|df=y(?:es|)|)\|@YYYY(?:\|df=y(?:es|)|)\}\}/gi, '$1@YYYY'); //stripping start/end template (disabling to placate Pigsonthewing)
// ohc_regex(/\{\{(?:Start|End) date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\}\}/gi, '@Month @YYYY') //stripping start/end template notes
// ohc_regex(/<!--(?:Use)? \{\{(?:Start|End) date\|@YYYY\|@MM\|@DD\}\} -->/gi, ''); //stripping start/end template notes
ohc_regex(/(\{\{MONTHNAME\|@MM\}\})/gi, "@Month")
//expand one and two-digit years in ranges
regex(/(\()@Month @YYYY[-–]@Month @YYNN(\))/gi, '$1@Month1 @YYYY1 – @Month2 @YYYY2$2');
regex(/(\(1[789])(\d)(1)[-–]([2-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(1[789])(\d)(2)[-–]([3-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(1[789])(\d)(3)[-–]([4-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(1[789])(\d)(4)[-–]([5-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(1[789])(\d)(5)[-–]([6-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(1[789])(\d)(6)[-–]([7-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(1[789])(\d)(7)[-–]([8-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(1[789])(\d)(8)[-–](9\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(1)[-–]([2-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(2)[-–]([3-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(3)[-–]([4-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(4)[-–]([5-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(5)[-–]([6-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(6)[-–]([7-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(7)[-–]([8-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(8)[-–](9\))/gi, '$1$2$3–$2$4');
ohc_regex(/(\W)@DD@th?, @DD@th?((?:[ ]| )(?:and|&|to|or)(?:[ ]| ))@DD@th?(?:\sof\s?)?([ ]| )@Month(?=\W)/gi, '$1@Day1, @Day2$2@Day3$3@LMonth');
ohc_regex(/(\W)@DD@th?((?:[ ]| )(?:and|&|to|or)(?:[ ]| ))@DD@th?(?:\sof\s?|)([ ]| )@Month(?=\W)/gi, '$1@Day1$2@Day2$3@LMonth');
ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month,? @YYYY(?=\W\D)/g, '$1@Day @LMonth @YYYY');
ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month(?=\W\D)/g, '$1@Day @LMonth');
ohc_regex(/(\W)@Day@th?(?:\sof|)([ _]| |{{(?:break|nbsp)}})@Month(?=[^|\]\w])/gi, '$1@Day$2@LMonth');
ohc_regex(/(\W)@Month\s(?:the\s)?@DD@th?,(?:\sthe\s)?(?: | )@DD@th?(\s(?:and|&|to|or)(?:[ _]| ))(?:the\s)?@DD@th?(?=[^|\]\w])/gi, '$1@LMonth @Day1, @Day2$2@Day3');
ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?:,?(?:[ _]| )|\sof\s)?(\d{3,4}\W\D)/gi, '$1$2 $3$4$5@Day, $6');
ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?=\W\D)/gi, '$1$2 $3$4$5@Day');
ohc_regex(/(\W)@Month([ _]| |{{(?:break|nbsp)}})(?:the\s)?@DD@th?,? @Year/gi, '$1@LMonth$2@Day, @Year');
ohc_regex(/(\W)@Month @Day(?:\sof|,|)([ _]| |{{(?:break|nbsp)}})@Year(?=[^|\]\w])/gi, '$1@Month @Day,$2@Year');
// consolidating/amalgamating date fields
ohc_regex(/(\|[ ]*date[ ]*=[ ]*@day)\s*\|[ ]*month=[ ]*(@month)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2 $3");
ohc_regex(/(\|[ ]*date[ ]*=[ ]*@day.?@month)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2");
ohc_regex(/(\|[ ]*date[ ]*=[ ]*@month.?@day)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2");
// eliminating dates and time placed in author parameter
//removing artefacts from Indian news sites (TNN আগষ্ট 30, 2012, 05.46AM)
ohc_regex(/(\|\s*author\s*=\s*(?:[A-Z]{2,3}\b))(?:[^|}]*)\d{4}, [\d\.:]{4,5}( |)[AP]M IST(?=[ ]*\|)/g, '$1$2');
// ohc_regex(/(\|\s*author=(?:[^\[\]|{}]*))(TNN|PTI) @day @month @yyyy, [\d\.:]{4,5}( |)[AP]M IST(?=[ ]*\|)/g, '$1$2');
ohc_regex(/(\|\s*author\s*=\s*)@month @day,? @yyyy\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*| )(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|)|)(?=\|)/g, "$1");
ohc_regex(/(\|\s*author\s*=\s*)@day @month,? @yyyy\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*| )(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|)|)(?=\|)/g, "$1");
ohc_regex(/(\|\s*author\s*=\s*\w[\w\s]+)@month @day,? @yyyy(?:[^\[\]|{}]*)(?=[|}])/g, "$1");
ohc_regex(/(\|\s*author\s*=\s*\w[\w\s]+)@day @month,? @yyyy(?:[^\[\]|{}]*)(?=[|}])/g, "$1");
ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)@dd-@mm-@yyyy/gi, "$1");
ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)@YYYY-@MM-@DD ?/gi, "$1");
regex(/(\|\s*(?:date|archive-?date|access-?date|author)\s*=\s*(?:\w[\w\s]+)?)[0-2]\d:[0-5]\d(?:[ ]| )?(?:[ap]m|[ap]\.m\.|)(?: ?(?:[A-Z]{1,2}T|UTC)[\.,]?|)/gi, "$1");
// ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)\s*[0-2]\d[\.:][0-5]\d(?:[\.:][0-5]\d|)/gi, "$1"); //let's see later if we need this
// eliminating mm-dd-yyyy dates
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@MM[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY/gi, "$1@Month $2, @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Mon[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY/gi, "$1@Month $2, @YYYY");
ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@MM[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY(?=\D)/gi, " Retrieved @Month $1, @YYYY");
// ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@YYYY,? @Month @DD(?=\D)/gi, " Retrieved @Day @Month @YYYY");
ohc_regex(/([ =|])@Mon[-–](1[3-9]|2\d|3[01])[-–]@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
ohc_regex(/([ =|])@Mon\/(1[3-9]|2\d|3[01])\/@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
ohc_regex(/([ =|])@Mon\.(1[3-9]|2\d|3[01])\.@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
ohc_regex(/([ =|])@Mon (1[3-9]|2\d|3[01]) @YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
ohc_regex(/([ =|])@MM[-–](1[3-9]|2\d|3[01])[-–]@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
ohc_regex(/([ =|])@MM\/(1[3-9]|2\d|3[01])\/@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
ohc_regex(/([ =|])@MM\.(1[3-9]|2\d|3[01])\.@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
ohc_regex(/([ =|])@MM (1[3-9]|2\d|3[01]) @YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY");
// eliminating dd-mm-yyyy dates (assumed default)
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@MM[-–\/\.=\s]@YYYY/gi, "$1@Day @Month @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@Mon[-–\/\.=\s]@YYYY/gi, "$1@Day @Month @YYYY");
ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@DD[-–\/\.=\s]@MM[-–\/\.=\s]@YYYY(?=\D)/gi, " Retrieved @Day @Month @YYYY");
ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@YYYY,? @Month @DD(?=\D)/gi, " Retrieved @Day @Month @YYYY");
ohc_regex(/([ =|])@DD[-–]@Mon[-–]@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/([ =|])@DD\/@Mon\/@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/([ =|])@DD\.@Mon\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/([ =|])@DD @Mon @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/([ =|])@DD[-–]@MM[-–]@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/([ =|])@DD\/@MM\/@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/([ =|])@DD\.@MM\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/([ =|])@DD @MM @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@Month[-–\/\.=\s]@YYNN(?=\s*[|}\n])/gi, '$1@Day @Month @YYYY');
//convert yyyy-dd-mm to yyyy-mm-dd
ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:publication|archive|access|air|)-?date\s*=\s*(?:1[0-9]|20)\d{2})[-/\.=\s](1[3-9]|2\d|3[01])[-/\.=\s](0?\d|1[0-2])(\s*[\|}<])/gi, '{{$1$2$3-$5-$4$6'); //from Batty
// eliminating other errant formats
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)([0-2]?\d|30|31) @Month \2,? @YYYY(?=\s*[|}])/gi, "$1$2 @Month @YYYY"); //repeated digits
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day ?@Month ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Day @Month 20$2");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month ?@Day,? ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Month @Day, 20$2");
ohc_regex(/([ ]\()@DD-@MM-@YYYY(\)\W)/gi, '$1@Day @Month @YYYY$2');
ohc_regex(/([ ]\()@DD-@Month-@YYYY(\)\W)/gi, '$1@Day @Month @YYYY$2');
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@Month, @DD, @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY");
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@DD[\.,] @Month,? @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY");
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @Month @DD(?=\s*[|}])/gi, "$1@Day @Month @YYYY");
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @DD @Month(?=\s*[|}])/gi, "$1@Day @Month @YYYY");
ohc_regex(/[ ]\(@YYYY,? @Month @DD\)/gi, " (@Day @Month @YYYY)");
ohc_regex(/[ ]\(@YYYY @MM @DD\)/gi, " (@Day @Month @YYYY)");
ohc_regex(/[ ]\(@YYYY, @DD @Month\)/gi, " (@Day @Month @YYYY)");
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @Month(?=\s*[|}])/gi, "$1@Month @YYYY");
ohc_regex(/[ ]\(@YYYY, @Month\)/gi, " (@Month @YYYY)");
ohc_regex(/[ ]\(@Mon@YYYY\)/gi, " (@Mon @YYYY)");
//CS1 errors ISO-like dates (too few or too many digits)
ohc_regex(/(date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][–—‐]\[\[|[–—‐])@MM[\-–—‐]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@YYYY-@ZM-@ZD"); //ndashes and emdashes
ohc_regex(/(\|\s*access-?date\s*=)\s*@YYYY-0[–—]@DD(?=\s*[|}])/gi, ""); //rem nonsense access date
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY[-–—]@MM[-–—]@DD(?=\s*[|}])/gi, "$1@YYYY-@ZM-@ZD"); //ndashes and emdashes
// ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY[\-–—‐]@MM(?=\s*[|}])/gi, "$1@Month @YYYY"); //transform "yyyy-mm" to "month year"
ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[–—]@MM[–—]@DD([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3");
ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-]@MM[-]([1-9])([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2$3 @Month @YYYY$4");
// spaces and commas between month and year
ohc_regex(/@Month(?:,?|\s+of|)(\s| )@YYYY(?=\D)/gi, "@LMonth$1@YYYY");
// fix month names (capitalize, remove dots)
ohc_regex(/(\W)@DD\s@FullMonth(\s+|\s*,)/gi, "$1@Day @FullMonth$2");
ohc_regex(/(\W)@DD\s@Mon(\s+|\s*,)/gi, "$1@Day @Mon$2");
ohc_regex(/(\W)@FullMonth\s@DD(\s+|\s*,)/gi, "$1@FullMonth @Day$2");
ohc_regex(/(\W)@Mon\s@DD(\s+|\s*,)/gi, "$1@Mon @Day$2");
regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?=[ ]*(=|BC|AD|CE))/g, '$1c$2');
// regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ \-][A-Z]\w*|''|")/g, '$1c$2');
//spaces and commas - in date formats
ohc_regex(/(\D\W\[?\[?@dd)[ ]+(@month)(\]\])?[ ]*,[ ]*(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1 $2$3 $4");
ohc_regex(/(\D\W\[?\[?)(@month)[ ]+(@dd)(\]?\]?)(?:[ ]*,[ ]*)(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1$2 $3$4, $5");
ohc_regex(/(\D\W\[?\[?)(@month)[ ]+(@dd)(\]?\]?)[ ]+(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1$2 $3$4, $5");
ohc_regex(/(@month)(?:, | of )(@yyyy\w)/gi, "$1 $2"); //repeat after delinking
// spaces and commas - md-md and dm-dm date ranges
ohc_regex(/(\D\W)@Month\s@DD( |\s)(?:[-–—]|&[mn]dash;)(?: |\s)?@Month\s@DD(?=\W\D)/gi, "$1@LMonth1 @Day1$2– @LMonth2 @Day2");
ohc_regex(/(\D\W)@Month\s@DD(?:[-–—]|&[mn]dash;)(?: |\s)?@Month\s@DD(?=\W\D)/gi, "$1@LMonth1 @Day1 – @LMonth2 @Day2");
ohc_regex(/(\D\W)@DD\s@Month( |\s)(?:[-–—]|&[mn]dash;)(?: |\s)?@DD\s@Month(?=\W\D)/gi, "$1@Day1 @LMonth1$2– @Day2 @LMonth2");
ohc_regex(/(\D\W)@DD\s@Month(?:[-–—]|&[mn]dash;)(?: |\s)?@DD\s@Month(?=\W\D)/gi, "$1@Day1 @LMonth1 – @Day2 @LMonth2");
// spaces and commas - d-dm and md-d date ranges
ohc_regex(/(\D\W)@Month(\s| )@DD@th?(?:(?:\s*| |)[-–](?:\s*| |))@DD@th?(?=\W\D)/gi, "$1@LMonth1$2@Day1–@Day2");
ohc_regex(/(\D\W)@DD@th?(?:(?:\s*| |)[-–](?:\s*| |))@DD@th?(\s| )@Month(?=\W\D)/gi, "$1@Day1–@Day2$2@LMonth1");
// spaces and commas between month and year (again)
ohc_regex(/@Month(?:,\s+|\s+of\s+)@YYYY(\w)/gi, "@LMonth @YYYY$1");
}
/** ------------------------------------------------------------------------- */
/// ISO to long format
function ohc_ISO_to_dmy_in_citations()
{
//ISO dates within single citation
ohc_regex(/(\|\s*(?:publication|archive|access|air|designation\d?_|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY");
}
function ohc_ISO_to_mdy_in_citations()
{
//ISO dates within single citation
ohc_regex(/(\|\s*(?:publication|archive|access|air|designation\d?_|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY");
}
function ohc_ISO_to_dmy_in_references()
{
//multiple calls for multiple dates within single citation
ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3");
ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD(<\/ref>)/gi, "$1$2@Day @Month @YYYY$3");
}
function ohc_ISO_to_mdy_in_references()
{
//multiple calls for multiple dates within single citation
ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3");
ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD(<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3");
}
// currently unused
function ohc_ISO_to_dmy_anywhere()
{
//multiple calls for multiple dates within single citation
ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Day @Month @YYYY$2');
ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Day @Month @YYYY$2');
ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Day @Month @YYYY$2');
}
// currently unused
function ohc_ISO_to_mdy_anywhere()
{
//multiple calls for multiple dates within single citation
ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Month @Day, @YYYY$2');
ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Month @Day, @YYYY$2');
ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Month @Day, @YYYY$2');
}
function ohc_delink_ISO_to_dmy()
{
ohc_ISO_to_dmy_in_citations();
ohc_ISO_to_dmy_in_references();
regex(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '$1@Day @Month @Year$2');
ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, '$1{{dts|format=dmy|@YYYY|@MM|@DD}}$2'); //dts template for sortable tables
ohc_regex(/(\{\{dts\|format=)mdy\|/gi, '$1dmy|'); //flip dts template formats
}
function ohc_delink_ISO_to_mdy()
{
ohc_ISO_to_mdy_in_citations();
ohc_ISO_to_mdy_in_references();
regex(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '$1@Month @Day, @Year$2');
ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, '$1{{dts|@YYYY|@MM|@DD}}$2'); //dts template for sortable tables (mdy is default)
ohc_regex(/(\{\{dts\|)format=(?:mdy|dmy|) ?\|/gi, '$1'); //flip dts template formats
}
function ohc_delink_year_in_X()
{
// ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|(@year)\}\}/gi, "$1"); //disabled 3/5/21 discussion at https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Baseball&oldid=1021203365#Links_to_baseball_year_articles_in_infobox?
// ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|@year\|(@year)\}\}/gi, "$1");
ohc_regex(/\[\[@yyyy\sin\s[^|\]]+\|((?:(?:@day |)@month |)@yyyy)\]\]/gi, '$1');
regex(/\[\[(?:\d{4}[-–]\d{2} in English football)\|((?:(?:@Day |)@Month |)@YYYY)\]\]/gi, '$1');
regex(/\[\[\d{4} Major League Baseball season\|(\d{4})(\sseason)?\]\]/gi, '$1$2');
}
// format parameter must be 'dmy' or 'mdy'
function ohc_fix_dts_template(format)
{
// dts - format=dmy in this case (per D12000)
// per {{dts}} doc, remove the obsolete link=off param
regex(/(\{\{dts[^}]*)(?:\|link=off)/gi, '$1');
ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\|\s*format=)(?:dmy|mdy)(\}\})/gi, '$1'+format+'$2');
ohc_regex(/(\{\{dts\s*\|\s*format=)(?:dmy|mdy)(\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\}\})/gi, '$1'+format+'$2');
ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*)(\}\})/gi, '$1|format='+format+'$2');
// stripping – {{dts}} serves no purpose inside date parameters
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*format=(?:dmy|mdy)\s*\|\s*([|}]*)\}\}(?=\s*[|}])/gi, "$1$2");
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*([|}]*)(?:\|\s*format=(?:dmy|mdy)\s*|)\}\}(?=\s*[|}])/gi, "$1$2");
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*format=(?:dmy|mdy)\s*\|\s*@YYYY(\s*\|\s*|-)@MM(\s*\|\s*|-)@DD\s*\}\}(?=\s*[|}])/gi, "$1@YYYY-@MM-@DD ");
ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*@YYYY(\s*\|\s*|-)@MM(\s*\|\s*|-)@DD\s*\|\s*format=(?:dmy|mdy)\s*\}\}(?=\s*[|}])/gi, "$1@YYYY-@MM-@DD ");
}
// format parameter must be 'dmy' or 'mdy'
function ohc_fix_gr_template(format)
{
// GR - date formatting parameter
// per {GR} doc, insert date formatting param
regex(/(\{\{GR\|\d\d?)(?!\|date)/gi, '$1|dateform=' + format);
}
function ohc_dates_to_dmy()
{
regex(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '');
regex(/\|format=mdy/gi, '|format=dmy');
//change start and end templates; vgrelease new v=2 or mdy is default
regex(/(\{\{(?:start date|end date)[^|}]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2');
regex(/(\{\{vgrelease new[^|}]*\|)(?:v=1\||)([A-Z]{2,3}\|)/g, '$1v=2|$2');
ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY"); //spotted at [[Template:Infobox recurring event]]
//change birth and death templates
regex(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start)[^}]*\|)m(f=ye?s?)/gi, '$1d$2'); // substitute df for mf
regex(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start|film ?date|Wayback)[\|\d]+)(\}\})/gi, '$1|df=y$2'); //insert df parameter
regex(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start|film ?date|Wayback)[\|\d]+\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2'); //put date format parameter at the end
regex(/(\{\{(?:start date|end date)\|)df=ye?s?\|((?:1[789]|20)\d{2}\}\})/gi, '$1$2'); //date format parameter not needed – year only
//convert date ranges (md,d,d-dy to d,d,d-dmy; md,d,d-d to d,d,d-dm; md,d,d to d,d,dm)
ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}),?(\/|\s?(?:[-–]|–)\s?|(?:[ _]| )(?:and|&|to|or)(?:[ _]| )+?)@Day,?\s(?:of\s)?(@yyyy\W\D)/gi, "$1$2$3@Day @LMonth $4");
ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}),?(\/|\s?(?:[-–]|–)\s?|(?:[ _]| )(?:and|&|to|or)(?:[ _]| )+?)@Day(?=\W\D)/gi, "$1$2$3@Day @LMonth");
// ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}) @Day(?=\W\D)/gi, "$1$2 @Day @LMonth"); //disabling as unlikely and ungrammatical constructions causing false positives
//'md, md,' to 'dm, dm,'
ohc_regex(/(\D\W)@Month @Day, @Month @Day(?=[,\.]\W\D)/gi, "$1@Day1 @LMonth1, @Day2 @LMonth2");
//convert simple mdy dates to dmy
ohc_regex(/(p(?:g?\.?|age) ?\d+|p(?:p\.?|ages) ?\d+[-–]\d+), @Month((?:\s@day?,?){1,6}) @Day(?=\W\D)/gi, "$1. $2 @Day @LMonth");
ohc_regex(/(\D\W)@Month\s@Day,?\s@Year(\s?(?:AD|BC|CE|BCE)\W\D)/gi, "$1@Day @LMonth @Year$2");
ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Month\s@Day,?\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @Year");
ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Month\s@Day(?=\W\D)/gi, "$1@Day @LMonth");
//Month+day_number " 7th মার্চ" -> "7 মার্চ"
ohc_regex(/(\D\W)@Day\s@Month\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @Year");
ohc_regex(/(\D\W)@Day\s@Month(?=\W\D)/gi, "$1@Day @LMonth");
ohc_regex(/(\D\W)@Month\s@Day,?\s@Year(?=\W\D)/gi, "$1@Day @LMonth @Year");
//dates with embedded nbsp
ohc_regex(/(\D\W)@Month([ _]| )(\d{1,2},(?: | )\d{1,2}(?:\s(?:and|&|to|or)(?:[ _]| ))\d{1,2})(?=[^|\]\w])/gi, '$1$3$2@LMonth ');
ohc_regex(/(\D\W)@Month([ _]| |{{(?:break|nbsp)}})@Day,([ _]| |{{(?:break|nbsp)}})@YYYY(?=[^|\]\w])/gi, '$1@Day$2@Month$3@Year');
//remove comma
ohc_regex(/(\D\W)@Day\s@Month,\s?@Year(?=\W\D)/gi, "$1@Day @LMonth @Year");
// remove "the" from "on the dd month"
ohc_regex(/(on |by )the @Day\s@Month(?=[ ,\)\.])/gi, "$1@Day @LMonth");
//remove space from date range conversion
ohc_regex(/(\D ) @Day(\/|\s?(?:[-–]|–)\s?|(?:[ _]| )(?:and|&|to|or)(?:[ _]| )+?)/gi, "$1@Day$2");
}
function ohc_dates_to_mdy()
{
//change birth and death templates – mf=y is the default; vgrelease new v=2 or mdy is default
regex(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '');
regex(/\|df=y(?:es|)(?=[|}\s])/gi, '');
regex(/(mf=y(?:es|)\|[^}]*\|)(?:mf=y(?:es|)\|)/gi, '$1');
regex(/(\{\{vgrelease new[^|}]*\|)(?:v=2\||)([A-Z]{2,3}\|)/g, '$1$2');
ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY");
//convert date ranges (d,d,d-dmy to md,d,d-dy; d,d,d-dm to md,d,d-d; dm,d,d to md,d,d)
ohc_regex(/(\D\W)@Day((?:, @day){0,5})(\/|\s?(?:[-–]|–)\s?|\s(?:and|&|to|or)\s+?)@Day\s@Month,? @YYYY(?=\W\D)/gi, "$1@LMonth @Day1$2$3@Day2, @YYYY");
ohc_regex(/(\D\W)@Day((?:, @day){0,5})(\/|\s?(?:[-–]|–)\s?|\s(?:and|&|to|or)\s+?)@Day\s@Month(?=\W\D)/gi, "$1@LMonth @Day1$2$3@Day2");
// ohc_regex(/(\D\W)@Day((?:, @day){0,5})\s@Month,? @YYYY(?=\W\D)/gi, "$1@LMonth @Day1$2, @YYYY"); //disabling as unlikely and ungrammatical constructions causing false positives
// ohc_regex(/(\D\W)@Day((?:, @day){0,5})\s@Month(?=\W\D)/gi, "$1@LMonth @Day1$2"); //disabling as unlikely and ungrammatical constructions causing false positives
//'dm, dm,' to 'md, md,'
ohc_regex(/(\D\W)@Day @Month, @Day @Month(?=[,\.]?\W\D)/gi, "$1@LMonth1 @Day1, @LMonth2 @Day2");
//convert simple dmy dates to mdy
ohc_regex(/(p(?:g?\.?|age) ?\d+|p(?:p\.?|ages) ?\d+[-–]\d+), @Month((?:\s@day?,?){1,6}) @Day(?=\W\D)/gi, "$1. @LMonth $2 @Day");
ohc_regex(/(\D\W)@Day(\s| )@Month,?(\s| )@Year(?=\W\D)/gi, "$1@LMonth$2@Day,$3@Year");
ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Day[ ]+@Month,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @Year");
ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Day[ ]+@Month(?=\W\D)/gi, "$1@LMonth @Day");
//Month+day_number "মার্চ 7th" -> "মার্চ 7"
ohc_regex(/(\D\W)@Month\s@Day@th?,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @YYYY");
ohc_regex(/(\D\W)@Day@th?(\s| )@Month(\s| )@YYYY(?=\W\D)/gi, "$1@LMonth$2@Day,$3@YYYY");
ohc_regex(/(\D\W)@Month(\s| )@Day(?=\W\D)/gi, "$1@LMonth$2@Day");
ohc_regex(/(\D\W)@Day@th?(\s| )@Month([,\.])(?=\W\D)/gi, "$1@LMonth$2@Day$3");
//add comma where missing
ohc_regex(/(\D\W)@Month\s@Day,?\s@YYYY,?(?=\s\w)/gi, "$1@LMonth @Day, @YYYY,");
//rem superfluous comma where applicable
ohc_regex(/(\D[^\w\/])@Month\s@ZD,,(?=\W\D|\b)/gi, "$1@LMonth @Day,");
}
function ohc_fix_dmy_redundancies()
{
//month-range redundancies (repeating month names)
ohc_regex(/([\D]@dd)@th? @Month[ ]{1,2}((?:to|and|-|–)[ ]{1,2}@dd)@th? @Month/, "$1 $2 @LMonth", function(d1, d2) {
if (d1.m == d2.m) return true;
return false;
});
}
//not currently used
function ohc_fix_mdy_redundancies()
{
//month-range redundancies (repeating month names)
ohc_regex(/(@Month[ ]{1,2}@dd)@th? (to|and|-|–)[ ]{1,2}@Month[ ]{1,2}@DD@th?/, "$1 $2 @LDay", function(d1, d2) {
if (d1.m == d2.m) return true;
return false;
});
}
function ohc_expand_ref_dates()
{
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @YYYY(?=\s*[|}])/gi, "$1@FullMonth @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day @FullMonth @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@FullMonth @Day, @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|–) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=\s*[|}])/gi, "$1$2 @FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day(, (?:19|20)\d\d) ?(?:-|–|–) ?@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Month,? @YYYY(?=\s*[|}])/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)((?:19|20)\d\d) ?(?:-|–|–) ?@Month @YYYY(?=\s*[|}])/gi, "$1@$2 – @FullMonth @YYYY");
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|–) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2");
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month @Day(, (?:19|20)\d\d) ?(?:-|–|–) ?@Month @Day, @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY");
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Day @Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY");
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Month,? @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY");
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))((?:19|20)\d\d) ?(?:-|–|–) ?@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 – @FullMonth @YYYY");
}
function ohc_expand_all_dates()
{
ohc_regex(/([^-\w/])@Month @YYYY(?=[^-\w/])/gi, '$1@FullMonth @YYYY');
ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, '$1@Day @FullMonth @YYYY');
ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, '$1@FullMonth @Day, @YYYY');
ohc_regex(/([^-\w/])((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|–) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=[^-\w/])/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2");
ohc_regex(/([^-\w/])@Month @Day(, (?:19|20)\d\d) ?(?:-|–|–) ?@Month @Day, @YYYY(?=[^-\w/])/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY");
ohc_regex(/([^-\w/])@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Day @Month @YYYY(?=[^-\w/])/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY");
ohc_regex(/([^-\w/])@Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Month,? @YYYY(?=[^-\w/])/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY");
ohc_regex(/([^-\w/])((?:19|20)\d\d) ?(?:-|–|–) ?@Month @YYYY(?=[^-\w/])/gi, "$1$2 – @FullMonth @YYYY");
ohc_regex(/([ ]\(|\|\s*)@Day @Month @YYYY(?=\)\W|\s*[|\n])/gi, "$1@Day @FullMonth @YYYY");
ohc_regex(/([ ]\(|\|\s*)@Month @Day,? @YYYY(?=\)\W|\s*[|\n])/gi, "$1@FullMonth @Day, @YYYY");
ohc_regex(/([ ]\((?:c\. |))@Month @YYYY ?(?:-|–| ) ?@Day @Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 @YYYY1 – @Day @FullMonth2 @YYYY2");
ohc_regex(/([ ]\((?:c\. |))@Month @YYYY ?(?:-|–| ) ?@Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 @YYYY1 – @FullMonth2 @YYYY2");
ohc_regex(/([ ]\((?:c\. |))@YYYY ?(?:-|–| ) ?@Month @YYYY(?=\)\W)/gi, "$1@YYYY1 – @FullMonth @YYYY2");
ohc_regex(/([ ]\((?:c\. |))@Month ?(?:-|–| ) ?@Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 – @FullMonth2 @YYYY");
ohc_regex(/([ ]\((?:c\. |))@Month @YYYY(?=\)\W)/gi, "$1@FullMonth @YYYY");
}
function ohc_abbrev_ref_dates()
{
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day @Mon @YYYY");
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))([12]?\d|30|31) (জানুয়ারি|ফেব্রুয়ারি|মার্চ|এপ্রিল|মে|জুন|জুলাই|আগষ্ট|অক্টোবর|Oct|নভেম্বর|ডিসেম্বর)(?:r?uary|ch|il|[ey]|ust|(?:t?em|o)ber)( (?:19\d|20[01])\d)(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 $3$4");
ohc_regex(/([ ]\()@Day @Month @YYYY([^-\w\/])/gi, "$1@Day @Mon @YYYY$2");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@Mon @Day, @YYYY");
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))(জানুয়ারি|ফেব্রুয়ারি|মার্চ|এপ্রিল|মে|জুন|জুলাই|আগষ্ট|অক্টোবর|Oct|নভেম্বর|ডিসেম্বর)(?:r?uary|ch|il|[ey]|ust|(?:t?em|o)ber) ([12]?\d|30|31),( (?:19\d|20[01])\d)(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 $3,$4");
ohc_regex(/([^-\w\/])@Month @Day, @YYYY([^-\w\/])/gi, '$1@Mon @Day, @YYYY$2');
}
//not currently used
function ohc_abbrev_all_dates()
{
ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, '$1@Day @Mon @YYYY');
ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, '$1@Mon @Day, @YYYY');
}
//not currently used
function ohc_dmy_publication_dates()
{
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day,? @YYYY/gi, "$1@Day @Month @YYYY"); // conversion of dates in references outside of the protection loop (eg for quotations etc.)
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@Day @Month @YYYY");
//replace ISO dates (within parentheses) only within refs
ohc_regex(/(<ref[^>]*>[^<]+?)([ ]\()@YYYY-@MM-@DD(\))(\W[^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3$4");
}
function ohc_mdy_publication_dates()
{
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month @YYYY/gi, "$1@Month @Day, @YYYY"); // conversion of dates in references outside of the protection loop (eg for quotations etc.)
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@Month @Day, @YYYY");
//replace ISO dates (within parentheses) only within refs
ohc_regex(/(<ref[^>]*>[^<]+?)([ ]\()@YYYY-@MM-@DD(\))(\W[^<]*?<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3$4");
}
function ohc_Bigendian_ref_dates() {
// Add a tag to the summary box
regex(/(\{\{use (?:mdy|dmy) dates)(?:\|cs1-dates=\w{1,2}|)(\|[^\}\|]+\}\})/gi, '$1|cs1-dates=y$2');
}
/** ------------------------------------------------------------------------ **/
/// EDIT SUMMARIES & USE DMY TEMPLATE
// this function modified 2019-03-27 from [[Special:Permalink/846525463]]
// format parameter must be 'dmy' or 'mdy'
function ohc_use_dates_template(format)
{
var txt = document.editform.wpTextbox1;
// current month-year
var currentDate = new Date();
var currmonth = currentDate.getMonth();
var curryear = currentDate.getFullYear();
var myMonths = ["জানুয়ারি", "ফেব্রুয়ারি", "মার্চ", "এপ্রিল", "মে", "জুন", "জুলাই", "আগষ্ট", "সেপ্টেম্বর", "অক্টোবর", "নভেম্বর", "ডিসেম্বর"];
var curryyyymm = myMonths[currmonth] + ' ' + curryear;
// step 1: normalize redirect template names to canonical template names 'Use dmy dates' or 'Use mdy dates' according to 'format' argument
// rename redirects 'dmy', 'mdy', 'usedmydates', 'usemdydates' ('usedmydates' and 'usemdydates' are not currently listed as redirects but might be encountered?)
regex(/\{\{ *(?:use(?:dmy|mdy)dates|dmy|mdy) *([\|\}])/gi, '{{Use ' + format + ' dates$1');
// rename redirects 'usedmy', 'usemdy', 'use dmy', 'use mdy' to canonical form
regex(/\{\{ *use *(?:dmy|mdy) *([\|\}])/gi, '{{Use ' + format + ' dates$1');
// strip leading / trailing whitespace from 'use xxx dates'
regex(/\{\{ *use (?:dmy|mdy) dates *([\|\}])/gi, '{{Use ' + format + ' dates$1');
// step 2: look for a canonical template name (the above might not have had anthing to work on) ; if found continue, write new template else
var rxpdd = new RegExp("{{Use " + format + " dates", "gi"); // here we search for canonical form {{use xxx dates}} that has current date
var dflagfound = txt.value.search(rxpdd);
if (dflagfound === -1) {
txt.value = '{{Use ' + format + ' dates|date=' + curryyyymm + '}}\r\n' + txt.value; // not found so insert new template at top of wikitext
return; // and done
}
// step 3: rewrite existing canonical templates; add or refresh |date= to current month year; preserve |cs1-dates= as is
regex(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|]*\| *cs1\-dates *= *([^\|\}]*?) *\}\}/gi, '$1|date=' + curryyyymm + '|cs1-dates=$2}}'); // with |date= followed by |cs1-dates=
regex(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) *\| *date *=[^\}]*\}\}/gi, '$1|date=' + curryyyymm + '|cs1-dates=$2}}'); // with |cs1-dates= followed by |date=
regex(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|\}]*\}\}/gi, '$1|date=' + curryyyymm + '}}'); // with |date=
regex(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) \}\}/gi, '$1|date=' + curryyyymm + '|cs1-dates=$2}}'); // with |cs1-dates
regex(/(\{\{use (?:dmy|mdy) dates)\}\}/gi, '$1|date=' + curryyyymm + '}}'); // no parameters so add |date=curryyyymm
regex(/(\{\{[\t_ ]*use[\t_ ]+(?:dmy|mdy)[\t_ ]+dates[^{}]*\}\})([\r\n\t ]*)(\{\{[\t ]*short description[^{}]*\}\})/gi, '$3$2$1'); // repositioning "short description" template at the top
}
/** ------------------------------------------------------------------------ **/
/// DATE PROTECTION
var linkmap = [];
function ohc_protect_dates()
{
// protects dates within links, quotes, etc
// the sensitive part is stored and replaced with a unique identifier,
// which is later replaced with the stored part.
var protect_function = function(s, begin, replace, end) {
linkmap.push(replace);
return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
};
//\|x=
regex(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function);
regex(/(<!--)([^<\{\}]*?)(-->)/gi, protect_function);
regex(/(<math>)([\s\S]*?)(<\/math>)/gi, protect_function);
regex(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function);
regex(/(<ref)([^>]+)(>)/gi, protect_function);
regex(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function);
regex(/(\{(?:See ?also|Main))(\|[^}]*)(\})/gi, protect_function);
regex(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{(?:harvnb|r|wikisource)\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{(?:Canadian federal by-election))([^}]+)(\}\})/gi, protect_function);
regex(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
regex(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function);
// regex(/(https?:|ftp:)([^\s\]]*)([\s\]])/gi, protect_function);
regex(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function);
regex(/(<noinclude>)([\s\S]*?)(<\/noinclude>)/gi, protect_function);
regex(/(<gallery)([\s\S]*?)(<\/gallery>)/gi, protect_function);
regex(/(<poem>)([\s\S]*?)(<\/poem>)/gi, protect_function);
regex(/(\{[^\{]{0,6}(?:quot[^|]{1,7}\s?|sic)\|)([^}]+)(\})/gi, protect_function);
regex(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|image[ _]file|img|map\d|pic)\s*=)([^|}]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|(?:trans-?|)title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|(?:trans-?|)title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:[xy])\s*=)(\s*[^\|]+\s*)(\|)/gi, protect_function);
regex(/(\{\{navsource\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{(?:singlechart)\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{(?:defaultsort|graph):)([^}]+)(\})/gi, protect_function);
regex(/(["“])([^"”\n]*)(["”])/gi, protect_function);
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function);
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function);
regex(/(\[\[)(4AD)(\]\]|\|)/gi, protect_function);
//retraining redirects containing a date
regex(/(\[\[)(?:সেপ্টেম্বর 3 Society)(\]\]|\|)/gi, '$1Jiusan Society$2');
regex(/(\[\[)(?:জুন 4th incident)(\]\]|\|)/gi, '$1Tiananmen Square protests of 1989$2');
regex(/(\[\[)(?:5@th? অক্টোবর (?:\(Serbia\)|overthrow))(\]\]|\|)/gi, '$1Overthrow of Slobodan Milošević$2');
regex(/(\[\[)(?:অক্টোবর 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi, '$1Overthrow of Slobodan Milošević$2');
//protect alternate meanings of 'মে' and 'মার্চ' (note: not case insensitive)
// ohc_regex(/([^\w])(@day,?\s{0,3}মে)([^\w][^\d])/g, protect_function); //disabled 26 মে – not case senstitve: false negatives in converting dates in মে
ohc_regex(/([^\w])(মার্চ\s@day)(\s(?:mile|kilomet|met))/g, protect_function);
//protect all links containing a date and some text
ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@day[^\]\|\n]+?@fullmonth[^\]\|\n]*)(\]\]|\|)/gi, protect_function);
ohc_regex(/(\[\[)([^\]\|\n]*?@day[^\]\|\n]+?@fullmonth(?:,? @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function);
ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@fullmonth[^\]\|\n]+?@day[^\]\|\n]*)(\|)/gi, protect_function);
ohc_regex(/(\[\[)([^\]\|\n]*?@fullmonth[^\]\|\n]+?@day(?:, @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function);
//protects certain dates
regex(/(\[\[)(4AD)([\s\S])/gi, protect_function);
regex(/([\s\S])(মার্চ (?:8|14) Alliance)([\s\S])/gi, protect_function);
regex(/([\s\S])(23rd মার্চ 1931: Shaheed)([\s\S])/gi, protect_function);
regex(/([\s\S])(Long মার্চ [1-7])([\s\S])/gi, protect_function);
regex(/([\s\S])(National সেপ্টেম্বর 11 Memorial & Museum)([\s\S])/gi, protect_function);
regex(/([\s\S])(Queen Elizabeth II সেপ্টেম্বর 11th Garden)([\s\S])/gi, protect_function);
regex(/([\s\S])(Bombay মার্চ 12)([\s\S])/gi, protect_function);
regex(/([\s\S])(movement 2 জুন)([\s\S])/gi, protect_function);
regex(/([\s\S])(6th\sof অক্টোবর City)([\s\S])/gi, protect_function);
regex(/([\s\S])(Party Workers' Liberation Front 30th of মে)([\s\S])/gi, protect_function);
regex(/([\s\S])(4th\sof আগষ্ট regime)([\s\S])/gi, protect_function);
regex(/([\s\S])(19th\sof এপ্রিল movement)([\s\S])/gi, protect_function);
regex(/([\s\S])(জুন 4th (?:incident|museum))([\s\S])/gi, protect_function);
regex(/([\s\S])(The Battle Of Marston Moor \(জুলাই 2nd,? 1644\))([\s\S])/gi, protect_function);
regex(/([\s\S])(Night of জানুয়ারি 16th)([\s\S])/gi, protect_function);
regex(/([\s\S])(Observance of 5th নভেম্বর Act)([\s\S])/gi, protect_function);
regex(/(\[\[)(13 মে incident)(\|)/gi, protect_function);
regex(/(\'\'\')(22nd\sof মে)(\'\'\')/gi, protect_function);
regex(/(\[\[)(22nd\sof মে \(film\))([|\]\'])/gi, protect_function);
regex(/(\[\[)(জুলাই 12, 2007, Baghdad airstrike)(\|)/gi, protect_function);
regex(/(\[\[)(নভেম্বর 1828)(\]\])/gi, protect_function);
regex(/(.)(4th\sof জুলাই)(.)/gi, protect_function);
regex(/(\[\[)((?:2300|2000)\s?AD)(\]\])/gi, protect_function);
regex(/(\[\[)(29 ফেব্রুয়ারি)(\]\])/gi, protect_function);
regex(/(\[\[)(ফেব্রুয়ারি 29)(\]\])/gi, protect_function);
// works names
// regex(/(.)(protect string)(.)/gi, protect_function);
regex(/(.)(11\/22\/63)(.)/gi, protect_function);
regex(/(.)(1\.1\.1994)(.)/gi, protect_function);
regex(/([\s\S])(2\.13\.61)([\s\S])/gi, protect_function);
// regex(/(.)(4th of জুলাই, Asbury)(.)/gi, protect_function); //protected above globally
regex(/(.)(26 অক্টোবর 1993)(.)/gi, protect_function);
regex(/(\[\[|\'\')(জুন 1, 1974)(.)/gi, protect_function);
regex(/(\[\[|\'\')(জুলাই 15, 1972)(.)/gi, protect_function);
regex(/(\[\[|\'\')(আগষ্ট 1914)(.)/gi, protect_function);
ohc_regex(/(\[\[|\'\')(@fullmonth @dd@th? \((?:@yyyy |)film\)(?:\|@fullmonth @dd@th?|))([\s\S])/gi, protect_function);
ohc_regex(/(\[\[|\'\')(@dd@th? @fullmonth \((?:@yyyy |)film\)(?:\|@dd@th? @fullmonth|))([\s\S])/gi, protect_function);
// regex(/(Les Bains Douches 18)( ডিসেম্বর 1979)(.)/gi, protect_function);
regex(/(আগষ্ট)( 7, 4:15)(.)/gi, protect_function);
regex(/(In Concert, Zürich, অক্টোবর)( 28, 1979)(.)/gi, protect_function);
regex(/(CBGB OMFUG Masters: Live জুন)( 29, 2001)(.)/gi, protect_function);
ohc_regex(/(Live at [\w ]*,? [1-3]\d)( @fullmonth)(.)/gi, protect_function);
ohc_regex(/(Live at [\w ]*,? @fullmonth)( @dd)(.)/gi, protect_function);
ohc_regex(/(Bootmoon Series: [\w ]*[-–] @fullmonth)( @day, @YYYY)(.)/gi, protect_function);
// expressions and grammatical strings including modal "মে"
regex(/(\W)((?:\d{1,3}) মে)((?: have(?: \w+|)|) be)/g, protect_function);
regex(/(\W)((?:\d{3}|3[2-9]|[4-9]\d)\/\d ডিসেম্বর(?:l\.?|))(\W)/gi, protect_function);
regex(/(\W)((?:\d{2,3})\/\d ডিসেম্বর(?:l\.?|))( \(\d\d? overs)/gi, protect_function);
}
/** ------------------------------------------------------------------------ **/
/// DATE PROTECTION FOR ALL REF SECTION
var linkmap = [];
function ohc_protect_dates_ref()
{
// protects dates within links, quotes, etc
// the sensitive part is stored and replaced with a unique identifier,
// which is later replaced with the stored part.
var protect_function = function (s, begin, replace, end) {
linkmap.push(replace);
return begin + "⍌" + (linkmap.length - 1) + "⍍" + end;
};
regex(/(<ref\s?(?:>|name=[^>]+))([^<]+)(<\/ref>)/gi, protect_function);
regex(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function);
regex(/(<math>)([\s\S]*?)(<\/math>)/gi, protect_function);
regex(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function);
regex(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function);
regex(/(\{(?:See ?also|Main))(\|[^}]*)(\})/gi, protect_function);
regex(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{(?:harvnb|wikisource)\|)([^}]+)(\})/gi, protect_function);
regex(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
regex(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function);
//regex(/(https?:|ftp:)([^\s\]]*)([\s\]])/gi, protect_function);
regex(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function);
regex(/(\{[^\{]{0,6}(?:quot[^|]{1,7}\s?|sic)\|)([^}]+)(\})/gi, protect_function);
regex(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|image[ _]file|img|pic)\s*=)([^|}]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([|}])/gi, protect_function);
regex(/(\{\{navsource\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{singlechart\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{defaultsort:)([^}]+)(\})/gi, protect_function);
regex(/([\s\(>]")([^"\n]*)(")/gi, protect_function);
regex(/([\s\(>]“)([^”\n]*)(”)/gi, protect_function);
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function);
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function);
//retraining redirects containing a date
regex(/(\[\[)(?:সেপ্টেম্বর 3 Society)(\]\]|\|)/gi, '$1Jiusan Society$2');
regex(/(\[\[)(?:জুন 4th incident)(\]\]|\|)/gi, '$1Tiananmen Square protests of 1989$2');
ohc_regex(/(\[\[)(?:5@th? অক্টোবর (?:\(Serbia\)|overthrow))(\]\]|\|)/gi, '$1Overthrow of Slobodan Milošević$2');
ohc_regex(/(\[\[)(?:অক্টোবর 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi, '$1Overthrow of Slobodan Milošević$2');
//protect alternate meanings of 'মে' and 'মার্চ' (note: not case insensitive)
ohc_regex(/([^\w])(@day,?\s{0,3}মে)([^\w][^\d])/g, protect_function);
ohc_regex(/([^\w])(মার্চ\s@day)(\s(?:mile|kilomet|met))/g, protect_function);
//protect all links containing a date and some text
ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@day[^\]\|\n]+?@fullmonth[^\]\|\n]*)(\]\]|\|)/gi, protect_function);
ohc_regex(/(\[\[)([^\]\|\n]*?@day[^\]\|\n]+?@fullmonth(?:,? @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function);
ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@fullmonth[^\]\|\n]+?@day[^\]\|\n]*)(\|)/gi, protect_function);
ohc_regex(/(\[\[)([^\]\|\n]*?@fullmonth[^\]\|\n]+?@day(?:, @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function);
//protects certain dates
regex(/(\[\[)(4AD)([\s\S])/gi, protect_function);
regex(/([\s\S])(মার্চ (?:8|14) Alliance)([\s\S])/gi, protect_function);
regex(/([\s\S])(23rd মার্চ 1931: Shaheed)([\s\S])/gi, protect_function);
regex(/([\s\S])(Long মার্চ [1-7])([\s\S])/gi, protect_function);
regex(/([\s\S])(Bombay মার্চ 12)([\s\S])/gi, protect_function);
regex(/([\s\S])(movement 2 জুন)([\s\S])/gi, protect_function);
regex(/([\s\S])(6th\sof অক্টোবর City)([\s\S])/gi, protect_function);
regex(/([\s\S])(Party Workers' Liberation Front 30th of মে)([\s\S])/gi, protect_function);
regex(/([\s\S])(4th\sof আগষ্ট regime)([\s\S])/gi, protect_function);
regex(/([\s\S])(19th\sof এপ্রিল movement)([\s\S])/gi, protect_function);
regex(/([\s\S])(জুন 4th incident)([\s\S])/gi, protect_function);
regex(/([\s\S])(The Battle Of Marston Moor \(জুলাই 2nd,? 1644\))([\s\S])/gi, protect_function);
regex(/([\s\S])(Night of জানুয়ারি 16th)([\s\S])/gi, protect_function);
regex(/([\s\S])(Observance of 5th নভেম্বর Act)([\s\S])/gi, protect_function);
regex(/(\[\[)(13 মে incident)(\|)/gi, protect_function);
regex(/(\'\'\')(22nd\sof মে)(\'\'\')/gi, protect_function);
regex(/(\[\[)(22nd\sof মে \(film\))([|\]\'])/gi, protect_function);
regex(/(\[\[)(জুলাই 12, 2007, Baghdad airstrike)(\|)/gi, protect_function);
regex(/(\[\[)(নভেম্বর 1828)(\]\])/gi, protect_function);
regex(/(.)(4th\sof জুলাই)(.)/gi, protect_function);
regex(/(\[\[)((?:2300|2000)\s?AD)(\]\])/gi, protect_function);
regex(/(\[\[)(29 ফেব্রুয়ারি)(\]\])/gi, protect_function);
regex(/(\[\[)(ফেব্রুয়ারি 29)(\]\])/gi, protect_function);
// works names
//regex(/(.)(protect string)(.)/gi, protect_function);
regex(/(.)(11\/22\/63)(.)/gi, protect_function);
regex(/(.)(1\.1\.1994)(.)/gi, protect_function);
regex(/([\s\S])(2\.13\.61)([\s\S])/gi, protect_function);
//regex(/(.)(4th of জুলাই, Asbury)(.)/gi, protect_function); //protected above globally
regex(/(.)(26 অক্টোবর 1993)(.)/gi, protect_function);
regex(/(\[\[|\'\')(জুন 1, 1974)(.)/gi, protect_function);
regex(/(\[\[|\'\')(জুলাই 15, 1972)(.)/gi, protect_function);
regex(/(\[\[|\'\')(আগষ্ট 1914)(.)/gi, protect_function);
ohc_regex(/(\[\[|\'\')(@fullmonth @dd@th? \((?:@yyyy |)film\)(?:\|@fullmonth @dd@th?|))([\s\S])/gi, protect_function);
ohc_regex(/(\[\[|\'\')(@dd@th? @fullmonth \((?:@yyyy |)film\)(?:\|@dd@th? @fullmonth|))([\s\S])/gi, protect_function);
//regex(/(Les Bains Douches 18)( ডিসেম্বর 1979)(.)/gi, protect_function);
regex(/(আগষ্ট)( 7, 4:15)(.)/gi, protect_function);
regex(/(In Concert, Zürich, অক্টোবর)( 28, 1979)(.)/gi, protect_function);
regex(/(CBGB OMFUG Masters: Live জুন)( 29, 2001)(.)/gi, protect_function);
ohc_regex(/(Live at [\w ]*,? [1-3]\d)( @fullmonth)(.)/gi, protect_function);
ohc_regex(/(Live at [\w ]*,? @fullmonth)( @dd)(.)/gi, protect_function);
ohc_regex(/(Bootmoon Series: [\w ]*[-–] @fullmonth)( @day, @YYYY)(.)/gi, protect_function);
regex(/(\W)((?:\d{3}|3[2-9]|[4-9]\d)\/\d ডিসেম্বর(?:l\.?|))(\W)/gi, protect_function);
regex(/(\W)((?:\d{2,3})\/\d ডিসেম্বর(?:l\.?|))( \(\d\d? overs)/gi, protect_function);
}
/** ------------------------------------------------------------------------ **/
/// DATE PROTECTION FOR SLASH modules
var linkmap = [];
function ohc_protect_dates_slash()
{
// protects dates within links, quotes, etc
// the sensitive part is stored and replaced with a unique identifier,
// which is later replaced with the stored part.
var protect_function = function (s, begin, replace, end) {
linkmap.push(replace);
return begin + "⍌" + (linkmap.length - 1) + "⍍" + end;
};
regex(/(<ref\s?(?:>|name=[^>]+))([^<]+)(<\/ref>)/gi, protect_function);
regex(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function);
regex(/(<math>)([\s\S]*?)(<\/math>)/gi, protect_function);
regex(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function);
regex(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function);
regex(/(\{(?:See ?also|Main))(\|[^}]*)(\})/gi, protect_function);
regex(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{(?:harvnb|wikisource)\|)([^}]+)(\})/gi, protect_function);
regex(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
regex(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function);
//regex(/(https?:|ftp:)([^\s\]]*)([\s\]])/gi, protect_function);
regex(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function);
regex(/(\{[^\{]{0,6}(?:quot[^|]{1,7}\s?|sic)\|)([^}]+)(\})/gi, protect_function);
regex(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|image[ _]file|img|pic)\s*=)([^|}]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
regex(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([|}])/gi, protect_function);
regex(/(\{\{navsource\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{singlechart\|)([^}]+)(\})/gi, protect_function);
regex(/(\{\{defaultsort:)([^}]+)(\})/gi, protect_function);
regex(/([\s\(>]")([^"\n]*)(")/gi, protect_function);
regex(/([\s\(>]“)([^”\n]*)(”)/gi, protect_function);
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function);
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function);
}
function ohc_unprotect_dates()
{
//unprotect all dates
regex(/[♫]/g, '');
regex(/⍌([0-9]+)⍍/g, function (x, n) {
var res = linkmap[n];
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
var res = linkmap[n];
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
var res = linkmap[n];
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
return linkmap[n];
});
return res;
});
return res;
});
return res;
});
}
function ohc_MOSNUM_edit_summary()
{
//Add a tag to the summary box
setoptions(minor = 'true');
setreason('date formats per [[MOS:DATEFORMAT]] by [[WP:MOSNUMscript|script]]', 'append');
doaction('diff');
}
function ohc_bigendien_edit_summary()
{
//Add a tag to the summary box
setoptions(minor = 'true');
setreason('ymd ref dates', 'append');
doaction('diff');
}
function ohc_expand_edit_summary()
{
//Add a tag to the summary box
setoptions(minor = 'true');
setreason('expand month names', 'append');
doaction('diff');
}
function ohc_slash_edit_summary()
{
//Add a tag to the summary box
setoptions(minor = 'true');
setreason('resolved slash dates', 'append');
doaction('diff');
}
function ohc_abbrev_edit_summary()
{
//Add a tag to the summary box
setoptions(minor = 'true');
setreason('abbrev month names', 'append');
doaction('diff');
}
/** ------------------------------------------------------------------------ **/
/// CUSTOMIZATION POINTS
function ohc_customize_all_to_dmy() {
}
function ohc_customize_all_to_mdy() {
}
function ohc_customize_body_to_dmy() {
}
function ohc_customize_body_to_mdy() {
}
function ohc_customize_ISO_to_dmy() {
}
function ohc_customize_ISO_to_mdy() {
}
/** ------------------------------------------------------------------------ **/
function ohc_body_dates_to_dmy()
{
ohc_use_dates_template('dmy');
ohc_fix_common_errors();
ohc_fix_dts_template('dmy');
ohc_fix_gr_template('dmy');
ohc_dates_to_dmy();
ohc_remove_leading_zeroes();
ohc_fix_dmy_redundancies();
}
function ohc_body_dates_to_mdy()
{
ohc_use_dates_template('mdy');
ohc_fix_common_errors();
ohc_fix_dts_template('mdy');
ohc_fix_gr_template('mdy');
ohc_dates_to_mdy();
ohc_remove_leading_zeroes();
ohc_fix_mdy_redundancies();
}
/** ------------------------------------------------------------------------ **/
function ohc_all_to_dmy_driver(e)
{
e.preventDefault();
ohc_delink_dates();
ohc_protect_dates();
ohc_fix_unambiguous_dates();
ohc_body_dates_to_dmy();
ohc_delink_ISO_to_dmy();
ohc_delink_year_in_X();
ohc_customize_all_to_dmy();
ohc_ISO_to_dmy_in_citations();
ohc_unprotect_dates();
ohc_MOSNUM_edit_summary();
}
function ohc_all_to_mdy_driver(e)
{
e.preventDefault();
ohc_delink_dates();
ohc_protect_dates();
ohc_fix_unambiguous_dates();
ohc_body_dates_to_mdy();
ohc_delink_ISO_to_mdy();
ohc_delink_year_in_X();
ohc_customize_all_to_mdy();
ohc_ISO_to_mdy_in_citations();
ohc_unprotect_dates();
ohc_MOSNUM_edit_summary();
}
function ohc_dmy_publication_dates_driver(e)
{
e.preventDefault();
// ohc_delink_dates();
ohc_protect_dates();
ohc_body_dates_to_dmy();
ohc_customize_body_to_dmy();
ohc_dmy_publication_dates();
ohc_unprotect_dates();
ohc_MOSNUM_edit_summary();
}
function ohc_mdy_publication_dates_driver(e)
{
e.preventDefault();
// ohc_delink_dates();
ohc_protect_dates();
ohc_body_dates_to_mdy();
ohc_customize_body_to_mdy();
ohc_mdy_publication_dates();
ohc_unprotect_dates();
ohc_MOSNUM_edit_summary();
}
function ohc_body_to_dmy_driver(e)
{
e.preventDefault();
// ohc_delink_dates();
ohc_protect_dates_ref();
ohc_body_dates_to_dmy();
ohc_customize_body_to_dmy();
ohc_unprotect_dates();
ohc_MOSNUM_edit_summary();
}
function ohc_body_to_mdy_driver(e)
{
e.preventDefault();
// ohc_delink_dates();
ohc_protect_dates_ref();
ohc_body_dates_to_mdy();
ohc_customize_body_to_mdy();
ohc_unprotect_dates();
ohc_MOSNUM_edit_summary();
}
function ohc_ISO_to_dmy_driver(e)
{
e.preventDefault();
ohc_protect_dates();
ohc_delink_ISO_to_dmy();
ohc_customize_ISO_to_dmy();
ohc_unprotect_dates();
// ohc_MOSNUM_edit_summary();
}
function ohc_ISO_to_mdy_driver(e) {
e.preventDefault();
ohc_protect_dates();
ohc_delink_ISO_to_mdy();
ohc_customize_ISO_to_mdy();
ohc_unprotect_dates();
// ohc_MOSNUM_edit_summary();
}
function ohc_delink_year_in_X_driver(e)
{
e.preventDefault();
ohc_delink_year_in_X();
}
function ohc_expand_ref_dates_driver(e) {
e.preventDefault();
ohc_expand_ref_dates();
ohc_protect_dates();
ohc_unprotect_dates();
ohc_expand_edit_summary();
}
function ohc_expand_all_dates_driver(e)
{
e.preventDefault();
ohc_expand_ref_dates();
ohc_protect_dates();
ohc_expand_all_dates();
ohc_unprotect_dates();
ohc_expand_edit_summary();
}
function ohc_abbrev_ref_dates_driver(e)
{
e.preventDefault();
ohc_protect_dates();
ohc_abbrev_ref_dates();
ohc_unprotect_dates();
ohc_slash_edit_summary();
}
function ohc_UK_slash_dates_driver(e)
{
e.preventDefault();
ohc_expand_ref_dates();
ohc_protect_dates_slash();
ohc_UK_slash_dates_to_dmy();
ohc_unprotect_dates();
ohc_slash_edit_summary();
}
function ohc_US_slash_dates_driver(e)
{
e.preventDefault();
ohc_expand_ref_dates();
ohc_protect_dates_slash();
ohc_US_slash_dates_to_mdy();
ohc_unprotect_dates();
ohc_expand_edit_summary();
}
// </pre>
//সংশ্লিষ্ট পাতা ত্যাগ না করেই অন্য পাতা থেকে পুনর্নির্দেশ করা যাবে।
//<nowiki>
( function () {
var redir = $(mw.util.addPortletLink('p-tb','#','পুনর্নির্দেশক','পুনর্নির্দেশ তৈরিকারী','পুনর্নির্দেশ তৈরিকারী','','#pt-mytalk'));
$( redir ).click( function() {
var redirec = prompt("যে পাতা থেকে এই পাতায় পুনর্নির্দেশ করতে চান তার নাম লিখুন:", "");
if (redirec === null || redirec === "") {
alert( 'আপনি কোনও নাম প্রবেশ করান নি। দয়া করে আবার চেষ্টা করুন।' );
} else {
var params = {
action: 'edit',
title: redirec ,
createonly: 1,
prependtext: '#পুনর্নির্দেশ [[' + mw.config.get("wgPageName") + ']]',
appendtext: " \n" + '{{একটি পুনর্নির্দেশ}}',
summary: '[[' + mw.config.get("wgPageName") + ']] পাতায় পুনর্নির্দেশ করা হল' ,
format: 'json'
};
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
alert( 'সফলভাবে ' + redirec + ' পাতা থেকে একটি পুনর্নির্দেশ তৈরি করা হয়েছে!' );
});
}
}
);
}() );
//</nowiki>
//<nowiki>
( function () {
var talkp = $(mw.util.addPortletLink('p-tb','#','স্বাগত জানান','স্বাগত জানান','স্বাগত জানান','','#pt-mytalk'));
$( talkp ).click( function() {
var talk = prompt("কোন ধরনের স্বাগত বার্তা যুক্ত করতে চান এমন টেমপ্লেটটি লিখুন {{Subst:}} সাথে, অন্যথায় পূর্বনির্ধারিত {{Subst:স্বাগতম}} যুক্ত হবে:", "");
if (talk === null || talk === "") {
var params1 = {
action: 'edit',
title: 'User talk:' + mw.config.get("wgRelevantUserName"),
prependtext: '{{Subst:স্বাগতম}}'
,
summary: 'ভারতপিডিয়ায় স্বাগতম!',
format: 'json'
};
api = new mw.Api();
api.postWithToken( 'csrf', params1 ).done( function ( data ) {
alert( 'সফলভাবে স্বাগত জানানো হয়েছে!' );
} );
} else {
var params = {
action: 'edit',
title: 'User talk:' + mw.config.get("wgRelevantUserName"),
prependtext: talk
,
summary: 'ভারতপিডিয়ায় স্বাগত!',
format: 'json'
};
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
alert( 'সফলভাবে স্বাগত জানানো হয়েছে!' );
} );
}
}
);
}() );
//</nowiki>
//<nowiki>
console.time('mobileUndo');
$.when(mw.loader.using(['mediawiki.util', 'mediawiki.api', 'oojs-ui-windows', 'oojs-ui-core', 'oojs-ui.styles.icons-editing-core'])).then(function() {
return new mw.Api().getMessages(['editundo', 'Undo-nochange']);
}).then(function(globalmessages) {
var mobileUndo, i18n_lang = mw.config.get('wgUserLanguage');
var i18n = {
"en": {
"mu-success": "Successful",
"mu-fail": "Failed",
"mu-loading": "Loading...",
"editsummary-ad": "",
"mu-undo-successful": "Revert successful.... Reloading in a sec",
"mu-empty-reponse-from-server": "An empty response was received from the server",
"mu-edit-summary-prompt": "Add a reason to your edit summary !",
"mu-edit-summary-prompt-placeholder": "Reason...",
"mu-thank-success": "Thanked",
"mu-thank-confirm": "Send public thanks ?",
"mu-thank-loading": "Thanking...",
"mu-thank-successful": "You thanked $1.",
"mu-thank-failed": "Failed to thank $1.",
"mu-http-error":"HTTP error: "
},
"bn": {
"mu-success": "সফল",
"mu-fail": "ব্যর্থ হয়েছে",
"mu-loading": "লোড করা হচ্ছে...",
"editsummary-ad": "",
"mu-undo-successful": "পূর্বাবস্থায় ফেরত যাওয়া সফল হয়েছে.... পুনঃলোড করা হচ্ছে",
"mu-empty-reponse-from-server": "সার্ভার থেকে একটি খালি প্রতিক্রিয়া পাওয়া গেছে।",
"mu-edit-summary-prompt": "সম্পাদনা সারাংশে কারণ উল্লেখ করুন!",
"mu-edit-summary-prompt-placeholder": "কারণ...",
"mu-thank-success": "ধন্যবাদ দিয়েছেন",
"mu-thank-confirm": "প্রকাশ্য ধন্যবাদ জানাবেন?",
"mu-thank-loading": "ধন্যবাদ জানানো হচ্ছে...",
"mu-thank-successful": "আপনি $1 কে ধন্যবাদ জানিয়েছেন।",
"mu-thank-failed": "$1 কে ধন্যবাদ জানানো ব্যর্থ হয়েছে।",
"mu-http-error":"HTTP ত্রুটি: "
}
};
if(undefined === i18n[i18n_lang]){
i18n_lang = 'en';
}
if (mw.config.get('wgCanonicalSpecialPageName') === 'MobileDiff') {
mw.util.addCSS('#mw-mf-userinfo .mobileUndo-ui .mw-ui-icon.mw-ui-icon-before:before{display:none;}\n#mobileUndo > a > span.oo-ui-iconElement-icon.oo-ui-icon-editUndo.oo-ui-image-invert{display:inline-block; position:initial;}\n#mobileUndo > a{padding:0.57142857em 0.9375em;}'+
'#mw-mf-userinfo > div > div.mobileUndo-ui > a > div{line-height:normal;}');
if (mw.config.get('wgVisualEditor').pageLanguageDir === 'ltr') {
$('#mw-mf-userinfo .post-content').append($('<div>').attr('class', 'mobileUndo-ui').css({
'display': 'inline-block',
'float': 'right'
}));
} else {
$('#mw-mf-userinfo .post-content').append($('<div>').attr('class', 'mobileUndo-ui').css({
'display': 'inline-block',
'float': 'left'
}));
}
$('.mobileUndo-ui').append($('.mw-mf-action-button').remove().css({
'clear': 'none'
}));
if (!$('.warningbox').length && mw.config.get('wgRelevantPageIsProbablyEditable')) {
mobileUndo = new OO.ui.ButtonWidget({
label: (globalmessages.editundo).charAt(0).toUpperCase() + (globalmessages.editundo).slice(1),
icon: 'editUndo',
title: 'mobileUndo',
flags: ['destructive', 'primary'],
id: 'mobileUndo'
});
$('.mobileUndo-ui').append(mobileUndo.$element);
if (mw.config.get('wgVisualEditor').pageLanguageDir === 'ltr') {
$('#mobileUndo').css('margin-right', '0.3em');
} else {
$('#mobileUndo').css('margin-left', '0.3em');
}
}
window.wgRelevantUser = function() {
var user;
if ($('.mw-mf-user-link').text() !== '') {
user = $('.mw-mf-user-link').text();
} else {
user = $('#mw-mf-userinfo .post-content div:nth-child(2)').text();
}
return user;
};
window.wgRevId = ($('#mw-mf-diffarea > div.mw-mf-diff-info > h3 > a').attr('href')).split('&oldid=')[1];
var revId = wgRevId;
console.log(revId);
var username = wgRelevantUser();
$('#mw-mf-userinfo .post-content .mobileUndo-ui .mw-mf-action-button').click(function(e) {
e.preventDefault();
OO.ui.confirm(i18n[i18n_lang]['mu-thank-confirm']).done(function(confirmed) {
if (confirmed) {
$('.mw-mf-action-button').css('pointer-events', 'none').text(i18n[i18n_lang]['mu-thank-loading']);
var api = new mw.Api();
api.postWithToken('csrf', {
action: "thank",
rev: revId,
}).done(function(result) {
mw.notify((i18n[i18n_lang]['mu-thank-successful']).replace(/\$1/g, username));
$('.mw-mf-action-button').text(i18n[i18n_lang]['mu-thank-success']);
}).fail(function() {
mw.notify((i18n[i18n_lang]['mu-thank-failed']).replace(/\$1/g, username));
$('.mw-mf-action-button').text(i18n[i18n_lang]['mu-failed']);
});
}
});
});
console.timeEnd('mobileUndo');
mobileUndo.on('click', function() {
OO.ui.prompt(i18n[i18n_lang]['mu-edit-summary-prompt'], {
textInput: {
placeholder: i18n[i18n_lang]['mu-edit-summary-prompt-placeholder']
}
}).done(function(customEditSummary) {
$.when(mw.loader.using('mediawiki.api')).then(function() {
return new mw.Api().getMessages(['undo-summary'], {
amlang: mw.config.get('wgServerName').split('.wik')[0]
});
}).then(function(message) {
var editSummaryMessage = message['undo-summary'];
var editSummary = editSummaryMessage.replace(/\$1/g, revId);
editSummary = editSummary.replace(/\$2/g, username);
if (customEditSummary !== null) {
mobileUndo.setDisabled(true);
editSummary = editSummary + ' ' + customEditSummary + (i18n[i18n_lang]['editsummary-ad']);
//call the API
var api = new mw.Api({
ajax: {
headers: {
'Api-User-Agent': 'mobileUndo/2.0.2(https://en.wikipedia.org/wiki/User:FR30799386/undo.js)'
}
}
});
//Feedback UI
mobileUndo.setLabel(i18n[i18n_lang]['mu-loading']);
api.postWithToken('csrf', {
action: "edit",
title: mw.config.get('wgRelevantPageName'),
summary: editSummary,
undo: revId,
}).done(function(result) {
if (result.edit.code === 'abusefilter-warning' || result.edit.code === 'abusefilter-disallowed') {
mobileUndo.setLabel(i18n[i18n_lang]['mu-fail']);
OO.ui.alert($('<p>').html(result.edit.warning), {
title: result.edit.info
}).done(function() {});
return;
} else if (typeof result.edit.nochange !== 'undefined') {
mobileUndo.setLabel(i18n[i18n_lang]['mu-fail']);
OO.ui.alert($('<p>').html(globalmessages['Undo-nochange'])).done(function() {});
return;
}
console.log(result);
mobileUndo.setLabel(i18n[i18n_lang]['mu-success']);
mw.notify(i18n[i18n_lang]['mu-undo-successful']);
setTimeout(function() {
location.href = mw.util.getUrl('Special:MobileDiff/' + result.edit.newrevid);
}, 1500);
}).fail(function(code, jqxhr) {
mobileUndo.setLabel(i18n[i18n_lang]['mu-fail']);
var details;
if (code === 'http' && jqxhr.textStatus === 'error') {
details = i18n[i18n_lang]['mu-http-error'] + jqxhr.xhr.status;
} else if (code === 'http') {
details = i18n[i18n_lang]['mu-http-error'] + jqxhr.textStatus;
} else if (code === 'ok-but-empty') {
details = i18n[i18n_lang]['mu-empty response-from-server'];
} else {
details = jqxhr.error.info;
}
OO.ui.alert($('<p>').html(details)).done(function() {});
});
}
});
});
});
}
});
//End of code
//</nowiki>
window.wgRelevantUser = function() {
var user;
if ($('.mw-mf-user-link').text() !== '') {
user = $('.mw-mf-user-link').text();
} else {
user = $('#mw-mf-userinfo .post-content div:nth-child(2)').text();
}
return user;
};
var href = ($('#mw-mf-diffarea > div.mw-mf-diff-info > h3 > a').attr('href')) || '';
window.wgRevId = href.split('&oldid=')[1];
if( $('#mw-mf-diffarea > ul > li.revision-history-next').length ) {
$('#mw-mf-diffarea > div.mw-mf-diff-info > h3').append(
$('<a>').attr('id','mobileRestore').attr('href','javascript:void(0)').append(
$('<b>').text('(পুনরুদ্ধার)')
)
);
}
$('#mobileRestore').click(function(e){
e.preventDefault();
$('#mobileRestore b').text('(লোড হচ্ছে....)');
$('#mobileRestore').css('pointer-events','none');
var customEditSummary = prompt('পুনরুদ্ধারের কারণ (ঐচ্ছিক)');
if(customEditSummary === null) {
$('#mobileRestore b').text('(পুনরুদ্ধার)');
$('#mobileRestore').css('pointer-events','auto');
return;
}
var username =wgRelevantUser();
var editSummary = '[[Special:Contributions/'+username+'|'+username+']] ([[User talk:'+username+'|আলাপ]])-এর করা ' +wgRevId+ 'নং সংস্করণ পুনরুদ্ধার করা হয়েছে';
editSummary = editSummary + customEditSummary + ' (পুনরুদ্ধারায়ন)';
$.when(mw.loader.load('mediawiki.api')).then(function(){
var api = new mw.Api();
api.get({
'action':'query',
'prop':'revisions',
'titles':mw.config.get('wgRelevantPageName'),
'rvprop':'ids'
}).done(function(result){
if(result.query.pages) {
var StartRevId = result.query.pages[mw.config.get('wgRelevantArticleId')].revisions[0].revid;
console.log(StartRevId);
api.postWithToken('csrf', {
action: "edit",
title: mw.config.get('wgRelevantPageName'),
summary: editSummary,
undo:StartRevId,
undoafter:wgRevId,
}).done(function(result) {
if (typeof result.edit.nochange !== 'undefined') {
$('#mobileRestore b').text('(Failed)');
alert( 'No change occured');
return;
}
console.log(result);
$('#mobileRestore b').text('(সফলভাবে হয়েছে)')
mw.notify('সংস্করণ পুনরুদ্ধার সফল হয়েছে.... পুনঃলোড করা হচ্ছে');
setTimeout(function() {
location.href = mw.util.getUrl('Special:MobileDiff/' + result.edit.newrevid);
}, 1500);
}).fail(function(code, jqxhr) {
$('#mobileRestore b').text('(পুনরুদ্ধার কার্য বাতিল করা হয়েছে)');
var details;
if (code === 'http' && jqxhr.textStatus === 'error') {
details = 'HTTP error: ' + jqxhr.xhr.status;
} else if (code === 'http') {
details = 'HTTP error: ' + jqxhr.textStatus;
} else if (code === 'ok-but-empty') {
details = 'An empty response was given the server';
} else {
details = jqxhr.error.info;
}
alert( details );
});
} else {
alert('Failed to retrieve page details');
}
});
});
});
if(mw.config.get('wgCanonicalSpecialPageName') === 'MobileDiff') {
mw.loader.using('mediawiki.util', function() {
var ele_a = document.createElement('a');
ele_a.setAttribute('href', mw.util.getUrl(mw.config.get('wgRelevantPageName'), {action: 'history'}));
ele_a.innerHTML = '(ইতিহাস)';
document.getElementsByTagName('h2')[0].appendChild(ele_a);
});
}
//my common.js
$.when(mw.loader.using(['mediawiki.util'], $.ready)).done( function() {
mw.util.addPortletLink("p-tb", mw.config.get('wgArticlePath').replace('$1', "ব্যবহারকারী:রবি/common.js"), "common.js", "tb-awbscript", "Personal common.js");
});
if (mw.config.get('wgCanonicalNamespace')+':'+mw.config.get('wgTitle') === 'ব্যবহারকারী:রবি/common.js' && mw.config.get('wgAction') == 'view');
//শীর্ষক
(function($, mw) {
var scrollDownButtonId = 'scrollDownButton',
scrollUpButtonId = 'scrollUpButton';
if (mw.config.get('wgServerName').match(/wikimirror\.org$/)) {
scrollDownButtonId += '-zhwiki';
scrollUpButtonId += '-zhwiki'
}
var scrollButtonIcon = '//upload.wikimedia.org/wikipedia/commons/7/7f/Font_Awesome_5_regular_arrow-circle-up_green.svg';
if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1'))
scrollButtonIcon = '//upload.wikimedia.org/wikipedia/commons/thumb/7/7f/Font_Awesome_5_regular_arrow-circle-up_green.svg/32px-Font_Awesome_5_regular_arrow-circle-up_green.svg.png';
$scrollDownButton = $('<img>', {
src: scrollButtonIcon,
id: scrollDownButtonId
}).css({
cursor: 'pointer',
opacity: 0.7,
position: 'fixed',
display: 'none',
right: '18px',
transform: 'rotate(180deg)',
'-webkit-transform': 'rotate(180deg)',
'-moz-transform': 'rotate(180deg)',
'-o-transform': 'rotate(180deg)',
'-ms-transform': 'rotate(180deg)'
}).on('click', function() {
$('html, body').animate({
scrollTop: $(document).height() - $(window).height()
}, 660)
}).on('mouseenter mouseleave', function(e) {
this.style.opacity = e.type === 'mouseenter' ? 1 : 0.7
}).appendTo('body');
$scrollUpButton = $('<img>', {
src: scrollButtonIcon,
id: scrollUpButtonId
}).css({
cursor: 'pointer',
opacity: 0.7,
position: 'fixed',
display: 'none',
right: '18px'
}).on('click', function() {
$('html, body').animate({
scrollTop: 0
}, 660)
}).on('mouseenter mouseleave', function(e) {
this.style.opacity = e.type === 'mouseenter' ? 1 : 0.7
}).appendTo('body');
var scrollButtonTimer;
$(window).on('scroll', function() {
var dingHeight = $('#bluedeck_ding>div').height() ? $('#bluedeck_ding>div').height() : 0;
$('#mw-ge-help-panel-cta-button').length > 0 ? $scrollDownButton.css('bottom', dingHeight + 75 + 'px') && $scrollUpButton.css('bottom', dingHeight + 116 + 'px') : $scrollDownButton.css('bottom', dingHeight + 24 + 'px') && $scrollUpButton.css('bottom', dingHeight + 65 + 'px');
$('#cat_a_lot').length > 0 || $('#proveit').length > 0 || $('.wordcount').length > 0 ? $scrollDownButton.css('left', '10px') && $scrollUpButton.css('left', '10px') : $scrollDownButton.css('left', 'unset') && $scrollUpButton.css('left', 'unset');
$(this).scrollTop() > 60 ? $scrollDownButton.fadeIn('slow') && $scrollUpButton.fadeIn('slow') : $scrollDownButton.fadeOut('slow') && $scrollUpButton.fadeOut('slow');
this.clearTimeout(scrollButtonTimer);
scrollButtonTimer = this.setTimeout(function() {
$scrollDownButton.fadeOut('slow');
$scrollUpButton.fadeOut('slow')
}, 2000)
});
$scrollDownButton.on('mouseenter', function() {
window.clearTimeout(scrollButtonTimer)
});
$scrollUpButton.on('mouseenter', function() {
window.clearTimeout(scrollButtonTimer)
})
})(jQuery, mw);
/**
* Add "Purge" content action link.
*
* Dependencies: mediawiki.util, mediawiki.api
*
* @source https://www.mediawiki.org/wiki/Snippets/Purge_action
* @revision 2016-05-22
*/
$( function () {
if ( $( '#ca-purge' ).length || !mw.config.get( 'wgIsArticle' ) ) return;
var node = mw.util.addPortletLink(
'p-cactions',
mw.util.getUrl( null, { action: 'purge' } ),
mw.config.get( 'skin' ) === 'vector' ? 'শোধন' : 'শোধন',
'ca-purge',
'এই পাতার সার্ভার ক্যাশে পরিস্কার করুন',
'শোধন'
);
$(node).on( 'click', function (e) {
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then(function () {
location.reload();
}, function () {
mw.notify( 'শোধন ব্যর্থ হয়েছে', { type: 'error' } );
});
e.preventDefault();
});
});
//rollback confirmation
//<nowiki>
(function() {
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
$(".mw-rollback-link").on('click', function(e) {
var linkText = $(e.target).text(),
count = linkText.match(/\d/) ? linkText.match(/\d+/)[0] : null,
message = 'Rollback ' + (count ? count + ' edits' : 'edit') + ' by ' + mw.util.getParamValue('from',e.target.href) + '?';
if(!confirm(message)) return e.preventDefault();
});
}
}());
//</nowiki>
/** Quick Edit **/
// Edit sections of a page without leaving the article
// [[en:w:User:BrandonXLF/QuickEdit]]
// By [[en:w:User:BrandonXLF]]
(function() {
var mobile = mw.config.get('skin') === 'minerva',
apiSingleton,
titleRegexp = new RegExp(
mw.config.get('wgArticlePath').replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\\\$1/, '([^?]+)') +
'|[?&]title=([^&#]*)'
);
function api(func, params) {
if (!apiSingleton) apiSingleton = new mw.Api();
$.extend(params, {
errorformat: 'html',
errorlang: mw.config.get('wgUserLanguage'),
errorsuselocal: true
});
return apiSingleton[func](params).fail(function(_, data) {
mw.notify(apiSingleton.getErrorMessage(data), {
type: 'error',
tag: 'quickedit'
});
});
}
function getPageInfo(title, sectionID) {
return api('get', {
action: 'query',
curtimestamp: 1,
prop: 'revisions',
indexpageids: 1,
titles: title,
rvprop: ['timestamp', 'content'],
rvslots: 'main',
rvsection: sectionID
}).then(function(res) {
var rev = res.query.pages[res.query.pageids[0]].revisions[0];
return {
start: res.curtimestamp,
base: rev.timestamp,
full: rev.slots.main['*']
};
});
}
function getPreviewCallback(editor) {
editor.children('.preview').remove();
new OO.ui.ProgressBarWidget().$element.css({
maxWidth: '100%',
borderRadius: '0',
boxShadow: 'none',
margin: '8px 0'
}).addClass('preview').appendTo(editor);
return function(html) {
editor.children('.preview').remove();
$('<div>').html(html).css({
margin: '8px 0',
border: '1px solid #a2a9b1',
padding: '8px',
overflowX: 'hidden'
}).addClass('preview').appendTo(editor);
};
}
function showCompare(editor, title, from, to) {
mw.loader.load('mediawiki.diff.styles');
api('post', {
action: 'compare',
fromslots: 'main',
'fromtext-main': from,
fromtitle: title,
frompst: 'true',
toslots: 'main',
'totext-main': to,
totitle: title,
topst: 'true'
}).then(function(r) {
return r.compare['*'] ? $('<table>').addClass('diff').append(
$('<colgroup>').append(
$('<col>').addClass('diff-marker'),
$('<col>').addClass('diff-content'),
$('<col>').addClass('diff-marker'),
$('<col>').addClass('diff-content')
)
).append(r.compare['*']) : 'কোন পার্থক্য নেই';
}).then(getPreviewCallback(editor));
}
// Parts taken from EditPage::extractSectionTitle and Parser::stripSectionName
function getSectionSummary(text) {
var match = text.match(/^(=+)(.+)\1\s*(\n|$)/);
return !match ? '' : '/* ' + match[2].trim()
// Strip internal link markup
.replace(/\[\[:?([^[|]+)\|([^[]+)\]\]/g, '$2')
.replace(/\[\[:?([^[]+)\|?\]\]/g, '$1')
// Strip external link markup
.replace(new RegExp('\\[(?:' + mw.config.get('wgUrlProtocols') + ')([^ ]+?) ([^\\[]+)\\]', 'ig'), '$2')
// Remove wikitext quotes
.replace(/(''|'''|''''')(?!')/g, '')
// Strip HTML tags
.replace(/<[^>]+?>/g, '') + ' */ ';
}
function showEditor(el) {
var progress = new OO.ui.ProgressBarWidget(),
heading = el.closest(':header'),
matcher = heading.nextUntil.bind(heading),
inserter = heading.after.bind(heading),
targetEl = el.siblings('.quickedit-target').last(),
titleMatch = targetEl.attr('href').match(titleRegexp),
title = decodeURIComponent(titleMatch[1] || titleMatch[2]),
sectionID = /[?&]v?e?section=T?-?(\d*)/.exec(targetEl.attr('href'))[1];
if (!heading.closest('.mw-parser-output').length) {
var articleContent = $('#mw-content-text .mw-parser-output');
matcher = function(selector) {
var child = articleContent.children(selector).first();
if (child.length) return child.prevAll();
return articleContent.children();
};
inserter = articleContent.prepend.bind(articleContent);
}
inserter(progress.$element.css({
maxWidth: '100%',
borderRadius: '0',
boxShadow: 'none'
}));
el.addClass('quickedit-loading');
$('.quickedit-hide').removeClass('quickedit-hide');
$('.quickedit-heading').removeClass('quickedit-heading');
$('#quickedit-editor').remove();
getPageInfo(title, sectionID).then(function(r) {
var start = r.start,
base = r.base,
full = r.full,
saving = false,
expanded = false,
remainderStart = full.match(/\n=+.+=+(?:\n|$)/),
part = remainderStart ? full.substring(0, remainderStart.index) : full,
remainder = remainderStart ? full.substring(remainderStart.index) : '',
level = 0,
editor;
full.replace(/^(=+).+?(=+)(?:\n|$)/, function(m, a, b) {
level = Math.min(a.length, b.length);
return m;
});
var levelMatch = 'h1';
for (var i = 2; i <= level; i++) levelMatch += ',h' + i + ':has(*)';
var partSection = matcher(':header:has(*)'),
fullSection = matcher(levelMatch),
textarea = new OO.ui.MultilineTextInputWidget({
rows: 1,
maxRows: 20,
autosize: true,
value: part
}),
summary = new OO.ui.TextInputWidget({
value: getSectionSummary(part)
}),
minor = new OO.ui.CheckboxInputWidget(),
save = new OO.ui.ButtonInputWidget({
label: 'পরিবর্তন প্রকাশ করুন',
title: 'Save your changes',
flags: ['primary', 'progressive']
}),
preview = new OO.ui.ButtonInputWidget({
label: 'প্রাকদর্শন',
title: 'Preview the new wikitext'
}),
compare = new OO.ui.ButtonInputWidget({
label: 'পরিবর্তনসমূহ',
title: 'View the difference between the current revision and your revision'
}),
cancel = new OO.ui.ButtonInputWidget({
useInputTag: true,
label: 'বাতিল',
title: 'Close the edit form and discard changes',
flags: ['secondary', 'destructive']
}),
more = new OO.ui.ButtonInputWidget({
label: '+',
title: 'Edit the entire section (including subsections)'
}),
buttons = new OO.ui.HorizontalLayout({
items: [save, preview, compare, cancel]
});
if (part != full) {
buttons.addItems([more], 3);
}
partSection.addClass('quickedit-hide');
heading.addClass('quickedit-heading');
el.removeClass('quickedit-loading');
progress.$element.remove();
textarea.$input.css({
borderRadius: '0'
});
summary.on('enter', function() {
save.emit('click');
});
save.on('click', function() {
if (saving) return;
var fullText = textarea.getValue() + (expanded ? '' : remainder);
saving = true;
save.setLabel('সংরক্ষণ করা হচ্ছে...');
compare.setDisabled(true);
preview.setDisabled(true);
cancel.setDisabled(true);
more.setDisabled(true);
api('postWithEditToken', {
action: 'edit',
title: title,
section: sectionID,
summary: summary.getValue(),
text: fullText,
minor: minor.isSelected() ? true : undefined,
notminor: minor.isSelected() ? undefined : true,
starttimestamp: start,
basetimestamp: base
}).then(function() {
api('get', {
action: 'parse',
page: mw.config.get('wgPageName'),
prop: ['text', 'categorieshtml']
}).then(function(r) {
var contentText = $('#mw-content-text'),
catLinks = $('#catlinks');
contentText.find('.mw-parser-output').replaceWith(r.parse.text['*']);
mw.hook('wikipage.content').fire(contentText);
catLinks.replaceWith(r.parse.categorieshtml['*']);
mw.hook('wikipage.categories').fire(catLinks);
saving = false;
});
}, function(code) {
if (code == 'editconflict') {
showEditConflict(editor, title, sectionID, fullText).then(function(r) {
start = r.start;
base = r.base;
textarea = r.textarea;
expanded = true;
});
}
compare.setDisabled(false);
preview.setDisabled(false);
cancel.setDisabled(false);
more.setDisabled(expanded);
saving = false;
save.setLabel('Save');
});
});
preview.on('click', function() {
api('post', {
action: 'parse',
title: title,
prop: 'text',
pst: 'true',
disablelimitreport: 'true',
disableeditsection: 'true',
sectionpreview: 'true',
disabletoc: 'true',
text: textarea.getValue()
}).then(function(r) {
return r.parse.text['*'] + '<div style="clear:both;"></div>';
}).then(getPreviewCallback(editor));
});
compare.on('click', function() {
showCompare(editor, title, part + (expanded ? remainder : ''), textarea.getValue());
});
cancel.on('click', function() {
editor.remove();
heading.removeClass('quickedit-heading');
fullSection.removeClass('quickedit-hide');
});
more.on('click', function() {
expanded = true;
textarea.setValue(textarea.getValue() + remainder);
fullSection.addClass('quickedit-hide');
more.setDisabled(true);
});
editor = $('<div id="quickedit-editor">').css({
overflowX: 'hidden'
}).append(
$('<div>').css({
backgroundColor: '#eaecf0',
borderBottom: '1px solid #a2a9b1',
marginBottom: '8px'
}).append(
textarea.$element.css({
width: '100%',
maxWidth: '100%',
fontFamily: 'monospace, monospace'
}).addClass('quickedit-textarea'),
$('<div>').css({
border: '1px solid #a2a9b1',
borderWidth: '0 1px'
}).append(
$('<div>').css({
padding: '8px 4px 8px 8px',
display: 'table-cell',
verticalAlign: 'middle'
}).html('সারাংশ:'),
summary.$element.css({
width: '100%',
maxWidth: '100%',
padding: '8px 0px',
display: 'table-cell',
verticalAlign: 'middle'
}),
new OO.ui.FieldLayout(minor, {
label: new OO.ui.HtmlSnippet('🤏?'),
align: 'inline'
}).$element.css({
padding: '8px 8px 8px 4px',
display: 'table-cell',
verticalAlign: 'middle'
})
),
buttons.$element.css({
border: '1px solid #a2a9b1',
borderWidth: '0 1px',
padding: '0px 8px 0'
}),
title !== mw.config.get('wgPageName') ? $('<div>').css({
border: '1px solid #a2a9b1',
borderWidth: '0 1px',
padding: '0px 8px 8px'
}).append(
'Editing page: ',
$('<a>').attr('href', mw.config.get('wgArticlePath').replace('$1', title)).css({
fontWeight: 'bold'
}).text(title.replace(/_/g, ' '))
) : undefined
)
);
inserter(editor);
}, function() {
el.removeClass('quickedit-loading');
progress.$element.remove();
});
}
function showEditConflict(editor, title, sectionID, text) {
return getPageInfo(title, sectionID).then(function(r) {
var textarea = new OO.ui.MultilineTextInputWidget({
rows: 1,
maxRows: 20,
autosize: true,
value: r.full
}),
textarea2 = new OO.ui.MultilineTextInputWidget({
rows: 1,
maxRows: 20,
autosize: true,
value: text,
});
function syncSize() {
textarea.styleHeight = -1;
textarea.adjustSize(true);
textarea2.styleHeight = -1;
textarea2.adjustSize(true);
var height = Math.max(textarea.$input.height(), textarea2.$input.height());
textarea.$input.height(height);
textarea2.$input.height(height);
}
textarea.$input.css({
borderRadius: '0'
});
editor.find('> :first-child > :first-child').remove();
$('<table>').css({
width: '100%',
border: '1px solid #a2a9b1',
borderBottom: 'none',
borderSpacing: '0',
margin: '0 !important'
}).append(
$('<tr>').append(
$('<th>').css({
width: '50%',
paddingTop: '4px'
}).text('Their version (to be saved)'),
$('<th>').css({
width: '50%',
paddingTop: '4px'
}).text('Your version')
),
$('<tr>').append(
$('<td>').css({
width: '50%',
padding: '4px 4px 0 8px'
}).append(
textarea.$element.css({
width: '100%',
maxWidth: '100%',
fontFamily: 'monospace, monospace'
})
),
$('<td>').css({
width: '50%',
padding: '4px 8px 0 4px'
}).append(
textarea2.$element.css({
width: '100%',
maxWidth: '100%',
fontFamily: 'monospace, monospace'
})
)
)
).prependTo(editor.find('> :first-child'));
textarea.on('change', syncSize);
textarea2.on('change', syncSize);
syncSize();
showCompare(editor, title, text, r.full);
r.textarea = textarea;
return r;
});
}
function clickHandler(e) {
var el = $(e.target);
if (!el.hasClass('quickedit-editlink') || el.hasClass('quickedit-loading')) return;
e.preventDefault();
showEditor(el);
}
function addLinksToChildren(element) {
element.find('#quickedit-editor, .quickedit-section').remove();
element.find('.mw-editsection').each(function() {
$('[href*="section="]', this).last().after(
mobile ? '' : '<span class="quickedit-section"> | </span>',
$('<a>').html(mobile ? ' 💨' : 'দ্রুত সম্পাদনা').addClass('quickedit-section quickedit-editlink')
).addClass('quickedit-target');
});
}
$.when(mw.loader.using('oojs-ui-core'), $.ready).done(function() {
var body = $(document.body);
body.on('click', clickHandler);
addLinksToChildren(body);
mw.hook('wikipage.content').add(addLinksToChildren);
});
mw.loader.addStyleTag(
'.skin-minerva .mw-editsection { white-space: nowrap; }' +
'.skin-minerva .content .collapsible-heading .quickedit-section { visibility: hidden; }' +
'.skin-minerva .content .collapsible-heading.open-block .quickedit-section { visibility: visible; }' +
'.quickedit-hide { display: none !important; }' +
'.quickedit-loading, .quickedit-heading { color: #777; }'
);
})();
//খেলাঘর
$( document ).ready( function() {
mw.util.addPortletLink(
'p-personal',
mw.util.getUrl( 'Special:MyPage/খেলাঘর' ), //No need for a variable.
'খেলাঘর',
'pt-sandbox2',
'খেলাঘর',
null,
'#pt-sandbox'
);
});
/***********************************************************************************
* CatMan: The category manager for MediaWiki wikis that is simple, lightweight, *
* and modern. Nya nya. *
* *
* This script is largely a work in progress and may sometimes not work properly. *
* Please see the English Wikipedia for known problems that are currently being *
* fixed. *
***********************************************************************************
* IMPORTANT (particularly for those who are viewing a copy of the script): *
* THIS FILE IS AVAILABLE ON GITHUB AT https://github.com/Awesome-Aasim/CatMan *
* ALL PULL REQUESTS AND CHANGES MUST BE MADE THERE, OTHERWISE THEY WILL BE LOST *
* IF THE FILE AT THE REPOSITORY IS CHANGED OR REBUILT. *
***********************************************************************************
* LICENSING INFORMATION: Licensed under the MIT license *
* MIT License *
* Copyright (c) 2021 Aasim Syed *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* The above copyright notice and this permission notice shall be included in all *
* copies or substantial portions of the Software. *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
***********************************************************************************/
//<nowiki>
if (!Catman && mw.config.get("wgNamespaceNumber") >= 0 && mw.config.get("wgIsProbablyEditable") && mw.config.get("wgArticleId") > 0 && mw.config.get("wgNamespaceNumber") != 10) {
var Catman = {};
mw.loader.using(["oojs-ui-core", "oojs-ui-windows", "oojs-ui-widgets", "oojs-ui.styles.icons-moderation", "oojs-ui.styles.icons-interactions", "oojs-ui.styles.icons-editing-core"], function () {
Catman.start = function () {
// Create a factory.
Catman.factory = new OO.Factory();
Catman.getEditableCategories = function (text, categoryname = "Category") {
categoryname = categoryname[0].toUpperCase() + categoryname.slice(start = 1);
var temp = text.split("[[");
var res = []
for (var i in temp) {
if (temp[i].startsWith(categoryname + ":")) {
var temp2 = temp[i].split("]]")[0].slice(start = categoryname.length + 1);
res.push(temp2[0].toUpperCase() + temp2.substring(1));
}
}
/*
var catlist = mw.config.get("wgCategories");
var rtn = [];
for (var i in res) {
for (var j in catlist) {
if (catlist[j] == res[i]) {
rtn.push(res[i]);
}
}
}
*/
return res;
}
function CatManDialog(config) {
CatManDialog.super.call(this, config);
}
OO.inheritClass(CatManDialog, OO.ui.ProcessDialog);
CatManDialog.static.name = 'catmandialog';
CatManDialog.static.title = 'Category Manager';
CatManDialog.static.actions = [
{
flags: ['primary', 'progressive'],
icon: 'check',
title: 'Save changes',
action: 'next',
disabled: false
},
{
flags: 'safe',
icon: 'close',
title: 'Cancel',
action: 'back',
disabled: false
}
]
CatManDialog.prototype.getActionProcess = function (action) {
var categoriestoadd, categoriestoremove, summary, presummary, wikitext;
switch (action) {
case 'next':
return new OO.ui.Process(function () {
try {
categoriestoadd = [];
$(".catman-addcategory").each(function () {
categoriestoadd.push($(this).find(".catman-categoryname").text());
});
categoriestoremove = [];
$(".catman-remove").each(function () {
categoriestoremove.push($(this).find(".catman-categoryname").text());
});
summary = Catman.esinput.getValue();
presummary = "Run [[w:en:User:Awesome Aasim/CatMan|CatMan]]" + (summary ? " (reason: " + summary + ")" : "") + ": ";
if (categoriestoadd.length == 0 && categoriestoremove.length == 0) {
throw new OO.ui.Error("No categories to add or remove.", { warning: true, recoverable: true });
}
return $.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
page: mw.config.get("wgPageName"),
prop: "wikitext"
}).then(function (result, status) {
if (status != 'success') {
throw new OO.ui.Error("Connection failed. Please check your Internet and try again.", {recoverable: true});
}
wikitext = result.parse.wikitext["*"];
debugger;
for (var i in categoriestoremove) {
for (var j in Catman.catprefixes) {
if (wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0 || wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0) {
presummary += "-cat [[Category:" + categoriestoremove[i].split("|")[0] + "|" + categoriestoremove[i].split("|")[0] + "]]"
}
if (i != categoriestoremove.length - 1) {
presummary += ", "
}
while (wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0) {
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]\n", "");
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toUpperCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]", "");
}
while (wikitext.search("\\[\\[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "\\]\\]") >= 0) {
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]\n", "");
wikitext = wikitext.replace("[[" + Catman.catprefixes[j][0].toLowerCase() + Catman.catprefixes[j].slice(start = 1) + ":" + categoriestoremove[i] + "]]", "");
}
}
}
if (categoriestoadd.length > 0 && categoriestoremove.length > 0) {
presummary += "; "
}
for (var i in categoriestoadd) {
if (wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0 && wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0) {
presummary += "+cat [[Category:" + categoriestoadd[i].split("|")[0] + "|" + categoriestoadd[i].split("|")[0] + "]]";
}
if (i != categoriestoadd.length - 1) {
presummary += ", ";
}
while (wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0 && wikitext.search("\\[\\[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "\\]\\]") < 0) {
wikitext += "\n[[" + mw.config.get("wgFormattedNamespaces")[14] + ":" + categoriestoadd[i] + "]]";
break;
}
}
return $.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "query",
format: "json",
meta: "tokens",
type: "csrf"
}).then(function (result, status) {
if (status != 'success') {
throw new OO.ui.Error("Connection failed. Please check your Internet and try again.", {recoverable: true});
}
if (result.error) {
throw new OO.ui.Error(result.error.info, { recoverable: true });
} else {
return $.post(mw.config.get("wgScriptPath") + "/api.php", {
action: "edit",
format: "json",
title: mw.config.get("wgPageName"),
token: result.query.tokens.csrftoken,
text: wikitext,
summary: presummary
}).then(function (result, status) {
if (status != 'success') {
throw new OO.ui.Error("Connection failed. Please check your Internet and try again.", {recoverable: true});
}
if (result.error) {
throw new OO.ui.Error(result.error.info, { recoverable: true });
} else {
Catman.windowManager.closeWindow('catmandialog');
Catman.windowManager.$element.remove();
mw.notify("Categories successfully edited. Reloading...");
location.reload();
}
});
}
});
});
} catch (error) {
return error;
}
}, this);
case 'back': return new OO.ui.Process(function () {
Catman.windowManager.closeWindow('catmandialog');
Catman.windowManager.$element.remove();
}, this);
}
// Fallback to parent handler
return CatManDialog.super.prototype.getActionProcess.call(this, action);
};
function CategoriesLayout(name, config) {
CategoriesLayout.super.call(this, name, config);
this.$element.append('<span id="catman-categories"></span>');
}
OO.inheritClass(CategoriesLayout, OO.ui.TabPanelLayout);
CategoriesLayout.prototype.setupTabItem = function () {
this.tabItem.setLabel('Categories');
}
function SummaryLayout(name, config) {
SummaryLayout.super.call(this, name, config);
this.$element.append('<span id="catman-summary"></span>');
}
OO.inheritClass(SummaryLayout, OO.ui.TabPanelLayout);
SummaryLayout.prototype.setupTabItem = function () {
this.tabItem.setLabel('Edit summary');
}
CategoriesLayout.prototype.getBodyHeight = function () {
return "full";
}
SummaryLayout.prototype.getBodyHeight = function () {
return "full";
}
CatManDialog.prototype.getBodyHeight = function () {
return "full";
}
CatManDialog.prototype.initialize = function () {
CatManDialog.super.prototype.initialize.call(this);
this.content = new OO.ui.PanelLayout({ padded: false, expanded: false, $overlay: this.$overlay });
var catinput = new OO.ui.ComboBoxInputWidget({ expanded: false, padded: true, placeholder: "Enter category name", options: [], $overlay: this.$overlay });
var catinputsubmit = new OO.ui.ButtonWidget({ flags: ["primary", "progressive"], icon: "add", title: 'Add category', $overlay: this.$overlay })
var esinput = new OO.ui.TextInputWidget({ placeholder: "Edit summary", $overlay: this.$overlay });
var catpage = new CategoriesLayout('categories', { expanded: false, $overlay: this.$overlay });
var sumpage = new SummaryLayout('summary', { expanded: false, $overlay: this.$overlay });
var index = new OO.ui.IndexLayout({ expanded: true, $overlay: this.$overlay });
index.addTabPanels([catpage, sumpage]);
this.content.$element.append('<span id="catman-loading"><p></p></span><span id="catman"></span>');
this.$body.append(this.content.$element);
var progressBar = new OO.ui.ProgressBarWidget( {
progress: false,
padded: true,
$overlay: this.$overlay
});
$("#catman-loading").find("p").html(progressBar.$element);
$("#catman").hide();
$("#catman").html(index.$element);
var catinputset = new OO.ui.FieldsetLayout({$overlay: this.$overlay});
catinputset.addItems([
new OO.ui.ActionFieldLayout(catinput, catinputsubmit, {$overlay: this.$overlay})
]);
$("#catman-categories").append(catinputset.$element);
$("#catman-summary").append(esinput.$element);
var categorylist = mw.config.get("wgCategories");
Catman.catinput = catinput;
Catman.catinputsubmit = catinputsubmit;
Catman.esinput = esinput;
Catman.catpage = catpage;
Catman.sumpage = sumpage;
Catman.index = index;
Catman.catinputset = catinputset;
Catman.$overlay = this.$overlay;
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
page: mw.config.get("wgPageName"),
prop: "wikitext"
}).then(function (result, status) {
if (status != "success") {
Catman.windowManager.closeWindow('catmandialog');
Catman.windowManager.$element.remove();
OO.ui.alert('Failed to load CatMan.');
}
//find all category links on the page
var text = result.parse.wikitext["*"];
var catprefixes = [];
for (var i in mw.config.get("wgNamespaceIds")) {
if (mw.config.get("wgNamespaceIds")[i] == 14) {
catprefixes.push(i);
}
}
Catman.catprefixes = catprefixes;
var editablelist = [];
for (var i of catprefixes) {
editablelist = Catman.getEditableCategories(text, i);
}
Catman.list = editablelist;
var uneditablelist = [];
for (var i in categorylist) {
var editablecategory = false;
for (var j in editablelist) {
if (categorylist[i] == editablelist[j].split("|")[0]) {
editablecategory = true;
break;
}
}
if (!editablecategory) {
uneditablelist.push(categorylist[i]);
}
}
$("#catman-categories").append("<style>\n.catman-remove {\ntext-decoration:line-through;\n}</style>")
$("#catman-categories").append("<table style=\"width:100%\"><caption><b>Categories you can edit</b></caption><tbody id=\"catman-table\"></tbody></table>");
for (var i of editablelist) {
var $el = $("<tr class=\"catman-category catman-currentcategory\"><td class=\"catman-categoryname\"><a href=\"" + mw.config.get("wgArticlePath").replace("$1", "Category:" + i.split("|")[0]) + "\">" + i.split("|")[0] + "</a>" + (i.split("|").length > 1 ? "<span title=\"This is a category sort key, used to sort category entries when viewing the page in the category.\" style=\"text-decoration-line:underline;text-decoration-style:dotted;\">|" + i.split("|")[1] + "</span>" : "") + "</td><td class=\"catman-categoryremove\"></td></tr>")
$("#catman-table").append($el);
var removeCat = new OO.ui.ButtonWidget({
icon: 'trash',
title: 'Remove category',
flags: 'destructive',
$overlay: Catman.$overlay,
classes: ['catman-categoryremovebutton']
});
$el.find(".catman-categoryremove").append(removeCat.$element);
removeCat.$element.click(function (e) {
e.preventDefault();
$(this).parent().parent().addClass("catman-remove");
$(this).parent().parent().find(".catman-undobutton").show();
$(this).hide();
});
var undoCat = new OO.ui.ButtonWidget({
icon: 'undo',
title: 'Undo remove',
$overlay: Catman.$overlay,
classes: ['catman-undobutton']
});
$el.find(".catman-categoryremove").append(undoCat.$element);
undoCat.$element.click(function (e) {
e.preventDefault();
$(this).parent().parent().removeClass("catman-remove");
$(this).parent().parent().find(".catman-categoryremovebutton").show();
$(this).hide();
});
undoCat.$element.hide();
}
if (uneditablelist.length > 0) {
$("#catman-categories").append("<table style=\"width:100%\"><caption><b>Categories you cannot edit</b> (<span title=\"These categories cannot be edited with CatMan because they are automatically added with templates or magic words. To remove these categories, remove the templates or magic words that populate these categories.\" style=\"text-decoration-line:underline;text-decoration-style:dotted;\">?</span>)</caption><tbody id=\"catman-uneditable\"></tbody></table>");
for (var i of uneditablelist) {
var $el = $("<tr><td class=\"catman-categoryname\"><a href=\"" + mw.config.get("wgArticlePath").replace("$1", "Category:" + i.split("|")[0]) + "\">" + i + "</a></td></tr>")
$("#catman-uneditable").append($el);
}
}
Catman.addCat = function (e) {
e.preventDefault();
if (catinput.getValue().length > 0) {
var $el = $("<tr class=\"catman-category catman-addcategory\"><td class=\"catman-categoryname\"><a href=\"" + mw.config.get("wgArticlePath").replace("$1", "Category:" + catinput.getValue().split("|")[0]) + "\">" + catinput.getValue().split("|")[0] + "</a>" + (catinput.getValue().split("|").length > 1 ? "<span title=\"This is a category sort key, used to sort category entries when viewing the page in the category.\" style=\"text-decoration-line:underline;text-decoration-style:dotted;\">|" + catinput.getValue().split("|")[1] + "</span>" : "") + "</td><td class=\"catman-categoryremove\"></td></tr>")
$("#catman-table").append($el);
var removeCat = new OO.ui.ButtonWidget({
icon: 'trash',
title: 'Remove category',
flags: 'destructive',
$overlay: Catman.$overlay
});
$el.find(".catman-categoryremove").append(removeCat.$element);
removeCat.$element.click(function (e) {
e.preventDefault();
$(this).parent().parent().remove();
});
catinput.setValue("");
}
$(".catman-categoryname").each(function() {
var that = this;
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
page: "Category:" + $(this).text().split("|")[0]
}).done(function(result) {
if (result.error) {
if (result.error.code == "missingtitle") {
$(that).find("a").addClass("new");
}
}
});
});
}
catinput.$element.keypress(function(e) {
if (e.which == 13) {
Catman.addCat(e);
} else {
var key = e.which || e.keyCode;
if (key == 91 || key == 93 || (catinput.getValue() == "" && key == 32) || (catinput.getValue().search("\\|") >= 0 && key == 124) || (catinput.getValue() == "" && key == 124) || key == 35 || key == 123 || key == 125 || key == 60 || key == 62) { // stop the input of forbidden wikitext characters (except for pipe which is used for category sorting)
e.preventDefault();
}
}
});
window.setInterval(function(e) {
//populate the combobox
var searchterm = catinput.getValue();
var splitsearch = searchterm.split("|");
$.get(mw.config.get("wgScriptPath") + "/api.php", {
"action": "query",
"format": "json",
"list": "search",
"utf8": 1,
"srsearch": splitsearch[0],
"srnamespace": "14"
}).then(function(result, status) {
if (status == "success") {
if (result.error) {
catinput.setOptions([]);
} else {
var options = [], searchresults = result.query.search;
var restofsearchterm = "";
for (var i in splitsearch) {
if (i != 0) {
restofsearchterm += splitsearch[i];
}
if (i != splitsearch.length - 1) {
restofsearchterm += "|";
}
}
for (var i in searchresults) {
options.push({data: searchresults[i].title.split(":")[1] + restofsearchterm, label: searchresults[i].title.split(":")[1]});
}
if (options.length == 0) {
options.push({data: searchterm, label: "No results found."})
}
catinput.setOptions(options);
}
}
})
}, 1000);
catinputsubmit.$element.click(Catman.addCat);
$(".catman-categoryname").each(function() {
var that = this;
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
page: "Category:" + $(this).text()
}).done(function(result) {
if (result.error) {
if (result.error.code == "missingtitle") {
$(that).find("a").addClass("new");
}
}
});
});
$("#catman").show();
$("#catman-loading").hide();
});
};
// Register the window constructor with the factory.
Catman.factory.register(CatManDialog);
// Create a window manager. Specify the name of the factory with the ‘factory’ config.
Catman.windowManager = new OO.ui.WindowManager({
factory: Catman.factory
});
$(document.body).append(Catman.windowManager.$element);
Catman.windowManager.openWindow('catmandialog', { size: "full" });
};
if (mw.config.get("skin") == "minerva") {
mw.util.addPortletLink('p-tb', 'javascript:Catman.start()', 'Start CatMan', 'pt-catman');
} else {
mw.util.addPortletLink('p-cactions', 'javascript:Catman.start()', 'Start CatMan', 'pt-catman');
}
});
}
//</nowiki>